cratestack_rusqlite/row.rs
1//! Row decoding trait for SQLite.
2//!
3//! Mirrors `sqlx::FromRow<PgRow>` for the rusqlite side. The model macro
4//! emits an impl of this trait when targeting the SQLite backend, so user
5//! code never sees this directly — it just calls `find_many().run()` and
6//! receives `Vec<UserModel>`.
7
8use rusqlite::Row;
9
10/// Decode a model from a rusqlite row.
11///
12/// Implementations are free to use either positional (`row.get(0)`) or named
13/// (`row.get("col")`) lookups. The codegen uses named lookups against the
14/// model's `rust_name` aliases, matching the projection produced by
15/// [`cratestack_sql::ModelDescriptor::select_projection`].
16pub trait FromRusqliteRow: Sized {
17 fn from_rusqlite_row(row: &Row<'_>) -> rusqlite::Result<Self>;
18}
19
20/// Partial-row decoder — mirrors [`cratestack_sqlx::FromPartialPgRow`]
21/// for the embedded backend. The macro emits this impl alongside
22/// `FromRusqliteRow`; users see it only as the bound on the typed
23/// builder's `T` generic when they call `.select(...)`.
24pub trait FromPartialRusqliteRow: Sized {
25 /// Decode `row` into `Self` using `selected` as the projection
26 /// manifest. Columns not in `selected` populate to their type's
27 /// `Default::default()` value.
28 fn from_partial_rusqlite_row(row: &Row<'_>, selected: &[&str]) -> rusqlite::Result<Self>;
29}