mirror of
https://github.com/isar/rusqlite.git
synced 2025-04-19 15:57:45 +08:00
Add example of OwningStatement using ouroboros
This commit is contained in:
parent
7dbc3175f9
commit
950b73e2de
27
examples/owning_statement.rs
Normal file
27
examples/owning_statement.rs
Normal file
@ -0,0 +1,27 @@
|
||||
extern crate rusqlite;
|
||||
use ouroboros::self_referencing;
|
||||
use rusqlite::{CachedStatement, Connection, Result, Rows};
|
||||
|
||||
#[self_referencing]
|
||||
struct OwningStatement {
|
||||
conn: Connection,
|
||||
#[borrows(conn)]
|
||||
#[covariant]
|
||||
stmt: CachedStatement<'this>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let conn = Connection::open_in_memory()?;
|
||||
|
||||
let mut os = OwningStatementTryBuilder {
|
||||
conn,
|
||||
stmt_builder: |c| c.prepare_cached("SELECT 1"),
|
||||
}
|
||||
.try_build()?;
|
||||
|
||||
let mut rows = os.with_stmt_mut(|stmt| -> Result<Rows<'_>> { stmt.query([]) })?;
|
||||
while let Some(row) = rows.next()? {
|
||||
assert_eq!(Ok(1), row.get(0));
|
||||
}
|
||||
Ok(())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user