Expand description
Exemplar is a boilerplate eliminator for rusqlite.
§Getting Started
A taste of what you can do:
#[derive(Debug, PartialEq, Model)]
#[table("users")]
#[check("../tests/schema.sql")]
struct User {
username: String,
#[bind(bind_path)]
#[extr(extr_path)]
home_dir: PathBuf,
#[column("pwd")]
password: Vec<u8>,
}
fn main() -> Result<()> {
let conn = Connection::open_in_memory()?;
conn.execute_batch(
include_str!("../tests/schema.sql")
)?;
let alice = User {
username: "Alice".to_owned(),
home_dir: "/var/home/alice".into(),
password: b"hunter2".to_vec()
};
let bob = User {
username: "Bob".to_owned(),
home_dir: "/var/home/robert".into(),
password: b"password".to_vec()
};
alice.insert(&conn)?;
bob.insert(&conn)?;
let mut stmt = conn.prepare("SELECT * FROM users ORDER BY username ASC")?;
let mut iter = stmt.query_and_then([], User::from_row)?;
assert_eq!(alice, iter.next().unwrap()?);
assert_eq!(bob, iter.next().unwrap()?);
Ok(())
}Exemplar is based around the Model trait, which has its own derive macro.
Macros§
- record
- Generate an “anonymous” record
structthat implementsfrom_row. - sql_
enum - Generate an SQL-compatible field-less
enum.
Structs§
Enums§
- OnConflict
- Possible conflict resolution strategies when using
Model::insert_or. - Parameter
Cow-like type for query parameters.
Traits§
- Model
- An interface for types that model SQLite database tables.
Type Aliases§
- Bind
Result - Type alias for the outcome of converting a value to an SQL-friendly representation.
- Extr
Result - Type alias for the outcome of extracting a value from a
Row. - Parameters
- Type alias for a boxed slice of named query parameters.