mdbxmou 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/types.d.ts CHANGED
@@ -73,6 +73,87 @@ export interface MDBXDbiStat {
73
73
  modTxnId: number;
74
74
  }
75
75
 
76
+ /** Result of cursor navigation/search operations */
77
+ export interface MDBXCursorResult<K extends MDBXKey = MDBXKey, V extends MDBXValue = MDBXValue> {
78
+ key: K;
79
+ value: V;
80
+ }
81
+
82
+ /**
83
+ * Database cursor for sequential access and range queries.
84
+ * Must be closed before transaction commit/abort.
85
+ * @example
86
+ * ```js
87
+ * const cursor = txn.openCursor(dbi);
88
+ * for (let item = cursor.first(); item; item = cursor.next()) {
89
+ * console.log(item.key, item.value);
90
+ * }
91
+ * cursor.close();
92
+ * txn.commit();
93
+ * ```
94
+ */
95
+ export interface MDBX_Cursor<K extends MDBXKey = MDBXKey, V extends MDBXValue = MDBXValue> {
96
+ /** Move to first record. Returns undefined if database is empty. */
97
+ first(): MDBXCursorResult<K, V> | undefined;
98
+ /** Move to last record. Returns undefined if database is empty. */
99
+ last(): MDBXCursorResult<K, V> | undefined;
100
+ /** Move to next record. Returns undefined if at end. */
101
+ next(): MDBXCursorResult<K, V> | undefined;
102
+ /** Move to previous record. Returns undefined if at beginning. */
103
+ prev(): MDBXCursorResult<K, V> | undefined;
104
+ /** Get current record without moving cursor. */
105
+ current(): MDBXCursorResult<K, V> | undefined;
106
+
107
+ /**
108
+ * Seek to exact key match.
109
+ * @param key - The key to find
110
+ * @returns Record if found, undefined otherwise
111
+ */
112
+ seek(key: K): MDBXCursorResult<K, V> | undefined;
113
+
114
+ /**
115
+ * Seek to key >= given key (lower_bound semantics).
116
+ * @param key - The key to search from
117
+ * @returns First record with key >= given key, undefined if none
118
+ */
119
+ seekGE(key: K): MDBXCursorResult<K, V> | undefined;
120
+
121
+ /**
122
+ * Insert or update a key-value pair.
123
+ * @param key - The key
124
+ * @param value - The value (Buffer or string)
125
+ * @param flags - Optional MDBX put flags
126
+ */
127
+ put(key: K, value: MDBXValue, flags?: number): void;
128
+
129
+ /**
130
+ * Delete record at current cursor position.
131
+ * @param flags - Optional MDBX delete flags
132
+ * @returns true if deleted, false if not found
133
+ */
134
+ del(flags?: number): boolean;
135
+
136
+ /**
137
+ * Iterate over all records.
138
+ * @param callback - Called for each record. Return true to stop iteration.
139
+ * @param backward - If true, iterate from last to first
140
+ * @example
141
+ * ```js
142
+ * cursor.forEach(({key, value}) => {
143
+ * console.log(key, value);
144
+ * if (key === 'stop') return true; // stop iteration
145
+ * });
146
+ * ```
147
+ */
148
+ forEach(callback: (item: MDBXCursorResult<K, V>) => boolean | void, backward?: boolean): void;
149
+
150
+ /**
151
+ * Close cursor. Must be called before transaction commit/abort.
152
+ * Safe to call multiple times.
153
+ */
154
+ close(): void;
155
+ }
156
+
76
157
  export interface MDBX_Dbi<K extends MDBXKey = MDBXKey, V extends MDBXValue = MDBXValue> {
77
158
  readonly id: bigint;
78
159
  readonly dbMode: number;
@@ -119,6 +200,11 @@ export interface MDBX_Txn {
119
200
  createMap(name: string, keyMode: number | bigint): MDBX_Dbi;
120
201
  createMap(name: string, keyMode: number | bigint, valueMode: number): MDBX_Dbi;
121
202
 
203
+ /** Open a cursor for the given dbi */
204
+ openCursor<K extends MDBXKey = MDBXKey, V extends MDBXValue = MDBXValue>(
205
+ dbi: MDBX_Dbi<K, V>
206
+ ): MDBX_Cursor<K, V>;
207
+
122
208
  isActive(): boolean;
123
209
  isTopLevel(): boolean;
124
210
 
package/package.json CHANGED
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "gypfile": true,
67
67
  "name": "mdbxmou",
68
- "version": "0.3.1",
68
+ "version": "0.3.2",
69
69
  "description": "Node bindings for mdbx",
70
70
  "repository": {
71
71
  "type": "git",
package/src/cursormou.cpp CHANGED
@@ -289,13 +289,10 @@ Napi::Value cursormou::for_each(const Napi::CallbackInfo& info) {
289
289
  // Вызов callback
290
290
  auto ret = callback.Call({result});
291
291
 
292
- // Если вернул false или undefined - остановить
293
- if (ret.IsBoolean() && !ret.As<Napi::Boolean>().Value()) {
292
+ // true stops the scan, false/undefined continues (same as dbi.forEach)
293
+ if (ret.IsBoolean() && ret.As<Napi::Boolean>().Value()) {
294
294
  break;
295
295
  }
296
- if (ret.IsUndefined() || ret.IsNull()) {
297
- // undefined/null = продолжаем (как forEach в JS)
298
- }
299
296
 
300
297
  // Следующий элемент
301
298
  rc = mdbx_cursor_get(cursor_, key, val, move_op);