From 640fa4854faa2bf0b27d4c280ced56583dc9a6a3 Mon Sep 17 00:00:00 2001 From: Skye Elliot Date: Wed, 25 Feb 2026 12:32:13 +0000 Subject: [PATCH] feat(sqlite): Add `query_many` helper trait method Signed-off-by: Skye Elliot --- crates/matrix-sdk-sqlite/src/utils.rs | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/crates/matrix-sdk-sqlite/src/utils.rs b/crates/matrix-sdk-sqlite/src/utils.rs index 765e08d2b..80933bab7 100644 --- a/crates/matrix-sdk-sqlite/src/utils.rs +++ b/crates/matrix-sdk-sqlite/src/utils.rs @@ -97,6 +97,17 @@ pub(crate) trait SqliteAsyncConnExt { P: Params + Send + 'static, F: FnOnce(&Row<'_>) -> rusqlite::Result + Send + 'static; + async fn query_many( + &self, + sql: impl AsRef + Send + 'static, + params: P, + f: F, + ) -> rusqlite::Result> + where + T: Send + 'static, + P: Params + Send + 'static, + F: FnMut(&Row<'_>) -> rusqlite::Result + Send + 'static; + async fn with_transaction(&self, f: F) -> Result where T: Send + 'static, @@ -278,6 +289,25 @@ impl SqliteAsyncConnExt for SqliteAsyncConn { .map_err(map_interact_err)? } + async fn query_many( + &self, + sql: impl AsRef + Send + 'static, + params: P, + f: F, + ) -> rusqlite::Result> + where + T: Send + 'static, + P: Params + Send + 'static, + F: FnMut(&Row<'_>) -> rusqlite::Result + 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(&self, f: F) -> Result where T: Send + 'static,