story-kit: merge 260_refactor_upgrade_libsqlite3_sys

This commit is contained in:
Dave
2026-03-17 13:39:08 +00:00
parent b0e4e04c9d
commit ea062400e5
73 changed files with 23405 additions and 10 deletions

View File

@@ -0,0 +1,30 @@
extern crate rusqlite;
use rusqlite::{CachedStatement, Connection, Result, Rows};
use self_cell::{self_cell, MutBorrow};
type CachedStatementRef<'a> = CachedStatement<'a>;
// Caveat: single statement at a time for one connection.
// But if you need multiple statements, you can still create your own struct
// with multiple fields (one for each statement).
self_cell!(
struct OwningStatement {
owner: MutBorrow<Connection>,
#[covariant]
dependent: CachedStatementRef,
}
);
fn main() -> Result<()> {
let conn = Connection::open_in_memory()?;
let mut os = OwningStatement::try_new(MutBorrow::new(conn), |s| {
s.borrow_mut().prepare_cached("SELECT 1")
})?;
let mut rows = os.with_dependent_mut(|_conn, stmt| -> Result<Rows<'_>> { stmt.query([]) })?;
while let Some(row) = rows.next()? {
assert_eq!(Ok(1), row.get(0));
}
Ok(())
}