├── examples
├── testdata
│ └── .gitignore
├── 7-largedb.js
├── 6-asyncio.js
├── 1-env.js
├── 9-unnamed-db.js
├── 11-createdbi-usertxn.js
├── 12-largedb-resize.js
├── 3-multiple-transactions.js
├── 2-datatypes.js
├── 4-cursors.js
├── 5-dupsort.js
├── 10-binkeycursors.js
├── 8-multiple-cursors-single-transaction.js
└── advanced1-indexing.js
├── index.js
├── dependencies
└── lmdb
│ └── libraries
│ └── liblmdb
│ ├── .gitignore
│ ├── tooltag
│ ├── COPYRIGHT
│ ├── mdb_copy.1
│ ├── sample-mdb.txt
│ ├── mdb_stat.1
│ ├── mdb_copy.c
│ ├── sample-bdb.txt
│ ├── LICENSE
│ ├── mdb_dump.1
│ ├── mdb_load.1
│ ├── Makefile
│ ├── mtest2.c
│ ├── mtest3.c
│ ├── mtest5.c
│ ├── mtest6.c
│ ├── mtest4.c
│ ├── mtest.c
│ ├── midl.h
│ ├── mdb_stat.c
│ ├── mdb_dump.c
│ ├── midl.c
│ ├── intro.doc
│ ├── CHANGES
│ └── mdb_load.c
├── .gitignore
├── .jshintrc
├── LICENSE
├── package.json
├── binding.gyp
├── src
├── node-lmdb.cpp
├── dbi.cpp
├── misc.cpp
├── txn.cpp
└── cursor.cpp
├── test
└── cluster.js
└── benchmark
└── index.js
/examples/testdata/.gitignore:
--------------------------------------------------------------------------------
1 | !.gitignore
2 | *
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | module.exports = require('bindings')('node-lmdb.node');
4 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/.gitignore:
--------------------------------------------------------------------------------
1 | mtest
2 | mtest[23456]
3 | testdb
4 | mdb_copy
5 | mdb_stat
6 | mdb_dump
7 | mdb_load
8 | *.lo
9 | *.[ao]
10 | *.so
11 | *.exe
12 | *[~#]
13 | *.bak
14 | *.orig
15 | *.rej
16 | *.gcov
17 | *.gcda
18 | *.gcno
19 | core
20 | core.*
21 | valgrind.*
22 | man/
23 | html/
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Build and test data
3 | build
4 | prebuilds
5 | testdata
6 | test/testdata
7 | benchmark/benchdata
8 |
9 | # qmake autogenerated files
10 | moc_*
11 | qrc_*
12 | ui_*
13 | Makefile
14 |
15 | # Qt Creator's stuff
16 | *.pro.user
17 | qtc_packaging
18 |
19 | # Other generated files
20 | *.o
21 | *.slo
22 | *.lo
23 | *.core
24 | MANIFEST
25 |
26 | # gedit's temp files
27 | *~
28 | .goutputstream*
29 |
30 | # Compiled Dynamic libraries
31 | *.so
32 | *.dylib
33 |
34 | # Compiled Static libraries
35 | *.lai
36 | *.la
37 | *.a
38 |
39 | # NPM dependencies
40 | node_modules/
41 |
42 | # Visual Studio Code directory
43 | .vscode
44 |
45 | package-lock.json
46 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/tooltag:
--------------------------------------------------------------------------------
1 |
2 |
3 | mdb_copy_1
4 | mdb_copy - environment copy tool
5 | mdb_copy.1
6 |
7 |
8 | mdb_dump_1
9 | mdb_dump - environment export tool
10 | mdb_dump.1
11 |
12 |
13 | mdb_load_1
14 | mdb_load - environment import tool
15 | mdb_load.1
16 |
17 |
18 | mdb_stat_1
19 | mdb_stat - environment status tool
20 | mdb_stat.1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/COPYRIGHT:
--------------------------------------------------------------------------------
1 | Copyright 2011-2019 Howard Chu, Symas Corp.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted only as authorized by the OpenLDAP
6 | Public License.
7 |
8 | A copy of this license is available in the file LICENSE in the
9 | top-level directory of the distribution or, alternatively, at
10 | .
11 |
12 | OpenLDAP is a registered trademark of the OpenLDAP Foundation.
13 |
14 | Individual files and/or contributed packages may be copyright by
15 | other parties and/or subject to additional restrictions.
16 |
17 | This work also contains materials derived from public sources.
18 |
19 | Additional information about OpenLDAP can be obtained at
20 | .
21 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "bitwise": false,
3 | "browser": true,
4 | "camelcase": false,
5 | "curly": true,
6 | "devel": false,
7 | "eqeqeq": true,
8 | "esnext": true,
9 | "freeze": true,
10 | "immed": true,
11 | "indent": 2,
12 | "latedef": true,
13 | "newcap": false,
14 | "noarg": true,
15 | "node": true,
16 | "noempty": true,
17 | "nonew": true,
18 | "quotmark": "single",
19 | "regexp": true,
20 | "smarttabs": false,
21 | "strict": true,
22 | "trailing": true,
23 | "undef": true,
24 | "unused": true,
25 | "maxparams": 4,
26 | "maxstatements": 15,
27 | "maxcomplexity": 10,
28 | "maxdepth": 3,
29 | "maxlen": 120,
30 | "multistr": true,
31 | "predef": [
32 | "after",
33 | "afterEach",
34 | "before",
35 | "beforeEach",
36 | "describe",
37 | "exports",
38 | "it",
39 | "module",
40 | "require"
41 | ]
42 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Timur Kristóf
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/examples/7-largedb.js:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | Example that shows how to use node-lmdb with LARGE databases
4 | */
5 |
6 | // Set things up
7 |
8 | var lmdb = require('..');
9 | var fs = require('fs');
10 |
11 | var env = new lmdb.Env();
12 | env.open({ path: './testdata', mapSize: 16 * 1024 * 1024 * 1024 });
13 | var dbi = env.openDbi({ name: 'test', create: true });
14 |
15 | // See how much we can squeeze into the db
16 |
17 | try {
18 | while (true) {
19 | for (var i = 0; i < 1000; i++) {
20 | var txn = env.beginTxn();
21 | txn.putString(dbi, randomString(128), randomString(512));
22 | txn.commit();
23 | }
24 | console.log('database size', getDbSize(), 'MB');
25 | }
26 | }
27 | catch (error) {
28 | console.log('database size', getDbSize(), 'MB');
29 | console.log('error is', error);
30 | }
31 |
32 | // Utility functions
33 |
34 | function getDbSize () {
35 | return fs.statSync('./testdata/data.mdb').size / 1024 / 1024;
36 | }
37 |
38 | function randomString (length) {
39 | var result = '';
40 | while (length-- > 0) {
41 | result += String.fromCharCode(97 + Math.floor(Math.random() * 26));
42 | }
43 | return result;
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/examples/6-asyncio.js:
--------------------------------------------------------------------------------
1 |
2 | // Require the module
3 | var lmdb = require('..');
4 |
5 | // Create new LMDB environment
6 | var env = new lmdb.Env();
7 | // Open the environment
8 | env.open({
9 | path: "./testdata",
10 | maxDbs: 10,
11 |
12 | // These options prevent LMDB from automatically syncing on commit
13 | noMetaSync: true,
14 | noSync: true
15 | });
16 | // Open database
17 | var dbi = env.openDbi({
18 | name: "mydb1",
19 | create: true
20 | });
21 |
22 | // Manipulate some data
23 | var txn = env.beginTxn();
24 | var data = txn.getString(dbi, "hello");
25 | console.log(data);
26 | if (data === null) {
27 | txn.putString(dbi, "hello", "Hello world!");
28 | }
29 | else {
30 | txn.del(dbi, "hello");
31 | }
32 | txn.commit();
33 |
34 | // Manually sync the environment
35 | env.sync(function(err) {
36 | if (err) {
37 | // There was an error
38 | console.log("error", err);
39 | }
40 | else {
41 | console.log("successful sync");
42 | }
43 |
44 | // Close the database
45 | dbi.close();
46 | // Close the environment
47 | env.close();
48 | });
49 |
50 | console.log("");
51 | console.log("Run this example again to see the alterations on the database!");
52 |
53 |
--------------------------------------------------------------------------------
/examples/1-env.js:
--------------------------------------------------------------------------------
1 |
2 | // Require the module
3 | var lmdb = require('..');
4 | // Now you can use the module
5 |
6 | // Print the version
7 | console.log("Current lmdb version is", lmdb.version);
8 | // Create new LMDB environment
9 | var env = new lmdb.Env();
10 | // Open the environment
11 | env.open({
12 | // Path to the environment
13 | // IMPORTANT: you will get an error if the directory doesn't exist!
14 | path: "./testdata",
15 | // Maximum number of databases
16 | maxDbs: 10
17 | });
18 | // Open database
19 | var dbi = env.openDbi({
20 | name: "mydb1",
21 | create: true
22 | });
23 |
24 | // Begin transaction
25 | var txn = env.beginTxn();
26 |
27 | // Get data
28 | var data = txn.getString(dbi, "hello");
29 | console.log(data);
30 |
31 | var stat = dbi.stat(txn);
32 | console.log("\ndatabase statistics:");
33 | console.dir(stat);
34 |
35 | if (data === null) {
36 | // Put data
37 | txn.putString(dbi, "hello", "Hello world!");
38 | }
39 | else {
40 | // Delete data
41 | txn.del(dbi, "hello");
42 | }
43 |
44 | console.log("");
45 | console.log("Run this example again to see the alterations on the database!");
46 |
47 | // Commit transaction
48 | txn.commit();
49 |
50 | // Close the database
51 | dbi.close();
52 | // Close the environment
53 | env.close();
54 |
--------------------------------------------------------------------------------
/examples/9-unnamed-db.js:
--------------------------------------------------------------------------------
1 |
2 | // Require the module
3 | var lmdb = require('..');
4 | // Now you can use the module
5 |
6 | // Print the version
7 | console.log("Current lmdb version is", lmdb.version);
8 | // Create new LMDB environment
9 | var env = new lmdb.Env();
10 | // Open the environment
11 | env.open({
12 | // Path to the environment
13 | // IMPORTANT: you will get an error if the directory doesn't exist!
14 | path: "./testdata",
15 | // Maximum number of databases
16 | maxDbs: 10
17 | });
18 | // Open database
19 | var dbi = env.openDbi({
20 | name: null,
21 | create: true
22 | });
23 |
24 | // Begin transaction
25 | var txn = env.beginTxn();
26 |
27 | // Get data
28 | var data = txn.getString(dbi, "hello");
29 | console.log(data);
30 |
31 | var stat = dbi.stat(txn);
32 | console.log("\ndatabase statistics:");
33 | console.dir(stat);
34 |
35 | if (data === null) {
36 | // Put data
37 | txn.putString(dbi, "hello", "Hello world!");
38 | }
39 | else {
40 | // Delete data
41 | txn.del(dbi, "hello");
42 | }
43 |
44 | console.log("");
45 | console.log("Run this example again to see the alterations on the database!");
46 |
47 | // Commit transaction
48 | txn.commit();
49 |
50 | // Close the database
51 | dbi.close();
52 | // Close the environment
53 | env.close();
54 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "node-lmdb",
3 | "description": "Node binding for LMDB, the Lightning Memory-Mapped Database",
4 | "author": "Timur Kristóf ",
5 | "contributors": [
6 | "Timur Kristóf",
7 | "Erich Ocean",
8 | "Braydon Fuller",
9 | "Andreas Holstenson (aholstenson)",
10 | "antoinevw",
11 | "b-ono",
12 | "da77a",
13 | "John Hewson (jahewson)",
14 | "Jeffrey Esquivel S. (jeffesquivels)",
15 | "Stefan Thomas (justmoon)",
16 | "Matt-Esch",
17 | "Oliver Zhou (oliverzy)",
18 | "Pascal Berrang (paberr)",
19 | "Raymond Neilson (rneilson)",
20 | "Kris Zyp (kriszyp)"
21 | ],
22 | "license": "MIT",
23 | "keywords": [
24 | "lmdb",
25 | "database",
26 | "mdb",
27 | "lightning",
28 | "binding"
29 | ],
30 | "repository": "https://github.com/Venemo/node-lmdb",
31 | "version": "0.7.0",
32 | "main": "./index.js",
33 | "scripts": {
34 | "install": "prebuild-install || node-gyp rebuild",
35 | "prebuild": "prebuild --all --verbose",
36 | "test": "./node_modules/.bin/mocha test/**.test.js --recursive",
37 | "benchmark": "node ./benchmark/index.js"
38 | },
39 | "gypfile": true,
40 | "dependencies": {
41 | "bindings": "^1.5.0",
42 | "prebuild-install": "^5.2.5",
43 | "nan": "^2.13.1"
44 | },
45 | "devDependencies": {
46 | "benchmark": "^2.1.4",
47 | "chai": "^3.5.0",
48 | "mkdirp": "^0.5.1",
49 | "mocha": "^5.2.0",
50 | "node-gyp": "^3.6.0",
51 | "prebuild": "8.2.1",
52 | "rimraf": "^2.6.1",
53 | "jshint": "^2.9.4"
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/examples/11-createdbi-usertxn.js:
--------------------------------------------------------------------------------
1 |
2 | // Created as an example for https://github.com/Venemo/node-lmdb/issues/99
3 | // Demonstrates how to create a Dbi from a user-created write transaction.
4 |
5 | // Require the module
6 | var lmdb = require('..');
7 | // Now you can use the module
8 |
9 | // Print the version
10 | console.log("Current lmdb version is", lmdb.version);
11 | // Create new LMDB environment
12 | var env = new lmdb.Env();
13 | // Open the environment
14 | env.open({
15 | // Path to the environment
16 | // IMPORTANT: you will get an error if the directory doesn't exist!
17 | path: "./testdata",
18 | // Maximum number of databases
19 | maxDbs: 10
20 | });
21 |
22 | var txn1 = env.beginTxn();
23 | var dbi = env.openDbi({
24 | name: 'dbUsingUserSuppliedTxn',
25 | create: true,
26 | txn: txn1
27 | });
28 | txn1.putString(dbi, 'hello', 'world');
29 | txn1.commit();
30 |
31 | var txn2 = env.beginTxn({ readOnly: true });
32 | var str = txn2.getString(dbi, 'hello');
33 | txn2.abort();
34 | console.log(str);
35 |
36 | var txn3 = env.beginTxn();
37 | dbi.drop({ txn: txn3 });
38 | txn3.commit();
39 |
40 | console.log("dbi dropped");
41 |
42 | var txn4 = env.beginTxn({ readOnly: true });
43 | try {
44 | dbi = env.openDbi({
45 | name: 'dbUsingUserSuppliedTxn',
46 | create: false,
47 | txn: txn4
48 | });
49 | }
50 | catch (err) {
51 | if (err.message.indexOf("MDB_NOTFOUND") >= 0) {
52 | console.log("dbi not found anymore, because we dropped it");
53 | }
54 | else {
55 | console.log(err);
56 | }
57 | }
58 | txn4.abort();
59 |
60 | // Close the environment
61 | env.close();
62 |
63 |
--------------------------------------------------------------------------------
/dependencies/lmdb/libraries/liblmdb/mdb_copy.1:
--------------------------------------------------------------------------------
1 | .TH MDB_COPY 1 "2014/07/01" "LMDB 0.9.14"
2 | .\" Copyright 2012-2018 Howard Chu, Symas Corp. All Rights Reserved.
3 | .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
4 | .SH NAME
5 | mdb_copy \- LMDB environment copy tool
6 | .SH SYNOPSIS
7 | .B mdb_copy
8 | [\c
9 | .BR \-V ]
10 | [\c
11 | .BR \-c ]
12 | [\c
13 | .BR \-n ]
14 | .B srcpath
15 | [\c
16 | .BR dstpath ]
17 | .SH DESCRIPTION
18 | The
19 | .B mdb_copy
20 | utility copies an LMDB environment. The environment can
21 | be copied regardless of whether it is currently in use.
22 | No lockfile is created, since it gets recreated at need.
23 |
24 | If
25 | .I dstpath
26 | is specified it must be the path of an empty directory
27 | for storing the backup. Otherwise, the backup will be
28 | written to stdout.
29 |
30 | .SH OPTIONS
31 | .TP
32 | .BR \-V
33 | Write the library version number to the standard output, and exit.
34 | .TP
35 | .BR \-c
36 | Compact while copying. Only current data pages will be copied; freed
37 | or unused pages will be omitted from the copy. This option will
38 | slow down the backup process as it is more CPU-intensive.
39 | Currently it fails if the environment has suffered a page leak.
40 | .TP
41 | .BR \-n
42 | Open LDMB environment(s) which do not use subdirectories.
43 |
44 | .SH DIAGNOSTICS
45 | Exit status is zero if no errors occur.
46 | Errors result in a non-zero exit status and
47 | a diagnostic message being written to standard error.
48 | .SH CAVEATS
49 | This utility can trigger significant file size growth if run
50 | in parallel with write transactions, because pages which they
51 | free during copying cannot be reused until the copy is done.
52 | .SH "SEE ALSO"
53 | .BR mdb_stat (1)
54 | .SH AUTHOR
55 | Howard Chu of Symas Corporation
56 |
--------------------------------------------------------------------------------
/examples/12-largedb-resize.js:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | Example that shows how to use node-lmdb with LARGE databases
4 | */
5 |
6 | // Set things up
7 |
8 | var lmdb = require('..');
9 | var fs = require('fs');
10 |
11 | var env = new lmdb.Env();
12 | env.open({ path: './testdata', mapSize: 16 * 1024 * 1024 });
13 |
14 | // Ensure that the database is empty
15 | var dbi = env.openDbi({
16 | name: "test12",
17 | create: true
18 | });
19 | dbi.drop();
20 | dbi = env.openDbi({
21 | name: "test12",
22 | create: true
23 | });
24 |
25 | // See how much we can squeeze into the db
26 | try {
27 | while (true) {
28 | for (var i = 0; i < 1000; i++) {
29 | var txn = env.beginTxn();
30 | txn.putString(dbi, randomString(128), randomString(512));
31 | txn.commit();
32 | }
33 | console.log('database size', getDbSize(), 'MB');
34 | }
35 | }
36 | catch (error) {
37 | console.log('database size', getDbSize(), 'MB');
38 | console.log('needs resize');
39 | }
40 |
41 | var info = env.info();
42 | console.log('maximal database size before resize', (info.mapSize / 1024 / 1024), 'MB');
43 | env.resize(info.mapSize * 2);
44 | info = env.info();
45 | console.log('maximal database size after resize', (info.mapSize / 1024 / 1024), 'MB');
46 |
47 | for (var i = 0; i < 1000; i++) {
48 | var txn = env.beginTxn();
49 | txn.putString(dbi, randomString(128), randomString(512));
50 | txn.commit();
51 | }
52 | console.log('database size', getDbSize(), 'MB');
53 |
54 | // Utility functions
55 |
56 | function getDbSize () {
57 | return fs.statSync('./testdata/data.mdb').size / 1024 / 1024;
58 | }
59 |
60 | function randomString (length) {
61 | var result = '';
62 | while (length-- > 0) {
63 | result += String.fromCharCode(97 + Math.floor(Math.random() * 26));
64 | }
65 | return result;
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/binding.gyp:
--------------------------------------------------------------------------------
1 | {
2 | "variables": {
3 | "os_linux_compiler%": "gcc",
4 | },
5 | "targets": [
6 | {
7 | "target_name": "node-lmdb",
8 | "win_delay_load_hook": "false",
9 | "sources": [
10 | "dependencies/lmdb/libraries/liblmdb/mdb.c",
11 | "dependencies/lmdb/libraries/liblmdb/midl.c",
12 | "src/node-lmdb.cpp",
13 | "src/env.cpp",
14 | "src/misc.cpp",
15 | "src/txn.cpp",
16 | "src/dbi.cpp",
17 | "src/cursor.cpp"
18 | ],
19 | "include_dirs": [
20 | "=7", {
30 | "cflags": [
31 | "-Wimplicit-fallthrough=2",
32 | ],
33 | }],
34 | ],
35 | "ldflags": [
36 | "-fPIC",
37 | "-fvisibility=hidden"
38 | ],
39 | "cflags": [
40 | "-fPIC",
41 | "-fvisibility=hidden"
42 | ],
43 | "cflags_cc": [
44 | "-fPIC",
45 | "-fvisibility=hidden",
46 | "-fvisibility-inlines-hidden",
47 | "-std=c++0x"
48 | ]
49 | }],
50 | ["OS=='mac'", {
51 | "xcode_settings": {
52 | "OTHER_CPLUSPLUSFLAGS" : ["-std=c++11"],
53 | "MACOSX_DEPLOYMENT_TARGET": "10.7",
54 | "OTHER_LDFLAGS": ["-std=c++11"],
55 | "CLANG_CXX_LIBRARY": "libc++"
56 | }
57 | }],
58 | ["OS=='win'", {
59 | "libraries": ["ntdll.lib"]
60 | }],
61 | ],
62 | }
63 | ]
64 | }
65 |
--------------------------------------------------------------------------------
/examples/3-multiple-transactions.js:
--------------------------------------------------------------------------------
1 |
2 | var lmdb = require('..');
3 | var env = new lmdb.Env();
4 | env.open({
5 | // Path to the environment
6 | path: "./testdata",
7 | // Maximum number of databases
8 | maxDbs: 10
9 | });
10 | var dbi = env.openDbi({
11 | name: "mydb3",
12 | create: true,
13 | keyIsUint32: true
14 | });
15 |
16 | var data;
17 |
18 | // Write values
19 |
20 | var txn0 = env.beginTxn();
21 | txn0.putString(dbi, 1, "Hello1");
22 | txn0.putString(dbi, 2, "Hello2");
23 | txn0.commit();
24 | console.log("wrote initial values");
25 |
26 | // Now mess around with transactions
27 |
28 | var txn1 = env.beginTxn({ readOnly: true });
29 | console.log("txn1: started (read only)");
30 | data = txn1.getString(dbi, 1);
31 | console.log("-----", "txn1", 1, data);
32 |
33 | var txn2 = env.beginTxn();
34 | console.log("txn2: started");
35 | txn2.putString(dbi, 1, "Ha ha ha");
36 | console.log("txn2: put other value to key 1");
37 |
38 | // txn2 sees the new value immediately
39 | data = txn2.getString(dbi, 1);
40 | console.log("-----", "txn2", 1, data);
41 |
42 | // txn1 still sees the old value
43 | data = txn1.getString(dbi, 1);
44 | console.log("-----", "txn1", 1, data);
45 |
46 | txn2.commit();
47 | console.log("txn2: committed");
48 |
49 | // txn1 still sees the old value!
50 | data = txn1.getString(dbi, 1);
51 | console.log("-----", "txn1", 1, data);
52 |
53 | txn1.reset();
54 | txn1.renew();
55 | console.log("rxn1: reset+renewed");
56 |
57 | // now txn1 sees the new value
58 | data = txn1.getString(dbi, 1);
59 | console.log("-----", "txn1", 1, data);
60 |
61 | try {
62 | console.log("error expected here:");
63 | // txn1 is readonly, this will throw an exception!
64 | txn1.putString(dbi, 2, "hööhh");
65 | }
66 | catch (err) {
67 | console.log(err);
68 | }
69 |
70 | txn1.commit();
71 | console.log("txn1: aborted");
72 |
73 | dbi.close();
74 | env.close();
75 |
76 |
--------------------------------------------------------------------------------
/src/node-lmdb.cpp:
--------------------------------------------------------------------------------
1 |
2 | // This file is part of node-lmdb, the Node.js binding for lmdb
3 | // Copyright (c) 2013-2017 Timur Kristóf
4 | // Licensed to you under the terms of the MIT license
5 | //
6 | // Permission is hereby granted, free of charge, to any person obtaining a copy
7 | // of this software and associated documentation files (the "Software"), to deal
8 | // in the Software without restriction, including without limitation the rights
9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | // copies of the Software, and to permit persons to whom the Software is
11 | // furnished to do so, subject to the following conditions:
12 |
13 | // The above copyright notice and this permission notice shall be included in
14 | // all copies or substantial portions of the Software.
15 |
16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | // THE SOFTWARE.
23 |
24 | #include "node-lmdb.h"
25 |
26 | using namespace v8;
27 | using namespace node;
28 |
29 | extern "C" {
30 | // Initializes the module
31 | void initializeModule(Local