mdbxmou 0.3.6 → 0.3.7

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.
Files changed (3) hide show
  1. package/README.md +73 -38
  2. package/package.json +1 -1
  3. package/src/dbi.cpp +0 -1
package/README.md CHANGED
@@ -24,29 +24,33 @@ CommonJS:
24
24
  ```javascript
25
25
  const { MDBX_Env, MDBX_Param } = require('mdbxmou');
26
26
 
27
- // Create environment
28
- const env = new MDBX_Env();
29
- await env.open({
30
- path: './data',
31
- keyFlag: MDBX_Param.keyFlag.string, // Default key encoding (optional)
32
- valueFlag: MDBX_Param.valueFlag.string // Default value encoding (optional)
33
- });
27
+ async function main() {
28
+ // Create environment
29
+ const env = new MDBX_Env();
30
+ await env.open({
31
+ path: './data',
32
+ keyFlag: MDBX_Param.keyFlag.string, // Default key encoding (optional)
33
+ valueFlag: MDBX_Param.valueFlag.string // Default value encoding (optional)
34
+ });
34
35
 
35
- // Write data
36
- const txn = env.startWrite();
37
- const dbi = txn.createMap(MDBX_Param.keyMode.ordinal);
38
- dbi.put(txn, 1, "hello");
39
- dbi.put(txn, 2, "world");
40
- txn.commit();
36
+ // Write data
37
+ const txn = env.startWrite();
38
+ const dbi = txn.createMap(MDBX_Param.keyMode.ordinal);
39
+ dbi.put(txn, 1, "hello");
40
+ dbi.put(txn, 2, "world");
41
+ txn.commit();
41
42
 
42
- // Read data
43
- const readTxn = env.startRead();
44
- const readDbi = readTxn.openMap(BigInt(MDBX_Param.keyMode.ordinal));
45
- const value = readDbi.get(readTxn, 1);
46
- console.log(value); // "hello"
47
- readTxn.commit();
43
+ // Read data
44
+ const readTxn = env.startRead();
45
+ const readDbi = readTxn.openMap(BigInt(MDBX_Param.keyMode.ordinal));
46
+ const value = readDbi.get(readTxn, 1);
47
+ console.log(value); // "hello"
48
+ readTxn.commit();
48
49
 
49
- await env.close();
50
+ await env.close();
51
+ }
52
+
53
+ main().catch(console.error);
50
54
  ```
51
55
 
52
56
  ESM:
@@ -628,6 +632,9 @@ async function asyncExample() {
628
632
  readTxn.commit();
629
633
  await env.close();
630
634
  }
635
+
636
+ syncExample();
637
+ asyncExample().catch(console.error);
631
638
  ```
632
639
 
633
640
  ### Key Type Behavior
@@ -670,6 +677,8 @@ function keyTypesExample() {
670
677
 
671
678
  env.closeSync();
672
679
  }
680
+
681
+ keyTypesExample();
673
682
  ```
674
683
 
675
684
  ### Cursor Operations
@@ -723,6 +732,8 @@ function cursorExample() {
723
732
  readTxn.commit();
724
733
  env.closeSync();
725
734
  }
735
+
736
+ cursorExample();
726
737
  ```
727
738
 
728
739
  ### Query API (Advanced Async)
@@ -742,7 +753,7 @@ async function queryExample() {
742
753
  // Async query with DBI object (not database name)
743
754
  const results = await env.query([
744
755
  {
745
- dbi: dbi,
756
+ dbi,
746
757
  mode: MDBX_Param.queryMode.insertUnique,
747
758
  item: [
748
759
  { key: 1, value: JSON.stringify({ name: "Alice" }) },
@@ -750,7 +761,7 @@ async function queryExample() {
750
761
  ]
751
762
  },
752
763
  {
753
- dbi: dbi,
764
+ dbi,
754
765
  mode: MDBX_Param.queryMode.get,
755
766
  item: [
756
767
  { key: 1 },
@@ -762,6 +773,8 @@ async function queryExample() {
762
773
  console.log('Query results:', JSON.stringify(results, null, 2));
763
774
  await env.close();
764
775
  }
776
+
777
+ queryExample().catch(console.error);
765
778
  ```
766
779
 
767
780
  ### Async Keys API
@@ -788,7 +801,7 @@ async function keysExample() {
788
801
  console.log("All keys:", allKeys);
789
802
 
790
803
  // Get keys with DBI object parameter
791
- const allKeys2 = await env.keys({ dbi: dbi });
804
+ const allKeys2 = await env.keys({ dbi });
792
805
  console.log("All keys (object):", allKeys2);
793
806
 
794
807
  // Get keys from multiple DBIs
@@ -797,32 +810,54 @@ async function keysExample() {
797
810
 
798
811
  // Get limited keys from specific position
799
812
  const limitedKeys = await env.keys([
800
- { dbi: dbi, limit: 3, from: 5 }
813
+ { dbi, limit: 3, from: 5 }
801
814
  ]);
802
815
  console.log("Limited keys:", limitedKeys);
803
816
 
804
817
  await env.close();
805
818
  }
819
+
820
+ keysExample().catch(console.error);
806
821
  ```
807
822
 
808
823
  ## Error Handling
809
824
 
810
825
  ```javascript
811
- try {
812
- const env = new MDBX_Env();
813
- await env.open({ path: './data' });
814
-
815
- const txn = env.startWrite();
816
- const dbi = txn.createMap(MDBX_Param.keyMode.ordinal);
817
-
818
- // This might throw if key already exists with MDBX_NOOVERWRITE
819
- dbi.put(txn, 123, "value");
820
-
821
- txn.commit();
822
- } catch (error) {
823
- console.error('Database error:', error.message);
824
- if (txn) txn.abort();
826
+ async function errorHandlingExample() {
827
+ let txn;
828
+ try {
829
+ const env = new MDBX_Env();
830
+ await env.open({ path: './data' });
831
+
832
+ txn = env.startWrite();
833
+ const dbi = txn.createMap(MDBX_Param.keyMode.ordinal);
834
+
835
+ // This might throw if key already exists with MDBX_NOOVERWRITE
836
+ dbi.put(txn, 123, "value");
837
+
838
+ txn.commit();
839
+ } catch (error) {
840
+ console.error('Database error:', error.message);
841
+ if (txn) txn.abort();
842
+ }
825
843
  }
844
+
845
+ errorHandlingExample().catch(console.error);
846
+ ```
847
+
848
+ ## Runnable README Tests
849
+
850
+ The examples above have matching runnable tests in `test/`. You can execute them directly:
851
+
852
+ ```bash
853
+ node test/readme-quick-start.js
854
+ node test/readme-sync-example.js
855
+ node test/readme-async-example.js
856
+ node test/readme-key-types.js
857
+ node test/readme-cursor-example.js
858
+ node test/readme-query-example.js
859
+ node test/readme-keys-example.js
860
+ node test/readme-error-handling.js
826
861
  ```
827
862
 
828
863
  ## Configuration Options
package/package.json CHANGED
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "gypfile": true,
67
67
  "name": "mdbxmou",
68
- "version": "0.3.6",
68
+ "version": "0.3.7",
69
69
  "description": "Node bindings for mdbx",
70
70
  "repository": {
71
71
  "type": "git",
package/src/dbi.cpp CHANGED
@@ -44,7 +44,6 @@ bool dbi::del(MDBX_txn* txn, const keymou& key)
44
44
  return true;
45
45
  }
46
46
 
47
-
48
47
  cursormou_managed dbi::open_cursor(MDBX_txn* txn) const
49
48
  {
50
49
  return open_cursor(txn, mdbx::map_handle{id_});