jsql-neo 3.4.5 → 3.4.6
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/wasm_client.js
CHANGED
|
@@ -5,9 +5,90 @@ function safeJsonParse(str) {
|
|
|
5
5
|
try { return JSON.parse(str); } catch { return str; }
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
const textEncoder = new TextEncoder();
|
|
9
|
+
|
|
10
|
+
function encodeBatch(rows) {
|
|
11
|
+
if (rows.length === 0) return new Uint8Array(0);
|
|
12
|
+
const fieldNames = Object.keys(rows[0]);
|
|
13
|
+
const nFields = fieldNames.length;
|
|
14
|
+
|
|
15
|
+
const nameBytes = fieldNames.map(n => textEncoder.encode(n));
|
|
16
|
+
let size = 1;
|
|
17
|
+
for (const nb of nameBytes) size += 1 + nb.length;
|
|
18
|
+
size += 4;
|
|
19
|
+
|
|
20
|
+
const strBufs = [];
|
|
21
|
+
for (let ri = 0; ri < rows.length; ri++) {
|
|
22
|
+
const row = rows[ri];
|
|
23
|
+
for (let fi = 0; fi < nFields; fi++) {
|
|
24
|
+
const val = row[fieldNames[fi]];
|
|
25
|
+
if (val === null || val === undefined) {
|
|
26
|
+
size += 1;
|
|
27
|
+
strBufs.push(null);
|
|
28
|
+
} else if (typeof val === 'number') {
|
|
29
|
+
size += 9;
|
|
30
|
+
strBufs.push(null);
|
|
31
|
+
} else if (typeof val === 'string') {
|
|
32
|
+
const b = textEncoder.encode(val);
|
|
33
|
+
strBufs.push(b);
|
|
34
|
+
size += 1 + 4 + b.length;
|
|
35
|
+
} else {
|
|
36
|
+
size += 2;
|
|
37
|
+
strBufs.push(val ? 1 : 0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const buf = new Uint8Array(size);
|
|
43
|
+
const dv = new DataView(buf.buffer, 0, size);
|
|
44
|
+
let off = 0;
|
|
45
|
+
|
|
46
|
+
buf[off++] = nFields;
|
|
47
|
+
for (const nb of nameBytes) {
|
|
48
|
+
buf[off++] = nb.length;
|
|
49
|
+
buf.set(nb, off);
|
|
50
|
+
off += nb.length;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
dv.setUint32(off, rows.length, true);
|
|
54
|
+
off += 4;
|
|
55
|
+
|
|
56
|
+
let si = 0;
|
|
57
|
+
for (const row of rows) {
|
|
58
|
+
for (let fi = 0; fi < nFields; fi++) {
|
|
59
|
+
const val = row[fieldNames[fi]];
|
|
60
|
+
const item = strBufs[si++];
|
|
61
|
+
if (val === null || val === undefined) {
|
|
62
|
+
buf[off++] = 0;
|
|
63
|
+
} else if (typeof val === 'number') {
|
|
64
|
+
if (Number.isInteger(val)) {
|
|
65
|
+
buf[off++] = 1;
|
|
66
|
+
dv.setBigInt64(off, BigInt(val), true);
|
|
67
|
+
off += 8;
|
|
68
|
+
} else {
|
|
69
|
+
buf[off++] = 2;
|
|
70
|
+
dv.setFloat64(off, val, true);
|
|
71
|
+
off += 8;
|
|
72
|
+
}
|
|
73
|
+
} else if (typeof val === 'string') {
|
|
74
|
+
buf[off++] = 3;
|
|
75
|
+
dv.setUint32(off, item.length, true);
|
|
76
|
+
off += 4;
|
|
77
|
+
buf.set(item, off);
|
|
78
|
+
off += item.length;
|
|
79
|
+
} else {
|
|
80
|
+
buf[off++] = 4;
|
|
81
|
+
buf[off++] = item;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return buf;
|
|
87
|
+
}
|
|
88
|
+
|
|
8
89
|
class JSQL {
|
|
9
90
|
constructor(opts = {}) {
|
|
10
|
-
this._flushThreshold = opts.flushThreshold ||
|
|
91
|
+
this._flushThreshold = opts.flushThreshold || 5000;
|
|
11
92
|
this._buffer = {};
|
|
12
93
|
this._bufferSize = 0;
|
|
13
94
|
}
|
|
@@ -15,7 +96,8 @@ class JSQL {
|
|
|
15
96
|
async start() {}
|
|
16
97
|
|
|
17
98
|
async _insertBatch(table, rows) {
|
|
18
|
-
const
|
|
99
|
+
const bin = encodeBatch(rows);
|
|
100
|
+
const r = safeJsonParse(wasmBindings.jsql_insert_buf(table, bin));
|
|
19
101
|
if (r && r.error) throw new Error(r.error);
|
|
20
102
|
return r;
|
|
21
103
|
}
|
package/package.json
CHANGED
package/wasm/jsql_neo_wasm.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export function jsql_insert(table: string, data_json: string): string;
|
|
|
15
15
|
|
|
16
16
|
export function jsql_insert_buf(table: string, data: Uint8Array): string;
|
|
17
17
|
|
|
18
|
+
export function jsql_insert_buf_count(table: string, data: Uint8Array): string;
|
|
19
|
+
|
|
18
20
|
export function jsql_remove_by_id(table: string, id: bigint): string;
|
|
19
21
|
|
|
20
22
|
export function jsql_update_by_id(table: string, id: bigint, data_json: string): string;
|
package/wasm/jsql_neo_wasm.js
CHANGED
|
@@ -155,6 +155,29 @@ function jsql_insert_buf(table, data) {
|
|
|
155
155
|
}
|
|
156
156
|
exports.jsql_insert_buf = jsql_insert_buf;
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @param {string} table
|
|
160
|
+
* @param {Uint8Array} data
|
|
161
|
+
* @returns {string}
|
|
162
|
+
*/
|
|
163
|
+
function jsql_insert_buf_count(table, data) {
|
|
164
|
+
let deferred3_0;
|
|
165
|
+
let deferred3_1;
|
|
166
|
+
try {
|
|
167
|
+
const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
168
|
+
const len0 = WASM_VECTOR_LEN;
|
|
169
|
+
const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
170
|
+
const len1 = WASM_VECTOR_LEN;
|
|
171
|
+
const ret = wasm.jsql_insert_buf_count(ptr0, len0, ptr1, len1);
|
|
172
|
+
deferred3_0 = ret[0];
|
|
173
|
+
deferred3_1 = ret[1];
|
|
174
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
175
|
+
} finally {
|
|
176
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.jsql_insert_buf_count = jsql_insert_buf_count;
|
|
180
|
+
|
|
158
181
|
/**
|
|
159
182
|
* @param {string} table
|
|
160
183
|
* @param {bigint} id
|
|
Binary file
|
|
@@ -8,6 +8,7 @@ export const jsql_find: (a: number, b: number, c: number, d: number, e: number,
|
|
|
8
8
|
export const jsql_find_by_id: (a: number, b: number, c: bigint) => [number, number];
|
|
9
9
|
export const jsql_insert: (a: number, b: number, c: number, d: number) => [number, number];
|
|
10
10
|
export const jsql_insert_buf: (a: number, b: number, c: number, d: number) => [number, number];
|
|
11
|
+
export const jsql_insert_buf_count: (a: number, b: number, c: number, d: number) => [number, number];
|
|
11
12
|
export const jsql_remove_by_id: (a: number, b: number, c: bigint) => [number, number];
|
|
12
13
|
export const jsql_update_by_id: (a: number, b: number, c: bigint, d: number, e: number) => [number, number];
|
|
13
14
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|