Skip to content

Commit

Permalink
feat: Add missing get_all_with_key_and_limit method
Browse files Browse the repository at this point in the history
Closes #31
  • Loading branch information
Alorel committed Jul 26, 2024
1 parent 65bca02 commit efee807
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/idb_query_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K: JsCast>(
&self,
key: &K,
limit: u32,
) -> Result<JsCastRequestFuture<js_sys::Array>, 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<K: Into<JsValue>>(
&self,
key: K,
limit: u32,
) -> Result<JsCastRequestFuture<js_sys::Array>, 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<CountFuture, DomException>;

Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K: wasm_bindgen::JsCast>(
&self,
key: &K,
limit: u32,
) -> Result<$crate::request::JsCastRequestFuture<js_sys::Array>, 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())
Expand Down

0 comments on commit efee807

Please sign in to comment.