feat(sqlite): Add query_many helper trait method
Signed-off-by: Skye Elliot <actuallyori@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user