aboutsummaryrefslogtreecommitdiffstats
path: root/src/select.rs
AgeCommit message (Collapse)Author
2022-03-27Add license (GNU GPLv3+)v0.0.1Teddy Wing
2022-03-23select: Add function documentationTeddy Wing
2022-03-21Add placeholders for code documentation remindersTeddy Wing
2022-03-21select: Fix test by adding new argumentTeddy Wing
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`.
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-19select: Idea for column exclusionTeddy Wing
2022-03-19select: Remove `dbg!` outputTeddy Wing
No longer need this.
2022-03-19select: Handle multiple records foundTeddy Wing
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.
2022-03-19select: Remove in-progress code ideasTeddy Wing
2022-03-19select: Remove unused `HashMap` importTeddy Wing
We switched this to a `yaml_rust::yaml::Hash`.
2022-03-19select: Remove `select_by_column()` idea codeTeddy Wing
This is implemented now.
2022-03-19select(): Parameterize primary key column nameTeddy Wing
2022-03-19select(): Column name interface and default primary key column interfaceTeddy Wing
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.
2022-03-19select(): Remove `unwrap()`sTeddy Wing
2022-03-19select(): Idea for selecting by a custom column nameTeddy Wing
2022-03-19select(): Don't include the primary key in the `Yaml` hashTeddy Wing
The primary key shouldn't be editable, so don't include it in the resulting YAML.
2022-03-19select(): Change `column_name` extraction to `to_owned()`Teddy Wing
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.
2022-03-19select(): Change `column_names` to `Vec<String>`Teddy Wing
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.
2022-03-19select(): Build a `yaml_rust::yaml::Hash` for each rowTeddy Wing
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.
2022-03-18select(): Add and check expected value in testTeddy Wing
2022-03-18select(): Try building a Yaml hash mapping column names to valuesTeddy Wing
Not quite what the `yaml_rust::Yaml` output should be, but getting closer.
2022-03-18select(): Remove debug and in-progress codeTeddy Wing
2022-03-18select(): Move primary key column name to format parameterTeddy Wing
2022-03-18select(): Remove parameterized primary key column nameTeddy Wing
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.
2022-03-18select(): Debug the parameterized SQL queryTeddy Wing
Add the `modern_sqlite` feature in order to use the `expanded_sql()` method. This shows us the SQL query with parameters expanded.
2022-03-18select(): Fix off-by-one error in column loopTeddy Wing
Had one iteration too many over each column.
2022-03-18select(): Tried to debug lack of results from `SELECT` queryTeddy Wing
2022-03-18select(): Trying to inspect data queried from databaseTeddy Wing
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.
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-14Idea for selecting a record from the database as YAMLTeddy Wing