Comparing version 2.0.0-beta3 to 2.0.0-beta4
28
index.js
@@ -5,4 +5,4 @@ import { extname, basename, dirname} from 'path'; | ||
import { CachingStore, setGetLastVersion } from './caching.js'; | ||
import { addQueryMethods, makeReusableBuffer } from './query.js'; | ||
import { addWriteMethods } from './writer.js'; | ||
import { addReadMethods, makeReusableBuffer } from './read.js'; | ||
import { addWriteMethods } from './write.js'; | ||
import { applyKeyHandling } from './keys.js'; | ||
@@ -146,12 +146,20 @@ import { Encoder as MsgpackrEncoder } from 'msgpackr'; | ||
}, dbOptions); | ||
if (!this.encoding || this.encoding == 'msgpack' || this.encoding == 'cbor') { | ||
this.encoder = this.decoder = new (this.encoding == 'cbor' ? require('cbor-x').Encoder : MsgpackrEncoder) | ||
(Object.assign(this.sharedStructuresKey ? | ||
this.setupSharedStructures() : { | ||
let Encoder; | ||
if (this.encoder) { | ||
Encoder = this.encoder.Encoder; | ||
} else if (!this.encoding || this.encoding == 'msgpack' || this.encoding == 'cbor') { | ||
Encoder = (this.encoding == 'cbor' ? require('cbor-x').Encoder : MsgpackrEncoder); | ||
} | ||
if (Encoder) { | ||
this.encoder = new Encoder(Object.assign( | ||
this.sharedStructuresKey ? this.setupSharedStructures() : { | ||
copyBuffers: true, // need to copy any embedded buffers that are found since we use unsafe buffers | ||
}, options, dbOptions)); | ||
} else if (this.encoding == 'json') { | ||
} | ||
if (this.encoding == 'json') { | ||
this.encoder = { | ||
encode: JSON.stringify, | ||
}; | ||
} else if (this.encoder) { | ||
this.decoder = this.encoder | ||
} | ||
@@ -282,3 +290,3 @@ applyKeyHandling(this); | ||
setLastVersion(lastVersion); | ||
return buffer ? this.encoder.decode(buffer) : []; | ||
return buffer ? this.decoder.decode(buffer) : []; | ||
}; | ||
@@ -289,3 +297,3 @@ return { | ||
let existingStructuresBuffer = this.getBinary(this.sharedStructuresKey); | ||
let existingStructures = existingStructuresBuffer ? this.encoder.decode(existingStructuresBuffer) : []; | ||
let existingStructures = existingStructuresBuffer ? this.decoder.decode(existingStructuresBuffer) : []; | ||
if (existingStructures.length != previousLength) | ||
@@ -304,3 +312,3 @@ return false; // it changed, we need to indicate that we couldn't update | ||
const removeSync = LMDBStore.prototype.removeSync; | ||
addQueryMethods(LMDBStore, { env, saveKey, keyBytes, keyBytesView, getLastVersion }); | ||
addReadMethods(LMDBStore, { env, saveKey, keyBytes, keyBytesView, getLastVersion }); | ||
addWriteMethods(LMDBStore, { env, fixedBuffer: keyBytes, | ||
@@ -307,0 +315,0 @@ resetReadTxn: LMDBStore.prototype.resetReadTxn, ...options }); |
@@ -58,3 +58,3 @@ import { setNativeFunctions } from './native.js'; | ||
export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary/index.js'; | ||
export { ABORT, asBinary } from './writer.js'; | ||
export { ABORT, asBinary } from './write.js'; | ||
export { levelup } from './level.js'; | ||
@@ -61,0 +61,0 @@ export { open, getLastVersion } from './index.js'; |
@@ -33,3 +33,3 @@ import { createRequire } from 'module'; | ||
export { toBufferKey as keyValueToBuffer, compareKeys, compareKeys as compareKey, fromBufferKey as bufferToKeyValue } from 'ordered-binary/index.js'; | ||
export { ABORT, asBinary } from './writer.js'; | ||
export { ABORT, asBinary } from './write.js'; | ||
export { levelup } from './level.js'; | ||
@@ -36,0 +36,0 @@ export { open, getLastVersion, getLastEntrySize, setLastVersion, allDbs } from './index.js'; |
{ | ||
"name": "lmdb", | ||
"author": "Kris Zyp", | ||
"version": "2.0.0-beta3", | ||
"version": "2.0.0-beta4", | ||
"description": "Simple, efficient, scalable data store wrapper for LMDB", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -353,2 +353,3 @@ [![license](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE) | ||
* `encoding` - Sets the encoding for the database values, which can be `'msgpack'`, `'json'`, `'cbor'`, `'string'`, `'ordered-binary'`or `'binary'`. | ||
* `encoder` - Directly set the encoder to use. This can be an object with `encode` and `decode` methods. It can also be an object with an `Encoder` that will be called to create the encoder instance. | ||
* `sharedStructuresKey` - Enables shared structures and sets the key where the shared structures will be stored. | ||
@@ -355,0 +356,0 @@ * `compression` - This enables compression. This can be set a truthy value to enable compression with default settings, or it can be an object with compression settings. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15973738
10981
468