jsql-neo 5.3.0 → 5.4.0

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.
@@ -0,0 +1,110 @@
1
+ /*
2
+ * Regression tests for SQL JOIN null-fill correctness.
3
+ * Zero runtime dependencies (uses Node builtins + in-repo libs only).
4
+ *
5
+ * node test/join.test.js
6
+ *
7
+ * Covers:
8
+ * J1 LEFT JOIN unmatched rows null-fill right-table qualified columns
9
+ * J2 RIGHT JOIN unmatched rows null-fill left-table qualified columns
10
+ * J3 INNER JOIN unaffected
11
+ * J4 unqualified column reference in JOIN
12
+ * J5 WHERE filtering on the null-filled side
13
+ * J6 self-join with table alias
14
+ * J7 chained joins
15
+ */
16
+ const path = require('path');
17
+
18
+ const ROOT = path.join(__dirname, '..');
19
+ const Database = require(path.join(ROOT, 'lib/database'));
20
+ const { executeSQL } = require(path.join(ROOT, 'lib/sql'));
21
+
22
+ let passed = 0, failed = 0;
23
+ function ok(name, cond, extra) {
24
+ if (cond) { passed++; console.log('[OK]', name); }
25
+ else { failed++; console.log('[FAIL]', name, extra !== undefined ? '-> ' + JSON.stringify(extra) : ''); }
26
+ }
27
+
28
+ async function setup(db) {
29
+ await executeSQL(db, 'CREATE TABLE a (id INT PRIMARY KEY, a_name STRING)');
30
+ await executeSQL(db, 'CREATE TABLE b (id INT PRIMARY KEY, a_id INT, b_name STRING)');
31
+ await executeSQL(db, "INSERT INTO a VALUES (1,'A1'),(2,'A2'),(3,'A3')");
32
+ await executeSQL(db, "INSERT INTO b VALUES (10,2,'B2'),(20,99,'B99')");
33
+ }
34
+
35
+ (async () => {
36
+ /* ============ J1 LEFT JOIN null-fill ============ */
37
+ {
38
+ const db = new Database(':memory:', { autoSave: false });
39
+ await setup(db);
40
+ const r = await executeSQL(db, 'SELECT a.id AS aid, a.a_name, b.id AS bid, b.b_name FROM a LEFT JOIN b ON a.id = b.a_id');
41
+ const row1 = r.rows[0]; // a=1 unmatched
42
+ ok('J1 left unmatched row', row1 && row1[0] === 1 && row1[1] === 'A1' && row1[2] === null && row1[3] === null, row1);
43
+ const row3 = r.rows[2]; // a=3 unmatched
44
+ ok('J1 second unmatched row', row3 && row3[0] === 3 && row3[2] === null, row3);
45
+ const row2 = r.rows[1]; // matched
46
+ ok('J1 matched row intact', row2 && row2[0] === 2 && row2[1] === 'A2' && row2[2] === 10 && row2[3] === 'B2', row2);
47
+ }
48
+
49
+ /* ============ J2 RIGHT JOIN null-fill ============ */
50
+ {
51
+ const db = new Database(':memory:', { autoSave: false });
52
+ await setup(db);
53
+ const r = await executeSQL(db, 'SELECT a.id AS aid, a.a_name, b.id AS bid, b.b_name FROM a RIGHT JOIN b ON a.id = b.a_id');
54
+ const b99 = r.rows[1]; // b=20 unmatched (a_id=99)
55
+ ok('J2 right unmatched row', b99 && b99[0] === null && b99[1] === null && b99[2] === 20 && b99[3] === 'B99', b99);
56
+ const b2 = r.rows[0]; // matched
57
+ ok('J2 matched row intact', b2 && b2[0] === 2 && b2[1] === 'A2' && b2[2] === 10 && b2[3] === 'B2', b2);
58
+ }
59
+
60
+ /* ============ J3 INNER JOIN ============ */
61
+ {
62
+ const db = new Database(':memory:', { autoSave: false });
63
+ await setup(db);
64
+ const r = await executeSQL(db, 'SELECT a.id AS aid, b.id AS bid FROM a INNER JOIN b ON a.id = b.a_id');
65
+ ok('J3 inner join', r.rows.length === 1 && r.rows[0][0] === 2 && r.rows[0][1] === 10, r.rows);
66
+ }
67
+
68
+ /* ============ J4 unqualified reference ============ */
69
+ {
70
+ const db = new Database(':memory:', { autoSave: false });
71
+ await setup(db);
72
+ const r = await executeSQL(db, 'SELECT a.id AS aid, b.b_name FROM a LEFT JOIN b ON a.id = b.a_id');
73
+ ok('J4 unprefixed id resolves to left table', r.rows[0][0] === 1 && r.rows[0][1] === null, r.rows[0]);
74
+ }
75
+
76
+ /* ============ J5 WHERE on null-filled side ============ */
77
+ {
78
+ const db = new Database(':memory:', { autoSave: false });
79
+ await setup(db);
80
+ const r = await executeSQL(db, "SELECT a.id AS aid, b.b_name FROM a LEFT JOIN b ON a.id = b.a_id WHERE b.id IS NULL");
81
+ ok('J5 left where b.id IS NULL', r.rows.length === 2 && r.rows.every(x => x[1] === null), r.rows);
82
+ const r2 = await executeSQL(db, "SELECT a.a_name, b.id AS bid FROM a RIGHT JOIN b ON a.id = b.a_id WHERE a.id IS NULL");
83
+ ok('J5 right where a.id IS NULL', r2.rows.length === 1 && r2.rows[0][0] === null && r2.rows[0][1] === 20, r2.rows);
84
+ }
85
+
86
+ /* ============ J6 self-join with alias ============ */
87
+ {
88
+ const db = new Database(':memory:', { autoSave: false });
89
+ await executeSQL(db, 'CREATE TABLE emp (id INT PRIMARY KEY, mgr_id INT, name STRING)');
90
+ await executeSQL(db, "INSERT INTO emp VALUES (1,NULL,'boss'),(2,1,'alice'),(3,999,'orphan')");
91
+ const r = await executeSQL(db, 'SELECT e.name AS ename, m.name AS mname FROM emp e LEFT JOIN emp m ON e.mgr_id = m.id');
92
+ ok('J6 self left join', r.rows.length === 3 && r.rows[0][0] === 'boss' && r.rows[0][1] === null && r.rows[1][1] === 'boss' && r.rows[2][1] === null, r.rows);
93
+ }
94
+
95
+ /* ============ J7 chained joins ============ */
96
+ {
97
+ const db = new Database(':memory:', { autoSave: false });
98
+ await executeSQL(db, 'CREATE TABLE a (id INT PRIMARY KEY, a_name STRING)');
99
+ await executeSQL(db, 'CREATE TABLE b (id INT PRIMARY KEY, a_id INT, b_name STRING)');
100
+ await executeSQL(db, 'CREATE TABLE c (id INT PRIMARY KEY, b_id INT, c_name STRING)');
101
+ await executeSQL(db, "INSERT INTO a VALUES (1,'A1'),(2,'A2'),(3,'A3')");
102
+ await executeSQL(db, "INSERT INTO b VALUES (10,2,'B2'),(20,99,'B99')");
103
+ await executeSQL(db, "INSERT INTO c VALUES (100,10,'C10'),(200,77,'C77')");
104
+ const r = await executeSQL(db, 'SELECT a.id AS aid, b.id AS bid, c.id AS cid, c.c_name FROM a LEFT JOIN b ON a.id = b.a_id LEFT JOIN c ON b.id = c.b_id');
105
+ ok('J7 chained left joins', r.rows.length === 3 && r.rows[1][1] === 10 && r.rows[1][2] === 100 && r.rows[1][3] === 'C10' && r.rows[0][1] === null && r.rows[0][2] === null, r.rows);
106
+ }
107
+
108
+ console.log(failed === 0 ? `\nALL ${passed} JOIN TESTS PASSED` : `\n${failed} FAILURES (${passed} passed)`);
109
+ process.exit(failed === 0 ? 0 : 1);
110
+ })().catch((e) => { console.error('FATAL', e); process.exit(1); });
@@ -0,0 +1,159 @@
1
+ /*
2
+ * Native (.node N-API) regression tests
3
+ * node test/native.test.js
4
+ * Covers: NativeJSQL CRUD + flat row shape, shorthand/snake_case schemas,
5
+ * disk persistence, and the better-sqlite3 compat layer on the native engine.
6
+ */
7
+ const path = require('path');
8
+ const fs = require('fs');
9
+ const os = require('os');
10
+ const ROOT = path.join(__dirname, '..');
11
+
12
+ let passed = 0, failed = 0;
13
+ function ok(name, cond, extra) {
14
+ if (cond) { passed++; console.log('[OK]', name); }
15
+ else { failed++; console.log('[FAIL]', name, extra !== undefined ? JSON.stringify(extra) : ''); }
16
+ }
17
+
18
+ (async () => {
19
+ const { JSQL } = require(path.join(ROOT, 'lib', 'native_client'));
20
+
21
+ /* ---------- basic CRUD + flat row shape ---------- */
22
+ {
23
+ const db = new JSQL();
24
+ await db.start();
25
+ await db.createTable('users', { id: 'integer primary key auto_increment', name: 'string', age: 'integer' });
26
+ const ids = await db.insert('users', [{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]);
27
+ ok('batch insert returns ids', Array.isArray(ids) && ids.length === 2, ids);
28
+
29
+ const row = db.findById('users', 1);
30
+ ok('findById returns flat row', row && row.id === 1 && row.name === 'Alice' && row.age === 30 && !('fields' in row), row);
31
+
32
+ const rows = await db.find('users', {});
33
+ ok('find returns flat rows', rows.length === 2 && rows[1].name === 'Bob' && rows[1].id === 2, rows);
34
+ ok('filter match', (await db.find('users', { age: 25 })).length === 1);
35
+ ok('filter no match', (await db.find('users', { age: 99 })).length === 0);
36
+ ok('count', (await db.count('users')) === 2);
37
+
38
+ db.updateByIds('users', [[1, { age: 99 }]]);
39
+ await new Promise(r => setTimeout(r, 150));
40
+ ok('updateByIds applied', db.findById('users', 1).age === 99, db.findById('users', 1));
41
+
42
+ db.removeByIds('users', [2]);
43
+ await new Promise(r => setTimeout(r, 150));
44
+ ok('removeByIds applied', (await db.count('users')) === 1, await db.count('users'));
45
+ await db.stop();
46
+ }
47
+
48
+ /* ---------- shorthand and snake_case schemas ---------- */
49
+ {
50
+ const db = new JSQL();
51
+ await db.start();
52
+ await db.createTable('t2', { name: 'string unique', n: 'number', ok: 'boolean' });
53
+ await db.insert('t2', { name: 'x', n: 1.5, ok: true });
54
+ const r2 = (await db.find('t2', {}))[0];
55
+ ok('shorthand schema fields', r2.name === 'x' && r2.n === 1.5 && r2.ok === true, r2);
56
+
57
+ await db.createTable('t3', { id: { type: 'integer', primary_key: true, auto_increment: true }, name: { type: 'string' } });
58
+ await db.insert('t3', { name: 'a' });
59
+ await db.insert('t3', { id: 7, name: 'b' });
60
+ ok('snake_case pk respected', db.findById('t3', 7).name === 'b', db.findById('t3', 7));
61
+ ok('explicit pk bumps next id', db.findById('t3', 1).name === 'a');
62
+
63
+ await db.createTable('cfg', 'key string primary key, value string');
64
+ const cfgIds = await db.insert('cfg', { key: 'a', value: '1' });
65
+ ok('full shorthand string schema', cfgIds[0] === 'a' && db.findById('cfg', 'a').value === '1', cfgIds);
66
+ await db.stop();
67
+ }
68
+
69
+ /* ---------- disk persistence roundtrip ---------- */
70
+ {
71
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'jsql-native-'));
72
+ const db = new JSQL({ path: dir, mode: 'disk' });
73
+ await db.start();
74
+ await db.createTable('p', { id: { type: 'integer', primaryKey: true, autoIncrement: true }, v: { type: 'string' } });
75
+ await db.insert('p', { v: 'persisted' });
76
+ await db.stop();
77
+ const db2 = new JSQL({ path: dir, mode: 'disk' });
78
+ await db2.start();
79
+ ok('tables restored', db2.getTables().includes('p'));
80
+ ok('rows persisted', (await db2.find('p', {}))[0].v === 'persisted', await db2.find('p', {}));
81
+ await db2.stop();
82
+ }
83
+
84
+ /* ---------- better-sqlite3 compat on native engine ---------- */
85
+ {
86
+ const Database = require(path.join(ROOT, 'lib', 'sqlite_compat'));
87
+ const db = new Database(':memory:', { engine: 'native' });
88
+ db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING, age INTEGER)');
89
+ const r = db.prepare('INSERT INTO t (name, age) VALUES (?, ?)').run('a', 1);
90
+ ok('compat run returns changes', r.changes === 1 && r.lastInsertRowid === 1, r);
91
+ db.prepare('INSERT INTO t (name, age) VALUES (?, ?)').run('b', 2);
92
+ ok('compat select', db.prepare('SELECT * FROM t WHERE age = ?').get(1).name === 'a');
93
+ db.prepare('UPDATE t SET age = 99 WHERE name = ?').run('b');
94
+ ok('compat update', db.prepare('SELECT age FROM t WHERE name = ?').get('b').age === 99);
95
+ db.exec('BEGIN');
96
+ db.prepare('INSERT INTO t (name) VALUES (?)').run('tx');
97
+ db.exec('ROLLBACK');
98
+ ok('compat rollback', db.prepare('SELECT COUNT(*) AS n FROM t').get().n === 2);
99
+ const buf = db.serialize();
100
+ db.close();
101
+ const db2 = new Database(':memory:', { engine: 'native' });
102
+ db2.deserialize(buf);
103
+ ok('compat serialize roundtrip', db2.prepare('SELECT COUNT(*) AS n FROM t').get().n === 2);
104
+ db2.close();
105
+ }
106
+
107
+ /* ---------- non-auto pk: id resolution by pk value ---------- */
108
+ {
109
+ const db = new JSQL();
110
+ await db.start();
111
+ await db.createTable('config', { key: { type: 'string', primaryKey: true }, value: 'string' });
112
+ const ids = await db.insert('config', [{ key: 'a', value: '1' }, { key: 'b', value: '2' }]);
113
+ ok('non-auto pk insert returns pk values', JSON.stringify(ids) === JSON.stringify(['a', 'b']), ids);
114
+
115
+ const a = db.findById('config', 'a');
116
+ ok('findById resolves string pk', a && a.value === '1' && !('fields' in a), a);
117
+ ok('findById pk miss returns null', db.findById('config', 'nope') === null);
118
+
119
+ db.updateById('config', 'b', { value: '22' });
120
+ await new Promise(r => setTimeout(r, 150));
121
+ ok('updateById resolves string pk', db.findById('config', 'b').value === '22', db.findById('config', 'b'));
122
+
123
+ db.removeById('config', 'a');
124
+ await new Promise(r => setTimeout(r, 150));
125
+ ok('removeById resolves string pk', (await db.count('config')) === 1, await db.count('config'));
126
+
127
+ db.updateByIds('config', [['b', { value: '222' }]]);
128
+ await new Promise(r => setTimeout(r, 150));
129
+ ok('updateByIds resolves string pk', db.findById('config', 'b').value === '222', db.findById('config', 'b'));
130
+
131
+ db.removeByIds('config', ['b']);
132
+ await new Promise(r => setTimeout(r, 150));
133
+ ok('removeByIds resolves string pk', (await db.count('config')) === 0, await db.count('config'));
134
+ await db.stop();
135
+ }
136
+
137
+ /* ---------- transaction aliases (beginTransaction / rollback / commit) ---------- */
138
+ {
139
+ const db = new JSQL();
140
+ await db.start();
141
+ await db.createTable('tx', { id: 'integer primary key auto_increment', name: 'string' });
142
+ await db.insert('tx', { name: 'n1' });
143
+ await db.beginTransaction();
144
+ await db.insert('tx', { name: 'n2' });
145
+ await db.rollback();
146
+ ok('rollback reverts insert', (await db.count('tx')) === 1, await db.count('tx'));
147
+ await db.beginTransaction();
148
+ await db.insert('tx', { name: 'n3' });
149
+ await db.commit();
150
+ ok('commit keeps insert', (await db.count('tx')) === 2, await db.count('tx'));
151
+ await db.stop();
152
+ }
153
+
154
+ console.log(`\n${passed} passed, ${failed} failed`);
155
+ process.exit(failed ? 1 : 0);
156
+ })().catch(e => {
157
+ console.error('[FATAL]', e.stack.split('\n').slice(0, 3).join('\n'));
158
+ process.exit(1);
159
+ });
@@ -0,0 +1,111 @@
1
+ /*
2
+ * WASM (.wasm) regression tests
3
+ * node test/wasm.test.js
4
+ * Covers: JSQL CRUD + flat row shape, shorthand schemas, pk-aware by-id CRUD,
5
+ * non-auto pk insert backfill, and beginTransaction / rollback / commit.
6
+ */
7
+ const path = require('path');
8
+ const ROOT = path.join(__dirname, '..');
9
+
10
+ let passed = 0, failed = 0;
11
+ function ok(name, cond, extra) {
12
+ if (cond) { passed++; console.log('[OK]', name); }
13
+ else { failed++; console.log('[FAIL]', name, extra !== undefined ? JSON.stringify(extra) : ''); }
14
+ }
15
+
16
+ (async () => {
17
+ const { JSQL } = require(path.join(ROOT, 'lib', 'wasm_client'));
18
+
19
+ /* ---------- basic CRUD + flat row shape ---------- */
20
+ {
21
+ const db = new JSQL({ modules: false });
22
+ await db.start();
23
+ await db.createTable('users', { id: 'integer primary key auto_increment', name: 'string', age: 'integer' });
24
+ const ids = await db.insert('users', [{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]);
25
+ ok('wasm batch insert returns ids', Array.isArray(ids) && ids.length === 2, ids);
26
+
27
+ const row = await db.findById('users', 1);
28
+ ok('wasm findById flat row', row && row.id === 1 && row.name === 'Alice' && !('fields' in row), row);
29
+
30
+ const rows = await db.find('users', {});
31
+ ok('wasm find returns flat rows', rows.length === 2 && rows[1].name === 'Bob', rows);
32
+ ok('wasm filter match', (await db.find('users', { age: 25 })).length === 1);
33
+ ok('wasm count', (await db.count('users')) === 2);
34
+
35
+ await db.updateById('users', 1, { age: 31 });
36
+ ok('wasm updateById applied', (await db.findById('users', 1)).age === 31, await db.findById('users', 1));
37
+
38
+ await db.updateByIds('users', [[2, { age: 99 }]]);
39
+ ok('wasm updateByIds applied', (await db.findById('users', 2)).age === 99, await db.findById('users', 2));
40
+
41
+ ok('wasm findByIds', (await db.findByIds('users', [1, 2])).length === 2);
42
+
43
+ await db.removeById('users', 1);
44
+ ok('wasm removeById applied', (await db.count('users')) === 1, await db.count('users'));
45
+
46
+ await db.removeByIds('users', [2]);
47
+ ok('wasm removeByIds applied', (await db.count('users')) === 0, await db.count('users'));
48
+ await db.stop();
49
+ }
50
+
51
+ /* ---------- non-auto pk: id resolution by pk value ---------- */
52
+ {
53
+ const db = new JSQL({ modules: false });
54
+ await db.start();
55
+ await db.createTable('config', { key: { type: 'string', primaryKey: true }, value: 'string' });
56
+ const ids = await db.insert('config', [{ key: 'a', value: '1' }, { key: 'b', value: '2' }]);
57
+ ok('wasm non-auto pk insert returns pk values', JSON.stringify(ids) === JSON.stringify(['a', 'b']), ids);
58
+
59
+ const a = await db.findById('config', 'a');
60
+ ok('wasm findById resolves string pk', a && a.value === '1' && !('fields' in a), a);
61
+ ok('wasm findById pk miss returns null', (await db.findById('config', 'nope')) === null);
62
+
63
+ await db.updateById('config', 'b', { value: '22' });
64
+ ok('wasm updateById resolves string pk', (await db.findById('config', 'b')).value === '22', await db.findById('config', 'b'));
65
+
66
+ await db.removeById('config', 'a');
67
+ ok('wasm removeById resolves string pk', (await db.count('config')) === 1, await db.count('config'));
68
+
69
+ await db.removeByIds('config', ['b']);
70
+ ok('wasm removeByIds resolves string pk', (await db.count('config')) === 0, await db.count('config'));
71
+ await db.stop();
72
+ }
73
+
74
+ /* ---------- shorthand schema ---------- */
75
+ {
76
+ const db = new JSQL({ modules: false });
77
+ await db.start();
78
+ await db.createTable('t2', { name: 'string unique', n: 'number', ok: 'boolean' });
79
+ await db.insert('t2', { name: 'x', n: 1.5, ok: true });
80
+ const r2 = (await db.find('t2', {}))[0];
81
+ ok('wasm shorthand schema fields', r2.name === 'x' && r2.n === 1.5 && r2.ok === true, r2);
82
+
83
+ await db.createTable('cfg', 'key string primary key, value string');
84
+ const cfgIds = await db.insert('cfg', { key: 'a', value: '1' });
85
+ ok('wasm full shorthand string schema', cfgIds[0] === 'a' && (await db.findById('cfg', 'a')).value === '1', cfgIds);
86
+ await db.stop();
87
+ }
88
+
89
+ /* ---------- transactions ---------- */
90
+ {
91
+ const db = new JSQL({ modules: false });
92
+ await db.start();
93
+ await db.createTable('tx', { id: 'integer primary key auto_increment', name: 'string' });
94
+ await db.insert('tx', { name: 'n1' });
95
+ await db.beginTransaction();
96
+ await db.insert('tx', { name: 'n2' });
97
+ await db.rollback();
98
+ ok('wasm rollback reverts insert', (await db.count('tx')) === 1, await db.count('tx'));
99
+ await db.beginTransaction();
100
+ await db.insert('tx', { name: 'n3' });
101
+ await db.commit();
102
+ ok('wasm commit keeps insert', (await db.count('tx')) === 2, await db.count('tx'));
103
+ await db.stop();
104
+ }
105
+
106
+ console.log(`\n${passed} passed, ${failed} failed`);
107
+ process.exit(failed ? 1 : 0);
108
+ })().catch(e => {
109
+ console.error('[FATAL]', e.stack.split('\n').slice(0, 3).join('\n'));
110
+ process.exit(1);
111
+ });
package/wasm/browser.d.ts CHANGED
@@ -1,88 +1,89 @@
1
- /**
2
- * JSQL-NEO browser (WASM + IndexedDB) — ESM entry `jsql-neo/wasm/browser.mjs`.
3
- */
1
+ /* tslint:disable */
2
+ /* eslint-disable */
4
3
 
5
- export type FieldType =
6
- | 'string' | 'integer' | 'float' | 'boolean' | 'date' | 'datetime' | 'timestamp'
7
- | 'object' | 'array' | 'any';
8
-
9
- export interface FieldDef {
10
- type: FieldType;
11
- primaryKey?: boolean;
12
- autoIncrement?: boolean;
13
- unique?: boolean;
14
- required?: boolean;
15
- length?: number;
16
- default?: unknown;
17
- computed?: boolean;
18
- }
4
+ export function jsql_begin_tx(): string;
19
5
 
20
- export type Schema = Record<string, FieldDef>;
6
+ export function jsql_commit_tx(tx_id: string): string;
21
7
 
22
- export interface Row {
23
- id: number | string;
24
- fields?: Record<string, unknown>;
25
- created_at?: string;
26
- updated_at?: string;
27
- [key: string]: unknown;
28
- }
8
+ export function jsql_count(table: string): string;
29
9
 
30
- export interface FindOptions {
31
- limit?: number;
32
- offset?: number;
33
- }
10
+ export function jsql_create_table(name: string, schema_json: string): string;
34
11
 
35
- export type JSQLHook =
36
- | 'beforeInsert' | 'afterInsert'
37
- | 'beforeUpdate' | 'afterUpdate'
38
- | 'beforeDelete' | 'afterDelete'
39
- | 'beforeFind' | 'afterFind'
40
- | 'beforeCreateTable' | 'afterCreateTable'
41
- | 'beforeDropTable' | 'afterDropTable'
42
- | 'beforeFlush' | 'afterFlush'
43
- | 'beforeCount' | 'afterCount'
44
- | 'onStart' | 'onStop';
45
-
46
- export interface JSQLOptions {
47
- dbName?: string;
48
- persistence?: boolean;
49
- flushThreshold?: number;
50
- pageSize?: number;
51
- }
12
+ export function jsql_drop_table(name: string): string;
13
+
14
+ export function jsql_find(table: string, filter_json: string, limit: number, offset: number): string;
15
+
16
+ export function jsql_find_by_id(table: string, id: bigint): string;
17
+
18
+ export function jsql_find_by_ids(table: string, ids_json: string): string;
19
+
20
+ export function jsql_insert(table: string, data_json: string): string;
21
+
22
+ export function jsql_insert_buf(table: string, data: Uint8Array): string;
23
+
24
+ export function jsql_insert_buf_count(table: string, data: Uint8Array): string;
25
+
26
+ export function jsql_insert_json(table: string, json: string): string;
52
27
 
53
- export class JSQL {
54
- constructor(opts?: JSQLOptions);
55
- on(event: JSQLHook, fn: (...args: any[]) => unknown): this;
56
- onEvent(fn: (event: string, data: unknown) => void): this;
57
- start(): Promise<void>;
58
- stop(): Promise<void>;
59
- flush(): Promise<void>;
60
- createTable(name: string, schema: Schema): Promise<unknown>;
61
- dropTable(name: string): Promise<unknown>;
62
- insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<unknown>;
63
- findById(table: string, id: number | string): Promise<Row | null>;
64
- findByIds(table: string, ids: Array<number | string>): Promise<Row[] | null>;
65
- find(table: string, filter?: Record<string, unknown>, opts?: FindOptions): Promise<Row[]>;
66
- count(table: string): Promise<number>;
67
- updateById(table: string, id: number | string, data: Record<string, unknown>): Promise<unknown>;
68
- updateByIds(table: string, entries: Array<[number | string, Record<string, unknown>]>): Promise<unknown>;
69
- removeById(table: string, id: number | string): Promise<unknown>;
70
- removeByIds(table: string, ids: Array<number | string>): Promise<unknown>;
71
- hasTable(name: string): Promise<boolean>;
72
- getTables(): Promise<string[]>;
73
- getTableSchema(name: string): Promise<Schema | null>;
74
- beginTx(): Promise<void>;
75
- commitTx(): Promise<void>;
76
- rollbackTx(): Promise<void>;
77
- begin(): Promise<void>;
78
- commit(): Promise<void>;
79
- rollback(): Promise<void>;
80
- listDatabases(): Promise<string[]>;
81
- createDatabase(name: string): Promise<void>;
82
- dropDatabase(name: string): Promise<void>;
83
- useDatabase(name: string): Promise<void>;
84
- executeSQL(sql: string, params?: unknown[]): Promise<unknown>;
85
- export default?: never;
28
+ export function jsql_remove_by_id(table: string, id: bigint): string;
29
+
30
+ export function jsql_remove_by_ids(table: string, ids_json: string): string;
31
+
32
+ export function jsql_reset(): void;
33
+
34
+ export function jsql_rollback_tx(tx_id: string): string;
35
+
36
+ export function jsql_update_by_id(table: string, id: bigint, data_json: string): string;
37
+
38
+ export function jsql_update_by_ids(table: string, batch_json: string): string;
39
+
40
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
41
+
42
+ export interface InitOutput {
43
+ readonly memory: WebAssembly.Memory;
44
+ readonly jsql_begin_tx: () => [number, number];
45
+ readonly jsql_commit_tx: (a: number, b: number) => [number, number];
46
+ readonly jsql_count: (a: number, b: number) => [number, number];
47
+ readonly jsql_create_table: (a: number, b: number, c: number, d: number) => [number, number];
48
+ readonly jsql_drop_table: (a: number, b: number) => [number, number];
49
+ readonly jsql_find: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
50
+ readonly jsql_find_by_id: (a: number, b: number, c: bigint) => [number, number];
51
+ readonly jsql_find_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
52
+ readonly jsql_insert: (a: number, b: number, c: number, d: number) => [number, number];
53
+ readonly jsql_insert_buf: (a: number, b: number, c: number, d: number) => [number, number];
54
+ readonly jsql_insert_buf_count: (a: number, b: number, c: number, d: number) => [number, number];
55
+ readonly jsql_insert_json: (a: number, b: number, c: number, d: number) => [number, number];
56
+ readonly jsql_remove_by_id: (a: number, b: number, c: bigint) => [number, number];
57
+ readonly jsql_remove_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
58
+ readonly jsql_rollback_tx: (a: number, b: number) => [number, number];
59
+ readonly jsql_update_by_id: (a: number, b: number, c: bigint, d: number, e: number) => [number, number];
60
+ readonly jsql_update_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
61
+ readonly jsql_reset: () => void;
62
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
63
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
64
+ readonly __wbindgen_externrefs: WebAssembly.Table;
65
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
66
+ readonly __wbindgen_start: () => void;
86
67
  }
87
68
 
88
- export function init(input?: Uint8Array | ArrayBuffer | Response | WebAssembly.Module | URL | string): Promise<JSQL | void>;
69
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
70
+
71
+ /**
72
+ * Instantiates the given `module`, which can either be bytes or
73
+ * a precompiled `WebAssembly.Module`.
74
+ *
75
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
76
+ *
77
+ * @returns {InitOutput}
78
+ */
79
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
80
+
81
+ /**
82
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
83
+ * for everything else, calls `WebAssembly.instantiate` directly.
84
+ *
85
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
86
+ *
87
+ * @returns {Promise<InitOutput>}
88
+ */
89
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;