aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
AgeCommit message (Collapse)Author
2022-03-27Add license (GNU GPLv3+)v0.0.1Teddy Wing
2022-03-20main: Print errors to standard error instead of panicking with `unwrap`Teddy Wing
Use `anyhow` to add context to errors and a `main()` wrapper that prints error messages and their context to standard error.
2022-03-20main: Add an option to include the primary key in outputTeddy Wing
Since the primary key column is excluded by default, there's no way to include it without excluding columns. Provide a way to include the primary key column when no columns have been excluded. Not a very good interface admittedly, but it enables a previously impossible behaviour.
2022-03-20select: Exclude primary key column unless given excluded columnsTeddy Wing
If no excluded columns are given, exclude the primary key column by default. Otherwise, exclude only those columns in the `exclude_columns` list.
2022-03-20select(): Allow columns to be excluded from YAML output hashTeddy Wing
Instead of only excluding the primary key column, exclude any columns in the given list. This allows us to pass a list of excluded columns on the command line.
2022-03-19main: Emit multiline YAML outputTeddy Wing
Only works with `|` YAML instead of `>` flowed output. Use a forked `yaml-rust` crate published by https://github.com/davvid/yaml-rust that includes a patch to support multiline output.
2022-03-19main: Write a newline after YAML outputTeddy Wing
It turns out the `YamlEmitter` doesn't output a newline at the end. Output a final newline as this is a command line program.
2022-03-19main: Write YAML to standard outputTeddy Wing
Create an adapter from `std::fmt::Write` to `std::io::Write` based on the following idea in the standard library: https://github.com/rust-lang/rust/blob/master/library/std/src/io/mod.rs#L1634-L1652 Since `yaml_rust::YamlEmitter::new()` requires a `std::fmt::Write`, adapt standard output so the emitter can write to it.
2022-03-19main: Try to emit serialized YAML to standard outputTeddy Wing
Doesn't work this way as `YamlEmitter` requires `std::fmt::Write` instead of `std::io::Write` (implemented by `Stdout`). Looks like I'll need some kind of intermediary buffer or adapter to convert between the different `Write` traits.
2022-03-19main: If `primary_key` option is given, select by given column nameTeddy Wing
2022-03-19main: Use `Result` from `yaqlite::select()`Teddy Wing
2022-03-13main(): Idea for custom column selectionTeddy Wing
2022-03-13main(): Remove debug outputTeddy Wing
No longer necessary.
2022-03-13main(): Accept input YAML from standard inputTeddy Wing
Either with a "-" argument or no file argument.
2022-03-13main(): Remove unnecessary column names commentTeddy Wing
2022-03-13main(): Remove "Hello, world" printTeddy Wing
2022-03-13main(): Move code to `insert` subcommandTeddy Wing
Change subcommand matcher to destructure the struct fields as I couldn't access the fields with dot notation before.
2022-03-13main(): Add subcommands and argumentsTeddy Wing
Trying to match the subcommand enum, but apparently can't get a variant (`Command::Insert`) out of the `@` binding, it seems it ends up being a `Command` type.
2022-03-13main(): Start adding command line argument parsingTeddy Wing
2022-03-13insert(): Remove `unwrap()`sTeddy Wing
Use a new `yaqlite::Error` type. Remove the other error types and use this main error type everywhere. For now, that seems simpler. The real reason why I centralised on one error type is that I wanted a single `Error::Sqlite` variant for both `rusqlite::Error` and `SqliteError` errors. However, I wasn't sure if it's possible to do that with `thiserror`, and I didn't want to bother having to write my own `std::error::Error` impls.
2022-03-13main(): Remove `get_column_names()` callTeddy Wing
That is now moved to `yaqlite::insert()`.
2022-03-12Add an `insert()` function for inserting YAML in databaseTeddy Wing
Make an interface that more cleanly says "insert this YAML into this database".
2022-03-12Move `yaml_extract()` to `yaqlite::yaml::extract()`Teddy Wing
2022-03-12get_column_names(): Get table name from argumentTeddy Wing
Remove the hard-coded table name.
2022-03-12yaml_extract(): Remove old commentsTeddy Wing
2022-03-12Move `get_column_names()` to `sqlite` moduleTeddy Wing
2022-03-12get_column_names(): Remove irrelevant commentsTeddy Wing
2022-03-12get_column_names(): Restore `Zero` valueTeddy Wing
Turns out I didn't need the type of the column, so get rid of that value and resume using `Zero`.
2022-03-12Move `Yaml` newtype to a new module in library crateTeddy Wing
Separate this code from the main binary file.
2022-03-12yaml_extract(): Don't try to insert data for nonexistent columnsTeddy Wing
If a hash key in the input YAML does not match one of the column names in the table we're inserting into, ignore that YAML field and use the other columns for insertion.
2022-03-12Convert `yaml::Yaml` values to `rusqlite::ToSql`Teddy Wing
This enables us to build a list of params for insertion and insert them into the database. Not sure if `NULL` makes sense for all of these types, but this at least gives us the type conversion necessary to get the YAML values into the SQL query, cool.
2022-03-12yaml_extract: Trying to build up a SQL insert statementTeddy Wing
Doesn't work yet as I need a way to convert `Yaml` values to Rusqlite SQL params.
2022-03-10Start encoding SQLite affinity rulesTeddy Wing
Need to figure out what to do for NUMERIC affinity since Rusqlite doesn't expose a variant for that pseudo-type.
2022-03-09get_column_names(): Add a note to map to the enum type instead of StringTeddy Wing
2022-03-09get_column_names(): Also get column typeTeddy Wing
Creates a map from column name to type.
2022-03-09yaml_extract(): Fix code from transaction argument ideaTeddy Wing
2022-03-09Add TODO for column typeTeddy Wing
Want to translate YAML types to SQLite types.
2022-03-09Idea for inserting values from YAML into SQLite tableTeddy Wing
Need to figure out how to insert `table_columns.len()` values.
2022-03-09Check if YAML hash key matches column nameTeddy Wing
Possibly ugly passing `table_columns` into `yaml_extract`, but just trying to get things working for now. Query a "people" DB table instead as that matches the test YAML file.
2022-03-09get_column_names(): Put column names in a `HashMap`Teddy Wing
Make it easier to find out if a column name exists in the table.
2022-03-08get_column_names(): Remove transaction codeTeddy Wing
We probably don't even need a transaction for a `SELECT`. Get rid of that code and remove the `mut` on `dbconn` which was only necessary for the transaction.
2022-03-08Get column names from SQLite tableTeddy Wing
Eliminated the transaction because of a borrow problem.
2022-03-08Try extracting YAML dataTeddy Wing
2022-03-07Try reading and parsing a YAML fileTeddy Wing
2022-03-07New Rust 1.59.0 projectTeddy Wing
$ rustc --version rustc 1.59.0 (9d1b2106e 2022-02-23) $ cargo init --bin