jsql-neo 3.4.1 → 3.4.3

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/table.js CHANGED
@@ -303,7 +303,39 @@ class Table {
303
303
 
304
304
  updateById(id, updates) {
305
305
  if (!this._primaryKey) throw createError('ER_PARSE_ERROR', 'Table has no primary key');
306
- return this.update({ [this._primaryKey]: id }, updates);
306
+ for (const hook of this._hooks.beforeUpdate) {
307
+ updates = hook({ [this._primaryKey]: id }, { ...updates }) || updates;
308
+ }
309
+ updates = this._validateDataTypes(updates, true);
310
+ let rowIndex;
311
+ if (this._pkIndex) {
312
+ rowIndex = this._pkIndex.get(id);
313
+ } else {
314
+ this._ensureBTrees();
315
+ if (this._btrees[this._primaryKey]) {
316
+ const indices = this._btrees[this._primaryKey].search(id);
317
+ rowIndex = indices.length > 0 ? indices[0] : undefined;
318
+ } else {
319
+ rowIndex = this._rows.findIndex(r => r[this._primaryKey] === id);
320
+ if (rowIndex === -1) rowIndex = undefined;
321
+ }
322
+ }
323
+ if (rowIndex === undefined) return 0;
324
+ const row = this._rows[rowIndex];
325
+ if (row && row._deleted) return 0;
326
+ const oldData = { ...row };
327
+ const merged = { ...row, ...updates };
328
+ this._validateConstraints(merged, rowIndex);
329
+ this._removeFromIndexes(rowIndex, oldData);
330
+ Object.assign(row, updates);
331
+ this._addToIndexes(rowIndex, row);
332
+ this._dirty = true;
333
+ this._db._markDirty();
334
+ for (const hook of this._hooks.afterUpdate) {
335
+ hook({ [this._primaryKey]: id }, updates, 1);
336
+ }
337
+ this._db._emitChange('update', this._name, { query: { [this._primaryKey]: id }, updates, count: 1 });
338
+ return 1;
307
339
  }
308
340
 
309
341
  // ============================================================
@@ -353,7 +385,38 @@ class Table {
353
385
 
354
386
  removeById(id) {
355
387
  if (!this._primaryKey) throw createError('ER_PARSE_ERROR', 'Table has no primary key');
356
- return this.remove({ [this._primaryKey]: id });
388
+ let rowIndex;
389
+ if (this._pkIndex) {
390
+ rowIndex = this._pkIndex.get(id);
391
+ } else {
392
+ this._ensureBTrees();
393
+ if (this._btrees[this._primaryKey]) {
394
+ const indices = this._btrees[this._primaryKey].search(id);
395
+ rowIndex = indices.length > 0 ? indices[0] : undefined;
396
+ } else {
397
+ rowIndex = this._rows.findIndex(r => r[this._primaryKey] === id);
398
+ if (rowIndex === -1) rowIndex = undefined;
399
+ }
400
+ }
401
+ if (rowIndex === undefined) return 0;
402
+ const row = this._rows[rowIndex];
403
+ if (!row || row._deleted) return 0;
404
+ this._cascadeForeignKeys(row);
405
+ if (this._softDelete) {
406
+ row._deleted = true;
407
+ row._deletedAt = Date.now();
408
+ } else {
409
+ this._removeFromIndexes(rowIndex, row);
410
+ this._rows.splice(rowIndex, 1);
411
+ this._adjustBTreeAfterRemove(rowIndex);
412
+ }
413
+ this._dirty = true;
414
+ this._db._markDirty();
415
+ for (const hook of this._hooks.afterRemove) {
416
+ hook({ [this._primaryKey]: id }, 1);
417
+ }
418
+ this._db._emitChange('remove', this._name, { query: { [this._primaryKey]: id }, count: 1 });
419
+ return 1;
357
420
  }
358
421
 
359
422
  removeSoft(query = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "3.4.1",
3
+ "version": "3.4.3",
4
4
  "description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,20 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function jsql_count(table: string): string;
5
+
6
+ export function jsql_create_table(name: string, schema_json: string): string;
7
+
8
+ export function jsql_drop_table(name: string): string;
9
+
10
+ export function jsql_find(table: string, filter_json: string, limit: number, offset: number): string;
11
+
12
+ export function jsql_find_by_id(table: string, id: bigint): string;
13
+
14
+ export function jsql_insert(table: string, data_json: string): string;
15
+
16
+ export function jsql_insert_buf(table: string, data: Uint8Array): string;
17
+
18
+ export function jsql_remove_by_id(table: string, id: bigint): string;
19
+
20
+ export function jsql_update_by_id(table: string, id: bigint, data_json: string): string;
@@ -0,0 +1,334 @@
1
+ /* @ts-self-types="./jsql_neo_wasm.d.ts" */
2
+
3
+ /**
4
+ * @param {string} table
5
+ * @returns {string}
6
+ */
7
+ function jsql_count(table) {
8
+ let deferred2_0;
9
+ let deferred2_1;
10
+ try {
11
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
12
+ const len0 = WASM_VECTOR_LEN;
13
+ const ret = wasm.jsql_count(ptr0, len0);
14
+ deferred2_0 = ret[0];
15
+ deferred2_1 = ret[1];
16
+ return getStringFromWasm0(ret[0], ret[1]);
17
+ } finally {
18
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
19
+ }
20
+ }
21
+ exports.jsql_count = jsql_count;
22
+
23
+ /**
24
+ * @param {string} name
25
+ * @param {string} schema_json
26
+ * @returns {string}
27
+ */
28
+ function jsql_create_table(name, schema_json) {
29
+ let deferred3_0;
30
+ let deferred3_1;
31
+ try {
32
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
33
+ const len0 = WASM_VECTOR_LEN;
34
+ const ptr1 = passStringToWasm0(schema_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35
+ const len1 = WASM_VECTOR_LEN;
36
+ const ret = wasm.jsql_create_table(ptr0, len0, ptr1, len1);
37
+ deferred3_0 = ret[0];
38
+ deferred3_1 = ret[1];
39
+ return getStringFromWasm0(ret[0], ret[1]);
40
+ } finally {
41
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
42
+ }
43
+ }
44
+ exports.jsql_create_table = jsql_create_table;
45
+
46
+ /**
47
+ * @param {string} name
48
+ * @returns {string}
49
+ */
50
+ function jsql_drop_table(name) {
51
+ let deferred2_0;
52
+ let deferred2_1;
53
+ try {
54
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
55
+ const len0 = WASM_VECTOR_LEN;
56
+ const ret = wasm.jsql_drop_table(ptr0, len0);
57
+ deferred2_0 = ret[0];
58
+ deferred2_1 = ret[1];
59
+ return getStringFromWasm0(ret[0], ret[1]);
60
+ } finally {
61
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
62
+ }
63
+ }
64
+ exports.jsql_drop_table = jsql_drop_table;
65
+
66
+ /**
67
+ * @param {string} table
68
+ * @param {string} filter_json
69
+ * @param {number} limit
70
+ * @param {number} offset
71
+ * @returns {string}
72
+ */
73
+ function jsql_find(table, filter_json, limit, offset) {
74
+ let deferred3_0;
75
+ let deferred3_1;
76
+ try {
77
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
78
+ const len0 = WASM_VECTOR_LEN;
79
+ const ptr1 = passStringToWasm0(filter_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
80
+ const len1 = WASM_VECTOR_LEN;
81
+ const ret = wasm.jsql_find(ptr0, len0, ptr1, len1, limit, offset);
82
+ deferred3_0 = ret[0];
83
+ deferred3_1 = ret[1];
84
+ return getStringFromWasm0(ret[0], ret[1]);
85
+ } finally {
86
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
87
+ }
88
+ }
89
+ exports.jsql_find = jsql_find;
90
+
91
+ /**
92
+ * @param {string} table
93
+ * @param {bigint} id
94
+ * @returns {string}
95
+ */
96
+ function jsql_find_by_id(table, id) {
97
+ let deferred2_0;
98
+ let deferred2_1;
99
+ try {
100
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
101
+ const len0 = WASM_VECTOR_LEN;
102
+ const ret = wasm.jsql_find_by_id(ptr0, len0, id);
103
+ deferred2_0 = ret[0];
104
+ deferred2_1 = ret[1];
105
+ return getStringFromWasm0(ret[0], ret[1]);
106
+ } finally {
107
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
108
+ }
109
+ }
110
+ exports.jsql_find_by_id = jsql_find_by_id;
111
+
112
+ /**
113
+ * @param {string} table
114
+ * @param {string} data_json
115
+ * @returns {string}
116
+ */
117
+ function jsql_insert(table, data_json) {
118
+ let deferred3_0;
119
+ let deferred3_1;
120
+ try {
121
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
122
+ const len0 = WASM_VECTOR_LEN;
123
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
124
+ const len1 = WASM_VECTOR_LEN;
125
+ const ret = wasm.jsql_insert(ptr0, len0, ptr1, len1);
126
+ deferred3_0 = ret[0];
127
+ deferred3_1 = ret[1];
128
+ return getStringFromWasm0(ret[0], ret[1]);
129
+ } finally {
130
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
131
+ }
132
+ }
133
+ exports.jsql_insert = jsql_insert;
134
+
135
+ /**
136
+ * @param {string} table
137
+ * @param {Uint8Array} data
138
+ * @returns {string}
139
+ */
140
+ function jsql_insert_buf(table, data) {
141
+ let deferred3_0;
142
+ let deferred3_1;
143
+ try {
144
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
145
+ const len0 = WASM_VECTOR_LEN;
146
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
147
+ const len1 = WASM_VECTOR_LEN;
148
+ const ret = wasm.jsql_insert_buf(ptr0, len0, ptr1, len1);
149
+ deferred3_0 = ret[0];
150
+ deferred3_1 = ret[1];
151
+ return getStringFromWasm0(ret[0], ret[1]);
152
+ } finally {
153
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
154
+ }
155
+ }
156
+ exports.jsql_insert_buf = jsql_insert_buf;
157
+
158
+ /**
159
+ * @param {string} table
160
+ * @param {bigint} id
161
+ * @returns {string}
162
+ */
163
+ function jsql_remove_by_id(table, id) {
164
+ let deferred2_0;
165
+ let deferred2_1;
166
+ try {
167
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
168
+ const len0 = WASM_VECTOR_LEN;
169
+ const ret = wasm.jsql_remove_by_id(ptr0, len0, id);
170
+ deferred2_0 = ret[0];
171
+ deferred2_1 = ret[1];
172
+ return getStringFromWasm0(ret[0], ret[1]);
173
+ } finally {
174
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
175
+ }
176
+ }
177
+ exports.jsql_remove_by_id = jsql_remove_by_id;
178
+
179
+ /**
180
+ * @param {string} table
181
+ * @param {bigint} id
182
+ * @param {string} data_json
183
+ * @returns {string}
184
+ */
185
+ function jsql_update_by_id(table, id, data_json) {
186
+ let deferred3_0;
187
+ let deferred3_1;
188
+ try {
189
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
192
+ const len1 = WASM_VECTOR_LEN;
193
+ const ret = wasm.jsql_update_by_id(ptr0, len0, id, ptr1, len1);
194
+ deferred3_0 = ret[0];
195
+ deferred3_1 = ret[1];
196
+ return getStringFromWasm0(ret[0], ret[1]);
197
+ } finally {
198
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
199
+ }
200
+ }
201
+ exports.jsql_update_by_id = jsql_update_by_id;
202
+ function __wbg_get_imports() {
203
+ const import0 = {
204
+ __proto__: null,
205
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
206
+ const obj = arg1;
207
+ const ret = typeof(obj) === 'string' ? obj : undefined;
208
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
209
+ var len1 = WASM_VECTOR_LEN;
210
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
211
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
212
+ },
213
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
214
+ throw new Error(getStringFromWasm0(arg0, arg1));
215
+ },
216
+ __wbg_new_0_3da9e97f24fc69be: function() {
217
+ const ret = new Date();
218
+ return ret;
219
+ },
220
+ __wbg_toISOString_706fbe321055ee58: function(arg0) {
221
+ const ret = arg0.toISOString();
222
+ return ret;
223
+ },
224
+ __wbindgen_init_externref_table: function() {
225
+ const table = wasm.__wbindgen_externrefs;
226
+ const offset = table.grow(4);
227
+ table.set(0, undefined);
228
+ table.set(offset + 0, undefined);
229
+ table.set(offset + 1, null);
230
+ table.set(offset + 2, true);
231
+ table.set(offset + 3, false);
232
+ },
233
+ };
234
+ return {
235
+ __proto__: null,
236
+ "./jsql_neo_wasm_bg.js": import0,
237
+ };
238
+ }
239
+
240
+ let cachedDataViewMemory0 = null;
241
+ function getDataViewMemory0() {
242
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
243
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
244
+ }
245
+ return cachedDataViewMemory0;
246
+ }
247
+
248
+ function getStringFromWasm0(ptr, len) {
249
+ return decodeText(ptr >>> 0, len);
250
+ }
251
+
252
+ let cachedUint8ArrayMemory0 = null;
253
+ function getUint8ArrayMemory0() {
254
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
255
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
256
+ }
257
+ return cachedUint8ArrayMemory0;
258
+ }
259
+
260
+ function isLikeNone(x) {
261
+ return x === undefined || x === null;
262
+ }
263
+
264
+ function passArray8ToWasm0(arg, malloc) {
265
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
266
+ getUint8ArrayMemory0().set(arg, ptr / 1);
267
+ WASM_VECTOR_LEN = arg.length;
268
+ return ptr;
269
+ }
270
+
271
+ function passStringToWasm0(arg, malloc, realloc) {
272
+ if (realloc === undefined) {
273
+ const buf = cachedTextEncoder.encode(arg);
274
+ const ptr = malloc(buf.length, 1) >>> 0;
275
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
276
+ WASM_VECTOR_LEN = buf.length;
277
+ return ptr;
278
+ }
279
+
280
+ let len = arg.length;
281
+ let ptr = malloc(len, 1) >>> 0;
282
+
283
+ const mem = getUint8ArrayMemory0();
284
+
285
+ let offset = 0;
286
+
287
+ for (; offset < len; offset++) {
288
+ const code = arg.charCodeAt(offset);
289
+ if (code > 0x7F) break;
290
+ mem[ptr + offset] = code;
291
+ }
292
+ if (offset !== len) {
293
+ if (offset !== 0) {
294
+ arg = arg.slice(offset);
295
+ }
296
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
297
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
298
+ const ret = cachedTextEncoder.encodeInto(arg, view);
299
+
300
+ offset += ret.written;
301
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
302
+ }
303
+
304
+ WASM_VECTOR_LEN = offset;
305
+ return ptr;
306
+ }
307
+
308
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
309
+ cachedTextDecoder.decode();
310
+ function decodeText(ptr, len) {
311
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
312
+ }
313
+
314
+ const cachedTextEncoder = new TextEncoder();
315
+
316
+ if (!('encodeInto' in cachedTextEncoder)) {
317
+ cachedTextEncoder.encodeInto = function (arg, view) {
318
+ const buf = cachedTextEncoder.encode(arg);
319
+ view.set(buf);
320
+ return {
321
+ read: arg.length,
322
+ written: buf.length
323
+ };
324
+ };
325
+ }
326
+
327
+ let WASM_VECTOR_LEN = 0;
328
+
329
+ const wasmPath = `${__dirname}/jsql_neo_wasm_bg.wasm`;
330
+ const wasmBytes = require('fs').readFileSync(wasmPath);
331
+ const wasmModule = new WebAssembly.Module(wasmBytes);
332
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
333
+ let wasm = wasmInstance.exports;
334
+ wasm.__wbindgen_start();
Binary file
@@ -0,0 +1,17 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const jsql_count: (a: number, b: number) => [number, number];
5
+ export const jsql_create_table: (a: number, b: number, c: number, d: number) => [number, number];
6
+ export const jsql_drop_table: (a: number, b: number) => [number, number];
7
+ export const jsql_find: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
8
+ export const jsql_find_by_id: (a: number, b: number, c: bigint) => [number, number];
9
+ export const jsql_insert: (a: number, b: number, c: number, d: number) => [number, number];
10
+ export const jsql_insert_buf: (a: number, b: number, c: number, d: number) => [number, number];
11
+ export const jsql_remove_by_id: (a: number, b: number, c: bigint) => [number, number];
12
+ export const jsql_update_by_id: (a: number, b: number, c: bigint, d: number, e: number) => [number, number];
13
+ export const __wbindgen_malloc: (a: number, b: number) => number;
14
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15
+ export const __wbindgen_externrefs: WebAssembly.Table;
16
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
17
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "jsql-neo-wasm",
3
+ "description": "JSQL Neo WASM bindings",
4
+ "version": "0.1.0",
5
+ "files": [
6
+ "jsql_neo_wasm_bg.wasm",
7
+ "jsql_neo_wasm.js",
8
+ "jsql_neo_wasm.d.ts"
9
+ ],
10
+ "main": "jsql_neo_wasm.js",
11
+ "types": "jsql_neo_wasm.d.ts"
12
+ }