From efee8076207053b698a01eed3e6ce157220f254f Mon Sep 17 00:00:00 2001 From: Art <4998038+Alorel@users.noreply.github.com> Date: Fri, 26 Jul 2024 21:15:44 +0100 Subject: [PATCH] feat: Add missing `get_all_with_key_and_limit` method Closes #31 --- src/idb_query_source.rs | 20 ++++++++++++++++++++ src/lib.rs | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/idb_query_source.rs b/src/idb_query_source.rs index 31ca466..7f0ef8a 100644 --- a/src/idb_query_source.rs +++ b/src/idb_query_source.rs @@ -49,6 +49,26 @@ pub trait IdbQuerySource: Sized { self.get_all_with_key(&key.into()) } + /// Get all values in the index/object store that correspond to the given key or are in + /// range, if the key is an [`IDBKeyRange`](web_sys::IdbKeyRange). `limit` controls the + /// maximum number of results to return + fn get_all_with_key_and_limit( + &self, + key: &K, + limit: u32, + ) -> Result, DomException>; + + /// Get all values in the index/object store that correspond to the given key or are in + /// range, if the key is an [`IDBKeyRange`](web_sys::IdbKeyRange). `limit` controls the + /// maximum number of results to return + fn get_all_with_key_and_limit_owned>( + &self, + key: K, + limit: u32, + ) -> Result, DomException> { + self.get_all_with_key_and_limit(&key.into(), limit) + } + /// Count the number of documents in the index/object store fn count(&self) -> Result; diff --git a/src/lib.rs b/src/lib.rs index 32800cd..dc5ad5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -226,6 +226,19 @@ macro_rules! impl_query_source { $crate::request::JsCastRequestFuture::new(self.inner.get_all_with_key(key.unchecked_ref())) } + #[inline] + fn get_all_with_key_and_limit( + &self, + key: &K, + limit: u32, + ) -> Result<$crate::request::JsCastRequestFuture, web_sys::DomException> + { + #[allow(unused_imports)] + use wasm_bindgen::JsCast; + let base = self.inner.get_all_with_key_and_limit(key.unchecked_ref(), limit); + $crate::request::JsCastRequestFuture::new(base) + } + #[inline] fn count(&self) -> Result<$crate::request::CountFuture, web_sys::DomException> { $crate::request::CountFuture::new(self.inner.count())