Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/js-drive/lib/storage/GroveDBStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,19 @@ class GroveDBStore {
*
* @param {PathQuery} query
* @param {Object} [options]
* @param {boolean} [options.skipCache=false]
* @param {boolean} [options.useTransaction=false]
* @return {Promise<StorageResult<Buffer|null>>}
*/
async query(query, options = { }) {
let items;

try {
[items] = await this.db.query(query, options.useTransaction || false);
[items] = await this.db.query(
query,
options.skipCache || false,
options.useTransaction || false,
);
} catch (e) {
if (
e.message.startsWith('grovedb: path key not found')
Expand Down
6 changes: 3 additions & 3 deletions packages/rs-drive-nodejs/GroveDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ class GroveDB {
* Get data using query.
*
* @param {PathQuery} query
* @param {boolean} [skipCache=false]
* @param {boolean} [useTransaction=false]
* @param {boolean} [allowCache=false]
* @return {Promise<*>}
*/
async query(query, useTransaction = false, allowCache = true) {
return groveDbQueryAsync.call(this.db, query, allowCache, useTransaction);
async query(query, skipCache = false, useTransaction = false) {
return groveDbQueryAsync.call(this.db, query, skipCache, useTransaction);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/rs-drive-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,14 +1576,14 @@ impl PlatformWrapper {

fn js_grove_db_query(mut cx: FunctionContext) -> JsResult<JsUndefined> {
let js_path_query = cx.argument::<JsObject>(0)?;
let js_allow_cache = cx.argument::<JsBoolean>(1)?;
let js_skip_cache = cx.argument::<JsBoolean>(1)?;
let js_using_transaction = cx.argument::<JsBoolean>(2)?;

let js_callback = cx.argument::<JsFunction>(3)?.root(&mut cx);

let path_query = converter::js_path_query_to_path_query(js_path_query, &mut cx)?;

let allow_cache = js_allow_cache.value(&mut cx);
let skip_cache = js_skip_cache.value(&mut cx);

let using_transaction = js_using_transaction.value(&mut cx);

Expand All @@ -1606,7 +1606,7 @@ impl PlatformWrapper {

let result = transaction_result.and_then(|transaction_arg| {
grove_db
.query_item_value(&path_query, allow_cache, transaction_arg)
.query_item_value(&path_query, !skip_cache, transaction_arg)
.unwrap()
.map_err(Error::GroveDB)
.map_err(|err| err.to_string())
Expand Down
45 changes: 14 additions & 31 deletions packages/rs-drive-nodejs/test/GroveDB.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ describe('GroveDB', () => {
});
});

describe('#query for Item subtrees', () => {
describe('#query', () => {
let aValue;
let aKey;
let bValue;
Expand Down Expand Up @@ -836,37 +836,21 @@ describe('GroveDB', () => {

expect(skipped).to.equals(0);
});
});

describe('#query', () => {
let dPath;
let dKey;
let ePath;

let daValue;
let dbValue;
let dcValue;
let eaValue;
let eaKey;
let ebValue;

beforeEach(async () => {
await groveDb.insert(
rootTreePath,
treeKey,
{ type: 'tree', epoch: 0 },
);
it('should be able to retrieve data with subquery', async () => {
// Prepare tree structure
const dKey = Buffer.from('dKey');
const daValue = Buffer.from('da');
const dbValue = Buffer.from('db');
const dcValue = Buffer.from('dc');
const eaValue = Buffer.from('ea');
const eaKey = Buffer.from('eaKey');
const ebValue = Buffer.from('eb');

dKey = Buffer.from('dKey');
daValue = Buffer.from('da');
dbValue = Buffer.from('db');
dcValue = Buffer.from('dc');
eaValue = Buffer.from('ea');
eaKey = Buffer.from('eaKey');
ebValue = Buffer.from('eb');
const dPath = [...itemTreePath];

dPath = [...itemTreePath];
dPath.push(dKey);

await groveDb.insert(
itemTreePath,
dKey,
Expand All @@ -892,7 +876,8 @@ describe('GroveDB', () => {
);

const eKey = Buffer.from('eKey');
ePath = [...itemTreePath];

const ePath = [...itemTreePath];
ePath.push(eKey);
await groveDb.insert(
itemTreePath,
Expand All @@ -911,9 +896,7 @@ describe('GroveDB', () => {
Buffer.from('ebKey'),
{ type: 'item', epoch: 0, value: ebValue },
);
});

it('should be able to retrieve data with subquery', async () => {
// This should give us only last subtree and apply subquery to it
const query = {
path: itemTreePath,
Expand Down
Loading