harperdb 3.2.1 → 3.3.0
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/README.md +20 -11
- package/bin/BinObjects.jsc +0 -0
- package/bin/harperdb.jsc +0 -0
- package/bin/install.jsc +0 -0
- package/bin/register.jsc +0 -0
- package/bin/run.jsc +0 -0
- package/bin/stop.jsc +0 -0
- package/bin/upgrade.jsc +0 -0
- package/bin/utility.jsc +0 -0
- package/bin/version.jsc +0 -0
- package/coverage/lcov.info +7142 -6704
- package/data_layer/CreateAttributeObject.jsc +0 -0
- package/data_layer/CreateTableObject.jsc +0 -0
- package/data_layer/DataLayerObjects.jsc +0 -0
- package/data_layer/DeleteBeforeObject.jsc +0 -0
- package/data_layer/DeleteObject.jsc +0 -0
- package/data_layer/DropAttributeObject.jsc +0 -0
- package/data_layer/InsertObject.jsc +0 -0
- package/data_layer/ReadTransactionLogObject.jsc +0 -0
- package/data_layer/SQLSearch.jsc +0 -0
- package/data_layer/SearchByConditionsObject.jsc +0 -0
- package/data_layer/SearchByHashObject.jsc +0 -0
- package/data_layer/SearchObject.jsc +0 -0
- package/data_layer/SqlSearchObject.jsc +0 -0
- package/data_layer/UpdateObject.jsc +0 -0
- package/data_layer/UpsertObject.jsc +0 -0
- package/data_layer/bulkLoad.jsc +0 -0
- package/data_layer/data_objects/BulkLoadObjects.jsc +0 -0
- package/data_layer/data_objects/UpsertObject.jsc +0 -0
- package/data_layer/delete.jsc +0 -0
- package/data_layer/export.jsc +0 -0
- package/data_layer/harperBridge/BridgeMethods.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/checkForNewAttr.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/convertOperationToTransaction.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/evaluateTableGetAttributes.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/insertUpdateReturnObj.jsc +0 -0
- package/data_layer/harperBridge/bridgeUtility/insertUpdateValidate.jsc +0 -0
- package/data_layer/harperBridge/harperBridge.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/LMDBBridge.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/DeleteTransactionsBeforeResults.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecordsBefore.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteTransactionLogsBefore.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadTransactionLog.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBDeleteTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBInsertTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpdateTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/LMDBUpsertTransactionObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/TableSizeObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/ThreadSearchObject.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsEnvironment.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbDropAllAttributes.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbThreadSearch.jsc +0 -0
- package/data_layer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.jsc +0 -0
- package/data_layer/hdbInfoController.jsc +0 -0
- package/data_layer/insert.jsc +0 -0
- package/data_layer/readTransactionLog.jsc +0 -0
- package/data_layer/schema.jsc +0 -0
- package/data_layer/schemaDescribe.jsc +0 -0
- package/data_layer/search.jsc +0 -0
- package/data_layer/update.jsc +0 -0
- package/events/ClusterStatusEmitter.jsc +0 -0
- package/events/SioServerStoppedEvent.jsc +0 -0
- package/events/SocketClusterStatusEmitter.jsc +0 -0
- package/license/LICENSE +91 -1
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/README.md +1 -0
- package/node_modules/{node-addon-api/src/nothing.c → @msgpackr-extract/msgpackr-extract-linux-x64/index.js} +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.abi93.glibc.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.abi93.musl.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.napi.glibc.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/node.napi.musl.node +0 -0
- package/node_modules/@msgpackr-extract/msgpackr-extract-linux-x64/package.json +53 -0
- package/node_modules/{msgpackr-extract → lmdb-store}/.github/workflows/prebuild.yml +9 -10
- package/node_modules/lmdb-store/.idea/lmdb-store.iml +12 -0
- package/node_modules/lmdb-store/.idea/misc.xml +6 -0
- package/node_modules/lmdb-store/.idea/modules.xml +8 -0
- package/node_modules/lmdb-store/.idea/workspace.xml +4 -0
- package/node_modules/lmdb-store/README.md +393 -388
- package/node_modules/lmdb-store/benchmark/index.js +162 -162
- package/node_modules/lmdb-store/binding.gyp +79 -88
- package/node_modules/lmdb-store/caching.js +113 -113
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -20
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -1631
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -47
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -183
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -14
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -121
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -192
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.c +12125 -12125
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -74
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -106
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -53
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -154
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -94
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -333
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -97
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -530
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -83
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -276
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.c +452 -452
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.h +208 -208
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/module.c +101 -101
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/module.h +16 -16
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -178
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -124
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -133
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -168
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -135
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -141
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -190
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -189
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -177
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -73
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -62
- package/node_modules/lmdb-store/dependencies/lmdb/libraries/liblmdb/tooltag +27 -27
- package/node_modules/lmdb-store/dependencies/lz4/LICENSE +11 -11
- package/node_modules/lmdb-store/dependencies/lz4/lib/README.md +137 -137
- package/node_modules/lmdb-store/dependencies/lz4/lib/dll/example/README.md +69 -69
- package/node_modules/lmdb-store/dependencies/lz4/lib/lz4frame.c +1899 -1899
- package/node_modules/lmdb-store/dependencies/lz4/lib/xxhash.c +1030 -1030
- package/node_modules/lmdb-store/dependencies/lz4/lib/xxhash.h +328 -328
- package/node_modules/lmdb-store/dist/index.cjs +2591 -0
- package/node_modules/lmdb-store/dist/index.cjs.map +1 -0
- package/node_modules/lmdb-store/index.d.ts +323 -323
- package/node_modules/lmdb-store/index.js +1274 -1274
- package/node_modules/lmdb-store/index.mjs +3 -3
- package/node_modules/lmdb-store/package.json +16 -11
- package/node_modules/lmdb-store/prebuilds/darwin-arm64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-arm64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-arm64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-arm64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-arm64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi83.musl.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi93.musl.node +0 -0
- package/node_modules/lmdb-store/prebuilds/linux-x64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/electron.abi98.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi83.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi93.node +0 -0
- package/node_modules/lmdb-store/src/compression.cpp +181 -181
- package/node_modules/lmdb-store/src/cursor.cpp +407 -407
- package/node_modules/lmdb-store/src/dbi.cpp +354 -354
- package/node_modules/lmdb-store/src/env.cpp +1134 -1134
- package/node_modules/lmdb-store/src/misc.cpp +528 -528
- package/node_modules/lmdb-store/src/node-lmdb.cpp +44 -44
- package/node_modules/lmdb-store/src/node-lmdb.h +965 -965
- package/node_modules/lmdb-store/src/ordered-binary.cpp +337 -337
- package/node_modules/lmdb-store/src/txn.cpp +513 -513
- package/node_modules/lmdb-store/src/v8-fast-api-calls.h +419 -419
- package/node_modules/lmdb-store/src/windows.c +30 -30
- package/node_modules/lmdb-store/test/index.test.js +584 -584
- package/node_modules/lmdb-store/test/node-lmdb.test.js +1525 -1525
- package/node_modules/lmdb-store/test/threads.js +100 -100
- package/node_modules/lmdb-store/util/ArrayLikeIterable.js +136 -136
- package/node_modules/lmdb-store/util/WeakValueMap.js +40 -40
- package/node_modules/lmdb-store/util/upgrade-lmdb.js +46 -46
- package/node_modules/lmdb-store/util/when.js +8 -8
- package/node_modules/microtime/.github/workflows/release.yml +76 -0
- package/node_modules/microtime/.github/workflows/test.yml +46 -0
- package/node_modules/microtime/README.md +0 -2
- package/node_modules/microtime/binding.gyp +28 -10
- package/node_modules/microtime/package.json +25 -20
- package/node_modules/microtime/prebuilds/darwin-x64+arm64/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/node.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-ia32/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-ia32/node.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/electron.napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/node.napi.node +0 -0
- package/node_modules/msgpackr/dist/index.js +1929 -1917
- package/node_modules/msgpackr/dist/index.min.js +67 -68
- package/node_modules/msgpackr/dist/node.cjs +1994 -1980
- package/node_modules/msgpackr/dist/test.js +683 -1235
- package/node_modules/msgpackr/index.d.ts +23 -12
- package/node_modules/msgpackr/node-index.js +23 -21
- package/node_modules/msgpackr/pack.js +935 -931
- package/node_modules/msgpackr/package.json +24 -12
- package/node_modules/msgpackr/unpack.d.ts +52 -50
- package/node_modules/msgpackr/unpack.js +1061 -1053
- package/node_modules/msgpackr-extract/bin/download-prebuilds.js +11 -0
- package/node_modules/msgpackr-extract/binding.gyp +22 -5
- package/node_modules/msgpackr-extract/index.js +1 -1
- package/node_modules/msgpackr-extract/package.json +46 -21
- package/node_modules/msgpackr-extract/src/.vs/ProjectSettings.json +3 -0
- package/node_modules/msgpackr-extract/src/.vs/VSWorkspaceState.json +7 -0
- package/node_modules/msgpackr-extract/src/.vs/slnx.sqlite +0 -0
- package/node_modules/msgpackr-extract/src/.vs/src/v16/.suo +0 -0
- package/node_modules/msgpackr-extract/src/.vs/src/v16/Browse.VC.db +0 -0
- package/node_modules/msgpackr-extract/{prebuilds/darwin-x64/node.abi72.node → src/.vs/src/v16/Browse.VC.db-shm} +0 -0
- package/node_modules/msgpackr-extract/src/.vs/src/v16/Browse.VC.db-wal +0 -0
- package/node_modules/msgpackr-extract/src/extract.cpp +272 -269
- package/node_modules/nan/package.json +0 -1
- package/node_modules/node-addon-api/README.md +146 -53
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +7 -41
- package/node_modules/node-addon-api/napi-inl.deprecated.h +8 -8
- package/node_modules/node-addon-api/napi-inl.h +2795 -633
- package/node_modules/node-addon-api/napi.h +1547 -597
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +203 -13
- package/node_modules/node-addon-api/tools/README.md +12 -6
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +4 -8
- package/node_modules/node-addon-api/tools/eslint-format.js +71 -0
- package/node_modules/node-gyp-build/README.md +17 -14
- package/node_modules/node-gyp-build/bin.js +28 -15
- package/node_modules/node-gyp-build/index.js +145 -34
- package/node_modules/node-gyp-build/package.json +18 -15
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/LICENSE +0 -0
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/README.md +0 -0
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/bin.js +1 -1
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/build-test.js +0 -0
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/index.js +17 -11
- package/node_modules/{lmdb-store/node_modules/node-gyp-build → node-gyp-build-optional-packages}/optional.js +0 -0
- package/node_modules/{msgpackr-extract/node_modules/node-gyp-build → node-gyp-build-optional-packages}/package.json +17 -17
- package/package.json +12 -11
- package/security/JWTObjects.jsc +0 -0
- package/security/auth.jsc +0 -0
- package/security/cryptoHash.jsc +0 -0
- package/security/data_objects/PermissionAttributeResponseObject.jsc +0 -0
- package/security/data_objects/PermissionResponseObject.jsc +0 -0
- package/security/data_objects/PermissionTableResponseObject.jsc +0 -0
- package/security/permissionsTranslator.jsc +0 -0
- package/security/role.jsc +0 -0
- package/security/tokenAuthentication.jsc +0 -0
- package/security/user.jsc +0 -0
- package/server/ClusteringOriginObject.jsc +0 -0
- package/server/JobObject.jsc +0 -0
- package/server/clustering/ClusterStatusObject.jsc +0 -0
- package/server/clustering/NodeObject.jsc +0 -0
- package/server/clustering/clusterUtilities.jsc +0 -0
- package/server/configuration.jsc +0 -0
- package/server/customFunctions/customFunctionsServer.jsc +0 -0
- package/server/customFunctions/helpers/getCORSOptions.jsc +0 -0
- package/server/customFunctions/helpers/getHeaderTimeoutConfig.jsc +0 -0
- package/server/customFunctions/helpers/getServerOptions.jsc +0 -0
- package/server/customFunctions/operations.jsc +0 -0
- package/server/customFunctions/operationsValidation.jsc +0 -0
- package/server/harperdb/hdbServer.jsc +0 -0
- package/server/ipc/IPCClient.jsc +0 -0
- package/server/ipc/hdbIpcServer.jsc +0 -0
- package/server/ipc/serverHandlers.jsc +0 -0
- package/server/ipc/utility/IPCEventObject.jsc +0 -0
- package/server/ipc/utility/ipcUtils.jsc +0 -0
- package/server/jobRunner.jsc +0 -0
- package/server/jobThread.jsc +0 -0
- package/server/jobs.jsc +0 -0
- package/server/serverHelpers/OperationFunctionObject.jsc +0 -0
- package/server/serverHelpers/requestTimePlugin.jsc +0 -0
- package/server/serverHelpers/serverHandlers.jsc +0 -0
- package/server/serverHelpers/serverUtilities.jsc +0 -0
- package/server/socketcluster/Server.jsc +0 -0
- package/server/socketcluster/broker.jsc +0 -0
- package/server/socketcluster/connector/HDBSocketConnector.jsc +0 -0
- package/server/socketcluster/connector/InterNodeSocketConnector.jsc +0 -0
- package/server/socketcluster/connector/SocketConnector.jsc +0 -0
- package/server/socketcluster/connector/spawnSCConnection.jsc +0 -0
- package/server/socketcluster/decisionMatrix/CoreDecisionMatrix.jsc +0 -0
- package/server/socketcluster/decisionMatrix/DecisionMatrixIF.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/AssignToHdbChildWorkerRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/CallRoomMsgHandlerRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/CleanDataObjectRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/CommandCollection.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/DummyRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/RulesIF.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/StripHdbHeaderRule.jsc +0 -0
- package/server/socketcluster/decisionMatrix/rules/TestRule.jsc +0 -0
- package/server/socketcluster/handlers/NodeConnectionsHandler.jsc +0 -0
- package/server/socketcluster/handlers/SCServer.jsc +0 -0
- package/server/socketcluster/handlers/ServerSocket.jsc +0 -0
- package/server/socketcluster/interNodeConnectionLauncher.jsc +0 -0
- package/server/socketcluster/messageQueue/MessageQueueIF.jsc +0 -0
- package/server/socketcluster/middleware/AuthMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/ConnectionNameCheckMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/GenericMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/MessagePrepMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/MiddlewareFactory.jsc +0 -0
- package/server/socketcluster/middleware/MiddlewareIF.jsc +0 -0
- package/server/socketcluster/middleware/OriginatorCheckMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/RequestDataValidMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/StampOriginatorMiddleware.jsc +0 -0
- package/server/socketcluster/middleware/StampRequestMiddleware.jsc +0 -0
- package/server/socketcluster/observer/EventableIF.jsc +0 -0
- package/server/socketcluster/room/AddUserRoom.jsc +0 -0
- package/server/socketcluster/room/AlterUserRoom.jsc +0 -0
- package/server/socketcluster/room/CoreRoom.jsc +0 -0
- package/server/socketcluster/room/CreateAttributeRoom.jsc +0 -0
- package/server/socketcluster/room/CreateSchemaRoom.jsc +0 -0
- package/server/socketcluster/room/CreateTableRoom.jsc +0 -0
- package/server/socketcluster/room/DropUserRoom.jsc +0 -0
- package/server/socketcluster/room/HDBNodeRoom.jsc +0 -0
- package/server/socketcluster/room/RoomIF.jsc +0 -0
- package/server/socketcluster/room/RoomMessageObjects.jsc +0 -0
- package/server/socketcluster/room/UsersRoom.jsc +0 -0
- package/server/socketcluster/room/WatchHDBWorkersRoom.jsc +0 -0
- package/server/socketcluster/room/WorkerRoom.jsc +0 -0
- package/server/socketcluster/room/roomFactory.jsc +0 -0
- package/server/socketcluster/socketClusterObjects.jsc +0 -0
- package/server/socketcluster/types.jsc +0 -0
- package/server/socketcluster/util/clusterData.jsc +0 -0
- package/server/socketcluster/util/socketClusterUtils.jsc +0 -0
- package/server/socketcluster/worker/ClusterWorker.jsc +0 -0
- package/server/socketcluster/worker/WorkerIF.jsc +0 -0
- package/server/socketcluster/worker/WorkerObjects.jsc +0 -0
- package/server/transactToClusteringUtilities.jsc +0 -0
- package/sqlTranslator/SelectValidator.jsc +0 -0
- package/sqlTranslator/alasqlFunctionImporter.jsc +0 -0
- package/sqlTranslator/conditionPatterns.jsc +0 -0
- package/sqlTranslator/deleteTranslator.jsc +0 -0
- package/sqlTranslator/index.jsc +0 -0
- package/sqlTranslator/sql_statement_bucket.jsc +0 -0
- package/upgrade/EnvironmentVariable.jsc +0 -0
- package/upgrade/UpgradeDirective.jsc +0 -0
- package/upgrade/UpgradeObjects.jsc +0 -0
- package/upgrade/directives/3-0-0.jsc +0 -0
- package/upgrade/directives/3-1-0.jsc +0 -0
- package/upgrade/directives/directivesController.jsc +0 -0
- package/upgrade/directives/upgrade_scripts/3_0_0_reindex_script.jsc +0 -0
- package/upgrade/directivesManager.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/DBIDefinition.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/OpenDBIObject.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/OpenEnvironmentObject.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/commonErrors.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/commonUtility.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/environmentUtility.jsc +0 -0
- package/upgrade/lmdb/nodeLMDB/terms.jsc +0 -0
- package/upgrade/upgradePrompt.jsc +0 -0
- package/upgrade/upgradeUtilities.jsc +0 -0
- package/utility/AWS/AWSConnector.jsc +0 -0
- package/utility/OperationFunctionCaller.jsc +0 -0
- package/utility/common_utils.jsc +0 -0
- package/utility/environment/SystemInformationObject.jsc +0 -0
- package/utility/environment/SystemInformationOperation.jsc +0 -0
- package/utility/environment/environmentManager.jsc +0 -0
- package/utility/environment/systemInformation.jsc +0 -0
- package/utility/errors/commonErrors.jsc +0 -0
- package/utility/errors/hdbError.jsc +0 -0
- package/utility/functions/date/dateFunctions.jsc +0 -0
- package/utility/functions/geo.jsc +0 -0
- package/utility/functions/math/avg.jsc +0 -0
- package/utility/functions/math/count.jsc +0 -0
- package/utility/functions/sql/alaSQLExtension.jsc +0 -0
- package/utility/functions/string/compare.jsc +0 -0
- package/utility/globalSchema.jsc +0 -0
- package/utility/hdbTerms.jsc +0 -0
- package/utility/install/checkJWTTokensExist.jsc +0 -0
- package/utility/install/installer.jsc +0 -0
- package/utility/install_user_permission.jsc +0 -0
- package/utility/lmdb/DBIDefinition.jsc +0 -0
- package/utility/lmdb/DeleteRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/InsertRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/OpenDBIObject.jsc +0 -0
- package/utility/lmdb/OpenEnvironmentObject.jsc +0 -0
- package/utility/lmdb/UpdateRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/UpsertRecordsResponseObject.jsc +0 -0
- package/utility/lmdb/cleanLMDBMap.jsc +0 -0
- package/utility/lmdb/commonUtility.jsc +0 -0
- package/utility/lmdb/deleteUtility.jsc +0 -0
- package/utility/lmdb/environmentUtility.jsc +0 -0
- package/utility/lmdb/searchCursorFunctions.jsc +0 -0
- package/utility/lmdb/searchUtility.jsc +0 -0
- package/utility/lmdb/terms.jsc +0 -0
- package/utility/lmdb/writeUtility.jsc +0 -0
- package/utility/logging/harper_logger.jsc +0 -0
- package/utility/mount_hdb.jsc +0 -0
- package/utility/npmUtilities.jsc +0 -0
- package/utility/operation_authorization.jsc +0 -0
- package/utility/password.jsc +0 -0
- package/utility/pm2/servicesConfig.jsc +0 -0
- package/utility/pm2/utilityFunctions.jsc +0 -0
- package/utility/psList.jsc +0 -0
- package/utility/registration/hdb_license.jsc +0 -0
- package/utility/registration/licenseObjects.jsc +0 -0
- package/utility/registration/registrationHandler.jsc +0 -0
- package/utility/scripts/restartHdb.jsc +0 -0
- package/utility/signalling.jsc +0 -0
- package/utility/system_info.jsc +0 -0
- package/validation/bulkDeleteValidator.jsc +0 -0
- package/validation/check_permissions.jsc +0 -0
- package/validation/clustering/configureValidator.jsc +0 -0
- package/validation/common_validators.jsc +0 -0
- package/validation/conditionalDeleteValidator.jsc +0 -0
- package/validation/deleteValidator.jsc +0 -0
- package/validation/fileLoadValidator.jsc +0 -0
- package/validation/insertValidator.jsc +0 -0
- package/validation/nodeSubscriptionValidator.jsc +0 -0
- package/validation/nodeValidator.jsc +0 -0
- package/validation/readLogValidator.jsc +0 -0
- package/validation/registration/license_key_object.jsc +0 -0
- package/validation/role_validation.jsc +0 -0
- package/validation/schemaMetadataValidator.jsc +0 -0
- package/validation/schema_validator.jsc +0 -0
- package/validation/searchValidator.jsc +0 -0
- package/validation/user_validation.jsc +0 -0
- package/validation/validationWrapper.jsc +0 -0
- package/node_modules/lmdb-store/build/Makefile +0 -324
- package/node_modules/lmdb-store/build/Release/.deps/Release/lmdb-store.node.d +0 -1
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.o.d +0 -6
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.o.d +0 -8
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.o.d +0 -8
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/dependencies/lz4/lib/lz4.o.d +0 -5
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/compression.o.d +0 -72
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/cursor.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/dbi.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/env.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/misc.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/node-lmdb.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/ordered-binary.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/txn.o.d +0 -73
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store/src/windows.o.d +0 -3
- package/node_modules/lmdb-store/build/Release/.deps/Release/obj.target/lmdb-store.node.d +0 -1
- package/node_modules/lmdb-store/build/Release/lmdb-store.node +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/chacha8.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/mdb.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lmdb/libraries/liblmdb/midl.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/dependencies/lz4/lib/lz4.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/compression.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/cursor.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/dbi.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/env.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/misc.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/node-lmdb.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/ordered-binary.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/txn.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store/src/windows.o +0 -0
- package/node_modules/lmdb-store/build/Release/obj.target/lmdb-store.node +0 -0
- package/node_modules/lmdb-store/build/binding.Makefile +0 -6
- package/node_modules/lmdb-store/build/config.gypi +0 -426
- package/node_modules/lmdb-store/build/lmdb-store.target.mk +0 -206
- package/node_modules/lmdb-store/node_modules/node-gyp-build/package.json +0 -60
- package/node_modules/lmdb-store/prebuilds/darwin-x64/electron.abi87.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi72.node +0 -0
- package/node_modules/lmdb-store/prebuilds/darwin-x64/node.abi88.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/electron.abi87.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi72.node +0 -0
- package/node_modules/lmdb-store/prebuilds/win32-x64/node.abi88.node +0 -0
- package/node_modules/microtime/prebuilds/darwin-x64/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/darwin-x64/node-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-arm/node-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/linux-x64/node-napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/electron-napi.node +0 -0
- package/node_modules/microtime/prebuilds/win32-x64/node-napi.node +0 -0
- package/node_modules/msgpackr-extract/.circleci/config.yml +0 -19
- package/node_modules/msgpackr-extract/.travis.yml +0 -30
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/LICENSE +0 -21
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/README.md +0 -58
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/bin.js +0 -77
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/build-test.js +0 -19
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/index.js +0 -202
- package/node_modules/msgpackr-extract/node_modules/node-gyp-build/optional.js +0 -7
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-arm64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi88.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/darwin-x64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-arm64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi102.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi72.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi72.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi83.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi88.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi93.musl.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/linux-x64/node.abi93.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/electron.abi98.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi102.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi72.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi83.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi88.node +0 -0
- package/node_modules/msgpackr-extract/prebuilds/win32-x64/node.abi93.node +0 -0
- package/node_modules/node-addon-api/.editorconfig +0 -8
- package/node_modules/node-addon-api/.travis.yml +0 -65
- package/node_modules/node-addon-api/CHANGELOG.md +0 -325
- package/node_modules/node-addon-api/CODE_OF_CONDUCT.md +0 -4
- package/node_modules/node-addon-api/CONTRIBUTING.md +0 -66
- package/node_modules/node-addon-api/appveyor.yml +0 -48
- package/node_modules/node-addon-api/doc/Doxyfile +0 -2450
- package/node_modules/node-addon-api/doc/array_buffer.md +0 -129
- package/node_modules/node-addon-api/doc/async_context.md +0 -76
- package/node_modules/node-addon-api/doc/async_operations.md +0 -31
- package/node_modules/node-addon-api/doc/async_worker.md +0 -397
- package/node_modules/node-addon-api/doc/basic_types.md +0 -415
- package/node_modules/node-addon-api/doc/bigint.md +0 -92
- package/node_modules/node-addon-api/doc/boolean.md +0 -64
- package/node_modules/node-addon-api/doc/buffer.md +0 -140
- package/node_modules/node-addon-api/doc/callback_scope.md +0 -54
- package/node_modules/node-addon-api/doc/callbackinfo.md +0 -97
- package/node_modules/node-addon-api/doc/checker-tool.md +0 -32
- package/node_modules/node-addon-api/doc/class_property_descriptor.md +0 -118
- package/node_modules/node-addon-api/doc/cmake-js.md +0 -19
- package/node_modules/node-addon-api/doc/conversion-tool.md +0 -28
- package/node_modules/node-addon-api/doc/creating_a_release.md +0 -62
- package/node_modules/node-addon-api/doc/dataview.md +0 -244
- package/node_modules/node-addon-api/doc/env.md +0 -63
- package/node_modules/node-addon-api/doc/error.md +0 -115
- package/node_modules/node-addon-api/doc/error_handling.md +0 -186
- package/node_modules/node-addon-api/doc/escapable_handle_scope.md +0 -82
- package/node_modules/node-addon-api/doc/external.md +0 -59
- package/node_modules/node-addon-api/doc/function.md +0 -294
- package/node_modules/node-addon-api/doc/function_reference.md +0 -238
- package/node_modules/node-addon-api/doc/generator.md +0 -13
- package/node_modules/node-addon-api/doc/handle_scope.md +0 -65
- package/node_modules/node-addon-api/doc/memory_management.md +0 -27
- package/node_modules/node-addon-api/doc/node-gyp.md +0 -82
- package/node_modules/node-addon-api/doc/number.md +0 -163
- package/node_modules/node-addon-api/doc/object.md +0 -202
- package/node_modules/node-addon-api/doc/object_lifetime_management.md +0 -83
- package/node_modules/node-addon-api/doc/object_reference.md +0 -117
- package/node_modules/node-addon-api/doc/object_wrap.md +0 -546
- package/node_modules/node-addon-api/doc/prebuild_tools.md +0 -16
- package/node_modules/node-addon-api/doc/promises.md +0 -74
- package/node_modules/node-addon-api/doc/property_descriptor.md +0 -231
- package/node_modules/node-addon-api/doc/range_error.md +0 -59
- package/node_modules/node-addon-api/doc/reference.md +0 -111
- package/node_modules/node-addon-api/doc/setup.md +0 -82
- package/node_modules/node-addon-api/doc/string.md +0 -89
- package/node_modules/node-addon-api/doc/symbol.md +0 -44
- package/node_modules/node-addon-api/doc/threadsafe_function.md +0 -303
- package/node_modules/node-addon-api/doc/type_error.md +0 -59
- package/node_modules/node-addon-api/doc/typed_array.md +0 -74
- package/node_modules/node-addon-api/doc/typed_array_of.md +0 -133
- package/node_modules/node-addon-api/doc/value.md +0 -269
- package/node_modules/node-addon-api/doc/version_management.md +0 -43
- package/node_modules/node-addon-api/doc/working_with_javascript_values.md +0 -14
- package/node_modules/node-addon-api/external-napi/node_api.h +0 -7
- package/node_modules/node-addon-api/src/node_api.cc +0 -3655
- package/node_modules/node-addon-api/src/node_api.gyp +0 -21
- package/node_modules/node-addon-api/src/node_api.h +0 -588
- package/node_modules/node-addon-api/src/node_api_types.h +0 -115
- package/node_modules/node-addon-api/src/node_internals.cc +0 -142
- package/node_modules/node-addon-api/src/node_internals.h +0 -157
- package/node_modules/node-addon-api/src/util-inl.h +0 -38
- package/node_modules/node-addon-api/src/util.h +0 -7
|
@@ -1,1525 +1,1525 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('path');
|
|
4
|
-
var mkdirp = require('mkdirp');
|
|
5
|
-
var rimraf = require('rimraf');
|
|
6
|
-
var chai = require('chai');
|
|
7
|
-
var fs = require('fs');
|
|
8
|
-
var should = chai.should();
|
|
9
|
-
var spawn = require('child_process').spawn;
|
|
10
|
-
var inspector = require('inspector')
|
|
11
|
-
//inspector.open(9330, null, true)
|
|
12
|
-
|
|
13
|
-
var lmdb = require('..');
|
|
14
|
-
const MAX_DB_SIZE = 256 * 1024 * 1024;
|
|
15
|
-
|
|
16
|
-
describe('Node.js LMDB Bindings', function() {
|
|
17
|
-
var testDirPath = path.resolve(__dirname, './testdata');
|
|
18
|
-
var testBackupDirPath = path.resolve(__dirname, './testdata/backup');
|
|
19
|
-
// just to make a reasonable sized chunk of data...
|
|
20
|
-
function expand(str) {
|
|
21
|
-
str = '(' + str + ')';
|
|
22
|
-
str = str + str;
|
|
23
|
-
str = str + str;
|
|
24
|
-
str = str + str;
|
|
25
|
-
str = str + str;
|
|
26
|
-
str = str + str;
|
|
27
|
-
return str;
|
|
28
|
-
}
|
|
29
|
-
before(function(done) {
|
|
30
|
-
// cleanup previous test directory
|
|
31
|
-
rimraf(testDirPath, function(err) {
|
|
32
|
-
if (err) {
|
|
33
|
-
return done(err);
|
|
34
|
-
}
|
|
35
|
-
// setup clean directory
|
|
36
|
-
mkdirp(testBackupDirPath).then(() => {
|
|
37
|
-
done();
|
|
38
|
-
}, error => done(error));
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
it('will construct, open and close an environment', function() {
|
|
42
|
-
this.timeout(10000);
|
|
43
|
-
var env = new lmdb.Env();
|
|
44
|
-
env.open({
|
|
45
|
-
path: testDirPath,
|
|
46
|
-
maxDbs: 10
|
|
47
|
-
});
|
|
48
|
-
env.close.should.be.a('function');
|
|
49
|
-
env.beginTxn.should.be.a('function');
|
|
50
|
-
env.openDbi.should.be.a('function');
|
|
51
|
-
env.sync.should.be.a('function');
|
|
52
|
-
env.resize.should.be.a('function');
|
|
53
|
-
env.stat.should.be.a('function');
|
|
54
|
-
env.info.should.be.a('function');
|
|
55
|
-
env.close();
|
|
56
|
-
});
|
|
57
|
-
it.skip('will open multiple environments and begin transactions', function() {
|
|
58
|
-
this.timeout(10000);
|
|
59
|
-
for (let i =0; i < 12; i++) {
|
|
60
|
-
var env = new lmdb.Env();
|
|
61
|
-
env.open({
|
|
62
|
-
path: testDirPath + '/data' + i + '.mdb',
|
|
63
|
-
noSubdir: true
|
|
64
|
-
});
|
|
65
|
-
env.beginTxn();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
describe('Basics', function() {
|
|
69
|
-
this.timeout(10000);
|
|
70
|
-
var env;
|
|
71
|
-
before(function() {
|
|
72
|
-
env = new lmdb.Env();
|
|
73
|
-
env.open({
|
|
74
|
-
path: testDirPath,
|
|
75
|
-
maxDbs: 10,
|
|
76
|
-
maxReaders: 422,
|
|
77
|
-
mapSize: MAX_DB_SIZE
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
after(function() {
|
|
81
|
-
env.close();
|
|
82
|
-
});
|
|
83
|
-
it('will attempt to create two write transactions', function () {
|
|
84
|
-
var wtxn1 = env.beginTxn();
|
|
85
|
-
(function() {
|
|
86
|
-
var wtxn2 = env.beginTxn();
|
|
87
|
-
}).should.throw("You have already opened a write transaction in the current process, can't open a second one.");
|
|
88
|
-
wtxn1.abort();
|
|
89
|
-
});
|
|
90
|
-
it('will open a database, begin a transaction and get/put/delete data', function() {
|
|
91
|
-
var dbi = env.openDbi({
|
|
92
|
-
name: 'mydb1',
|
|
93
|
-
create: true
|
|
94
|
-
});
|
|
95
|
-
var txn = env.beginTxn();
|
|
96
|
-
var data = txn.getUtf8(dbi, 'hello');
|
|
97
|
-
should.equal(data, undefined);
|
|
98
|
-
txn.putUtf8(dbi, 'hello', 'Hello world!');
|
|
99
|
-
var data2 = txn.getUtf8(dbi, 'hello');
|
|
100
|
-
data2.should.equal('Hello world!');
|
|
101
|
-
txn.del(dbi, 'hello');
|
|
102
|
-
var data3 = txn.getUtf8(dbi, 'hello');
|
|
103
|
-
should.equal(data3, undefined);
|
|
104
|
-
txn.commit();
|
|
105
|
-
dbi.close();
|
|
106
|
-
});
|
|
107
|
-
it('env.openDbi should throw an error when invalid parameters are passed', function() {
|
|
108
|
-
chai.assert.throw(function () {
|
|
109
|
-
env.openDbi();
|
|
110
|
-
});
|
|
111
|
-
chai.assert.throw(function () {
|
|
112
|
-
env.openDbi(null);
|
|
113
|
-
});
|
|
114
|
-
chai.assert.throw(function () {
|
|
115
|
-
env.openDbi(1);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
it('will open a database and empty the database without closing it', function() {
|
|
119
|
-
var dbi = env.openDbi({
|
|
120
|
-
name: 'mydb1',
|
|
121
|
-
create: true
|
|
122
|
-
});
|
|
123
|
-
dbi.drop({
|
|
124
|
-
justFreePages: true
|
|
125
|
-
});
|
|
126
|
-
dbi.close();
|
|
127
|
-
});
|
|
128
|
-
it('will open a database, begin a transaction and get/put/delete string data containing zeros', function() {
|
|
129
|
-
var dbi = env.openDbi({
|
|
130
|
-
name: 'mydb1x',
|
|
131
|
-
create: true
|
|
132
|
-
});
|
|
133
|
-
var txn = env.beginTxn();
|
|
134
|
-
var data = txn.getUtf8(dbi, 'hello');
|
|
135
|
-
should.equal(data, undefined);
|
|
136
|
-
txn.putUtf8(dbi, 'hello', 'Hello \0 world!');
|
|
137
|
-
var data2 = txn.getUtf8(dbi, 'hello');
|
|
138
|
-
data2.should.equal('Hello \0 world!');
|
|
139
|
-
txn.del(dbi, 'hello');
|
|
140
|
-
var data3 = txn.getUtf8(dbi, 'hello');
|
|
141
|
-
should.equal(data3, undefined);
|
|
142
|
-
txn.commit();
|
|
143
|
-
dbi.close();
|
|
144
|
-
});
|
|
145
|
-
it.skip('will check if UTF-16 Buffers can be read as strings', function() {
|
|
146
|
-
// The string we want to store using a buffer
|
|
147
|
-
var expectedString = 'Hello \0 world!';
|
|
148
|
-
|
|
149
|
-
// node-lmdb internally stores a terminating zero, so we need to manually emulate that here
|
|
150
|
-
// NOTE: this would NEVER work without 'utf16le'!
|
|
151
|
-
var buf = Buffer.from(expectedString + '\0', 'utf16le');
|
|
152
|
-
var key = 'hello';
|
|
153
|
-
|
|
154
|
-
// Open dbi and create cursor
|
|
155
|
-
var dbi = env.openDbi({
|
|
156
|
-
name: 'mydb1xx',
|
|
157
|
-
create: true
|
|
158
|
-
});
|
|
159
|
-
var txn = env.beginTxn();
|
|
160
|
-
|
|
161
|
-
// Check non-existence of the key
|
|
162
|
-
var data1 = txn.getBinary(dbi, key);
|
|
163
|
-
should.equal(data1, undefined);
|
|
164
|
-
|
|
165
|
-
// Store data as binary
|
|
166
|
-
txn.putBinary(dbi, key, buf);
|
|
167
|
-
|
|
168
|
-
// Retrieve data as binary and check
|
|
169
|
-
var data2 = txn.getBinary(dbi, key);
|
|
170
|
-
should.equal(buf.compare(data2), 0);
|
|
171
|
-
|
|
172
|
-
// Retrieve same data as string and check
|
|
173
|
-
var data3 = txn.getUtf8(dbi, key);
|
|
174
|
-
should.equal(data3, expectedString);
|
|
175
|
-
|
|
176
|
-
// Delete data
|
|
177
|
-
txn.del(dbi, key);
|
|
178
|
-
|
|
179
|
-
// Put new binary data without zero termination
|
|
180
|
-
txn.putBinary(dbi, key, Buffer.from(expectedString));
|
|
181
|
-
|
|
182
|
-
// Verify that you can't read it back as a string
|
|
183
|
-
(function () {
|
|
184
|
-
var data = txn.getUtf8(dbi, key);
|
|
185
|
-
}).should.throw('Invalid zero-terminated UTF-16 string');
|
|
186
|
-
|
|
187
|
-
// Delete data
|
|
188
|
-
txn.del(dbi, key);
|
|
189
|
-
|
|
190
|
-
// Verify non-existence of data
|
|
191
|
-
var data3 = txn.getBinary(dbi, key);
|
|
192
|
-
should.equal(data3, undefined);
|
|
193
|
-
|
|
194
|
-
txn.commit();
|
|
195
|
-
dbi.close();
|
|
196
|
-
});
|
|
197
|
-
it('will throw Javascript error if named database cannot be found', function () {
|
|
198
|
-
try {
|
|
199
|
-
env.openDbi({
|
|
200
|
-
name: 'does-not-exist',
|
|
201
|
-
create: false
|
|
202
|
-
});
|
|
203
|
-
} catch (err) {
|
|
204
|
-
err.should.be.an.instanceof(Error);
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
it('will get information about an environment', function() {
|
|
208
|
-
var info = env.info();
|
|
209
|
-
info.mapAddress.should.be.a('number');
|
|
210
|
-
info.mapSize.should.be.a('number');
|
|
211
|
-
info.lastPageNumber.should.be.a('number');
|
|
212
|
-
info.lastTxnId.should.be.a('number');
|
|
213
|
-
info.maxReaders.should.be.a('number');
|
|
214
|
-
info.numReaders.should.be.a('number');
|
|
215
|
-
|
|
216
|
-
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
217
|
-
should.equal(info.maxReaders, 422);
|
|
218
|
-
});
|
|
219
|
-
it('will check for open transactions before resizing the mapSize', function() {
|
|
220
|
-
var dbi = env.openDbi({
|
|
221
|
-
name: 'mydb1',
|
|
222
|
-
create: true
|
|
223
|
-
});
|
|
224
|
-
var info = env.info();
|
|
225
|
-
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
226
|
-
// Open write transaction
|
|
227
|
-
var txn = env.beginTxn();
|
|
228
|
-
try {
|
|
229
|
-
env.resize(info.mapSize * 2);
|
|
230
|
-
} catch (err) {
|
|
231
|
-
err.should.be.an.instanceof(Error);
|
|
232
|
-
}
|
|
233
|
-
txn.abort();
|
|
234
|
-
info = env.info();
|
|
235
|
-
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
236
|
-
dbi.close();
|
|
237
|
-
});
|
|
238
|
-
it('will resize the mapSize', function() {
|
|
239
|
-
var dbi = env.openDbi({
|
|
240
|
-
name: 'mydb1',
|
|
241
|
-
create: true
|
|
242
|
-
});
|
|
243
|
-
var info = env.info();
|
|
244
|
-
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
245
|
-
env.resize(info.mapSize * 2);
|
|
246
|
-
info = env.info();
|
|
247
|
-
should.equal(info.mapSize, 2 * MAX_DB_SIZE);
|
|
248
|
-
dbi.close();
|
|
249
|
-
});
|
|
250
|
-
it('will get statistics about an environment', function() {
|
|
251
|
-
var stat = env.stat();
|
|
252
|
-
stat.pageSize.should.be.a('number');
|
|
253
|
-
stat.treeDepth.should.be.a('number');
|
|
254
|
-
stat.treeBranchPageCount.should.be.a('number');
|
|
255
|
-
stat.treeLeafPageCount.should.be.a('number');
|
|
256
|
-
stat.entryCount.should.be.a('number');
|
|
257
|
-
});
|
|
258
|
-
it('will get statistics about a database', function() {
|
|
259
|
-
var dbi = env.openDbi({
|
|
260
|
-
name: 'mydb2',
|
|
261
|
-
create: true
|
|
262
|
-
});
|
|
263
|
-
var txn = env.beginTxn();
|
|
264
|
-
var stat = dbi.stat(txn);
|
|
265
|
-
stat.pageSize.should.be.a('number');
|
|
266
|
-
stat.treeDepth.should.be.a('number');
|
|
267
|
-
stat.treeBranchPageCount.should.be.a('number');
|
|
268
|
-
stat.treeLeafPageCount.should.be.a('number');
|
|
269
|
-
stat.entryCount.should.be.a('number');
|
|
270
|
-
txn.abort();
|
|
271
|
-
dbi.close();
|
|
272
|
-
});
|
|
273
|
-
it('will create a database with a user-supplied transaction', function () {
|
|
274
|
-
var txn = env.beginTxn();
|
|
275
|
-
var dbi = env.openDbi({
|
|
276
|
-
name: 'dbUsingUserSuppliedTxn',
|
|
277
|
-
create: true,
|
|
278
|
-
txn: txn
|
|
279
|
-
});
|
|
280
|
-
txn.putUtf8(dbi, 'hello', 'world');
|
|
281
|
-
txn.commit();
|
|
282
|
-
|
|
283
|
-
var txn = env.beginTxn({ readOnly: true });
|
|
284
|
-
var str = txn.getUtf8(dbi, 'hello');
|
|
285
|
-
should.equal(str, 'world');
|
|
286
|
-
|
|
287
|
-
txn.abort();
|
|
288
|
-
dbi.close();
|
|
289
|
-
});
|
|
290
|
-
it('will create a database and back it up', function (done) {
|
|
291
|
-
var txn = env.beginTxn();
|
|
292
|
-
var dbi = env.openDbi({
|
|
293
|
-
name: 'backup',
|
|
294
|
-
create: true,
|
|
295
|
-
txn: txn
|
|
296
|
-
});
|
|
297
|
-
txn.putUtf8(dbi, 'hello', 'world');
|
|
298
|
-
txn.commit();
|
|
299
|
-
env.copy(testBackupDirPath, true, (error) => {
|
|
300
|
-
done(error)
|
|
301
|
-
});
|
|
302
|
-
// console.log('sent copy')
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
describe('Data types', function() {
|
|
306
|
-
this.timeout(10000);
|
|
307
|
-
var env;
|
|
308
|
-
var dbi;
|
|
309
|
-
var txn;
|
|
310
|
-
before(function() {
|
|
311
|
-
env = new lmdb.Env();
|
|
312
|
-
env.open({
|
|
313
|
-
path: testDirPath,
|
|
314
|
-
maxDbs: 10
|
|
315
|
-
});
|
|
316
|
-
dbi = env.openDbi({
|
|
317
|
-
name: 'mydb3',
|
|
318
|
-
create: true,
|
|
319
|
-
useVersions: true,
|
|
320
|
-
compression: new lmdb.Compression({
|
|
321
|
-
threshold: 100,
|
|
322
|
-
dictionary: fs.readFileSync(require.resolve('../dict/dict.txt')),
|
|
323
|
-
})
|
|
324
|
-
});
|
|
325
|
-
txn = env.beginTxn();
|
|
326
|
-
});
|
|
327
|
-
after(function() {
|
|
328
|
-
txn.commit();
|
|
329
|
-
dbi.close();
|
|
330
|
-
env.close();
|
|
331
|
-
});
|
|
332
|
-
it('string', function() {
|
|
333
|
-
txn.putUtf8(dbi, 'key1', 'Hello world!');
|
|
334
|
-
var data = txn.getUtf8(dbi, 'key1');
|
|
335
|
-
data.should.equal('Hello world!');
|
|
336
|
-
txn.del(dbi, 'key1');
|
|
337
|
-
var data2 = txn.getUtf8(dbi, 'key1');
|
|
338
|
-
should.equal(data2, undefined);
|
|
339
|
-
});
|
|
340
|
-
it('string with non-latin characters', function() {
|
|
341
|
-
txn.putUtf8(dbi, 'k:中华人民共和', '中华人民共和');
|
|
342
|
-
var data = txn.getUtf8(dbi, 'k:中华人民共和');
|
|
343
|
-
data.should.equal('中华人民共和');
|
|
344
|
-
txn.del(dbi, 'k:中华人民共和');
|
|
345
|
-
var data2 = txn.getUtf8(dbi, 'k:中华人民共和');
|
|
346
|
-
should.equal(data2, undefined);
|
|
347
|
-
});
|
|
348
|
-
it('string with version', function() {
|
|
349
|
-
txn.putUtf8(dbi, 'key1', 'Hello world!', 334);
|
|
350
|
-
var data = txn.getUtf8(dbi, 'key1');
|
|
351
|
-
data.should.equal('Hello world!');
|
|
352
|
-
var lastVersion = lmdb.getLastVersion();
|
|
353
|
-
lastVersion.should.equal(334);
|
|
354
|
-
txn.del(dbi, 'key1');
|
|
355
|
-
var data2 = txn.getUtf8(dbi, 'key1');
|
|
356
|
-
should.equal(data2, undefined);
|
|
357
|
-
});
|
|
358
|
-
it('string with compression', function() {
|
|
359
|
-
let value = '{"id":34,"enabled":true,"title":"this is a test that should be using common words of our language and seeing if it is well compressed","children":[{"data":"some more"}]}'
|
|
360
|
-
for (let i = 0; i < 0; i++)
|
|
361
|
-
value += value;
|
|
362
|
-
txn.putUtf8(dbi, 'key1', value);
|
|
363
|
-
var data = txn.getUtf8(dbi, 'key1');
|
|
364
|
-
data.should.equal(value);
|
|
365
|
-
txn.del(dbi, 'key1');
|
|
366
|
-
var data2 = txn.getUtf8(dbi, 'key1');
|
|
367
|
-
should.equal(data2, undefined);
|
|
368
|
-
});
|
|
369
|
-
it('string with compression with version', function() {
|
|
370
|
-
let value = 'Hello world!'
|
|
371
|
-
for (let i = 0; i < 7; i++)
|
|
372
|
-
value += value;
|
|
373
|
-
txn.putUtf8(dbi, 'key1', value, 5555);
|
|
374
|
-
var data = txn.getUtf8(dbi, 'key1');
|
|
375
|
-
data.should.equal(value);
|
|
376
|
-
var lastVersion = lmdb.getLastVersion();
|
|
377
|
-
lastVersion.should.equal(5555);
|
|
378
|
-
txn.del(dbi, 'key1');
|
|
379
|
-
var data2 = txn.getUtf8(dbi, 'key1');
|
|
380
|
-
should.equal(data2, undefined);
|
|
381
|
-
});
|
|
382
|
-
it.skip('string (zero copy)', function() {
|
|
383
|
-
txn.putUtf8(dbi, 'key1', 'Hello world!');
|
|
384
|
-
var data = txn.getUtf8Unsafe(dbi, 'key1');
|
|
385
|
-
data.should.equal('Hello world!');
|
|
386
|
-
txn.del(dbi, 'key1');
|
|
387
|
-
var data2 = txn.getUtf8Unsafe(dbi, 'key1');
|
|
388
|
-
should.equal(data2, undefined);
|
|
389
|
-
});
|
|
390
|
-
it('binary', function() {
|
|
391
|
-
var buffer = new Buffer('48656c6c6f2c20776f726c6421', 'hex');
|
|
392
|
-
txn.putBinary(dbi, ['key2', 2], buffer);
|
|
393
|
-
var data = txn.getBinary(dbi, ['key2', 2]);
|
|
394
|
-
data.should.deep.equal(buffer);
|
|
395
|
-
txn.del(dbi, ['key2', 2]);
|
|
396
|
-
var data2 = txn.getBinary(dbi, ['key2', 2]);
|
|
397
|
-
should.equal(data2, undefined);
|
|
398
|
-
});
|
|
399
|
-
it('binary (zero copy)', function() {
|
|
400
|
-
var buffer = new Buffer('48656c6c6f2c20776f726c6421', 'hex');
|
|
401
|
-
txn.putBinary(dbi, 'key2', buffer);
|
|
402
|
-
var buffer2 = new Buffer('58636c6c6f2c20779f324c5414', 'hex');
|
|
403
|
-
txn.putBinary(dbi, 'key3', buffer2);
|
|
404
|
-
var length = txn.getBinaryUnsafe(dbi, 'key2');
|
|
405
|
-
var data = dbi.unsafeBuffer.slice(0, length);
|
|
406
|
-
data.toString()
|
|
407
|
-
//data.slice(0, buffer.length).should.deep.equal(buffer);
|
|
408
|
-
//env.detachBuffer(data.buffer);
|
|
409
|
-
var length = txn.getBinaryUnsafe(dbi, 'key3');
|
|
410
|
-
var data2 = dbi.unsafeBuffer.slice(0, length);
|
|
411
|
-
var byte = data[0]; // make sure we can access it
|
|
412
|
-
data.slice(0, buffer2.length).should.deep.equal(buffer2);
|
|
413
|
-
//env.detachBuffer(data.buffer);
|
|
414
|
-
txn.del(dbi, 'key2');
|
|
415
|
-
var data2 = txn.getBinaryUnsafe(dbi, 'key2');
|
|
416
|
-
should.equal(data2, undefined);
|
|
417
|
-
});
|
|
418
|
-
it('binary key', function() {
|
|
419
|
-
var buffer = new Buffer('48656c6c6f2c20776f726c6421', 'hex');
|
|
420
|
-
var key = new Buffer('key2');
|
|
421
|
-
txn.putBinary(dbi, key, buffer);
|
|
422
|
-
var data = txn.getBinary(dbi, key);
|
|
423
|
-
data.should.deep.equal(buffer);
|
|
424
|
-
txn.del(dbi, key, { keyIsBuffer: true });
|
|
425
|
-
var data2 = txn.getBinary(dbi, key);
|
|
426
|
-
should.equal(data2, undefined);
|
|
427
|
-
});
|
|
428
|
-
it.skip('number', function() {
|
|
429
|
-
txn.putNumber(dbi, 'key3', 900719925474099);
|
|
430
|
-
var data = txn.getNumber(dbi, 'key3');
|
|
431
|
-
data.should.equal(900719925474099);
|
|
432
|
-
txn.del(dbi, 'key3');
|
|
433
|
-
var data2 = txn.getNumber(dbi, 'key3');
|
|
434
|
-
should.equal(data2, undefined);
|
|
435
|
-
});
|
|
436
|
-
it('string and number key', function() {
|
|
437
|
-
txn.putUtf8(dbi, -2.4, 'Hello world!');
|
|
438
|
-
var data = txn.getUtf8(dbi, -2.4);
|
|
439
|
-
data.should.equal('Hello world!');
|
|
440
|
-
txn.del(dbi, -2.4);
|
|
441
|
-
var data2 = txn.getUtf8(dbi, -2.4);
|
|
442
|
-
should.equal(data2, undefined);
|
|
443
|
-
});
|
|
444
|
-
it('boolean', function() {
|
|
445
|
-
txn.putBoolean(dbi, 'key4', true);
|
|
446
|
-
var data = txn.getBoolean(dbi, 'key4');
|
|
447
|
-
data.should.equal(true);
|
|
448
|
-
txn.putBoolean(dbi, 'key5', false);
|
|
449
|
-
var data2 = txn.getBoolean(dbi, 'key5');
|
|
450
|
-
data2.should.equal(false);
|
|
451
|
-
txn.del(dbi, 'key4');
|
|
452
|
-
txn.del(dbi, 'key5');
|
|
453
|
-
var data3 = txn.getBoolean(dbi, 'key4');
|
|
454
|
-
var data4 = txn.getBoolean(dbi, 'key5');
|
|
455
|
-
should.equal(data3, undefined);
|
|
456
|
-
should.equal(data4, undefined);
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
describe('Multiple transactions', function() {
|
|
460
|
-
this.timeout(10000);
|
|
461
|
-
var env;
|
|
462
|
-
var dbi;
|
|
463
|
-
before(function() {
|
|
464
|
-
env = new lmdb.Env();
|
|
465
|
-
env.open({
|
|
466
|
-
path: testDirPath,
|
|
467
|
-
maxDbs: 10
|
|
468
|
-
});
|
|
469
|
-
dbi = env.openDbi({
|
|
470
|
-
name: 'mydb4',
|
|
471
|
-
create: true,
|
|
472
|
-
keyIsUint32: true
|
|
473
|
-
});
|
|
474
|
-
var txn = env.beginTxn();
|
|
475
|
-
txn.putUtf8(dbi, 1, 'Hello1');
|
|
476
|
-
txn.putUtf8(dbi, 2, 'Hello2');
|
|
477
|
-
txn.commit();
|
|
478
|
-
});
|
|
479
|
-
after(function() {
|
|
480
|
-
dbi.close();
|
|
481
|
-
env.close();
|
|
482
|
-
});
|
|
483
|
-
it('readonly transaction should not see uncommited changes', function() {
|
|
484
|
-
var readTxn = env.beginTxn({readOnly: true});
|
|
485
|
-
var data = readTxn.getUtf8(dbi, 1);
|
|
486
|
-
should.equal(data, 'Hello1');
|
|
487
|
-
|
|
488
|
-
var writeTxn = env.beginTxn();
|
|
489
|
-
writeTxn.putUtf8(dbi, 1, 'Ha ha ha');
|
|
490
|
-
|
|
491
|
-
var data2 = writeTxn.getUtf8(dbi, 1);
|
|
492
|
-
data2.should.equal('Ha ha ha');
|
|
493
|
-
|
|
494
|
-
var data3 = readTxn.getUtf8(dbi, 1);
|
|
495
|
-
should.equal(data3, 'Hello1');
|
|
496
|
-
|
|
497
|
-
writeTxn.commit();
|
|
498
|
-
var data4 = readTxn.getUtf8(dbi, 1);
|
|
499
|
-
should.equal(data4, 'Hello1');
|
|
500
|
-
|
|
501
|
-
readTxn.reset();
|
|
502
|
-
readTxn.renew();
|
|
503
|
-
var data5 = readTxn.getUtf8(dbi, 1);
|
|
504
|
-
should.equal(data5, 'Ha ha ha');
|
|
505
|
-
readTxn.abort();
|
|
506
|
-
});
|
|
507
|
-
it('readonly transaction will throw if tries to write', function() {
|
|
508
|
-
var readTxn = env.beginTxn({readOnly: true});
|
|
509
|
-
(function() {
|
|
510
|
-
readTxn.putUtf8(dbi, 2, 'hööhh');
|
|
511
|
-
}).should.throw('Permission denied');
|
|
512
|
-
readTxn.abort();
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
describe('Cursors, basic operation', function() {
|
|
516
|
-
this.timeout(10000);
|
|
517
|
-
var env;
|
|
518
|
-
var dbi;
|
|
519
|
-
var total = 5;
|
|
520
|
-
|
|
521
|
-
before(function() {
|
|
522
|
-
env = new lmdb.Env();
|
|
523
|
-
env.open({
|
|
524
|
-
path: testDirPath,
|
|
525
|
-
maxDbs: 10,
|
|
526
|
-
mapSize: MAX_DB_SIZE
|
|
527
|
-
});
|
|
528
|
-
dbi = env.openDbi({
|
|
529
|
-
name: 'cursor_verybasic',
|
|
530
|
-
create: true
|
|
531
|
-
});
|
|
532
|
-
const txn = env.beginTxn();
|
|
533
|
-
let count = 0;
|
|
534
|
-
while (count < total) {
|
|
535
|
-
let key = "hello\x1E_" + count.toString(16);
|
|
536
|
-
let data = key + "_data";
|
|
537
|
-
txn.putUtf8(dbi, key, data);
|
|
538
|
-
count++;
|
|
539
|
-
}
|
|
540
|
-
count = 0;
|
|
541
|
-
while (count < total) {
|
|
542
|
-
let key = count - 2
|
|
543
|
-
let data = key + "_data";
|
|
544
|
-
txn.putUtf8(dbi, key, data);
|
|
545
|
-
count++;
|
|
546
|
-
}
|
|
547
|
-
count = 0;
|
|
548
|
-
while (count < total) {
|
|
549
|
-
let key = ["hello_\x1B" + count.toString(16) + '\x1E', count];
|
|
550
|
-
let data = key + "_data";
|
|
551
|
-
txn.putUtf8(dbi, key, data);
|
|
552
|
-
count++;
|
|
553
|
-
}
|
|
554
|
-
count = 0;
|
|
555
|
-
while (count < total) {
|
|
556
|
-
let key = [count, "hello_" + count.toString(16)];
|
|
557
|
-
let data = key + "_data";
|
|
558
|
-
txn.putUtf8(dbi, key, data);
|
|
559
|
-
count++;
|
|
560
|
-
}
|
|
561
|
-
txn.commit();
|
|
562
|
-
});
|
|
563
|
-
it('will move cursor over values, expects to get correct key', function (done) {
|
|
564
|
-
var txn = env.beginTxn({ readOnly: true });
|
|
565
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
566
|
-
var count;
|
|
567
|
-
|
|
568
|
-
for (count = 0; count < total; count ++) {
|
|
569
|
-
var expectedKey = "hello\x1E_" + count.toString(16);
|
|
570
|
-
var key = cursor.goToKey(expectedKey);
|
|
571
|
-
should.equal(expectedKey, key);
|
|
572
|
-
}
|
|
573
|
-
for (count = 0; count < total; count ++) {
|
|
574
|
-
var expectedKey = count - 2;
|
|
575
|
-
var key = cursor.goToKey(expectedKey);
|
|
576
|
-
should.equal(expectedKey, key);
|
|
577
|
-
}
|
|
578
|
-
for (count = 0; count < total; count ++) {
|
|
579
|
-
var expectedKey = ["hello_\x1B" + count.toString(16) + '\x1E', count];
|
|
580
|
-
var key = cursor.goToKey(expectedKey);
|
|
581
|
-
should.equal(JSON.stringify(expectedKey), JSON.stringify(key));
|
|
582
|
-
}
|
|
583
|
-
for (count = 0; count < total; count ++) {
|
|
584
|
-
var expectedKey = [count, "hello_" + count.toString(16)];
|
|
585
|
-
var key = cursor.goToKey(expectedKey);
|
|
586
|
-
should.equal(JSON.stringify(expectedKey), JSON.stringify(key));
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
should.equal(count, total);
|
|
590
|
-
count = 0;
|
|
591
|
-
|
|
592
|
-
for (var key = cursor.goToFirst(); key != null; key = cursor.goToNext()) {
|
|
593
|
-
var key2 = cursor.goToKey(key);
|
|
594
|
-
should.equal(JSON.stringify(key), JSON.stringify(key2));
|
|
595
|
-
count ++;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
should.equal(count, total * 4);
|
|
599
|
-
|
|
600
|
-
cursor.close();
|
|
601
|
-
txn.abort();
|
|
602
|
-
|
|
603
|
-
done();
|
|
604
|
-
});
|
|
605
|
-
it.skip('will move cursor over values, expects to get correct key even if key is binary', function (done) {
|
|
606
|
-
var txn = env.beginTxn({ readOnly: true });
|
|
607
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
608
|
-
var count;
|
|
609
|
-
|
|
610
|
-
for (count = 0; count < total; count ++) {
|
|
611
|
-
var expectedKey = "hello_" + count.toString(16);
|
|
612
|
-
var binaryKey = new Buffer(expectedKey + "\0", "utf16le");
|
|
613
|
-
var key = cursor.goToKey(binaryKey);
|
|
614
|
-
should.equal(expectedKey, key);
|
|
615
|
-
should.equal(binaryKey.toString("utf16le"), key + "\0");
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
should.equal(count, total);
|
|
619
|
-
count = 0;
|
|
620
|
-
|
|
621
|
-
for (var key = cursor.goToFirst(); key; key = cursor.goToNext()) {
|
|
622
|
-
var key2 = cursor.goToKey(new Buffer(key + "\0", "utf16le"), { keyIsBuffer: true });
|
|
623
|
-
should.equal(key, key2);
|
|
624
|
-
count ++;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
should.equal(count, total);
|
|
628
|
-
|
|
629
|
-
cursor.close();
|
|
630
|
-
txn.abort();
|
|
631
|
-
|
|
632
|
-
done();
|
|
633
|
-
});
|
|
634
|
-
after(function () {
|
|
635
|
-
dbi.close();
|
|
636
|
-
env.close();
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
describe('Cursors', function() {
|
|
640
|
-
this.timeout(10000);
|
|
641
|
-
var env;
|
|
642
|
-
var dbi;
|
|
643
|
-
var total = 1000;
|
|
644
|
-
before(function() {
|
|
645
|
-
env = new lmdb.Env();
|
|
646
|
-
env.open({
|
|
647
|
-
path: testDirPath,
|
|
648
|
-
maxDbs: 10,
|
|
649
|
-
mapSize: MAX_DB_SIZE
|
|
650
|
-
});
|
|
651
|
-
dbi = env.openDbi({
|
|
652
|
-
name: 'mydb5',
|
|
653
|
-
create: true,
|
|
654
|
-
dupSort: false,
|
|
655
|
-
keyIsUint32: true
|
|
656
|
-
});
|
|
657
|
-
var txn = env.beginTxn();
|
|
658
|
-
var c = 0;
|
|
659
|
-
while(c < total) {
|
|
660
|
-
var buffer = new Buffer(new Array(8));
|
|
661
|
-
buffer.writeDoubleBE(c);
|
|
662
|
-
txn.putBinary(dbi, c, buffer);
|
|
663
|
-
c++;
|
|
664
|
-
}
|
|
665
|
-
txn.commit();
|
|
666
|
-
});
|
|
667
|
-
after(function() {
|
|
668
|
-
dbi.close();
|
|
669
|
-
env.close();
|
|
670
|
-
});
|
|
671
|
-
it('will move cursor over key/values', function(done) {
|
|
672
|
-
var txn = env.beginTxn();
|
|
673
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
674
|
-
cursor.goToKey(40);
|
|
675
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
676
|
-
key.should.equal(40);
|
|
677
|
-
value.readDoubleBE().should.equal(40);
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
var values = [];
|
|
681
|
-
cursor.goToKey(0);
|
|
682
|
-
function iterator() {
|
|
683
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
684
|
-
value.readDoubleBE().should.equal(values.length);
|
|
685
|
-
values.push(value);
|
|
686
|
-
});
|
|
687
|
-
cursor.goToNext();
|
|
688
|
-
if (values.length < total) {
|
|
689
|
-
// prevent maximum call stack errors
|
|
690
|
-
if (values.length % 1000 === 0) {
|
|
691
|
-
setImmediate(iterator);
|
|
692
|
-
} else {
|
|
693
|
-
iterator();
|
|
694
|
-
}
|
|
695
|
-
} else {
|
|
696
|
-
cursor.close();
|
|
697
|
-
txn.abort();
|
|
698
|
-
done();
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
iterator();
|
|
702
|
-
});
|
|
703
|
-
it.skip('will move cursor over key/values (zero copy)', function(done) {
|
|
704
|
-
var txn = env.beginTxn();
|
|
705
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
706
|
-
cursor.goToKey(40);
|
|
707
|
-
cursor.getCurrentBinaryUnsafe(function(key, value) {
|
|
708
|
-
key.should.equal(40);
|
|
709
|
-
value.readDoubleBE().should.equal(40);
|
|
710
|
-
});
|
|
711
|
-
var values = [];
|
|
712
|
-
cursor.goToKey(0);
|
|
713
|
-
function iterator() {
|
|
714
|
-
cursor.getCurrentBinaryUnsafe(function(key, value) {
|
|
715
|
-
value.readDoubleBE().should.equal(values.length);
|
|
716
|
-
values.push(value);
|
|
717
|
-
});
|
|
718
|
-
cursor.goToNext();
|
|
719
|
-
if (values.length < total) {
|
|
720
|
-
// prevent maximum call stack errors
|
|
721
|
-
if (values.length % 1000 === 0) {
|
|
722
|
-
setImmediate(iterator);
|
|
723
|
-
} else {
|
|
724
|
-
iterator();
|
|
725
|
-
}
|
|
726
|
-
} else {
|
|
727
|
-
cursor.close();
|
|
728
|
-
txn.abort();
|
|
729
|
-
done();
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
iterator();
|
|
733
|
-
});
|
|
734
|
-
it('will first/last key', function() {
|
|
735
|
-
var txn = env.beginTxn();
|
|
736
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
737
|
-
cursor.goToFirst();
|
|
738
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
739
|
-
key.should.equal(0);
|
|
740
|
-
value.readDoubleBE().should.equal(0);
|
|
741
|
-
});
|
|
742
|
-
cursor.goToLast();
|
|
743
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
744
|
-
key.should.equal(total - 1);
|
|
745
|
-
value.readDoubleBE().should.equal(total - 1);
|
|
746
|
-
});
|
|
747
|
-
cursor.close();
|
|
748
|
-
txn.abort();
|
|
749
|
-
});
|
|
750
|
-
});
|
|
751
|
-
describe.skip('Cursors, dupsort', function() {
|
|
752
|
-
this.timeout(10000);
|
|
753
|
-
var env;
|
|
754
|
-
var dbi;
|
|
755
|
-
var total = 50;
|
|
756
|
-
var dataCount = {};
|
|
757
|
-
|
|
758
|
-
before(function() {
|
|
759
|
-
env = new lmdb.Env();
|
|
760
|
-
env.open({
|
|
761
|
-
path: testDirPath,
|
|
762
|
-
maxDbs: 10,
|
|
763
|
-
mapSize: MAX_DB_SIZE
|
|
764
|
-
});
|
|
765
|
-
dbi = env.openDbi({
|
|
766
|
-
name: 'cursor_dupsort',
|
|
767
|
-
create: true,
|
|
768
|
-
dupSort: true
|
|
769
|
-
});
|
|
770
|
-
const txn = env.beginTxn();
|
|
771
|
-
var count;
|
|
772
|
-
for (count = 0; count < total; count ++) {
|
|
773
|
-
let key = "hello_" + count.toString(16);
|
|
774
|
-
let data = key + "_data";
|
|
775
|
-
dataCount[key] = (count % 4) + 1;
|
|
776
|
-
for (var j = 0; j < dataCount[key]; j++) {
|
|
777
|
-
txn.putUtf8(dbi, key, data + String(j));
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
txn.commit();
|
|
781
|
-
});
|
|
782
|
-
it('will move cursor over values, expects to get correct key and data', function (done) {
|
|
783
|
-
var txn = env.beginTxn({ readOnly: true });
|
|
784
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
785
|
-
var count;
|
|
786
|
-
|
|
787
|
-
for (count = 0; count < total; count ++) {
|
|
788
|
-
var expectedKey = "hello_" + count.toString(16);
|
|
789
|
-
var expectedDataX = expectedKey + "_data";
|
|
790
|
-
var key = cursor.goToRange(expectedKey);
|
|
791
|
-
should.equal(expectedKey, key);
|
|
792
|
-
|
|
793
|
-
var data = cursor.getCurrentUtf8();
|
|
794
|
-
should.equal(expectedDataX + "0", data);
|
|
795
|
-
|
|
796
|
-
var dc;
|
|
797
|
-
|
|
798
|
-
// Iterate over dup keys
|
|
799
|
-
dc = 0;
|
|
800
|
-
for (var k = cursor.goToFirstDup(); k; k = cursor.goToNextDup()) {
|
|
801
|
-
var data = cursor.getCurrentUtf8();
|
|
802
|
-
|
|
803
|
-
should.equal(expectedKey, k);
|
|
804
|
-
should.equal(expectedDataX + String(dc), data);
|
|
805
|
-
|
|
806
|
-
dc ++;
|
|
807
|
-
}
|
|
808
|
-
should.equal(dataCount[key], dc);
|
|
809
|
-
|
|
810
|
-
// Iterate over dup keys by using goToDup first
|
|
811
|
-
dc = 0;
|
|
812
|
-
for (var k = cursor.goToDup(expectedKey, expectedDataX + "0"); k; k = cursor.goToNextDup()) {
|
|
813
|
-
var data = cursor.getCurrentUtf8();
|
|
814
|
-
|
|
815
|
-
should.equal(expectedKey, k);
|
|
816
|
-
should.equal(expectedDataX + String(dc), data);
|
|
817
|
-
|
|
818
|
-
dc ++;
|
|
819
|
-
}
|
|
820
|
-
should.equal(dataCount[key], dc);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
should.equal(count, total);
|
|
824
|
-
count = 0;
|
|
825
|
-
|
|
826
|
-
cursor.close();
|
|
827
|
-
txn.abort();
|
|
828
|
-
|
|
829
|
-
done();
|
|
830
|
-
});
|
|
831
|
-
after(function () {
|
|
832
|
-
dbi.close();
|
|
833
|
-
env.close();
|
|
834
|
-
});
|
|
835
|
-
});
|
|
836
|
-
describe('Cursors (with strings)', function() {
|
|
837
|
-
this.timeout(10000);
|
|
838
|
-
var env;
|
|
839
|
-
var dbi;
|
|
840
|
-
var total = 1000;
|
|
841
|
-
before(function() {
|
|
842
|
-
env = new lmdb.Env();
|
|
843
|
-
env.open({
|
|
844
|
-
path: testDirPath,
|
|
845
|
-
maxDbs: 10,
|
|
846
|
-
mapSize: MAX_DB_SIZE
|
|
847
|
-
});
|
|
848
|
-
dbi = env.openDbi({
|
|
849
|
-
name: 'cursorstrings',
|
|
850
|
-
create: true,
|
|
851
|
-
dupSort: true,
|
|
852
|
-
//keyIsUint32: true
|
|
853
|
-
});
|
|
854
|
-
var txn = env.beginTxn();
|
|
855
|
-
var c = 0;
|
|
856
|
-
while(c < total) {
|
|
857
|
-
txn.putUtf8(dbi, c, c.toString());
|
|
858
|
-
c++;
|
|
859
|
-
}
|
|
860
|
-
txn.commit();
|
|
861
|
-
});
|
|
862
|
-
after(function() {
|
|
863
|
-
dbi.close();
|
|
864
|
-
env.close();
|
|
865
|
-
});
|
|
866
|
-
it.skip('will move cursor over key/values (zero copy)', function(done) {
|
|
867
|
-
var txn = env.beginTxn();
|
|
868
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
869
|
-
cursor.goToKey(40);
|
|
870
|
-
cursor.getCurrentStringUnsafe(function(key, value) {
|
|
871
|
-
key.should.equal(40);
|
|
872
|
-
value.should.equal('40');
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
var values = [];
|
|
876
|
-
cursor.goToKey(0);
|
|
877
|
-
function iterator() {
|
|
878
|
-
cursor.getCurrentStringUnsafe(function(key, value) {
|
|
879
|
-
value.should.equal(values.length.toString());
|
|
880
|
-
values.push(value);
|
|
881
|
-
});
|
|
882
|
-
cursor.goToNext();
|
|
883
|
-
if (values.length < total) {
|
|
884
|
-
// prevent maximum call stack errors
|
|
885
|
-
if (values.length % 1000 === 0) {
|
|
886
|
-
setImmediate(iterator);
|
|
887
|
-
} else {
|
|
888
|
-
iterator();
|
|
889
|
-
}
|
|
890
|
-
} else {
|
|
891
|
-
cursor.close();
|
|
892
|
-
txn.abort();
|
|
893
|
-
done();
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
iterator();
|
|
897
|
-
});
|
|
898
|
-
it('will move cursor over key/values', function(done) {
|
|
899
|
-
var txn = env.beginTxn();
|
|
900
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
901
|
-
cursor.goToKey(40);
|
|
902
|
-
cursor.getCurrentUtf8(function(key, value) {
|
|
903
|
-
key.should.equal(40);
|
|
904
|
-
value.should.equal('40');
|
|
905
|
-
});
|
|
906
|
-
var values = [];
|
|
907
|
-
cursor.goToKey(0);
|
|
908
|
-
function iterator() {
|
|
909
|
-
cursor.getCurrentUtf8(function(key, value) {
|
|
910
|
-
value.should.equal(values.length.toString());
|
|
911
|
-
values.push(value);
|
|
912
|
-
});
|
|
913
|
-
cursor.goToNext();
|
|
914
|
-
if (values.length < total) {
|
|
915
|
-
// prevent maximum call stack errors
|
|
916
|
-
if (values.length % 1000 === 0) {
|
|
917
|
-
setImmediate(iterator);
|
|
918
|
-
} else {
|
|
919
|
-
iterator();
|
|
920
|
-
}
|
|
921
|
-
} else {
|
|
922
|
-
cursor.close();
|
|
923
|
-
txn.abort();
|
|
924
|
-
done();
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
iterator();
|
|
928
|
-
});
|
|
929
|
-
it('will first/last key', function(done) {
|
|
930
|
-
var txn = env.beginTxn();
|
|
931
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
932
|
-
cursor.goToFirst();
|
|
933
|
-
cursor.getCurrentUtf8(function(key, value) {
|
|
934
|
-
key.should.equal(0);
|
|
935
|
-
value.should.equal('0');
|
|
936
|
-
});
|
|
937
|
-
cursor.goToLast();
|
|
938
|
-
cursor.getCurrentUtf8(function(key, value) {
|
|
939
|
-
key.should.equal(total - 1);
|
|
940
|
-
value.should.equal((total - 1).toString());
|
|
941
|
-
});
|
|
942
|
-
cursor.close();
|
|
943
|
-
txn.abort();
|
|
944
|
-
done();
|
|
945
|
-
});
|
|
946
|
-
});
|
|
947
|
-
|
|
948
|
-
describe('Remove last item', function() {
|
|
949
|
-
this.timeout(10000);
|
|
950
|
-
var env;
|
|
951
|
-
var dbi;
|
|
952
|
-
before(function() {
|
|
953
|
-
env = new lmdb.Env();
|
|
954
|
-
env.open({
|
|
955
|
-
path: testDirPath,
|
|
956
|
-
maxDbs: 10,
|
|
957
|
-
mapSize: MAX_DB_SIZE
|
|
958
|
-
});
|
|
959
|
-
dbi = env.openDbi({
|
|
960
|
-
name: 'removelast',
|
|
961
|
-
create: true,
|
|
962
|
-
keyIsBuffer: true
|
|
963
|
-
});
|
|
964
|
-
});
|
|
965
|
-
after(function() {
|
|
966
|
-
dbi.close();
|
|
967
|
-
env.close();
|
|
968
|
-
});
|
|
969
|
-
it('remove last entry', function() {
|
|
970
|
-
for (let i = 0; i < 10; i++) {
|
|
971
|
-
var readTxn = env.beginTxn({readOnly: true});
|
|
972
|
-
var txn = env.beginTxn();
|
|
973
|
-
txn.putBinary(dbi, Buffer.from([1]), Buffer.from([1]));
|
|
974
|
-
txn.putBinary(dbi, Buffer.from([2]), Buffer.from([1]));
|
|
975
|
-
txn.commit();
|
|
976
|
-
var txn = env.beginTxn();
|
|
977
|
-
txn.del(dbi, Buffer.from([1]));
|
|
978
|
-
txn.del(dbi, Buffer.from([2]));
|
|
979
|
-
txn.commit();
|
|
980
|
-
readTxn.commit();
|
|
981
|
-
}
|
|
982
|
-
})
|
|
983
|
-
});
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
describe('Cursors with binary key and data', function() {
|
|
987
|
-
this.timeout(10000);
|
|
988
|
-
var env;
|
|
989
|
-
var dbi;
|
|
990
|
-
var total = 1000;
|
|
991
|
-
let padding = '000000000';
|
|
992
|
-
let keyEnc = 'utf8';
|
|
993
|
-
let valueEnc = 'utf8';
|
|
994
|
-
|
|
995
|
-
before(function() {
|
|
996
|
-
env = new lmdb.Env();
|
|
997
|
-
env.open({
|
|
998
|
-
path: testDirPath,
|
|
999
|
-
maxDbs: 10,
|
|
1000
|
-
mapSize: MAX_DB_SIZE
|
|
1001
|
-
});
|
|
1002
|
-
dbi = env.openDbi({
|
|
1003
|
-
name: 'cursorbinkeydata',
|
|
1004
|
-
create: true,
|
|
1005
|
-
keyIsBuffer: true
|
|
1006
|
-
});
|
|
1007
|
-
const txn = env.beginTxn();
|
|
1008
|
-
let count = 0;
|
|
1009
|
-
while (count < total) {
|
|
1010
|
-
let keyStr = (padding + count).slice(-padding.length);
|
|
1011
|
-
let dataStr = expand(keyStr);
|
|
1012
|
-
let key = Buffer.from(keyStr,keyEnc);
|
|
1013
|
-
let data = Buffer.from(dataStr,valueEnc) // just for kicks.
|
|
1014
|
-
txn.putBinary(dbi, key, data);
|
|
1015
|
-
count++;
|
|
1016
|
-
}
|
|
1017
|
-
txn.commit();
|
|
1018
|
-
});
|
|
1019
|
-
after(function() {
|
|
1020
|
-
dbi.close();
|
|
1021
|
-
env.close();
|
|
1022
|
-
});
|
|
1023
|
-
it('will move cursor over key/values', function(done) {
|
|
1024
|
-
var txn = env.beginTxn();
|
|
1025
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
1026
|
-
let expectedKey = (padding + 40).slice(-padding.length);
|
|
1027
|
-
let key = Buffer.from(expectedKey,keyEnc);
|
|
1028
|
-
cursor.goToKey(key);
|
|
1029
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1030
|
-
let readKey = key.toString(keyEnc);
|
|
1031
|
-
let readValue = value.toString(valueEnc);
|
|
1032
|
-
readKey.should.equal(expectedKey);
|
|
1033
|
-
readValue.should.equal(expand(expectedKey));
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
let count = 0;
|
|
1037
|
-
key = cursor.goToFirst();
|
|
1038
|
-
// key is a string... bug...
|
|
1039
|
-
//(typeof key).should.not.equal('string');
|
|
1040
|
-
while (key && count < total+1) { //+1 to run off end if fails to return null
|
|
1041
|
-
let expectedKey = (padding + count).slice(-padding.length);
|
|
1042
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1043
|
-
(typeof key).should.not.equal('string');
|
|
1044
|
-
let readKey = key.toString(keyEnc);
|
|
1045
|
-
let readValue = value.toString(valueEnc);
|
|
1046
|
-
readKey.should.equal(expectedKey);
|
|
1047
|
-
readValue.should.equal(expand(expectedKey));
|
|
1048
|
-
});
|
|
1049
|
-
key = cursor.goToNext();
|
|
1050
|
-
(typeof key).should.not.equal('string');
|
|
1051
|
-
count++;
|
|
1052
|
-
}
|
|
1053
|
-
cursor.close();
|
|
1054
|
-
txn.commit();
|
|
1055
|
-
count.should.equal(total);
|
|
1056
|
-
done();
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
describe('Cursors reading existing binary key and data', function() {
|
|
1060
|
-
this.timeout(10000);
|
|
1061
|
-
var env;
|
|
1062
|
-
var dbi;
|
|
1063
|
-
var total = 1000;
|
|
1064
|
-
let padding = '000000000';
|
|
1065
|
-
let keyEnc = 'utf8';
|
|
1066
|
-
let valueEnc = 'utf8';
|
|
1067
|
-
|
|
1068
|
-
before(function() {
|
|
1069
|
-
env = new lmdb.Env();
|
|
1070
|
-
env.open({
|
|
1071
|
-
path: testDirPath,
|
|
1072
|
-
maxDbs: 10,
|
|
1073
|
-
mapSize: MAX_DB_SIZE
|
|
1074
|
-
});
|
|
1075
|
-
dbi = env.openDbi({
|
|
1076
|
-
name: 'cursorbinkeydata',
|
|
1077
|
-
create: false,
|
|
1078
|
-
keyIsBuffer: true
|
|
1079
|
-
});
|
|
1080
|
-
});
|
|
1081
|
-
|
|
1082
|
-
after(function() {
|
|
1083
|
-
dbi.close();
|
|
1084
|
-
env.close();
|
|
1085
|
-
});
|
|
1086
|
-
|
|
1087
|
-
it('will move cursor over existing key/values', function(done) {
|
|
1088
|
-
var txn = env.beginTxn();
|
|
1089
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
1090
|
-
let expectedKey = (padding + 40).slice(-padding.length);
|
|
1091
|
-
let key = Buffer.from(expectedKey,keyEnc);
|
|
1092
|
-
cursor.goToKey(key);
|
|
1093
|
-
let rvalue = cursor.getCurrentBinary(function(key, value) {
|
|
1094
|
-
(typeof key).should.not.equal('string');
|
|
1095
|
-
let readKey = key.toString(keyEnc);
|
|
1096
|
-
let readValue = value.toString(valueEnc);
|
|
1097
|
-
readKey.should.equal(expectedKey);
|
|
1098
|
-
readValue.should.equal(expand(expectedKey));
|
|
1099
|
-
});
|
|
1100
|
-
rvalue.toString(valueEnc).should.equal(expand(expectedKey));
|
|
1101
|
-
|
|
1102
|
-
let count = 0;
|
|
1103
|
-
key = cursor.goToFirst();
|
|
1104
|
-
(typeof key).should.not.equal('string');
|
|
1105
|
-
while (key && count < total+1) { //+1 to run off end if fails to return null
|
|
1106
|
-
let expectedKey = (padding + count).slice(-padding.length);
|
|
1107
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1108
|
-
let readKey = key.toString(keyEnc);
|
|
1109
|
-
let readValue = value.toString(valueEnc);
|
|
1110
|
-
readKey.should.equal(expectedKey);
|
|
1111
|
-
readValue.should.equal(expand(expectedKey));
|
|
1112
|
-
});
|
|
1113
|
-
key = cursor.goToNext();
|
|
1114
|
-
(typeof key).should.not.equal('string');
|
|
1115
|
-
count++;
|
|
1116
|
-
}
|
|
1117
|
-
cursor.close();
|
|
1118
|
-
txn.commit();
|
|
1119
|
-
count.should.equal(total);
|
|
1120
|
-
done();
|
|
1121
|
-
});
|
|
1122
|
-
});
|
|
1123
|
-
describe('Cluster', function() {
|
|
1124
|
-
this.timeout(10000);
|
|
1125
|
-
it('will run a cluster of processes with read-only transactions', function(done) {
|
|
1126
|
-
var child = spawn('node', [path.resolve(__dirname, './cluster')]);
|
|
1127
|
-
child.stdout.on('data', function(data) {
|
|
1128
|
-
console.log(data.toString());
|
|
1129
|
-
});
|
|
1130
|
-
child.stderr.on('data', function(data) {
|
|
1131
|
-
console.error(data.toString());
|
|
1132
|
-
});
|
|
1133
|
-
child.on('close', function(code) {
|
|
1134
|
-
code.should.equal(0);
|
|
1135
|
-
done();
|
|
1136
|
-
});
|
|
1137
|
-
});
|
|
1138
|
-
});
|
|
1139
|
-
describe('Threads', function() {
|
|
1140
|
-
this.timeout(10000);
|
|
1141
|
-
it('will run a group of threads with read-only transactions', function(done) {
|
|
1142
|
-
var child = spawn('node', [path.resolve(__dirname, './threads')]);
|
|
1143
|
-
child.stdout.on('data', function(data) {
|
|
1144
|
-
console.log(data.toString());
|
|
1145
|
-
});
|
|
1146
|
-
child.stderr.on('data', function(data) {
|
|
1147
|
-
console.error(data.toString());
|
|
1148
|
-
});
|
|
1149
|
-
child.on('close', function(code) {
|
|
1150
|
-
code.should.equal(0);
|
|
1151
|
-
done();
|
|
1152
|
-
});
|
|
1153
|
-
});
|
|
1154
|
-
});
|
|
1155
|
-
describe.skip('Dupsort', function () {
|
|
1156
|
-
this.timeout(10000);
|
|
1157
|
-
var env;
|
|
1158
|
-
var dbi;
|
|
1159
|
-
before(function() {
|
|
1160
|
-
env = new lmdb.Env();
|
|
1161
|
-
env.open({
|
|
1162
|
-
path: testDirPath,
|
|
1163
|
-
maxDbs: 10,
|
|
1164
|
-
mapSize: MAX_DB_SIZE
|
|
1165
|
-
});
|
|
1166
|
-
});
|
|
1167
|
-
after(function () {
|
|
1168
|
-
env.close();
|
|
1169
|
-
});
|
|
1170
|
-
beforeEach(function () {
|
|
1171
|
-
dbi = env.openDbi({
|
|
1172
|
-
name: 'testdb_dupsort',
|
|
1173
|
-
create: true,
|
|
1174
|
-
dupSort: true,
|
|
1175
|
-
dupFixed: false,
|
|
1176
|
-
keyIsBuffer: true
|
|
1177
|
-
});
|
|
1178
|
-
});
|
|
1179
|
-
afterEach(function () {
|
|
1180
|
-
dbi.drop();
|
|
1181
|
-
});
|
|
1182
|
-
it('will insert values with different lengths', function(done) {
|
|
1183
|
-
var txn = env.beginTxn();
|
|
1184
|
-
var value1 = new Buffer(new Array(8));
|
|
1185
|
-
var value2 = new Buffer(new Array(4));
|
|
1186
|
-
txn.putBinary(dbi, new Buffer('id'), value1);
|
|
1187
|
-
txn.putBinary(dbi, new Buffer('id'), value2);
|
|
1188
|
-
txn.commit();
|
|
1189
|
-
|
|
1190
|
-
var txn2 = env.beginTxn({readonly: true});
|
|
1191
|
-
var cursor = new lmdb.Cursor(txn2, dbi);
|
|
1192
|
-
var found = cursor.goToKey(new Buffer('id'));
|
|
1193
|
-
should.exist(found);
|
|
1194
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1195
|
-
key.toString().should.equal('id');
|
|
1196
|
-
value.length.should.equal(4);
|
|
1197
|
-
|
|
1198
|
-
cursor.goToNext();
|
|
1199
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1200
|
-
key.toString().should.equal('id');
|
|
1201
|
-
value.length.should.equal(8);
|
|
1202
|
-
cursor.close();
|
|
1203
|
-
txn2.abort();
|
|
1204
|
-
done();
|
|
1205
|
-
});
|
|
1206
|
-
});
|
|
1207
|
-
});
|
|
1208
|
-
it('will delete dupsort data correctly', function (done) {
|
|
1209
|
-
var txn;
|
|
1210
|
-
var cursor;
|
|
1211
|
-
var key;
|
|
1212
|
-
|
|
1213
|
-
// Add test data to database
|
|
1214
|
-
txn = env.beginTxn();
|
|
1215
|
-
txn.putNumber(dbi, 100, 1);
|
|
1216
|
-
txn.putNumber(dbi, 100, 2);
|
|
1217
|
-
txn.putNumber(dbi, 100, 3);
|
|
1218
|
-
txn.putNumber(dbi, 100, 4);
|
|
1219
|
-
txn.putNumber(dbi, 101, 1);
|
|
1220
|
-
txn.putNumber(dbi, 101, 2);
|
|
1221
|
-
txn.putNumber(dbi, 101, 3);
|
|
1222
|
-
txn.putNumber(dbi, 101, 4);
|
|
1223
|
-
txn.putNumber(dbi, 102, 1);
|
|
1224
|
-
txn.putNumber(dbi, 102, 2);
|
|
1225
|
-
txn.putNumber(dbi, 102, 3);
|
|
1226
|
-
txn.putNumber(dbi, 102, 4);
|
|
1227
|
-
txn.commit();
|
|
1228
|
-
|
|
1229
|
-
// Now delete some data
|
|
1230
|
-
txn = env.beginTxn();
|
|
1231
|
-
txn.del(dbi, 101, 2);
|
|
1232
|
-
txn.del(dbi, 101, 4);
|
|
1233
|
-
txn.del(dbi, 102, 1);
|
|
1234
|
-
txn.del(dbi, 102, 3);
|
|
1235
|
-
txn.commit();
|
|
1236
|
-
|
|
1237
|
-
// Verify data
|
|
1238
|
-
txn = env.beginTxn({ readOnly: true });
|
|
1239
|
-
cursor = new lmdb.Cursor(txn, dbi);
|
|
1240
|
-
cursor.goToFirst().readUInt32LE().should.equal(100);
|
|
1241
|
-
cursor.goToNext().readUInt32LE().should.equal(100);
|
|
1242
|
-
cursor.goToNext().readUInt32LE().should.equal(100);
|
|
1243
|
-
cursor.goToNext().readUInt32LE().should.equal(100);
|
|
1244
|
-
cursor.goToNext().readUInt32LE().should.equal(101);
|
|
1245
|
-
cursor.goToNext().readUInt32LE().should.equal(101);
|
|
1246
|
-
cursor.goToNext().readUInt32LE().should.equal(102);
|
|
1247
|
-
cursor.goToNext().readUInt32LE().should.equal(102);
|
|
1248
|
-
should.equal(cursor.goToNext(), undefined);
|
|
1249
|
-
|
|
1250
|
-
txn.abort();
|
|
1251
|
-
|
|
1252
|
-
done();
|
|
1253
|
-
});
|
|
1254
|
-
});
|
|
1255
|
-
describe('Dupfixed', function() {
|
|
1256
|
-
this.timeout(10000);
|
|
1257
|
-
var env;
|
|
1258
|
-
var dbi;
|
|
1259
|
-
before(function() {
|
|
1260
|
-
env = new lmdb.Env();
|
|
1261
|
-
env.open({
|
|
1262
|
-
path: testDirPath,
|
|
1263
|
-
maxDbs: 10,
|
|
1264
|
-
mapSize: MAX_DB_SIZE
|
|
1265
|
-
});
|
|
1266
|
-
dbi = env.openDbi({
|
|
1267
|
-
name: 'mydb7',
|
|
1268
|
-
create: true,
|
|
1269
|
-
dupSort: true,
|
|
1270
|
-
dupFixed: true,
|
|
1271
|
-
keyIsBuffer: true
|
|
1272
|
-
});
|
|
1273
|
-
});
|
|
1274
|
-
after(function() {
|
|
1275
|
-
dbi.close();
|
|
1276
|
-
env.close();
|
|
1277
|
-
});
|
|
1278
|
-
it('will insert values with the same length (inserted with different lengths)', function(done) {
|
|
1279
|
-
var txn = env.beginTxn();
|
|
1280
|
-
var value1 = new Buffer(new Array(4));
|
|
1281
|
-
value1.writeUInt32BE(100);
|
|
1282
|
-
var value2 = new Buffer(new Array(8));
|
|
1283
|
-
value2.writeUInt32BE(200);
|
|
1284
|
-
txn.putBinary(dbi, new Buffer('id'), value1);
|
|
1285
|
-
txn.putBinary(dbi, new Buffer('id'), value2);
|
|
1286
|
-
txn.commit();
|
|
1287
|
-
|
|
1288
|
-
var txn2 = env.beginTxn({readonly: true});
|
|
1289
|
-
var cursor = new lmdb.Cursor(txn2, dbi);
|
|
1290
|
-
var found = cursor.goToKey(new Buffer('id'));
|
|
1291
|
-
should.exist(found);
|
|
1292
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1293
|
-
key.toString().should.equal('id');
|
|
1294
|
-
value.length.should.equal(8);
|
|
1295
|
-
|
|
1296
|
-
cursor.goToNext();
|
|
1297
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1298
|
-
key.toString().should.equal('id');
|
|
1299
|
-
value.length.should.equal(8);
|
|
1300
|
-
cursor.close();
|
|
1301
|
-
txn2.abort();
|
|
1302
|
-
done();
|
|
1303
|
-
});
|
|
1304
|
-
});
|
|
1305
|
-
});
|
|
1306
|
-
});
|
|
1307
|
-
describe('Memory Freeing / Garbage Collection', function() {
|
|
1308
|
-
it('should not cause a segment fault', function(done) {
|
|
1309
|
-
var expectedKey = new Buffer('822285ee315d2b04');
|
|
1310
|
-
var expectedValue = new Buffer('ec65d632d9168c33350ed31a30848d01e95172931e90984c218ef6b08c1fa90a', 'hex');
|
|
1311
|
-
var env = new lmdb.Env();
|
|
1312
|
-
env.open({
|
|
1313
|
-
path: testDirPath,
|
|
1314
|
-
maxDbs: 12,
|
|
1315
|
-
mapSize: MAX_DB_SIZE
|
|
1316
|
-
});
|
|
1317
|
-
var dbi = env.openDbi({
|
|
1318
|
-
name: 'testfree',
|
|
1319
|
-
create: true,
|
|
1320
|
-
keyIsBuffer: true
|
|
1321
|
-
});
|
|
1322
|
-
var txn = env.beginTxn();
|
|
1323
|
-
txn.putBinary(dbi, expectedKey, expectedValue);
|
|
1324
|
-
txn.commit();
|
|
1325
|
-
var txn2 = env.beginTxn();
|
|
1326
|
-
var cursor = new lmdb.Cursor(txn2, dbi);
|
|
1327
|
-
var key;
|
|
1328
|
-
var value;
|
|
1329
|
-
cursor.goToFirst();
|
|
1330
|
-
cursor.getCurrentBinary(function(returnKey, returnValue) {
|
|
1331
|
-
key = returnKey;
|
|
1332
|
-
value = returnValue;
|
|
1333
|
-
});
|
|
1334
|
-
cursor.close();
|
|
1335
|
-
txn2.abort();
|
|
1336
|
-
dbi.close();
|
|
1337
|
-
env.close();
|
|
1338
|
-
key.should.deep.equal(expectedKey);
|
|
1339
|
-
value.compare(expectedValue).should.equal(0);
|
|
1340
|
-
done();
|
|
1341
|
-
});
|
|
1342
|
-
});
|
|
1343
|
-
describe('Type Conversion', function() {
|
|
1344
|
-
var env;
|
|
1345
|
-
var dbi;
|
|
1346
|
-
var expectedKey = new Buffer('822285ee315d2b04', 'hex');
|
|
1347
|
-
var expectedValue = new Buffer('ec65d632d9168c33350ed31a30848d01e95172931e90984c218ef6b08c1fa90a', 'hex');
|
|
1348
|
-
before(function() {
|
|
1349
|
-
env = new lmdb.Env();
|
|
1350
|
-
env.open({
|
|
1351
|
-
path: testDirPath,
|
|
1352
|
-
maxDbs: 12,
|
|
1353
|
-
mapSize: MAX_DB_SIZE
|
|
1354
|
-
});
|
|
1355
|
-
dbi = env.openDbi({
|
|
1356
|
-
name: 'testkeys',
|
|
1357
|
-
create: true,
|
|
1358
|
-
keyIsBuffer: true
|
|
1359
|
-
});
|
|
1360
|
-
var txn = env.beginTxn();
|
|
1361
|
-
txn.putBinary(dbi, expectedKey, expectedValue);
|
|
1362
|
-
txn.commit();
|
|
1363
|
-
});
|
|
1364
|
-
after(function() {
|
|
1365
|
-
dbi.close();
|
|
1366
|
-
env.close();
|
|
1367
|
-
});
|
|
1368
|
-
it('will be able to convert key to buffer', function(done) {
|
|
1369
|
-
var txn = env.beginTxn();
|
|
1370
|
-
var cursor = new lmdb.Cursor(txn, dbi);
|
|
1371
|
-
cursor.goToFirst();
|
|
1372
|
-
cursor.getCurrentBinary(function(key, value) {
|
|
1373
|
-
var keyBuffer = new Buffer(key);
|
|
1374
|
-
cursor.close();
|
|
1375
|
-
txn.abort();
|
|
1376
|
-
keyBuffer.compare(expectedKey).should.equal(0);
|
|
1377
|
-
value.compare(expectedValue).should.equal(0);
|
|
1378
|
-
done();
|
|
1379
|
-
});
|
|
1380
|
-
});
|
|
1381
|
-
});
|
|
1382
|
-
describe('Sync', function() {
|
|
1383
|
-
var env;
|
|
1384
|
-
var dbi;
|
|
1385
|
-
before(function() {
|
|
1386
|
-
env = new lmdb.Env();
|
|
1387
|
-
env.open({
|
|
1388
|
-
path: testDirPath,
|
|
1389
|
-
maxDbs: 12,
|
|
1390
|
-
mapSize: MAX_DB_SIZE
|
|
1391
|
-
});
|
|
1392
|
-
dbi = env.openDbi({
|
|
1393
|
-
name: 'testsync',
|
|
1394
|
-
create: true,
|
|
1395
|
-
keyIsBuffer: true
|
|
1396
|
-
});
|
|
1397
|
-
});
|
|
1398
|
-
after(function() {
|
|
1399
|
-
dbi.close();
|
|
1400
|
-
env.close();
|
|
1401
|
-
});
|
|
1402
|
-
it('should not block promise callbacks', function(done) {
|
|
1403
|
-
var timeoutResult
|
|
1404
|
-
new Promise(resolve => {
|
|
1405
|
-
env.sync(() => {
|
|
1406
|
-
resolve();
|
|
1407
|
-
})
|
|
1408
|
-
}).then(() => {
|
|
1409
|
-
// this should execute immediately after it is synced, before the timeout, so timeoutResult should be undefined
|
|
1410
|
-
done(timeoutResult)
|
|
1411
|
-
});
|
|
1412
|
-
setTimeout(() => {
|
|
1413
|
-
timeoutResult = 'Timeout occurred'
|
|
1414
|
-
}, 100);
|
|
1415
|
-
});
|
|
1416
|
-
});
|
|
1417
|
-
describe('batch', function() {
|
|
1418
|
-
this.timeout(10000);
|
|
1419
|
-
var env;
|
|
1420
|
-
before(function() {
|
|
1421
|
-
env = new lmdb.Env();
|
|
1422
|
-
env.open({
|
|
1423
|
-
path: testDirPath,
|
|
1424
|
-
maxDbs: 10,
|
|
1425
|
-
maxReaders: 422,
|
|
1426
|
-
mapSize: MAX_DB_SIZE
|
|
1427
|
-
});
|
|
1428
|
-
});
|
|
1429
|
-
after(function() {
|
|
1430
|
-
env.close();
|
|
1431
|
-
});
|
|
1432
|
-
it.skip('will batchWrite binary data and read it', function(done) {
|
|
1433
|
-
var dbi = env.openDbi({
|
|
1434
|
-
name: 'mydb8',
|
|
1435
|
-
create: true
|
|
1436
|
-
});
|
|
1437
|
-
var data = [
|
|
1438
|
-
[ dbi, Buffer.from([47]), Buffer.from([1, 2]), Buffer.from([5, 2]) ],
|
|
1439
|
-
[ dbi, Buffer.from([4]), Buffer.from([1, 2]) ],
|
|
1440
|
-
[ dbi, Buffer.from([5]), Buffer.from([3, 4]) ],
|
|
1441
|
-
[ dbi, Buffer.from([6]), Buffer.from([5, 6]) ],
|
|
1442
|
-
[ dbi, Buffer.from([7]) ],
|
|
1443
|
-
[ dbi, Buffer.from([6]), Buffer.from([7, 8]), Buffer.from([1, 1]) ],
|
|
1444
|
-
[ dbi, Buffer.from([6]), Buffer.from([7, 8]), Buffer.from([5]) ],
|
|
1445
|
-
{
|
|
1446
|
-
db: dbi,
|
|
1447
|
-
key: Buffer.from([5]),
|
|
1448
|
-
value: Buffer.from([8, 9]),
|
|
1449
|
-
ifValue: Buffer.from([7]),
|
|
1450
|
-
ifKey: Buffer.from([6]),
|
|
1451
|
-
ifExactMatch: false,
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1454
|
-
];
|
|
1455
|
-
env.batchWrite(data, { keyIsBuffer: true, progress(results) {
|
|
1456
|
-
//console.log('progress', results)
|
|
1457
|
-
} }, function(error, results) {
|
|
1458
|
-
if (error) {
|
|
1459
|
-
should.fail(error);
|
|
1460
|
-
return done();
|
|
1461
|
-
}
|
|
1462
|
-
results.should.deep.equal([ 1, 0, 0, 0, 2, 1, 0, 0 ]);
|
|
1463
|
-
|
|
1464
|
-
var txn = env.beginTxn();
|
|
1465
|
-
var expectedData = [
|
|
1466
|
-
[ Buffer.from([4]), Buffer.from([1, 2]) ],
|
|
1467
|
-
[ Buffer.from([5]), Buffer.from([8, 9]) ],
|
|
1468
|
-
[ Buffer.from([7]) ],
|
|
1469
|
-
[ Buffer.from([6]), Buffer.from([7, 8]) ],
|
|
1470
|
-
];
|
|
1471
|
-
for (var i = 0; i < expectedData.length; i++) {
|
|
1472
|
-
var key = expectedData[i][0];
|
|
1473
|
-
var value = expectedData[i][1];
|
|
1474
|
-
if (value) {
|
|
1475
|
-
should.equal(value.equals(txn.getBinary(dbi, key)), true);
|
|
1476
|
-
}
|
|
1477
|
-
else
|
|
1478
|
-
should.equal(txn.getBinary(dbi, key), undefined);
|
|
1479
|
-
}
|
|
1480
|
-
txn.commit();
|
|
1481
|
-
dbi.close();
|
|
1482
|
-
done();
|
|
1483
|
-
});
|
|
1484
|
-
});
|
|
1485
|
-
it('will batchWrite strings and read it', function(done) {
|
|
1486
|
-
var dbi = env.openDbi({
|
|
1487
|
-
name: 'mydb8',
|
|
1488
|
-
create: true,
|
|
1489
|
-
useVersions: true,
|
|
1490
|
-
});
|
|
1491
|
-
var data = [
|
|
1492
|
-
dbi,
|
|
1493
|
-
[ 'key 1', 'this is a test 1', 546 ],
|
|
1494
|
-
[ 'key 2', 'this is a test 2', 444 ],
|
|
1495
|
-
[ 'key 3', 'this is a test 3', 643 ]
|
|
1496
|
-
];
|
|
1497
|
-
var results = Buffer.alloc(3)
|
|
1498
|
-
env.batchWrite(data, results, function(error) {
|
|
1499
|
-
if (error) {
|
|
1500
|
-
should.fail(error);
|
|
1501
|
-
return done();
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
var txn = env.beginTxn();
|
|
1505
|
-
for (var i = 0; i < data.length; i++) {
|
|
1506
|
-
if (!data[i].length)
|
|
1507
|
-
continue
|
|
1508
|
-
var key = data[i][0];
|
|
1509
|
-
var value = data[i][1];
|
|
1510
|
-
var version = data[i][2];
|
|
1511
|
-
if (value)
|
|
1512
|
-
value.should.equal(txn.getUtf8(dbi, key));
|
|
1513
|
-
else
|
|
1514
|
-
should.equal(txn.getUtf8(dbi, key), undefined);
|
|
1515
|
-
if (version)
|
|
1516
|
-
version.should.equal(lmdb.getLastVersion())
|
|
1517
|
-
}
|
|
1518
|
-
txn.commit();
|
|
1519
|
-
dbi.close();
|
|
1520
|
-
done();
|
|
1521
|
-
});
|
|
1522
|
-
console.log('submitted batch')
|
|
1523
|
-
});
|
|
1524
|
-
});
|
|
1525
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var mkdirp = require('mkdirp');
|
|
5
|
+
var rimraf = require('rimraf');
|
|
6
|
+
var chai = require('chai');
|
|
7
|
+
var fs = require('fs');
|
|
8
|
+
var should = chai.should();
|
|
9
|
+
var spawn = require('child_process').spawn;
|
|
10
|
+
var inspector = require('inspector')
|
|
11
|
+
//inspector.open(9330, null, true)
|
|
12
|
+
|
|
13
|
+
var lmdb = require('..');
|
|
14
|
+
const MAX_DB_SIZE = 256 * 1024 * 1024;
|
|
15
|
+
|
|
16
|
+
describe('Node.js LMDB Bindings', function() {
|
|
17
|
+
var testDirPath = path.resolve(__dirname, './testdata');
|
|
18
|
+
var testBackupDirPath = path.resolve(__dirname, './testdata/backup');
|
|
19
|
+
// just to make a reasonable sized chunk of data...
|
|
20
|
+
function expand(str) {
|
|
21
|
+
str = '(' + str + ')';
|
|
22
|
+
str = str + str;
|
|
23
|
+
str = str + str;
|
|
24
|
+
str = str + str;
|
|
25
|
+
str = str + str;
|
|
26
|
+
str = str + str;
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
before(function(done) {
|
|
30
|
+
// cleanup previous test directory
|
|
31
|
+
rimraf(testDirPath, function(err) {
|
|
32
|
+
if (err) {
|
|
33
|
+
return done(err);
|
|
34
|
+
}
|
|
35
|
+
// setup clean directory
|
|
36
|
+
mkdirp(testBackupDirPath).then(() => {
|
|
37
|
+
done();
|
|
38
|
+
}, error => done(error));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('will construct, open and close an environment', function() {
|
|
42
|
+
this.timeout(10000);
|
|
43
|
+
var env = new lmdb.Env();
|
|
44
|
+
env.open({
|
|
45
|
+
path: testDirPath,
|
|
46
|
+
maxDbs: 10
|
|
47
|
+
});
|
|
48
|
+
env.close.should.be.a('function');
|
|
49
|
+
env.beginTxn.should.be.a('function');
|
|
50
|
+
env.openDbi.should.be.a('function');
|
|
51
|
+
env.sync.should.be.a('function');
|
|
52
|
+
env.resize.should.be.a('function');
|
|
53
|
+
env.stat.should.be.a('function');
|
|
54
|
+
env.info.should.be.a('function');
|
|
55
|
+
env.close();
|
|
56
|
+
});
|
|
57
|
+
it.skip('will open multiple environments and begin transactions', function() {
|
|
58
|
+
this.timeout(10000);
|
|
59
|
+
for (let i =0; i < 12; i++) {
|
|
60
|
+
var env = new lmdb.Env();
|
|
61
|
+
env.open({
|
|
62
|
+
path: testDirPath + '/data' + i + '.mdb',
|
|
63
|
+
noSubdir: true
|
|
64
|
+
});
|
|
65
|
+
env.beginTxn();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
describe('Basics', function() {
|
|
69
|
+
this.timeout(10000);
|
|
70
|
+
var env;
|
|
71
|
+
before(function() {
|
|
72
|
+
env = new lmdb.Env();
|
|
73
|
+
env.open({
|
|
74
|
+
path: testDirPath,
|
|
75
|
+
maxDbs: 10,
|
|
76
|
+
maxReaders: 422,
|
|
77
|
+
mapSize: MAX_DB_SIZE
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
after(function() {
|
|
81
|
+
env.close();
|
|
82
|
+
});
|
|
83
|
+
it('will attempt to create two write transactions', function () {
|
|
84
|
+
var wtxn1 = env.beginTxn();
|
|
85
|
+
(function() {
|
|
86
|
+
var wtxn2 = env.beginTxn();
|
|
87
|
+
}).should.throw("You have already opened a write transaction in the current process, can't open a second one.");
|
|
88
|
+
wtxn1.abort();
|
|
89
|
+
});
|
|
90
|
+
it('will open a database, begin a transaction and get/put/delete data', function() {
|
|
91
|
+
var dbi = env.openDbi({
|
|
92
|
+
name: 'mydb1',
|
|
93
|
+
create: true
|
|
94
|
+
});
|
|
95
|
+
var txn = env.beginTxn();
|
|
96
|
+
var data = txn.getUtf8(dbi, 'hello');
|
|
97
|
+
should.equal(data, undefined);
|
|
98
|
+
txn.putUtf8(dbi, 'hello', 'Hello world!');
|
|
99
|
+
var data2 = txn.getUtf8(dbi, 'hello');
|
|
100
|
+
data2.should.equal('Hello world!');
|
|
101
|
+
txn.del(dbi, 'hello');
|
|
102
|
+
var data3 = txn.getUtf8(dbi, 'hello');
|
|
103
|
+
should.equal(data3, undefined);
|
|
104
|
+
txn.commit();
|
|
105
|
+
dbi.close();
|
|
106
|
+
});
|
|
107
|
+
it('env.openDbi should throw an error when invalid parameters are passed', function() {
|
|
108
|
+
chai.assert.throw(function () {
|
|
109
|
+
env.openDbi();
|
|
110
|
+
});
|
|
111
|
+
chai.assert.throw(function () {
|
|
112
|
+
env.openDbi(null);
|
|
113
|
+
});
|
|
114
|
+
chai.assert.throw(function () {
|
|
115
|
+
env.openDbi(1);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
it('will open a database and empty the database without closing it', function() {
|
|
119
|
+
var dbi = env.openDbi({
|
|
120
|
+
name: 'mydb1',
|
|
121
|
+
create: true
|
|
122
|
+
});
|
|
123
|
+
dbi.drop({
|
|
124
|
+
justFreePages: true
|
|
125
|
+
});
|
|
126
|
+
dbi.close();
|
|
127
|
+
});
|
|
128
|
+
it('will open a database, begin a transaction and get/put/delete string data containing zeros', function() {
|
|
129
|
+
var dbi = env.openDbi({
|
|
130
|
+
name: 'mydb1x',
|
|
131
|
+
create: true
|
|
132
|
+
});
|
|
133
|
+
var txn = env.beginTxn();
|
|
134
|
+
var data = txn.getUtf8(dbi, 'hello');
|
|
135
|
+
should.equal(data, undefined);
|
|
136
|
+
txn.putUtf8(dbi, 'hello', 'Hello \0 world!');
|
|
137
|
+
var data2 = txn.getUtf8(dbi, 'hello');
|
|
138
|
+
data2.should.equal('Hello \0 world!');
|
|
139
|
+
txn.del(dbi, 'hello');
|
|
140
|
+
var data3 = txn.getUtf8(dbi, 'hello');
|
|
141
|
+
should.equal(data3, undefined);
|
|
142
|
+
txn.commit();
|
|
143
|
+
dbi.close();
|
|
144
|
+
});
|
|
145
|
+
it.skip('will check if UTF-16 Buffers can be read as strings', function() {
|
|
146
|
+
// The string we want to store using a buffer
|
|
147
|
+
var expectedString = 'Hello \0 world!';
|
|
148
|
+
|
|
149
|
+
// node-lmdb internally stores a terminating zero, so we need to manually emulate that here
|
|
150
|
+
// NOTE: this would NEVER work without 'utf16le'!
|
|
151
|
+
var buf = Buffer.from(expectedString + '\0', 'utf16le');
|
|
152
|
+
var key = 'hello';
|
|
153
|
+
|
|
154
|
+
// Open dbi and create cursor
|
|
155
|
+
var dbi = env.openDbi({
|
|
156
|
+
name: 'mydb1xx',
|
|
157
|
+
create: true
|
|
158
|
+
});
|
|
159
|
+
var txn = env.beginTxn();
|
|
160
|
+
|
|
161
|
+
// Check non-existence of the key
|
|
162
|
+
var data1 = txn.getBinary(dbi, key);
|
|
163
|
+
should.equal(data1, undefined);
|
|
164
|
+
|
|
165
|
+
// Store data as binary
|
|
166
|
+
txn.putBinary(dbi, key, buf);
|
|
167
|
+
|
|
168
|
+
// Retrieve data as binary and check
|
|
169
|
+
var data2 = txn.getBinary(dbi, key);
|
|
170
|
+
should.equal(buf.compare(data2), 0);
|
|
171
|
+
|
|
172
|
+
// Retrieve same data as string and check
|
|
173
|
+
var data3 = txn.getUtf8(dbi, key);
|
|
174
|
+
should.equal(data3, expectedString);
|
|
175
|
+
|
|
176
|
+
// Delete data
|
|
177
|
+
txn.del(dbi, key);
|
|
178
|
+
|
|
179
|
+
// Put new binary data without zero termination
|
|
180
|
+
txn.putBinary(dbi, key, Buffer.from(expectedString));
|
|
181
|
+
|
|
182
|
+
// Verify that you can't read it back as a string
|
|
183
|
+
(function () {
|
|
184
|
+
var data = txn.getUtf8(dbi, key);
|
|
185
|
+
}).should.throw('Invalid zero-terminated UTF-16 string');
|
|
186
|
+
|
|
187
|
+
// Delete data
|
|
188
|
+
txn.del(dbi, key);
|
|
189
|
+
|
|
190
|
+
// Verify non-existence of data
|
|
191
|
+
var data3 = txn.getBinary(dbi, key);
|
|
192
|
+
should.equal(data3, undefined);
|
|
193
|
+
|
|
194
|
+
txn.commit();
|
|
195
|
+
dbi.close();
|
|
196
|
+
});
|
|
197
|
+
it('will throw Javascript error if named database cannot be found', function () {
|
|
198
|
+
try {
|
|
199
|
+
env.openDbi({
|
|
200
|
+
name: 'does-not-exist',
|
|
201
|
+
create: false
|
|
202
|
+
});
|
|
203
|
+
} catch (err) {
|
|
204
|
+
err.should.be.an.instanceof(Error);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
it('will get information about an environment', function() {
|
|
208
|
+
var info = env.info();
|
|
209
|
+
info.mapAddress.should.be.a('number');
|
|
210
|
+
info.mapSize.should.be.a('number');
|
|
211
|
+
info.lastPageNumber.should.be.a('number');
|
|
212
|
+
info.lastTxnId.should.be.a('number');
|
|
213
|
+
info.maxReaders.should.be.a('number');
|
|
214
|
+
info.numReaders.should.be.a('number');
|
|
215
|
+
|
|
216
|
+
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
217
|
+
should.equal(info.maxReaders, 422);
|
|
218
|
+
});
|
|
219
|
+
it('will check for open transactions before resizing the mapSize', function() {
|
|
220
|
+
var dbi = env.openDbi({
|
|
221
|
+
name: 'mydb1',
|
|
222
|
+
create: true
|
|
223
|
+
});
|
|
224
|
+
var info = env.info();
|
|
225
|
+
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
226
|
+
// Open write transaction
|
|
227
|
+
var txn = env.beginTxn();
|
|
228
|
+
try {
|
|
229
|
+
env.resize(info.mapSize * 2);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
err.should.be.an.instanceof(Error);
|
|
232
|
+
}
|
|
233
|
+
txn.abort();
|
|
234
|
+
info = env.info();
|
|
235
|
+
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
236
|
+
dbi.close();
|
|
237
|
+
});
|
|
238
|
+
it('will resize the mapSize', function() {
|
|
239
|
+
var dbi = env.openDbi({
|
|
240
|
+
name: 'mydb1',
|
|
241
|
+
create: true
|
|
242
|
+
});
|
|
243
|
+
var info = env.info();
|
|
244
|
+
should.equal(info.mapSize, MAX_DB_SIZE);
|
|
245
|
+
env.resize(info.mapSize * 2);
|
|
246
|
+
info = env.info();
|
|
247
|
+
should.equal(info.mapSize, 2 * MAX_DB_SIZE);
|
|
248
|
+
dbi.close();
|
|
249
|
+
});
|
|
250
|
+
it('will get statistics about an environment', function() {
|
|
251
|
+
var stat = env.stat();
|
|
252
|
+
stat.pageSize.should.be.a('number');
|
|
253
|
+
stat.treeDepth.should.be.a('number');
|
|
254
|
+
stat.treeBranchPageCount.should.be.a('number');
|
|
255
|
+
stat.treeLeafPageCount.should.be.a('number');
|
|
256
|
+
stat.entryCount.should.be.a('number');
|
|
257
|
+
});
|
|
258
|
+
it('will get statistics about a database', function() {
|
|
259
|
+
var dbi = env.openDbi({
|
|
260
|
+
name: 'mydb2',
|
|
261
|
+
create: true
|
|
262
|
+
});
|
|
263
|
+
var txn = env.beginTxn();
|
|
264
|
+
var stat = dbi.stat(txn);
|
|
265
|
+
stat.pageSize.should.be.a('number');
|
|
266
|
+
stat.treeDepth.should.be.a('number');
|
|
267
|
+
stat.treeBranchPageCount.should.be.a('number');
|
|
268
|
+
stat.treeLeafPageCount.should.be.a('number');
|
|
269
|
+
stat.entryCount.should.be.a('number');
|
|
270
|
+
txn.abort();
|
|
271
|
+
dbi.close();
|
|
272
|
+
});
|
|
273
|
+
it('will create a database with a user-supplied transaction', function () {
|
|
274
|
+
var txn = env.beginTxn();
|
|
275
|
+
var dbi = env.openDbi({
|
|
276
|
+
name: 'dbUsingUserSuppliedTxn',
|
|
277
|
+
create: true,
|
|
278
|
+
txn: txn
|
|
279
|
+
});
|
|
280
|
+
txn.putUtf8(dbi, 'hello', 'world');
|
|
281
|
+
txn.commit();
|
|
282
|
+
|
|
283
|
+
var txn = env.beginTxn({ readOnly: true });
|
|
284
|
+
var str = txn.getUtf8(dbi, 'hello');
|
|
285
|
+
should.equal(str, 'world');
|
|
286
|
+
|
|
287
|
+
txn.abort();
|
|
288
|
+
dbi.close();
|
|
289
|
+
});
|
|
290
|
+
it('will create a database and back it up', function (done) {
|
|
291
|
+
var txn = env.beginTxn();
|
|
292
|
+
var dbi = env.openDbi({
|
|
293
|
+
name: 'backup',
|
|
294
|
+
create: true,
|
|
295
|
+
txn: txn
|
|
296
|
+
});
|
|
297
|
+
txn.putUtf8(dbi, 'hello', 'world');
|
|
298
|
+
txn.commit();
|
|
299
|
+
env.copy(testBackupDirPath, true, (error) => {
|
|
300
|
+
done(error)
|
|
301
|
+
});
|
|
302
|
+
// console.log('sent copy')
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
describe('Data types', function() {
|
|
306
|
+
this.timeout(10000);
|
|
307
|
+
var env;
|
|
308
|
+
var dbi;
|
|
309
|
+
var txn;
|
|
310
|
+
before(function() {
|
|
311
|
+
env = new lmdb.Env();
|
|
312
|
+
env.open({
|
|
313
|
+
path: testDirPath,
|
|
314
|
+
maxDbs: 10
|
|
315
|
+
});
|
|
316
|
+
dbi = env.openDbi({
|
|
317
|
+
name: 'mydb3',
|
|
318
|
+
create: true,
|
|
319
|
+
useVersions: true,
|
|
320
|
+
compression: new lmdb.Compression({
|
|
321
|
+
threshold: 100,
|
|
322
|
+
dictionary: fs.readFileSync(require.resolve('../dict/dict.txt')),
|
|
323
|
+
})
|
|
324
|
+
});
|
|
325
|
+
txn = env.beginTxn();
|
|
326
|
+
});
|
|
327
|
+
after(function() {
|
|
328
|
+
txn.commit();
|
|
329
|
+
dbi.close();
|
|
330
|
+
env.close();
|
|
331
|
+
});
|
|
332
|
+
it('string', function() {
|
|
333
|
+
txn.putUtf8(dbi, 'key1', 'Hello world!');
|
|
334
|
+
var data = txn.getUtf8(dbi, 'key1');
|
|
335
|
+
data.should.equal('Hello world!');
|
|
336
|
+
txn.del(dbi, 'key1');
|
|
337
|
+
var data2 = txn.getUtf8(dbi, 'key1');
|
|
338
|
+
should.equal(data2, undefined);
|
|
339
|
+
});
|
|
340
|
+
it('string with non-latin characters', function() {
|
|
341
|
+
txn.putUtf8(dbi, 'k:中华人民共和', '中华人民共和');
|
|
342
|
+
var data = txn.getUtf8(dbi, 'k:中华人民共和');
|
|
343
|
+
data.should.equal('中华人民共和');
|
|
344
|
+
txn.del(dbi, 'k:中华人民共和');
|
|
345
|
+
var data2 = txn.getUtf8(dbi, 'k:中华人民共和');
|
|
346
|
+
should.equal(data2, undefined);
|
|
347
|
+
});
|
|
348
|
+
it('string with version', function() {
|
|
349
|
+
txn.putUtf8(dbi, 'key1', 'Hello world!', 334);
|
|
350
|
+
var data = txn.getUtf8(dbi, 'key1');
|
|
351
|
+
data.should.equal('Hello world!');
|
|
352
|
+
var lastVersion = lmdb.getLastVersion();
|
|
353
|
+
lastVersion.should.equal(334);
|
|
354
|
+
txn.del(dbi, 'key1');
|
|
355
|
+
var data2 = txn.getUtf8(dbi, 'key1');
|
|
356
|
+
should.equal(data2, undefined);
|
|
357
|
+
});
|
|
358
|
+
it('string with compression', function() {
|
|
359
|
+
let value = '{"id":34,"enabled":true,"title":"this is a test that should be using common words of our language and seeing if it is well compressed","children":[{"data":"some more"}]}'
|
|
360
|
+
for (let i = 0; i < 0; i++)
|
|
361
|
+
value += value;
|
|
362
|
+
txn.putUtf8(dbi, 'key1', value);
|
|
363
|
+
var data = txn.getUtf8(dbi, 'key1');
|
|
364
|
+
data.should.equal(value);
|
|
365
|
+
txn.del(dbi, 'key1');
|
|
366
|
+
var data2 = txn.getUtf8(dbi, 'key1');
|
|
367
|
+
should.equal(data2, undefined);
|
|
368
|
+
});
|
|
369
|
+
it('string with compression with version', function() {
|
|
370
|
+
let value = 'Hello world!'
|
|
371
|
+
for (let i = 0; i < 7; i++)
|
|
372
|
+
value += value;
|
|
373
|
+
txn.putUtf8(dbi, 'key1', value, 5555);
|
|
374
|
+
var data = txn.getUtf8(dbi, 'key1');
|
|
375
|
+
data.should.equal(value);
|
|
376
|
+
var lastVersion = lmdb.getLastVersion();
|
|
377
|
+
lastVersion.should.equal(5555);
|
|
378
|
+
txn.del(dbi, 'key1');
|
|
379
|
+
var data2 = txn.getUtf8(dbi, 'key1');
|
|
380
|
+
should.equal(data2, undefined);
|
|
381
|
+
});
|
|
382
|
+
it.skip('string (zero copy)', function() {
|
|
383
|
+
txn.putUtf8(dbi, 'key1', 'Hello world!');
|
|
384
|
+
var data = txn.getUtf8Unsafe(dbi, 'key1');
|
|
385
|
+
data.should.equal('Hello world!');
|
|
386
|
+
txn.del(dbi, 'key1');
|
|
387
|
+
var data2 = txn.getUtf8Unsafe(dbi, 'key1');
|
|
388
|
+
should.equal(data2, undefined);
|
|
389
|
+
});
|
|
390
|
+
it('binary', function() {
|
|
391
|
+
var buffer = new Buffer('48656c6c6f2c20776f726c6421', 'hex');
|
|
392
|
+
txn.putBinary(dbi, ['key2', 2], buffer);
|
|
393
|
+
var data = txn.getBinary(dbi, ['key2', 2]);
|
|
394
|
+
data.should.deep.equal(buffer);
|
|
395
|
+
txn.del(dbi, ['key2', 2]);
|
|
396
|
+
var data2 = txn.getBinary(dbi, ['key2', 2]);
|
|
397
|
+
should.equal(data2, undefined);
|
|
398
|
+
});
|
|
399
|
+
it('binary (zero copy)', function() {
|
|
400
|
+
var buffer = new Buffer('48656c6c6f2c20776f726c6421', 'hex');
|
|
401
|
+
txn.putBinary(dbi, 'key2', buffer);
|
|
402
|
+
var buffer2 = new Buffer('58636c6c6f2c20779f324c5414', 'hex');
|
|
403
|
+
txn.putBinary(dbi, 'key3', buffer2);
|
|
404
|
+
var length = txn.getBinaryUnsafe(dbi, 'key2');
|
|
405
|
+
var data = dbi.unsafeBuffer.slice(0, length);
|
|
406
|
+
data.toString()
|
|
407
|
+
//data.slice(0, buffer.length).should.deep.equal(buffer);
|
|
408
|
+
//env.detachBuffer(data.buffer);
|
|
409
|
+
var length = txn.getBinaryUnsafe(dbi, 'key3');
|
|
410
|
+
var data2 = dbi.unsafeBuffer.slice(0, length);
|
|
411
|
+
var byte = data[0]; // make sure we can access it
|
|
412
|
+
data.slice(0, buffer2.length).should.deep.equal(buffer2);
|
|
413
|
+
//env.detachBuffer(data.buffer);
|
|
414
|
+
txn.del(dbi, 'key2');
|
|
415
|
+
var data2 = txn.getBinaryUnsafe(dbi, 'key2');
|
|
416
|
+
should.equal(data2, undefined);
|
|
417
|
+
});
|
|
418
|
+
it('binary key', function() {
|
|
419
|
+
var buffer = new Buffer('48656c6c6f2c20776f726c6421', 'hex');
|
|
420
|
+
var key = new Buffer('key2');
|
|
421
|
+
txn.putBinary(dbi, key, buffer);
|
|
422
|
+
var data = txn.getBinary(dbi, key);
|
|
423
|
+
data.should.deep.equal(buffer);
|
|
424
|
+
txn.del(dbi, key, { keyIsBuffer: true });
|
|
425
|
+
var data2 = txn.getBinary(dbi, key);
|
|
426
|
+
should.equal(data2, undefined);
|
|
427
|
+
});
|
|
428
|
+
it.skip('number', function() {
|
|
429
|
+
txn.putNumber(dbi, 'key3', 900719925474099);
|
|
430
|
+
var data = txn.getNumber(dbi, 'key3');
|
|
431
|
+
data.should.equal(900719925474099);
|
|
432
|
+
txn.del(dbi, 'key3');
|
|
433
|
+
var data2 = txn.getNumber(dbi, 'key3');
|
|
434
|
+
should.equal(data2, undefined);
|
|
435
|
+
});
|
|
436
|
+
it('string and number key', function() {
|
|
437
|
+
txn.putUtf8(dbi, -2.4, 'Hello world!');
|
|
438
|
+
var data = txn.getUtf8(dbi, -2.4);
|
|
439
|
+
data.should.equal('Hello world!');
|
|
440
|
+
txn.del(dbi, -2.4);
|
|
441
|
+
var data2 = txn.getUtf8(dbi, -2.4);
|
|
442
|
+
should.equal(data2, undefined);
|
|
443
|
+
});
|
|
444
|
+
it('boolean', function() {
|
|
445
|
+
txn.putBoolean(dbi, 'key4', true);
|
|
446
|
+
var data = txn.getBoolean(dbi, 'key4');
|
|
447
|
+
data.should.equal(true);
|
|
448
|
+
txn.putBoolean(dbi, 'key5', false);
|
|
449
|
+
var data2 = txn.getBoolean(dbi, 'key5');
|
|
450
|
+
data2.should.equal(false);
|
|
451
|
+
txn.del(dbi, 'key4');
|
|
452
|
+
txn.del(dbi, 'key5');
|
|
453
|
+
var data3 = txn.getBoolean(dbi, 'key4');
|
|
454
|
+
var data4 = txn.getBoolean(dbi, 'key5');
|
|
455
|
+
should.equal(data3, undefined);
|
|
456
|
+
should.equal(data4, undefined);
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
describe('Multiple transactions', function() {
|
|
460
|
+
this.timeout(10000);
|
|
461
|
+
var env;
|
|
462
|
+
var dbi;
|
|
463
|
+
before(function() {
|
|
464
|
+
env = new lmdb.Env();
|
|
465
|
+
env.open({
|
|
466
|
+
path: testDirPath,
|
|
467
|
+
maxDbs: 10
|
|
468
|
+
});
|
|
469
|
+
dbi = env.openDbi({
|
|
470
|
+
name: 'mydb4',
|
|
471
|
+
create: true,
|
|
472
|
+
keyIsUint32: true
|
|
473
|
+
});
|
|
474
|
+
var txn = env.beginTxn();
|
|
475
|
+
txn.putUtf8(dbi, 1, 'Hello1');
|
|
476
|
+
txn.putUtf8(dbi, 2, 'Hello2');
|
|
477
|
+
txn.commit();
|
|
478
|
+
});
|
|
479
|
+
after(function() {
|
|
480
|
+
dbi.close();
|
|
481
|
+
env.close();
|
|
482
|
+
});
|
|
483
|
+
it('readonly transaction should not see uncommited changes', function() {
|
|
484
|
+
var readTxn = env.beginTxn({readOnly: true});
|
|
485
|
+
var data = readTxn.getUtf8(dbi, 1);
|
|
486
|
+
should.equal(data, 'Hello1');
|
|
487
|
+
|
|
488
|
+
var writeTxn = env.beginTxn();
|
|
489
|
+
writeTxn.putUtf8(dbi, 1, 'Ha ha ha');
|
|
490
|
+
|
|
491
|
+
var data2 = writeTxn.getUtf8(dbi, 1);
|
|
492
|
+
data2.should.equal('Ha ha ha');
|
|
493
|
+
|
|
494
|
+
var data3 = readTxn.getUtf8(dbi, 1);
|
|
495
|
+
should.equal(data3, 'Hello1');
|
|
496
|
+
|
|
497
|
+
writeTxn.commit();
|
|
498
|
+
var data4 = readTxn.getUtf8(dbi, 1);
|
|
499
|
+
should.equal(data4, 'Hello1');
|
|
500
|
+
|
|
501
|
+
readTxn.reset();
|
|
502
|
+
readTxn.renew();
|
|
503
|
+
var data5 = readTxn.getUtf8(dbi, 1);
|
|
504
|
+
should.equal(data5, 'Ha ha ha');
|
|
505
|
+
readTxn.abort();
|
|
506
|
+
});
|
|
507
|
+
it('readonly transaction will throw if tries to write', function() {
|
|
508
|
+
var readTxn = env.beginTxn({readOnly: true});
|
|
509
|
+
(function() {
|
|
510
|
+
readTxn.putUtf8(dbi, 2, 'hööhh');
|
|
511
|
+
}).should.throw('Permission denied');
|
|
512
|
+
readTxn.abort();
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
describe('Cursors, basic operation', function() {
|
|
516
|
+
this.timeout(10000);
|
|
517
|
+
var env;
|
|
518
|
+
var dbi;
|
|
519
|
+
var total = 5;
|
|
520
|
+
|
|
521
|
+
before(function() {
|
|
522
|
+
env = new lmdb.Env();
|
|
523
|
+
env.open({
|
|
524
|
+
path: testDirPath,
|
|
525
|
+
maxDbs: 10,
|
|
526
|
+
mapSize: MAX_DB_SIZE
|
|
527
|
+
});
|
|
528
|
+
dbi = env.openDbi({
|
|
529
|
+
name: 'cursor_verybasic',
|
|
530
|
+
create: true
|
|
531
|
+
});
|
|
532
|
+
const txn = env.beginTxn();
|
|
533
|
+
let count = 0;
|
|
534
|
+
while (count < total) {
|
|
535
|
+
let key = "hello\x1E_" + count.toString(16);
|
|
536
|
+
let data = key + "_data";
|
|
537
|
+
txn.putUtf8(dbi, key, data);
|
|
538
|
+
count++;
|
|
539
|
+
}
|
|
540
|
+
count = 0;
|
|
541
|
+
while (count < total) {
|
|
542
|
+
let key = count - 2
|
|
543
|
+
let data = key + "_data";
|
|
544
|
+
txn.putUtf8(dbi, key, data);
|
|
545
|
+
count++;
|
|
546
|
+
}
|
|
547
|
+
count = 0;
|
|
548
|
+
while (count < total) {
|
|
549
|
+
let key = ["hello_\x1B" + count.toString(16) + '\x1E', count];
|
|
550
|
+
let data = key + "_data";
|
|
551
|
+
txn.putUtf8(dbi, key, data);
|
|
552
|
+
count++;
|
|
553
|
+
}
|
|
554
|
+
count = 0;
|
|
555
|
+
while (count < total) {
|
|
556
|
+
let key = [count, "hello_" + count.toString(16)];
|
|
557
|
+
let data = key + "_data";
|
|
558
|
+
txn.putUtf8(dbi, key, data);
|
|
559
|
+
count++;
|
|
560
|
+
}
|
|
561
|
+
txn.commit();
|
|
562
|
+
});
|
|
563
|
+
it('will move cursor over values, expects to get correct key', function (done) {
|
|
564
|
+
var txn = env.beginTxn({ readOnly: true });
|
|
565
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
566
|
+
var count;
|
|
567
|
+
|
|
568
|
+
for (count = 0; count < total; count ++) {
|
|
569
|
+
var expectedKey = "hello\x1E_" + count.toString(16);
|
|
570
|
+
var key = cursor.goToKey(expectedKey);
|
|
571
|
+
should.equal(expectedKey, key);
|
|
572
|
+
}
|
|
573
|
+
for (count = 0; count < total; count ++) {
|
|
574
|
+
var expectedKey = count - 2;
|
|
575
|
+
var key = cursor.goToKey(expectedKey);
|
|
576
|
+
should.equal(expectedKey, key);
|
|
577
|
+
}
|
|
578
|
+
for (count = 0; count < total; count ++) {
|
|
579
|
+
var expectedKey = ["hello_\x1B" + count.toString(16) + '\x1E', count];
|
|
580
|
+
var key = cursor.goToKey(expectedKey);
|
|
581
|
+
should.equal(JSON.stringify(expectedKey), JSON.stringify(key));
|
|
582
|
+
}
|
|
583
|
+
for (count = 0; count < total; count ++) {
|
|
584
|
+
var expectedKey = [count, "hello_" + count.toString(16)];
|
|
585
|
+
var key = cursor.goToKey(expectedKey);
|
|
586
|
+
should.equal(JSON.stringify(expectedKey), JSON.stringify(key));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
should.equal(count, total);
|
|
590
|
+
count = 0;
|
|
591
|
+
|
|
592
|
+
for (var key = cursor.goToFirst(); key != null; key = cursor.goToNext()) {
|
|
593
|
+
var key2 = cursor.goToKey(key);
|
|
594
|
+
should.equal(JSON.stringify(key), JSON.stringify(key2));
|
|
595
|
+
count ++;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
should.equal(count, total * 4);
|
|
599
|
+
|
|
600
|
+
cursor.close();
|
|
601
|
+
txn.abort();
|
|
602
|
+
|
|
603
|
+
done();
|
|
604
|
+
});
|
|
605
|
+
it.skip('will move cursor over values, expects to get correct key even if key is binary', function (done) {
|
|
606
|
+
var txn = env.beginTxn({ readOnly: true });
|
|
607
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
608
|
+
var count;
|
|
609
|
+
|
|
610
|
+
for (count = 0; count < total; count ++) {
|
|
611
|
+
var expectedKey = "hello_" + count.toString(16);
|
|
612
|
+
var binaryKey = new Buffer(expectedKey + "\0", "utf16le");
|
|
613
|
+
var key = cursor.goToKey(binaryKey);
|
|
614
|
+
should.equal(expectedKey, key);
|
|
615
|
+
should.equal(binaryKey.toString("utf16le"), key + "\0");
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
should.equal(count, total);
|
|
619
|
+
count = 0;
|
|
620
|
+
|
|
621
|
+
for (var key = cursor.goToFirst(); key; key = cursor.goToNext()) {
|
|
622
|
+
var key2 = cursor.goToKey(new Buffer(key + "\0", "utf16le"), { keyIsBuffer: true });
|
|
623
|
+
should.equal(key, key2);
|
|
624
|
+
count ++;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
should.equal(count, total);
|
|
628
|
+
|
|
629
|
+
cursor.close();
|
|
630
|
+
txn.abort();
|
|
631
|
+
|
|
632
|
+
done();
|
|
633
|
+
});
|
|
634
|
+
after(function () {
|
|
635
|
+
dbi.close();
|
|
636
|
+
env.close();
|
|
637
|
+
});
|
|
638
|
+
});
|
|
639
|
+
describe('Cursors', function() {
|
|
640
|
+
this.timeout(10000);
|
|
641
|
+
var env;
|
|
642
|
+
var dbi;
|
|
643
|
+
var total = 1000;
|
|
644
|
+
before(function() {
|
|
645
|
+
env = new lmdb.Env();
|
|
646
|
+
env.open({
|
|
647
|
+
path: testDirPath,
|
|
648
|
+
maxDbs: 10,
|
|
649
|
+
mapSize: MAX_DB_SIZE
|
|
650
|
+
});
|
|
651
|
+
dbi = env.openDbi({
|
|
652
|
+
name: 'mydb5',
|
|
653
|
+
create: true,
|
|
654
|
+
dupSort: false,
|
|
655
|
+
keyIsUint32: true
|
|
656
|
+
});
|
|
657
|
+
var txn = env.beginTxn();
|
|
658
|
+
var c = 0;
|
|
659
|
+
while(c < total) {
|
|
660
|
+
var buffer = new Buffer(new Array(8));
|
|
661
|
+
buffer.writeDoubleBE(c);
|
|
662
|
+
txn.putBinary(dbi, c, buffer);
|
|
663
|
+
c++;
|
|
664
|
+
}
|
|
665
|
+
txn.commit();
|
|
666
|
+
});
|
|
667
|
+
after(function() {
|
|
668
|
+
dbi.close();
|
|
669
|
+
env.close();
|
|
670
|
+
});
|
|
671
|
+
it('will move cursor over key/values', function(done) {
|
|
672
|
+
var txn = env.beginTxn();
|
|
673
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
674
|
+
cursor.goToKey(40);
|
|
675
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
676
|
+
key.should.equal(40);
|
|
677
|
+
value.readDoubleBE().should.equal(40);
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
var values = [];
|
|
681
|
+
cursor.goToKey(0);
|
|
682
|
+
function iterator() {
|
|
683
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
684
|
+
value.readDoubleBE().should.equal(values.length);
|
|
685
|
+
values.push(value);
|
|
686
|
+
});
|
|
687
|
+
cursor.goToNext();
|
|
688
|
+
if (values.length < total) {
|
|
689
|
+
// prevent maximum call stack errors
|
|
690
|
+
if (values.length % 1000 === 0) {
|
|
691
|
+
setImmediate(iterator);
|
|
692
|
+
} else {
|
|
693
|
+
iterator();
|
|
694
|
+
}
|
|
695
|
+
} else {
|
|
696
|
+
cursor.close();
|
|
697
|
+
txn.abort();
|
|
698
|
+
done();
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
iterator();
|
|
702
|
+
});
|
|
703
|
+
it.skip('will move cursor over key/values (zero copy)', function(done) {
|
|
704
|
+
var txn = env.beginTxn();
|
|
705
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
706
|
+
cursor.goToKey(40);
|
|
707
|
+
cursor.getCurrentBinaryUnsafe(function(key, value) {
|
|
708
|
+
key.should.equal(40);
|
|
709
|
+
value.readDoubleBE().should.equal(40);
|
|
710
|
+
});
|
|
711
|
+
var values = [];
|
|
712
|
+
cursor.goToKey(0);
|
|
713
|
+
function iterator() {
|
|
714
|
+
cursor.getCurrentBinaryUnsafe(function(key, value) {
|
|
715
|
+
value.readDoubleBE().should.equal(values.length);
|
|
716
|
+
values.push(value);
|
|
717
|
+
});
|
|
718
|
+
cursor.goToNext();
|
|
719
|
+
if (values.length < total) {
|
|
720
|
+
// prevent maximum call stack errors
|
|
721
|
+
if (values.length % 1000 === 0) {
|
|
722
|
+
setImmediate(iterator);
|
|
723
|
+
} else {
|
|
724
|
+
iterator();
|
|
725
|
+
}
|
|
726
|
+
} else {
|
|
727
|
+
cursor.close();
|
|
728
|
+
txn.abort();
|
|
729
|
+
done();
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
iterator();
|
|
733
|
+
});
|
|
734
|
+
it('will first/last key', function() {
|
|
735
|
+
var txn = env.beginTxn();
|
|
736
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
737
|
+
cursor.goToFirst();
|
|
738
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
739
|
+
key.should.equal(0);
|
|
740
|
+
value.readDoubleBE().should.equal(0);
|
|
741
|
+
});
|
|
742
|
+
cursor.goToLast();
|
|
743
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
744
|
+
key.should.equal(total - 1);
|
|
745
|
+
value.readDoubleBE().should.equal(total - 1);
|
|
746
|
+
});
|
|
747
|
+
cursor.close();
|
|
748
|
+
txn.abort();
|
|
749
|
+
});
|
|
750
|
+
});
|
|
751
|
+
describe.skip('Cursors, dupsort', function() {
|
|
752
|
+
this.timeout(10000);
|
|
753
|
+
var env;
|
|
754
|
+
var dbi;
|
|
755
|
+
var total = 50;
|
|
756
|
+
var dataCount = {};
|
|
757
|
+
|
|
758
|
+
before(function() {
|
|
759
|
+
env = new lmdb.Env();
|
|
760
|
+
env.open({
|
|
761
|
+
path: testDirPath,
|
|
762
|
+
maxDbs: 10,
|
|
763
|
+
mapSize: MAX_DB_SIZE
|
|
764
|
+
});
|
|
765
|
+
dbi = env.openDbi({
|
|
766
|
+
name: 'cursor_dupsort',
|
|
767
|
+
create: true,
|
|
768
|
+
dupSort: true
|
|
769
|
+
});
|
|
770
|
+
const txn = env.beginTxn();
|
|
771
|
+
var count;
|
|
772
|
+
for (count = 0; count < total; count ++) {
|
|
773
|
+
let key = "hello_" + count.toString(16);
|
|
774
|
+
let data = key + "_data";
|
|
775
|
+
dataCount[key] = (count % 4) + 1;
|
|
776
|
+
for (var j = 0; j < dataCount[key]; j++) {
|
|
777
|
+
txn.putUtf8(dbi, key, data + String(j));
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
txn.commit();
|
|
781
|
+
});
|
|
782
|
+
it('will move cursor over values, expects to get correct key and data', function (done) {
|
|
783
|
+
var txn = env.beginTxn({ readOnly: true });
|
|
784
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
785
|
+
var count;
|
|
786
|
+
|
|
787
|
+
for (count = 0; count < total; count ++) {
|
|
788
|
+
var expectedKey = "hello_" + count.toString(16);
|
|
789
|
+
var expectedDataX = expectedKey + "_data";
|
|
790
|
+
var key = cursor.goToRange(expectedKey);
|
|
791
|
+
should.equal(expectedKey, key);
|
|
792
|
+
|
|
793
|
+
var data = cursor.getCurrentUtf8();
|
|
794
|
+
should.equal(expectedDataX + "0", data);
|
|
795
|
+
|
|
796
|
+
var dc;
|
|
797
|
+
|
|
798
|
+
// Iterate over dup keys
|
|
799
|
+
dc = 0;
|
|
800
|
+
for (var k = cursor.goToFirstDup(); k; k = cursor.goToNextDup()) {
|
|
801
|
+
var data = cursor.getCurrentUtf8();
|
|
802
|
+
|
|
803
|
+
should.equal(expectedKey, k);
|
|
804
|
+
should.equal(expectedDataX + String(dc), data);
|
|
805
|
+
|
|
806
|
+
dc ++;
|
|
807
|
+
}
|
|
808
|
+
should.equal(dataCount[key], dc);
|
|
809
|
+
|
|
810
|
+
// Iterate over dup keys by using goToDup first
|
|
811
|
+
dc = 0;
|
|
812
|
+
for (var k = cursor.goToDup(expectedKey, expectedDataX + "0"); k; k = cursor.goToNextDup()) {
|
|
813
|
+
var data = cursor.getCurrentUtf8();
|
|
814
|
+
|
|
815
|
+
should.equal(expectedKey, k);
|
|
816
|
+
should.equal(expectedDataX + String(dc), data);
|
|
817
|
+
|
|
818
|
+
dc ++;
|
|
819
|
+
}
|
|
820
|
+
should.equal(dataCount[key], dc);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
should.equal(count, total);
|
|
824
|
+
count = 0;
|
|
825
|
+
|
|
826
|
+
cursor.close();
|
|
827
|
+
txn.abort();
|
|
828
|
+
|
|
829
|
+
done();
|
|
830
|
+
});
|
|
831
|
+
after(function () {
|
|
832
|
+
dbi.close();
|
|
833
|
+
env.close();
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
describe('Cursors (with strings)', function() {
|
|
837
|
+
this.timeout(10000);
|
|
838
|
+
var env;
|
|
839
|
+
var dbi;
|
|
840
|
+
var total = 1000;
|
|
841
|
+
before(function() {
|
|
842
|
+
env = new lmdb.Env();
|
|
843
|
+
env.open({
|
|
844
|
+
path: testDirPath,
|
|
845
|
+
maxDbs: 10,
|
|
846
|
+
mapSize: MAX_DB_SIZE
|
|
847
|
+
});
|
|
848
|
+
dbi = env.openDbi({
|
|
849
|
+
name: 'cursorstrings',
|
|
850
|
+
create: true,
|
|
851
|
+
dupSort: true,
|
|
852
|
+
//keyIsUint32: true
|
|
853
|
+
});
|
|
854
|
+
var txn = env.beginTxn();
|
|
855
|
+
var c = 0;
|
|
856
|
+
while(c < total) {
|
|
857
|
+
txn.putUtf8(dbi, c, c.toString());
|
|
858
|
+
c++;
|
|
859
|
+
}
|
|
860
|
+
txn.commit();
|
|
861
|
+
});
|
|
862
|
+
after(function() {
|
|
863
|
+
dbi.close();
|
|
864
|
+
env.close();
|
|
865
|
+
});
|
|
866
|
+
it.skip('will move cursor over key/values (zero copy)', function(done) {
|
|
867
|
+
var txn = env.beginTxn();
|
|
868
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
869
|
+
cursor.goToKey(40);
|
|
870
|
+
cursor.getCurrentStringUnsafe(function(key, value) {
|
|
871
|
+
key.should.equal(40);
|
|
872
|
+
value.should.equal('40');
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
var values = [];
|
|
876
|
+
cursor.goToKey(0);
|
|
877
|
+
function iterator() {
|
|
878
|
+
cursor.getCurrentStringUnsafe(function(key, value) {
|
|
879
|
+
value.should.equal(values.length.toString());
|
|
880
|
+
values.push(value);
|
|
881
|
+
});
|
|
882
|
+
cursor.goToNext();
|
|
883
|
+
if (values.length < total) {
|
|
884
|
+
// prevent maximum call stack errors
|
|
885
|
+
if (values.length % 1000 === 0) {
|
|
886
|
+
setImmediate(iterator);
|
|
887
|
+
} else {
|
|
888
|
+
iterator();
|
|
889
|
+
}
|
|
890
|
+
} else {
|
|
891
|
+
cursor.close();
|
|
892
|
+
txn.abort();
|
|
893
|
+
done();
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
iterator();
|
|
897
|
+
});
|
|
898
|
+
it('will move cursor over key/values', function(done) {
|
|
899
|
+
var txn = env.beginTxn();
|
|
900
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
901
|
+
cursor.goToKey(40);
|
|
902
|
+
cursor.getCurrentUtf8(function(key, value) {
|
|
903
|
+
key.should.equal(40);
|
|
904
|
+
value.should.equal('40');
|
|
905
|
+
});
|
|
906
|
+
var values = [];
|
|
907
|
+
cursor.goToKey(0);
|
|
908
|
+
function iterator() {
|
|
909
|
+
cursor.getCurrentUtf8(function(key, value) {
|
|
910
|
+
value.should.equal(values.length.toString());
|
|
911
|
+
values.push(value);
|
|
912
|
+
});
|
|
913
|
+
cursor.goToNext();
|
|
914
|
+
if (values.length < total) {
|
|
915
|
+
// prevent maximum call stack errors
|
|
916
|
+
if (values.length % 1000 === 0) {
|
|
917
|
+
setImmediate(iterator);
|
|
918
|
+
} else {
|
|
919
|
+
iterator();
|
|
920
|
+
}
|
|
921
|
+
} else {
|
|
922
|
+
cursor.close();
|
|
923
|
+
txn.abort();
|
|
924
|
+
done();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
iterator();
|
|
928
|
+
});
|
|
929
|
+
it('will first/last key', function(done) {
|
|
930
|
+
var txn = env.beginTxn();
|
|
931
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
932
|
+
cursor.goToFirst();
|
|
933
|
+
cursor.getCurrentUtf8(function(key, value) {
|
|
934
|
+
key.should.equal(0);
|
|
935
|
+
value.should.equal('0');
|
|
936
|
+
});
|
|
937
|
+
cursor.goToLast();
|
|
938
|
+
cursor.getCurrentUtf8(function(key, value) {
|
|
939
|
+
key.should.equal(total - 1);
|
|
940
|
+
value.should.equal((total - 1).toString());
|
|
941
|
+
});
|
|
942
|
+
cursor.close();
|
|
943
|
+
txn.abort();
|
|
944
|
+
done();
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
describe('Remove last item', function() {
|
|
949
|
+
this.timeout(10000);
|
|
950
|
+
var env;
|
|
951
|
+
var dbi;
|
|
952
|
+
before(function() {
|
|
953
|
+
env = new lmdb.Env();
|
|
954
|
+
env.open({
|
|
955
|
+
path: testDirPath,
|
|
956
|
+
maxDbs: 10,
|
|
957
|
+
mapSize: MAX_DB_SIZE
|
|
958
|
+
});
|
|
959
|
+
dbi = env.openDbi({
|
|
960
|
+
name: 'removelast',
|
|
961
|
+
create: true,
|
|
962
|
+
keyIsBuffer: true
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
after(function() {
|
|
966
|
+
dbi.close();
|
|
967
|
+
env.close();
|
|
968
|
+
});
|
|
969
|
+
it('remove last entry', function() {
|
|
970
|
+
for (let i = 0; i < 10; i++) {
|
|
971
|
+
var readTxn = env.beginTxn({readOnly: true});
|
|
972
|
+
var txn = env.beginTxn();
|
|
973
|
+
txn.putBinary(dbi, Buffer.from([1]), Buffer.from([1]));
|
|
974
|
+
txn.putBinary(dbi, Buffer.from([2]), Buffer.from([1]));
|
|
975
|
+
txn.commit();
|
|
976
|
+
var txn = env.beginTxn();
|
|
977
|
+
txn.del(dbi, Buffer.from([1]));
|
|
978
|
+
txn.del(dbi, Buffer.from([2]));
|
|
979
|
+
txn.commit();
|
|
980
|
+
readTxn.commit();
|
|
981
|
+
}
|
|
982
|
+
})
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
describe('Cursors with binary key and data', function() {
|
|
987
|
+
this.timeout(10000);
|
|
988
|
+
var env;
|
|
989
|
+
var dbi;
|
|
990
|
+
var total = 1000;
|
|
991
|
+
let padding = '000000000';
|
|
992
|
+
let keyEnc = 'utf8';
|
|
993
|
+
let valueEnc = 'utf8';
|
|
994
|
+
|
|
995
|
+
before(function() {
|
|
996
|
+
env = new lmdb.Env();
|
|
997
|
+
env.open({
|
|
998
|
+
path: testDirPath,
|
|
999
|
+
maxDbs: 10,
|
|
1000
|
+
mapSize: MAX_DB_SIZE
|
|
1001
|
+
});
|
|
1002
|
+
dbi = env.openDbi({
|
|
1003
|
+
name: 'cursorbinkeydata',
|
|
1004
|
+
create: true,
|
|
1005
|
+
keyIsBuffer: true
|
|
1006
|
+
});
|
|
1007
|
+
const txn = env.beginTxn();
|
|
1008
|
+
let count = 0;
|
|
1009
|
+
while (count < total) {
|
|
1010
|
+
let keyStr = (padding + count).slice(-padding.length);
|
|
1011
|
+
let dataStr = expand(keyStr);
|
|
1012
|
+
let key = Buffer.from(keyStr,keyEnc);
|
|
1013
|
+
let data = Buffer.from(dataStr,valueEnc) // just for kicks.
|
|
1014
|
+
txn.putBinary(dbi, key, data);
|
|
1015
|
+
count++;
|
|
1016
|
+
}
|
|
1017
|
+
txn.commit();
|
|
1018
|
+
});
|
|
1019
|
+
after(function() {
|
|
1020
|
+
dbi.close();
|
|
1021
|
+
env.close();
|
|
1022
|
+
});
|
|
1023
|
+
it('will move cursor over key/values', function(done) {
|
|
1024
|
+
var txn = env.beginTxn();
|
|
1025
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
1026
|
+
let expectedKey = (padding + 40).slice(-padding.length);
|
|
1027
|
+
let key = Buffer.from(expectedKey,keyEnc);
|
|
1028
|
+
cursor.goToKey(key);
|
|
1029
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1030
|
+
let readKey = key.toString(keyEnc);
|
|
1031
|
+
let readValue = value.toString(valueEnc);
|
|
1032
|
+
readKey.should.equal(expectedKey);
|
|
1033
|
+
readValue.should.equal(expand(expectedKey));
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
let count = 0;
|
|
1037
|
+
key = cursor.goToFirst();
|
|
1038
|
+
// key is a string... bug...
|
|
1039
|
+
//(typeof key).should.not.equal('string');
|
|
1040
|
+
while (key && count < total+1) { //+1 to run off end if fails to return null
|
|
1041
|
+
let expectedKey = (padding + count).slice(-padding.length);
|
|
1042
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1043
|
+
(typeof key).should.not.equal('string');
|
|
1044
|
+
let readKey = key.toString(keyEnc);
|
|
1045
|
+
let readValue = value.toString(valueEnc);
|
|
1046
|
+
readKey.should.equal(expectedKey);
|
|
1047
|
+
readValue.should.equal(expand(expectedKey));
|
|
1048
|
+
});
|
|
1049
|
+
key = cursor.goToNext();
|
|
1050
|
+
(typeof key).should.not.equal('string');
|
|
1051
|
+
count++;
|
|
1052
|
+
}
|
|
1053
|
+
cursor.close();
|
|
1054
|
+
txn.commit();
|
|
1055
|
+
count.should.equal(total);
|
|
1056
|
+
done();
|
|
1057
|
+
});
|
|
1058
|
+
});
|
|
1059
|
+
describe('Cursors reading existing binary key and data', function() {
|
|
1060
|
+
this.timeout(10000);
|
|
1061
|
+
var env;
|
|
1062
|
+
var dbi;
|
|
1063
|
+
var total = 1000;
|
|
1064
|
+
let padding = '000000000';
|
|
1065
|
+
let keyEnc = 'utf8';
|
|
1066
|
+
let valueEnc = 'utf8';
|
|
1067
|
+
|
|
1068
|
+
before(function() {
|
|
1069
|
+
env = new lmdb.Env();
|
|
1070
|
+
env.open({
|
|
1071
|
+
path: testDirPath,
|
|
1072
|
+
maxDbs: 10,
|
|
1073
|
+
mapSize: MAX_DB_SIZE
|
|
1074
|
+
});
|
|
1075
|
+
dbi = env.openDbi({
|
|
1076
|
+
name: 'cursorbinkeydata',
|
|
1077
|
+
create: false,
|
|
1078
|
+
keyIsBuffer: true
|
|
1079
|
+
});
|
|
1080
|
+
});
|
|
1081
|
+
|
|
1082
|
+
after(function() {
|
|
1083
|
+
dbi.close();
|
|
1084
|
+
env.close();
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
it('will move cursor over existing key/values', function(done) {
|
|
1088
|
+
var txn = env.beginTxn();
|
|
1089
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
1090
|
+
let expectedKey = (padding + 40).slice(-padding.length);
|
|
1091
|
+
let key = Buffer.from(expectedKey,keyEnc);
|
|
1092
|
+
cursor.goToKey(key);
|
|
1093
|
+
let rvalue = cursor.getCurrentBinary(function(key, value) {
|
|
1094
|
+
(typeof key).should.not.equal('string');
|
|
1095
|
+
let readKey = key.toString(keyEnc);
|
|
1096
|
+
let readValue = value.toString(valueEnc);
|
|
1097
|
+
readKey.should.equal(expectedKey);
|
|
1098
|
+
readValue.should.equal(expand(expectedKey));
|
|
1099
|
+
});
|
|
1100
|
+
rvalue.toString(valueEnc).should.equal(expand(expectedKey));
|
|
1101
|
+
|
|
1102
|
+
let count = 0;
|
|
1103
|
+
key = cursor.goToFirst();
|
|
1104
|
+
(typeof key).should.not.equal('string');
|
|
1105
|
+
while (key && count < total+1) { //+1 to run off end if fails to return null
|
|
1106
|
+
let expectedKey = (padding + count).slice(-padding.length);
|
|
1107
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1108
|
+
let readKey = key.toString(keyEnc);
|
|
1109
|
+
let readValue = value.toString(valueEnc);
|
|
1110
|
+
readKey.should.equal(expectedKey);
|
|
1111
|
+
readValue.should.equal(expand(expectedKey));
|
|
1112
|
+
});
|
|
1113
|
+
key = cursor.goToNext();
|
|
1114
|
+
(typeof key).should.not.equal('string');
|
|
1115
|
+
count++;
|
|
1116
|
+
}
|
|
1117
|
+
cursor.close();
|
|
1118
|
+
txn.commit();
|
|
1119
|
+
count.should.equal(total);
|
|
1120
|
+
done();
|
|
1121
|
+
});
|
|
1122
|
+
});
|
|
1123
|
+
describe('Cluster', function() {
|
|
1124
|
+
this.timeout(10000);
|
|
1125
|
+
it('will run a cluster of processes with read-only transactions', function(done) {
|
|
1126
|
+
var child = spawn('node', [path.resolve(__dirname, './cluster')]);
|
|
1127
|
+
child.stdout.on('data', function(data) {
|
|
1128
|
+
console.log(data.toString());
|
|
1129
|
+
});
|
|
1130
|
+
child.stderr.on('data', function(data) {
|
|
1131
|
+
console.error(data.toString());
|
|
1132
|
+
});
|
|
1133
|
+
child.on('close', function(code) {
|
|
1134
|
+
code.should.equal(0);
|
|
1135
|
+
done();
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
});
|
|
1139
|
+
describe('Threads', function() {
|
|
1140
|
+
this.timeout(10000);
|
|
1141
|
+
it('will run a group of threads with read-only transactions', function(done) {
|
|
1142
|
+
var child = spawn('node', [path.resolve(__dirname, './threads')]);
|
|
1143
|
+
child.stdout.on('data', function(data) {
|
|
1144
|
+
console.log(data.toString());
|
|
1145
|
+
});
|
|
1146
|
+
child.stderr.on('data', function(data) {
|
|
1147
|
+
console.error(data.toString());
|
|
1148
|
+
});
|
|
1149
|
+
child.on('close', function(code) {
|
|
1150
|
+
code.should.equal(0);
|
|
1151
|
+
done();
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
1154
|
+
});
|
|
1155
|
+
describe.skip('Dupsort', function () {
|
|
1156
|
+
this.timeout(10000);
|
|
1157
|
+
var env;
|
|
1158
|
+
var dbi;
|
|
1159
|
+
before(function() {
|
|
1160
|
+
env = new lmdb.Env();
|
|
1161
|
+
env.open({
|
|
1162
|
+
path: testDirPath,
|
|
1163
|
+
maxDbs: 10,
|
|
1164
|
+
mapSize: MAX_DB_SIZE
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
after(function () {
|
|
1168
|
+
env.close();
|
|
1169
|
+
});
|
|
1170
|
+
beforeEach(function () {
|
|
1171
|
+
dbi = env.openDbi({
|
|
1172
|
+
name: 'testdb_dupsort',
|
|
1173
|
+
create: true,
|
|
1174
|
+
dupSort: true,
|
|
1175
|
+
dupFixed: false,
|
|
1176
|
+
keyIsBuffer: true
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
afterEach(function () {
|
|
1180
|
+
dbi.drop();
|
|
1181
|
+
});
|
|
1182
|
+
it('will insert values with different lengths', function(done) {
|
|
1183
|
+
var txn = env.beginTxn();
|
|
1184
|
+
var value1 = new Buffer(new Array(8));
|
|
1185
|
+
var value2 = new Buffer(new Array(4));
|
|
1186
|
+
txn.putBinary(dbi, new Buffer('id'), value1);
|
|
1187
|
+
txn.putBinary(dbi, new Buffer('id'), value2);
|
|
1188
|
+
txn.commit();
|
|
1189
|
+
|
|
1190
|
+
var txn2 = env.beginTxn({readonly: true});
|
|
1191
|
+
var cursor = new lmdb.Cursor(txn2, dbi);
|
|
1192
|
+
var found = cursor.goToKey(new Buffer('id'));
|
|
1193
|
+
should.exist(found);
|
|
1194
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1195
|
+
key.toString().should.equal('id');
|
|
1196
|
+
value.length.should.equal(4);
|
|
1197
|
+
|
|
1198
|
+
cursor.goToNext();
|
|
1199
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1200
|
+
key.toString().should.equal('id');
|
|
1201
|
+
value.length.should.equal(8);
|
|
1202
|
+
cursor.close();
|
|
1203
|
+
txn2.abort();
|
|
1204
|
+
done();
|
|
1205
|
+
});
|
|
1206
|
+
});
|
|
1207
|
+
});
|
|
1208
|
+
it('will delete dupsort data correctly', function (done) {
|
|
1209
|
+
var txn;
|
|
1210
|
+
var cursor;
|
|
1211
|
+
var key;
|
|
1212
|
+
|
|
1213
|
+
// Add test data to database
|
|
1214
|
+
txn = env.beginTxn();
|
|
1215
|
+
txn.putNumber(dbi, 100, 1);
|
|
1216
|
+
txn.putNumber(dbi, 100, 2);
|
|
1217
|
+
txn.putNumber(dbi, 100, 3);
|
|
1218
|
+
txn.putNumber(dbi, 100, 4);
|
|
1219
|
+
txn.putNumber(dbi, 101, 1);
|
|
1220
|
+
txn.putNumber(dbi, 101, 2);
|
|
1221
|
+
txn.putNumber(dbi, 101, 3);
|
|
1222
|
+
txn.putNumber(dbi, 101, 4);
|
|
1223
|
+
txn.putNumber(dbi, 102, 1);
|
|
1224
|
+
txn.putNumber(dbi, 102, 2);
|
|
1225
|
+
txn.putNumber(dbi, 102, 3);
|
|
1226
|
+
txn.putNumber(dbi, 102, 4);
|
|
1227
|
+
txn.commit();
|
|
1228
|
+
|
|
1229
|
+
// Now delete some data
|
|
1230
|
+
txn = env.beginTxn();
|
|
1231
|
+
txn.del(dbi, 101, 2);
|
|
1232
|
+
txn.del(dbi, 101, 4);
|
|
1233
|
+
txn.del(dbi, 102, 1);
|
|
1234
|
+
txn.del(dbi, 102, 3);
|
|
1235
|
+
txn.commit();
|
|
1236
|
+
|
|
1237
|
+
// Verify data
|
|
1238
|
+
txn = env.beginTxn({ readOnly: true });
|
|
1239
|
+
cursor = new lmdb.Cursor(txn, dbi);
|
|
1240
|
+
cursor.goToFirst().readUInt32LE().should.equal(100);
|
|
1241
|
+
cursor.goToNext().readUInt32LE().should.equal(100);
|
|
1242
|
+
cursor.goToNext().readUInt32LE().should.equal(100);
|
|
1243
|
+
cursor.goToNext().readUInt32LE().should.equal(100);
|
|
1244
|
+
cursor.goToNext().readUInt32LE().should.equal(101);
|
|
1245
|
+
cursor.goToNext().readUInt32LE().should.equal(101);
|
|
1246
|
+
cursor.goToNext().readUInt32LE().should.equal(102);
|
|
1247
|
+
cursor.goToNext().readUInt32LE().should.equal(102);
|
|
1248
|
+
should.equal(cursor.goToNext(), undefined);
|
|
1249
|
+
|
|
1250
|
+
txn.abort();
|
|
1251
|
+
|
|
1252
|
+
done();
|
|
1253
|
+
});
|
|
1254
|
+
});
|
|
1255
|
+
describe('Dupfixed', function() {
|
|
1256
|
+
this.timeout(10000);
|
|
1257
|
+
var env;
|
|
1258
|
+
var dbi;
|
|
1259
|
+
before(function() {
|
|
1260
|
+
env = new lmdb.Env();
|
|
1261
|
+
env.open({
|
|
1262
|
+
path: testDirPath,
|
|
1263
|
+
maxDbs: 10,
|
|
1264
|
+
mapSize: MAX_DB_SIZE
|
|
1265
|
+
});
|
|
1266
|
+
dbi = env.openDbi({
|
|
1267
|
+
name: 'mydb7',
|
|
1268
|
+
create: true,
|
|
1269
|
+
dupSort: true,
|
|
1270
|
+
dupFixed: true,
|
|
1271
|
+
keyIsBuffer: true
|
|
1272
|
+
});
|
|
1273
|
+
});
|
|
1274
|
+
after(function() {
|
|
1275
|
+
dbi.close();
|
|
1276
|
+
env.close();
|
|
1277
|
+
});
|
|
1278
|
+
it('will insert values with the same length (inserted with different lengths)', function(done) {
|
|
1279
|
+
var txn = env.beginTxn();
|
|
1280
|
+
var value1 = new Buffer(new Array(4));
|
|
1281
|
+
value1.writeUInt32BE(100);
|
|
1282
|
+
var value2 = new Buffer(new Array(8));
|
|
1283
|
+
value2.writeUInt32BE(200);
|
|
1284
|
+
txn.putBinary(dbi, new Buffer('id'), value1);
|
|
1285
|
+
txn.putBinary(dbi, new Buffer('id'), value2);
|
|
1286
|
+
txn.commit();
|
|
1287
|
+
|
|
1288
|
+
var txn2 = env.beginTxn({readonly: true});
|
|
1289
|
+
var cursor = new lmdb.Cursor(txn2, dbi);
|
|
1290
|
+
var found = cursor.goToKey(new Buffer('id'));
|
|
1291
|
+
should.exist(found);
|
|
1292
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1293
|
+
key.toString().should.equal('id');
|
|
1294
|
+
value.length.should.equal(8);
|
|
1295
|
+
|
|
1296
|
+
cursor.goToNext();
|
|
1297
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1298
|
+
key.toString().should.equal('id');
|
|
1299
|
+
value.length.should.equal(8);
|
|
1300
|
+
cursor.close();
|
|
1301
|
+
txn2.abort();
|
|
1302
|
+
done();
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
describe('Memory Freeing / Garbage Collection', function() {
|
|
1308
|
+
it('should not cause a segment fault', function(done) {
|
|
1309
|
+
var expectedKey = new Buffer('822285ee315d2b04');
|
|
1310
|
+
var expectedValue = new Buffer('ec65d632d9168c33350ed31a30848d01e95172931e90984c218ef6b08c1fa90a', 'hex');
|
|
1311
|
+
var env = new lmdb.Env();
|
|
1312
|
+
env.open({
|
|
1313
|
+
path: testDirPath,
|
|
1314
|
+
maxDbs: 12,
|
|
1315
|
+
mapSize: MAX_DB_SIZE
|
|
1316
|
+
});
|
|
1317
|
+
var dbi = env.openDbi({
|
|
1318
|
+
name: 'testfree',
|
|
1319
|
+
create: true,
|
|
1320
|
+
keyIsBuffer: true
|
|
1321
|
+
});
|
|
1322
|
+
var txn = env.beginTxn();
|
|
1323
|
+
txn.putBinary(dbi, expectedKey, expectedValue);
|
|
1324
|
+
txn.commit();
|
|
1325
|
+
var txn2 = env.beginTxn();
|
|
1326
|
+
var cursor = new lmdb.Cursor(txn2, dbi);
|
|
1327
|
+
var key;
|
|
1328
|
+
var value;
|
|
1329
|
+
cursor.goToFirst();
|
|
1330
|
+
cursor.getCurrentBinary(function(returnKey, returnValue) {
|
|
1331
|
+
key = returnKey;
|
|
1332
|
+
value = returnValue;
|
|
1333
|
+
});
|
|
1334
|
+
cursor.close();
|
|
1335
|
+
txn2.abort();
|
|
1336
|
+
dbi.close();
|
|
1337
|
+
env.close();
|
|
1338
|
+
key.should.deep.equal(expectedKey);
|
|
1339
|
+
value.compare(expectedValue).should.equal(0);
|
|
1340
|
+
done();
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
describe('Type Conversion', function() {
|
|
1344
|
+
var env;
|
|
1345
|
+
var dbi;
|
|
1346
|
+
var expectedKey = new Buffer('822285ee315d2b04', 'hex');
|
|
1347
|
+
var expectedValue = new Buffer('ec65d632d9168c33350ed31a30848d01e95172931e90984c218ef6b08c1fa90a', 'hex');
|
|
1348
|
+
before(function() {
|
|
1349
|
+
env = new lmdb.Env();
|
|
1350
|
+
env.open({
|
|
1351
|
+
path: testDirPath,
|
|
1352
|
+
maxDbs: 12,
|
|
1353
|
+
mapSize: MAX_DB_SIZE
|
|
1354
|
+
});
|
|
1355
|
+
dbi = env.openDbi({
|
|
1356
|
+
name: 'testkeys',
|
|
1357
|
+
create: true,
|
|
1358
|
+
keyIsBuffer: true
|
|
1359
|
+
});
|
|
1360
|
+
var txn = env.beginTxn();
|
|
1361
|
+
txn.putBinary(dbi, expectedKey, expectedValue);
|
|
1362
|
+
txn.commit();
|
|
1363
|
+
});
|
|
1364
|
+
after(function() {
|
|
1365
|
+
dbi.close();
|
|
1366
|
+
env.close();
|
|
1367
|
+
});
|
|
1368
|
+
it('will be able to convert key to buffer', function(done) {
|
|
1369
|
+
var txn = env.beginTxn();
|
|
1370
|
+
var cursor = new lmdb.Cursor(txn, dbi);
|
|
1371
|
+
cursor.goToFirst();
|
|
1372
|
+
cursor.getCurrentBinary(function(key, value) {
|
|
1373
|
+
var keyBuffer = new Buffer(key);
|
|
1374
|
+
cursor.close();
|
|
1375
|
+
txn.abort();
|
|
1376
|
+
keyBuffer.compare(expectedKey).should.equal(0);
|
|
1377
|
+
value.compare(expectedValue).should.equal(0);
|
|
1378
|
+
done();
|
|
1379
|
+
});
|
|
1380
|
+
});
|
|
1381
|
+
});
|
|
1382
|
+
describe('Sync', function() {
|
|
1383
|
+
var env;
|
|
1384
|
+
var dbi;
|
|
1385
|
+
before(function() {
|
|
1386
|
+
env = new lmdb.Env();
|
|
1387
|
+
env.open({
|
|
1388
|
+
path: testDirPath,
|
|
1389
|
+
maxDbs: 12,
|
|
1390
|
+
mapSize: MAX_DB_SIZE
|
|
1391
|
+
});
|
|
1392
|
+
dbi = env.openDbi({
|
|
1393
|
+
name: 'testsync',
|
|
1394
|
+
create: true,
|
|
1395
|
+
keyIsBuffer: true
|
|
1396
|
+
});
|
|
1397
|
+
});
|
|
1398
|
+
after(function() {
|
|
1399
|
+
dbi.close();
|
|
1400
|
+
env.close();
|
|
1401
|
+
});
|
|
1402
|
+
it('should not block promise callbacks', function(done) {
|
|
1403
|
+
var timeoutResult
|
|
1404
|
+
new Promise(resolve => {
|
|
1405
|
+
env.sync(() => {
|
|
1406
|
+
resolve();
|
|
1407
|
+
})
|
|
1408
|
+
}).then(() => {
|
|
1409
|
+
// this should execute immediately after it is synced, before the timeout, so timeoutResult should be undefined
|
|
1410
|
+
done(timeoutResult)
|
|
1411
|
+
});
|
|
1412
|
+
setTimeout(() => {
|
|
1413
|
+
timeoutResult = 'Timeout occurred'
|
|
1414
|
+
}, 100);
|
|
1415
|
+
});
|
|
1416
|
+
});
|
|
1417
|
+
describe('batch', function() {
|
|
1418
|
+
this.timeout(10000);
|
|
1419
|
+
var env;
|
|
1420
|
+
before(function() {
|
|
1421
|
+
env = new lmdb.Env();
|
|
1422
|
+
env.open({
|
|
1423
|
+
path: testDirPath,
|
|
1424
|
+
maxDbs: 10,
|
|
1425
|
+
maxReaders: 422,
|
|
1426
|
+
mapSize: MAX_DB_SIZE
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
after(function() {
|
|
1430
|
+
env.close();
|
|
1431
|
+
});
|
|
1432
|
+
it.skip('will batchWrite binary data and read it', function(done) {
|
|
1433
|
+
var dbi = env.openDbi({
|
|
1434
|
+
name: 'mydb8',
|
|
1435
|
+
create: true
|
|
1436
|
+
});
|
|
1437
|
+
var data = [
|
|
1438
|
+
[ dbi, Buffer.from([47]), Buffer.from([1, 2]), Buffer.from([5, 2]) ],
|
|
1439
|
+
[ dbi, Buffer.from([4]), Buffer.from([1, 2]) ],
|
|
1440
|
+
[ dbi, Buffer.from([5]), Buffer.from([3, 4]) ],
|
|
1441
|
+
[ dbi, Buffer.from([6]), Buffer.from([5, 6]) ],
|
|
1442
|
+
[ dbi, Buffer.from([7]) ],
|
|
1443
|
+
[ dbi, Buffer.from([6]), Buffer.from([7, 8]), Buffer.from([1, 1]) ],
|
|
1444
|
+
[ dbi, Buffer.from([6]), Buffer.from([7, 8]), Buffer.from([5]) ],
|
|
1445
|
+
{
|
|
1446
|
+
db: dbi,
|
|
1447
|
+
key: Buffer.from([5]),
|
|
1448
|
+
value: Buffer.from([8, 9]),
|
|
1449
|
+
ifValue: Buffer.from([7]),
|
|
1450
|
+
ifKey: Buffer.from([6]),
|
|
1451
|
+
ifExactMatch: false,
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
];
|
|
1455
|
+
env.batchWrite(data, { keyIsBuffer: true, progress(results) {
|
|
1456
|
+
//console.log('progress', results)
|
|
1457
|
+
} }, function(error, results) {
|
|
1458
|
+
if (error) {
|
|
1459
|
+
should.fail(error);
|
|
1460
|
+
return done();
|
|
1461
|
+
}
|
|
1462
|
+
results.should.deep.equal([ 1, 0, 0, 0, 2, 1, 0, 0 ]);
|
|
1463
|
+
|
|
1464
|
+
var txn = env.beginTxn();
|
|
1465
|
+
var expectedData = [
|
|
1466
|
+
[ Buffer.from([4]), Buffer.from([1, 2]) ],
|
|
1467
|
+
[ Buffer.from([5]), Buffer.from([8, 9]) ],
|
|
1468
|
+
[ Buffer.from([7]) ],
|
|
1469
|
+
[ Buffer.from([6]), Buffer.from([7, 8]) ],
|
|
1470
|
+
];
|
|
1471
|
+
for (var i = 0; i < expectedData.length; i++) {
|
|
1472
|
+
var key = expectedData[i][0];
|
|
1473
|
+
var value = expectedData[i][1];
|
|
1474
|
+
if (value) {
|
|
1475
|
+
should.equal(value.equals(txn.getBinary(dbi, key)), true);
|
|
1476
|
+
}
|
|
1477
|
+
else
|
|
1478
|
+
should.equal(txn.getBinary(dbi, key), undefined);
|
|
1479
|
+
}
|
|
1480
|
+
txn.commit();
|
|
1481
|
+
dbi.close();
|
|
1482
|
+
done();
|
|
1483
|
+
});
|
|
1484
|
+
});
|
|
1485
|
+
it('will batchWrite strings and read it', function(done) {
|
|
1486
|
+
var dbi = env.openDbi({
|
|
1487
|
+
name: 'mydb8',
|
|
1488
|
+
create: true,
|
|
1489
|
+
useVersions: true,
|
|
1490
|
+
});
|
|
1491
|
+
var data = [
|
|
1492
|
+
dbi,
|
|
1493
|
+
[ 'key 1', 'this is a test 1', 546 ],
|
|
1494
|
+
[ 'key 2', 'this is a test 2', 444 ],
|
|
1495
|
+
[ 'key 3', 'this is a test 3', 643 ]
|
|
1496
|
+
];
|
|
1497
|
+
var results = Buffer.alloc(3)
|
|
1498
|
+
env.batchWrite(data, results, function(error) {
|
|
1499
|
+
if (error) {
|
|
1500
|
+
should.fail(error);
|
|
1501
|
+
return done();
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
var txn = env.beginTxn();
|
|
1505
|
+
for (var i = 0; i < data.length; i++) {
|
|
1506
|
+
if (!data[i].length)
|
|
1507
|
+
continue
|
|
1508
|
+
var key = data[i][0];
|
|
1509
|
+
var value = data[i][1];
|
|
1510
|
+
var version = data[i][2];
|
|
1511
|
+
if (value)
|
|
1512
|
+
value.should.equal(txn.getUtf8(dbi, key));
|
|
1513
|
+
else
|
|
1514
|
+
should.equal(txn.getUtf8(dbi, key), undefined);
|
|
1515
|
+
if (version)
|
|
1516
|
+
version.should.equal(lmdb.getLastVersion())
|
|
1517
|
+
}
|
|
1518
|
+
txn.commit();
|
|
1519
|
+
dbi.close();
|
|
1520
|
+
done();
|
|
1521
|
+
});
|
|
1522
|
+
console.log('submitted batch')
|
|
1523
|
+
});
|
|
1524
|
+
});
|
|
1525
|
+
});
|