forked from rusqlite/rusqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
15 changed files
with
218 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ignore: | ||
- "examples" | ||
- "libsqlite3-sys/bindgen-bindings" | ||
- "libsqlite3-sys/sqlite3" | ||
coverage: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
extern crate rusqlite; | ||
|
||
use ouroboros::self_referencing; | ||
use rusqlite::{CachedStatement, Connection, Result, Rows}; | ||
|
||
#[self_referencing] | ||
struct OwningRows<'conn> { | ||
stmt: CachedStatement<'conn>, | ||
#[borrows(mut stmt)] | ||
#[covariant] | ||
rows: Rows<'this>, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let conn = Connection::open_in_memory()?; | ||
let stmt = conn.prepare_cached("SELECT 1")?; | ||
let mut or = OwningRowsTryBuilder { | ||
stmt, | ||
rows_builder: |s| s.query([]), | ||
} | ||
.try_build()?; | ||
or.with_rows_mut(|rows| -> Result<()> { | ||
while let Some(row) = rows.next()? { | ||
assert_eq!(Ok(1), row.get(0)); | ||
} | ||
Ok(()) | ||
})?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
extern crate rusqlite; | ||
|
||
use rusqlite::{CachedStatement, Connection, Result, Rows}; | ||
use self_cell::{self_cell, MutBorrow}; | ||
|
||
type RowsRef<'a> = Rows<'a>; | ||
|
||
self_cell!( | ||
struct OwningRows<'conn> { | ||
owner: MutBorrow<CachedStatement<'conn>>, | ||
#[covariant] | ||
dependent: RowsRef, | ||
} | ||
); | ||
|
||
fn main() -> Result<()> { | ||
let conn = Connection::open_in_memory()?; | ||
let stmt = conn.prepare_cached("SELECT 1")?; | ||
let mut or = OwningRows::try_new(MutBorrow::new(stmt), |s| s.borrow_mut().query([]))?; | ||
or.with_dependent_mut(|_stmt, rows| -> Result<()> { | ||
while let Some(row) = rows.next()? { | ||
assert_eq!(Ok(1), row.get(0)); | ||
} | ||
Ok(()) | ||
})?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extern crate rusqlite; | ||
use ouroboros::self_referencing; | ||
use rusqlite::{CachedStatement, Connection, Result, Rows}; | ||
|
||
/// 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_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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.