Skip to content

Commit

Permalink
Enhanced documentation. Addressed/documented underlying issues with `…
Browse files Browse the repository at this point in the history
  • Loading branch information
anywhichway committed May 21, 2023
1 parent 05e6218 commit dd37f5c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
18 changes: 13 additions & 5 deletions README.md
Expand Up @@ -56,7 +56,7 @@ if(id) {
address:{city:"York"} // fulltext indexing turned on, partial matches returned so long as `valueMatch` is relaxed
},(value)=>value)].forEach((person) => {
console.log(person)
});
},null,{fulltext:true});
}
```
## API
Expand Down Expand Up @@ -197,17 +197,23 @@ The `key` or the object id (in the case of indexed object) is returned if the tr

Synchronous version of `db.put`.

***DO NOT USE***: An underlying issue with `lmdb` results in this occassionally returning a Promise instead of a value. Use `await db.put` instead.
***DO NOT USE***: An underlying issue with `lmdb` results in this occasionally returning a Promise instead of a value. Use `await db.put` instead.

#### async db.remove(key:LMDBKey,?version:number,?ifVersion:number) - returns LMDBKey|undefined

Same behavior as `lmdb` except that the index entries are removed inside a transaction

#### db.removeSync(key:LMDBKey,?version:number,?ifVersion:number) - returns LMDBKey|undefined

Synchronous version of `db.remove`.

***DO NOT USE***: An underlying issue with `lmdb` results in this occasionally returning a Promise instead of a value. Use `await db.put` instead.

#### withExtensions(db:LMDBDatabase,?extensions:object) - returns LMDBDatabase`

Extends an LMDB database and any child databases it opens to have the `extensions` provided as well as any child databases it opens. This utility is common to other `lmdb` extensions like `lmdb-patch`, `lmdb-copy`, `lmdb-move`.

Automatically adds `copy`, `getRangeFromIndex`, `index`, `indexSync`, `move`, `patch` and modified behavior of `put`, `putSync`,`remove` and `removeSync`.
Returns a child database that has the extensions `copy`, `getRangeFromIndex`, `index`, `indexSync`, `move`, `patch` and modified behavior of `clearAsync`, clearSync`, `put`, `putSync`,`remove` and `removeSync`.

## Operators

Expand Down Expand Up @@ -296,7 +302,7 @@ index.js | 93.82 | 82.76 | 96.87 | 98.16 | 271-275,306,395,488,570
lmdb-index/src | 100 | 98.96 | 100 | 100 |
operators.js | 100 | 98.96 | 100 | 100 | 14,190

Note: Lines 265-307 are for code that will be deprecated.
Note: Lines 271-275 are for code that will be deprecated.

# Release Notes (Reverse Chronological Order)

Expand All @@ -306,7 +312,9 @@ During ALPHA and BETA, the following semantic versioning rules apply:
* Breaking changes or feature additions will increment the minor version.
* Bug fixes and documentation changes will increment the patch version.

2023-05-21 v0.11.1 Enhanced documentation. Added unit tests. Added `scan` options to `db.getRangeFromIndex`. Fixed issue with `putSync` where special values were not getting serialized and underlying `lmdb` library falsely reporting a `db.putSync` failed. Improved fulltext index matching counts when the same word is repeated. Discovered and documented that `db.putSync` sometimes returns a Promise. Advise against using.
2023-05-21 v0.11.2 Enhanced documentation. Addressed/documented underlying issues with `lmdb`: https://github.com/kriszyp/lmdb-js/issues/235 and https://github.com/kriszyp/lmdb-js/issues/234.

2023-05-21 v0.11.1 Enhanced documentation. Added unit tests. Added `scan` option to `db.getRangeFromIndex`. Fixed issue with `putSync` where special values were not getting serialized and underlying `lmdb` library falsely reporting a `db.putSync` failed. Improved fulltext index matching counts when the same word is repeated. Discovered and documented that `db.putSync` sometimes returns a Promise. Advise against using.

2023-05-19 v0.11.0 Added an index to better support queries where the value is known but properties might be ambiguous.

Expand Down
8 changes: 4 additions & 4 deletions index.benchmark.js
Expand Up @@ -27,21 +27,21 @@ let count = 0,
}).on('cycle', async (event) => {
log(event,1);
}).run({});
(new Benchmark.Suite).add("put primitive sync",() => {
/*(new Benchmark.Suite).add("put primitive sync",() => {
db.putSync("sync",2);
}).on('cycle', async (event) => {
log(event,1);
}).run({});
}).run({});*/
(new Benchmark.Suite).add("get primitive for async",() => {
db.get("async");
}).on('cycle', async (event) => {
log(event,1);
}).run({});
(new Benchmark.Suite).add("get primitive for sync",() => {
/*(new Benchmark.Suite).add("get primitive for sync",() => {
db.get("sync");
}).on('cycle', async (event) => {
log(event,1);
}).run({});
}).run({});*/
(new Benchmark.Suite).add("index sync",() => {
if(count>maxCount) return;
db.putSync(null,{name:"joe",address:{city:"Albany",state:"NY"},"#":`TestObject@${count++}`});
Expand Down
16 changes: 9 additions & 7 deletions index.js
Expand Up @@ -389,16 +389,16 @@ function *matchIndex(pattern,{cname,minScore,sortable,fulltext,scan}={}) {
let i = 0;
if(keys.length===0 && scan) {
const start = [cname+"@"];
try {
//try {
for(const entry of this.getRange({start})) {
if(!entry.key.startsWith(start)) {
break;
}
yield {id:entry.key,count:0};
}
} catch(e) {
true; // above sometimes throws due to underlying lmdb issue
}
// } catch(e) {
// true; // above sometimes throws due to underlying lmdb issue
// }
return;
}
for(let key of keys) {
Expand Down Expand Up @@ -697,11 +697,13 @@ const functionalOperators = Object.entries(operators).reduce((operators,[key,f])
},{});

const withExtensions = (db,extensions={}) => {
db.valueIndex = db.openDB(`${db.name}.valueIndex`); //,{dupSort:true,encoding:"ordered-binary"}
db.propertyIndex = db.openDB(`${db.name}.propertyIndex`); //,{dupSort:true,encoding:"ordered-binary"}
db.data = db.openDB(`${db.name}.data`); //,{dupSort:true,encoding:"ordered-binary"}
db.data.valueIndex = db.openDB(`${db.name}.valueIndex`); //,{dupSort:true,encoding:"ordered-binary"}
db.data.propertyIndex = db.openDB(`${db.name}.propertyIndex`); //,{dupSort:true,encoding:"ordered-binary"}
//db.valueIndex = db.propertyIndex;
/* index, indexSync */
return lmdbExtend(db,{clearAsync,clearSync,copy,defineSchema,get,getRangeFromIndex,getSchema,index, indexSync,move,patch,put,putSync,remove,removeSync,...extensions})
db.data.indexOptions = db.indexOptions;
return lmdbExtend(db.data,{clearAsync,clearSync,copy,defineSchema,get,getRangeFromIndex,getSchema,index, indexSync,move,patch,put,putSync,remove,removeSync,...extensions})
}

export {DONE,ANY,functionalOperators as operators,withExtensions}
17 changes: 11 additions & 6 deletions index.test.js
Expand Up @@ -250,17 +250,22 @@ test("getRangeFromIndex - fulltext",async () => {
expect(range.length).toBe(3);
expect(range[0].value).toBeInstanceOf(Person);
expect(range.every((item) => item.value.name.startsWith("john"))).toBe(true);
ids.forEach((id) => db.removeSync(id))
for(const id of ids) {
await db.remove(id)
}
})

test("getRangeFromIndex - fulltext percentage",async () => {
await db.put(null,new Person({name:"john jones"}));
await db.put(null,new Person({name:"john johnston"}));
await db.put(null,new Person({name:"john johnson"}));
test("getRangeFromIndex - fulltext all",async () => {
const ids = [await db.put(null,new Person({name:"john jones"})),
await db.put(null,new Person({name:"john johnston"})),
await db.put(null,new Person({name:"john johnson"}))];
const range = [...db.getRangeFromIndex({name:"john johnson"},null, null,{cname:"Person"})];
expect(range.length).toBe(1);
expect(range[0].value).toBeInstanceOf(Person);
expect(range[0].value.name.startsWith("john")).toBe(true);
expect(range[0].value.name).toBe("john johnson");
for(const id of ids) {
await db.remove(id)
}
})

test("put no index",async () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "lmdb-index",
"version": "0.11.1",
"version": "0.11.2",
"description": "Object indexing and index based queries for LMDB",
"type": "module",
"main": "index.js",
Expand Down

0 comments on commit dd37f5c

Please sign in to comment.