Age | Commit message (Collapse) | Author |
|
|
|
|
|
|
|
|
|
It's unnecessary.
|
|
Separate the paragraphs with an empty line.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The name `extract()` didn't make sense to me any more since the function
is doing more than its originally intended behaviour which was to
extract the YAML into a hash-like format for easy insertion into the
database.
I decided to give up on that behaviour since this works for what we want
it to do. Maybe this function is doing more than it should, but I'm okay
with that for the current functional requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This was obviated by using `Cow::Borrowed` and `Cow::Owned` directly
when creating a `Yaml`.
|
|
|
|
This saves us from having to declare and use a vestigial unit struct
value for the hash.
In retrospect, I could have used the unit type instead of creating a
unit struct, but this is even cleaner. Only a couple hours ago learned
that `HashSet` exists.
|
|
Split this code out into its own module like we've done with `select()`.
Feels better organised this way.
|
|
Turns out I didn't need this. The `ToSql` and `FromSql` type conversion
traits were what I needed instead to convert between YAML and SQLite
types.
|
|
We added a new argument to the `select()` functions in
f30a4dafa5736c58bda54569ec9f46e6fdb2e200 to allow columns to be excluded
from the YAML output. Update the test to include the new argument in its
call.
I was getting this error about the `C` type parameter on the function:
error[E0282]: type annotations needed
--> src/select.rs:152:23
|
152 | let got = select(&conn, "test", "1", None).unwrap();
| ^^^^^^ cannot infer type for type parameter `C` declared on the function `select`
For more information about this error, try `rustc --explain E0282`.
The error makes sense in a way, but it also doesn't at all, because I'm
not passing a `Some` value into the function. If it's a `None`, then
what need is there to specify a type that's never used?
I wonder if there's a way to get this to work in a way that doesn't
require me to specify the type parameter when passing `None` for
`exclude_columns`.
|
|
I just learned about `HashSet`, and it looks like a cleaner way to do
exactly what I was trying to do with `HashMap`.
|
|
|
|
Use `anyhow` to add context to errors and a `main()` wrapper that prints
error messages and their context to standard error.
|
|
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.
|
|
If no excluded columns are given, exclude the primary key column by
default. Otherwise, exclude only those columns in the `exclude_columns`
list.
|
|
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.
|
|
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.
|
|
It turns out the `YamlEmitter` doesn't output a newline at the end.
Output a final newline as this is a command line program.
|
|
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.
|
|
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.
|