Age | Commit message (Collapse) | Author |
|
This allows us to use a borrowed `yaml_rust::Yaml` for `ToSql` and an
owned `yaml_rust::Yaml` for `FromSql`.
|
|
|
|
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.
|
|
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.
|
|
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.
|
|
|
|
|
|
No longer necessary.
|
|
Either with a "-" argument or no file argument.
|
|
|
|
|
|
Change subcommand matcher to destructure the struct fields as I couldn't
access the fields with dot notation before.
|
|
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.
|
|
|
|
|
|
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.
|
|
|
|
|
|
If any value extraction comes back as `None`, convert it to a SQL
`Null`.
|
|
Return a `Result` and wrap errors in a `thiserror` struct.
|
|
That is now moved to `yaqlite::insert()`.
|
|
Found some documentation that reminded me how unit structs are written.
Change this definition as that makes more sense.
|
|
|
|
|
|
Test that a plain YAML hash gets inserted even when not wrapped in an
array.
|
|
Check that nonexistent columns are ignored from the input YAML.
|
|
|
|
Extract the test code to a new function so that it can be reused to test
other YAML inputs and database records.
|
|
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.
|
|
Make an interface that more cleanly says "insert this YAML into this
database".
|
|
|
|
Want to use `yaqlite::yaml` for the YAML extraction function.
|
|
Remove the hard-coded table name.
|
|
|
|
|
|
|
|
Turns out I didn't need the type of the column, so get rid of that value
and resume using `Zero`.
|
|
Separate this code from the main binary file.
|
|
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.
|
|
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.
|
|
Doesn't work yet as I need a way to convert `Yaml` values to Rusqlite
SQL params.
|
|
Need to figure out what to do for NUMERIC affinity since Rusqlite
doesn't expose a variant for that pseudo-type.
|
|
|
|
|
|
Creates a map from column name to type.
|
|
|
|
Want to translate YAML types to SQLite types.
|
|
Need to figure out how to insert `table_columns.len()` values.
|
|
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.
|
|
Make it easier to find out if a column name exists in the table.
|