@live-change/db-store-lmdb 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Store.js +11 -5
- package/package.json +2 -2
package/lib/Store.js
CHANGED
|
@@ -308,9 +308,15 @@ class CountObservable extends ReactiveDao.ObservableValue {
|
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
class Store {
|
|
311
|
-
constructor(env, db) {
|
|
311
|
+
constructor(env, db, options = {}) {
|
|
312
312
|
this.env = env
|
|
313
313
|
this.lmdb = db
|
|
314
|
+
|
|
315
|
+
const {
|
|
316
|
+
serialization = JSON
|
|
317
|
+
} = options
|
|
318
|
+
this.serialization = serialization
|
|
319
|
+
|
|
314
320
|
this.objectObservables = new Map()
|
|
315
321
|
this.rangeObservables = new Map()
|
|
316
322
|
this.countObservables = new Map()
|
|
@@ -403,7 +409,7 @@ class Store {
|
|
|
403
409
|
const key = keys[i]
|
|
404
410
|
const json = txn.getString(this.lmdb, key)
|
|
405
411
|
try {
|
|
406
|
-
const obj =
|
|
412
|
+
const obj = this.serialization.parse(json)
|
|
407
413
|
//obj.id = found
|
|
408
414
|
data[i] = obj
|
|
409
415
|
} catch(e) {
|
|
@@ -490,7 +496,7 @@ class Store {
|
|
|
490
496
|
const key = keys[i]
|
|
491
497
|
const json = txn.getString(this.lmdb, key)
|
|
492
498
|
try {
|
|
493
|
-
const obj =
|
|
499
|
+
const obj = this.serialization.parse(json)
|
|
494
500
|
txn.del(this.lmdb, key)
|
|
495
501
|
const objectObservable = this.objectObservables.get(key)
|
|
496
502
|
if(objectObservable) objectObservable.set(null)
|
|
@@ -586,8 +592,8 @@ class Store {
|
|
|
586
592
|
const txn = this.env.beginTxn()
|
|
587
593
|
try {
|
|
588
594
|
const json = txn.getString(this.lmdb, id)
|
|
589
|
-
oldObject = json ?
|
|
590
|
-
txn.putString(this.lmdb, id,
|
|
595
|
+
oldObject = json ? this.serialization.parse(json) : null
|
|
596
|
+
txn.putString(this.lmdb, id, this.serialization.stringify(object), { noOverwrite: false })
|
|
591
597
|
} catch(err) {
|
|
592
598
|
console.log("ERROR WHILE PUTTING OBJECT", id)
|
|
593
599
|
console.error(err)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/db-store-lmdb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Database with observable data for live queries",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"napi-macros": "^2.0.0",
|
|
31
31
|
"node-lmdb": "^0.9.6"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "9a1b104864c08f3e35b009f191889e3308e3eeb0"
|
|
34
34
|
}
|