aboutsummaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2022-03-17Yaml: Wrap a `Cow<'_, yaml_rust::Yaml>` instead of `yaml_rust::Yaml`Teddy Wing
This allows us to use a borrowed `yaml_rust::Yaml` for `ToSql` and an owned `yaml_rust::Yaml` for `FromSql`.
2022-03-17select(): Make `data` column Vec mutableTeddy Wing
2022-03-16select(): Trying to convert a SQLite row to `yaml_rust::Yaml`Teddy Wing
Still a work in progress. Trying to figure out what makes the most sense for converting between the different types in SQLite and YAML. This code still has some compilation errors.
2022-03-15select(): Add a test that invokes the function and prints the resultTeddy Wing
It turns out the previous code failed with error: thread 'select::tests::select_extracts_a_database_record_as_yaml' panicked at 'called `Result::unwrap()` on an `Err` value: SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("near \":table\": syntax error"))', src/select.rs:11:9 Seems that I can't use named parameters to pass the table name to `FROM`. Use string formatting for that instead. Converted the named parameter array to a `rusqlite::named_params!` macro when I read about it, as that seems a bit more concise.
2022-03-14Add `table_primary_key_column()`Teddy Wing
Add a function to get the column name of the table's primary key. This allows us to use a primary key value given by the user while saving users the trouble of having to input the primary key column name. We likely still want to offer the option of passing in a primary key column name in case this function can't determine the table's primary key, or if the table has a `UNIQUE` column we can query but no primary key.
2022-03-14Idea for selecting a record from the database as YAMLTeddy 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-13yaqlite::Error: Include `rusqlite` error descriptionTeddy 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-13extract(): Remove handled TODOTeddy Wing
2022-03-13extract(): Remove `unwrap()`sTeddy Wing
2022-03-13Yaml::to_sql(): Remove `unwrap()`sTeddy Wing
If any value extraction comes back as `None`, convert it to a SQL `Null`.
2022-03-13get_column_names(): Remove `unwrap()`sTeddy Wing
Return a `Result` and wrap errors in a `thiserror` struct.
2022-03-13main(): Remove `get_column_names()` callTeddy Wing
That is now moved to `yaqlite::insert()`.
2022-03-13sqlite::Zero: Change to unit struct syntaxTeddy Wing
Found some documentation that reminded me how unit structs are written. Change this definition as that makes more sense.
2022-03-13extract(): Idea for splitting up this functionTeddy Wing
2022-03-13insert(): Test that an array of YAML records get insertedTeddy Wing
2022-03-13insert(): Add test for non-array YAML hashTeddy Wing
Test that a plain YAML hash gets inserted even when not wrapped in an array.
2022-03-13insert(): Add a test for nonexistent column handlingTeddy Wing
Check that nonexistent columns are ignored from the input YAML.
2022-03-13insert(): Two new test ideasTeddy Wing
2022-03-13inserts_yaml_in_database(): Generalise test codeTeddy Wing
Extract the test code to a new function so that it can be reused to test other YAML inputs and database records.
2022-03-13yaqlite::insert(): Add testTeddy Wing
Check that the function inserts a record into the database based on a YAML input. Adjust the `extract()` function to take the table name as an argument.
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-12Move `yaqlite::yaml` to `yaqlite::yaml::sql`Teddy Wing
Want to use `yaqlite::yaml` for the YAML extraction function.
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-09Idea for getting SQLite type affinity from a type stringTeddy Wing
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.