feat(sqlite): Add query_many helper trait method

Signed-off-by: Skye Elliot <actuallyori@gmail.com>
This commit is contained in:
Skye Elliot
2026-02-25 12:32:13 +00:00
parent a90cf28d3c
commit 640fa4854f
+30
View File
@@ -97,6 +97,17 @@ pub(crate) trait SqliteAsyncConnExt {
P: Params + Send + 'static,
F: FnOnce(&Row<'_>) -> rusqlite::Result<T> + Send + 'static;
async fn query_many<T, P, F>(
&self,
sql: impl AsRef<str> + Send + 'static,
params: P,
f: F,
) -> rusqlite::Result<Vec<T>>
where
T: Send + 'static,
P: Params + Send + 'static,
F: FnMut(&Row<'_>) -> rusqlite::Result<T> + Send + 'static;
async fn with_transaction<T, E, F>(&self, f: F) -> Result<T, E>
where
T: Send + 'static,
@@ -278,6 +289,25 @@ impl SqliteAsyncConnExt for SqliteAsyncConn {
.map_err(map_interact_err)?
}
async fn query_many<T, P, F>(
&self,
sql: impl AsRef<str> + Send + 'static,
params: P,
f: F,
) -> rusqlite::Result<Vec<T>>
where
T: Send + 'static,
P: Params + Send + 'static,
F: FnMut(&Row<'_>) -> rusqlite::Result<T> + Send + 'static,
{
self.interact(move |conn| {
let mut stmt = conn.prepare(sql.as_ref())?;
stmt.query_and_then(params, f)?.collect()
})
.await
.map_err(map_interact_err)?
}
async fn with_transaction<T, E, F>(&self, f: F) -> Result<T, E>
where
T: Send + 'static,