Age | Commit message (Collapse) | Author |
|
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.
|
|
|
|
|
|
|
|
No longer need this.
|
|
If no records were found, continue to return `Yaml::Null`. If a single
record was found, return a `Yaml::Hash`. Otherwise, return a
`Yaml::Array` containing all the records.
|
|
|
|
We switched this to a `yaml_rust::yaml::Hash`.
|
|
This is implemented now.
|
|
|
|
Add a new function that allows using a specified column name for
selection. The `select()` function will default to using the table's
primary key column.
Still need to update the references to the "id" column in the function.
|
|
|
|
|
|
The primary key shouldn't be editable, so don't include it in the
resulting YAML.
|
|
I had used `to_string()` before because the in-progress code wouldn't
let me use `to_owned()`. Now that I've changed things around, this is
possible.
|
|
Change `column_names` from `Vec<yaml_rust::Yaml::String>` to
`Vec<String>`. This way we don't have to clone the `yaml_rust::Yaml`
value to insert into the `yaml_rust::yaml::Hash`.
Had some issues getting this to work. I tried calling
`stmt.column_names()` on its own, but this caused a borrow checker
error, as that creates an immutable borrow, while the `stmt.query_map()`
call is a mutable borrow, and we can't do both.
Found this ticket that describes exactly the problem I was having:
https://github.com/rusqlite/rusqlite/pull/523
Turns out I had the right idea to begin with: I needed to collect the
column names into a `Vec`. But don't use a `Vec` of `yaml_rust::Yaml`
values, because that requires excess cloning.
|
|
Instead of my earlier `std::collections::HashMap`, build the type we
want to return directly in the row closure.
Required copying some data like the column names, but I don't see a way
around that. I suppose we could make `yaml_rust::Yaml`s from the column
headers in the row closure too instead of copying an existing column
header that we otherwise never use.
This nearly passes the test I have for this function, but it includes
the `id` column in the `Yaml` hash. The primary key column will need to
be removed.
|
|
|
|
Not quite what the `yaml_rust::Yaml` output should be, but getting
closer.
|
|
|
|
|
|
It turns out that adding the primary key column name to the query via a
prepared parameter was causing it to be set as a literal instead of a
column name. The resulting SQL was:
SELECT
*
FROM test
WHERE 'id' = '1';
instead of:
SELECT
*
FROM test
WHERE "id" = '1';
When the `id` column is hard-coded, this works correctly, producing the
right SQL and extracting the correct record.
We'll need to update this to add the column name via the format string
like we've done with the table name so we can make it dynamic.
|
|
Add the `modern_sqlite` feature in order to use the `expanded_sql()`
method. This shows us the SQL query with parameters expanded.
|
|
Had one iteration too many over each column.
|
|
|
|
Can't get the info from inside the closure it seems. The row iterator
doesn't seem to be looping. Not sure what the story is yet. Maybe I'm
not converting the data types correctly.
|
|
It doesn't need to be completely public.
|
|
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.
|
|
|