Skip to content

Commit

Permalink
feat: advanced indexing (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo authored Jan 26, 2025
2 parents fe9f58d + 537c7c3 commit 23a0342
Show file tree
Hide file tree
Showing 25 changed files with 5,620 additions and 2,021 deletions.
4,299 changes: 3,139 additions & 1,160 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions packages/ridb-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## @trust0/ridb-core [1.2.0-rc.1](https://github.com/trust0-project/RIDB/compare/@trust0/[email protected]...@trust0/[email protected]) (2025-01-26)

### Features

* add inmemory count advanced indexing ([a43b945](https://github.com/trust0-project/RIDB/commit/a43b94555481b6aa1dce726849f0320a0becabd3))
* advanced indexing ([1a26e79](https://github.com/trust0-project/RIDB/commit/1a26e798a541762f1876184187f9d9ccd1f72f96))

### Bug Fixes

* cargo version [skip ci] ([ed82dee](https://github.com/trust0-project/RIDB/commit/ed82dee851f40bd16acbbdc6f4326cfdbc2530cf))
* implement indexing in InMemory, IndexDB, find and count methods ([fe41c7c](https://github.com/trust0-project/RIDB/commit/fe41c7c0d7929369bf0c7d817ae7ee7c131ced97))
* improve docs ([e3439f5](https://github.com/trust0-project/RIDB/commit/e3439f52212021506d2d0f78ee3dedc8dd395623))
* testing ([60b5f76](https://github.com/trust0-project/RIDB/commit/60b5f76918822aa28bf369e0def67e273080e1ec))

## @trust0/ridb-core [1.1.0](https://github.com/trust0-project/RIDB/compare/@trust0/[email protected]...@trust0/[email protected]) (2025-01-01)

### Features
Expand Down
45 changes: 1 addition & 44 deletions packages/ridb-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/ridb-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ serde = { version = "1.0.195", features = ["derive"] }
serde-wasm-bindgen = "0.6.3"
console = "0.15.8"
serde_json = "1.0.111"
web-sys = { version = "0.3.69", features = ["Storage","IdbTransaction", "IdbVersionChangeEvent", "IdbObjectStoreParameters", "Event", "DomException", "IdbCursor", "IdbKeyRange", "IdbObjectStore", "IdbRequest", "IdbTransactionMode", "IdbOpenDbRequest", "console", "Window", "Request", "Response", "IdbDatabase", "IdbFactory", "DomStringList"] }
web-sys = { version = "0.3.69", features = ["Storage", "IdbTransaction", "IdbVersionChangeEvent", "IdbObjectStoreParameters","IdbIndexParameters", "Event", "DomException", "IdbCursor", "IdbKeyRange", "IdbObjectStore", "IdbRequest", "IdbTransactionMode", "IdbOpenDbRequest", "console", "Window", "Request", "Response", "IdbDatabase", "IdbFactory", "DomStringList", "IdbIndex"] }
wasm-bindgen-test = {version="^0.3.42"}
sha2 = "0.11.0-pre.4"
base64 = "0.22.1"
chacha20poly1305 = { version = "0.10.1", features = ["std"] }
rand = "0.9.0-alpha.2"
getrandom = { version = "0.2", features = ["js"] }
parking_lot = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion packages/ridb-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"publishConfig": {
"access": "public"
},
"version": "1.1.0",
"version": "1.2.0-rc.1",
"main": "./pkg/ridb_core.js",
"types": "./pkg/ridb_core.d.ts",
"sideEffects": [
Expand Down
39 changes: 20 additions & 19 deletions packages/ridb-core/src/collection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Collection<T extends SchemaType> {
#[derive(Clone)]
pub struct Collection {
pub(crate) name: String,
pub(crate) storage: Storage,
pub(crate) storage: Storage
}

#[wasm_bindgen]
Expand All @@ -121,7 +121,7 @@ impl Collection {
) -> Collection {
Collection {
name,
storage,
storage
}
}

Expand All @@ -140,22 +140,19 @@ impl Collection {

/// Finds and returns all documents in the collection.
///
/// This function is asynchronous and returns a `Schema` representing
/// This function is asynchronous and returns a `JsValue` representing
/// the documents found in the collection.
#[wasm_bindgen]
pub async fn find(&mut self, query: JsValue) -> Result<JsValue, JsValue> {
let result = match self.storage.internal.find(&self.name, query).await {
Ok(docs) => {
docs
},
Err(e) => {
return Err(js_sys::Error::new(&format!("Failed to find documents: {:?}", e)).into())
}
};
pub async fn find(&mut self, query_js: JsValue) -> Result<JsValue, JsValue> {
// No index available, perform a regular find
let docs = self.storage.find(
&self.name,
query_js
).await?;

// Convert the result to a JavaScript array
let array = js_sys::Array::from(&result);
let processed_array = js_sys::Array::new();
// Process and return the result
let array = js_sys::Array::from(&docs);
let processed_array = js_sys::Array::new();

// Iterate over each document in the array
for item in array.iter() {
Expand All @@ -164,16 +161,20 @@ impl Collection {
processed_array.push(&processed_item);
}

Ok(processed_array.into())
Ok(
JsValue::from(
processed_array
)
)
}

/// counts and returns all documents in the collection.
///
/// This function is asynchronous and returns a `Schema` representing
/// the documents found in the collection.
#[wasm_bindgen]
pub async fn count(&self, query: JsValue) -> Result<JsValue, JsValue> {
match self.storage.internal.count(&self.name, query).await {
pub async fn count(&self, query_js: JsValue) -> Result<JsValue, JsValue> {
match self.storage.count(&self.name, query_js).await {
Ok(count) => Ok(count),
Err(e) => Err(js_sys::Error::new(&format!("Failed to count documents: {:?}", e)).into())
}
Expand All @@ -184,7 +185,7 @@ impl Collection {
/// This function is asynchronous.
#[wasm_bindgen(js_name="findById")]
pub async fn find_by_id(&self, primary_key: JsValue) -> Result<JsValue, JsValue>{
let document = match self.storage.internal.find_document_by_id(&self.name, primary_key ).await {
let document = match self.storage.find_document_by_id(&self.name, primary_key ).await {
Ok(doc) => doc,
Err(e) => return Err(js_sys::Error::new(&format!("Failed to find document by ID: {:?}", e)).into())
};
Expand Down
Loading

0 comments on commit 23a0342

Please sign in to comment.