mdbxmou 0.3.0 → 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 +86 -0
- package/package.json +2 -3
- package/src/cursormou.cpp +2 -5
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
|
@@ -46,8 +46,7 @@
|
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"cmake-js": "^7.3.1",
|
|
49
|
-
"node-addon-api": "^8.5.0"
|
|
50
|
-
"uuid": "^13.0.0"
|
|
49
|
+
"node-addon-api": "^8.5.0"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@types/node": "^22.10.2",
|
|
@@ -66,7 +65,7 @@
|
|
|
66
65
|
},
|
|
67
66
|
"gypfile": true,
|
|
68
67
|
"name": "mdbxmou",
|
|
69
|
-
"version": "0.3.
|
|
68
|
+
"version": "0.3.2",
|
|
70
69
|
"description": "Node bindings for mdbx",
|
|
71
70
|
"repository": {
|
|
72
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
|
-
//
|
|
293
|
-
if (ret.IsBoolean() &&
|
|
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);
|