jsql-neo 5.4.2 → 5.5.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.
- package/LICENSE +202 -202
- package/README.md +8097 -7971
- package/bin/jsql +320 -320
- package/bin/jsql-server +90 -90
- package/bin/jsql-server-control.js +177 -177
- package/index.d.ts +385 -357
- package/index.js +124 -118
- package/lib/ast.js +214 -0
- package/lib/btree.js +413 -413
- package/lib/cache.js +328 -328
- package/lib/client.js +125 -125
- package/lib/database.js +1744 -1744
- package/lib/date-types.js +182 -182
- package/lib/errors.js +89 -89
- package/lib/jsql_format.js +497 -497
- package/lib/migrate.js +254 -254
- package/lib/mod.js +292 -292
- package/lib/mongo_server.js +607 -607
- package/lib/multiserver.js +140 -140
- package/lib/mysql_compat.js +413 -413
- package/lib/mysql_server.js +1237 -1237
- package/lib/native_client.js +732 -732
- package/lib/nedb_compat.js +506 -506
- package/lib/pg_server.js +864 -864
- package/lib/plugin.js +34 -34
- package/lib/query.js +815 -815
- package/lib/redis_server.js +571 -571
- package/lib/sql.js +3460 -2925
- package/lib/sqlite_compat.js +323 -323
- package/lib/sqlite_worker.js +264 -264
- package/lib/table.js +1304 -1304
- package/lib/tui.js +502 -502
- package/lib/wasm.js +1 -1
- package/lib/wasm_client.js +718 -718
- package/lib/web_ui.js +257 -257
- package/native/jsql-neo-native.node +0 -0
- package/nativesrc/jsql-neo-core/Cargo.lock +455 -455
- package/nativesrc/jsql-neo-core/Cargo.toml +24 -24
- package/nativesrc/jsql-neo-core/src/engine/hybrid.rs +455 -455
- package/nativesrc/jsql-neo-core/src/engine/memory.rs +168 -168
- package/nativesrc/jsql-neo-core/src/engine/mod.rs +62 -62
- package/nativesrc/jsql-neo-core/src/engine/table.rs +700 -700
- package/nativesrc/jsql-neo-core/src/lib.rs +2 -2
- package/nativesrc/jsql-neo-core/src/storage/mod.rs +2 -2
- package/nativesrc/jsql-neo-core/src/storage/persistent.rs +1 -1
- package/nativesrc/jsql-neo-core/src/storage/wal.rs +85 -85
- package/nativesrc/jsql-neo-core/src/types.rs +93 -93
- package/nativesrc/jsql-neo-native/Cargo.lock +606 -606
- package/nativesrc/jsql-neo-native/Cargo.toml +16 -16
- package/nativesrc/jsql-neo-native/build.rs +3 -3
- package/nativesrc/jsql-neo-native/package.json +7 -7
- package/nativesrc/jsql-neo-native/src/lib.rs +269 -269
- package/nativesrc/jsql-neo-wasm/Cargo.lock +465 -465
- package/nativesrc/jsql-neo-wasm/Cargo.toml +15 -15
- package/nativesrc/jsql-neo-wasm/src/lib.rs +447 -447
- package/package.json +87 -86
- package/postinstall.js +158 -158
- package/test/btree.test.js +128 -128
- package/test/coverage.js +187 -187
- package/test/join.test.js +110 -110
- package/test/native.test.js +158 -158
- package/test/regress-5.1.0.js +271 -271
- package/test/smoke.js +58 -58
- package/test/sql-parser.test.js +273 -0
- package/test/wasm.test.js +110 -110
- package/wasm/browser.d.ts +89 -89
- package/wasm/browser.mjs +569 -569
- package/wasm/browser_bg.mjs +597 -597
- package/wasm/jsql_neo_wasm.d.ts +38 -38
- package/wasm/jsql_neo_wasm.js +520 -520
- package/wasm/jsql_neo_wasm_bg.wasm.d.ts +26 -26
- package/wasm/package.json +11 -11
package/lib/client.js
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
const http = require('http');
|
|
2
|
-
const { spawn } = require('child_process');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
|
|
6
|
-
function binPath() {
|
|
7
|
-
const dir = path.join(__dirname, '..', 'bin');
|
|
8
|
-
const name = process.platform === 'win32' ? 'jsql-neo-server.exe' : 'jsql-neo-server';
|
|
9
|
-
return path.join(dir, name);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
class JSQL {
|
|
13
|
-
constructor(opts = {}) {
|
|
14
|
-
this.host = opts.host || '127.0.0.1';
|
|
15
|
-
this.port = opts.port || 6379;
|
|
16
|
-
this.dataDir = opts.dataDir || null;
|
|
17
|
-
this._process = null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async start() {
|
|
21
|
-
if (this._process) return;
|
|
22
|
-
const bp = binPath();
|
|
23
|
-
if (!fs.existsSync(bp)) {
|
|
24
|
-
throw new Error(`jsql-neo-server binary not found at ${bp}. Run 'npm run postinstall' to build it.`);
|
|
25
|
-
}
|
|
26
|
-
const args = [];
|
|
27
|
-
if (this.dataDir) {
|
|
28
|
-
args.push('--data-dir', this.dataDir);
|
|
29
|
-
}
|
|
30
|
-
this._process = spawn(bp, args, {
|
|
31
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
32
|
-
env: {
|
|
33
|
-
...process.env,
|
|
34
|
-
JSQL_HOST: this.host,
|
|
35
|
-
JSQL_PORT: String(this.port),
|
|
36
|
-
...(this.dataDir ? { JSQL_DATA_DIR: this.dataDir } : {}),
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
this._process.stdout.on('data', d => process.stdout.write(d));
|
|
40
|
-
this._process.stderr.on('data', d => process.stderr.write(d));
|
|
41
|
-
this._process.on('exit', (code) => { this._process = null; });
|
|
42
|
-
await this._waitForServer();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async stop() {
|
|
46
|
-
if (!this._process) return;
|
|
47
|
-
this._process.kill();
|
|
48
|
-
await new Promise(r => setTimeout(r, 500));
|
|
49
|
-
this._process = null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_waitForServer(retries = 20) {
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
const tryConnect = (n) => {
|
|
55
|
-
if (n <= 0) return reject(new Error('server did not start'));
|
|
56
|
-
const req = http.get(`http://${this.host}:${this.port}/health`, (res) => {
|
|
57
|
-
if (res.statusCode === 200) resolve();
|
|
58
|
-
else setTimeout(() => tryConnect(n - 1), 200);
|
|
59
|
-
});
|
|
60
|
-
req.on('error', () => setTimeout(() => tryConnect(n - 1), 200));
|
|
61
|
-
req.setTimeout(500, () => { req.destroy(); setTimeout(() => tryConnect(n - 1), 200); });
|
|
62
|
-
};
|
|
63
|
-
tryConnect(retries);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async _request(method, path, body) {
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
const opts = {
|
|
70
|
-
hostname: this.host,
|
|
71
|
-
port: this.port,
|
|
72
|
-
path,
|
|
73
|
-
method,
|
|
74
|
-
headers: body ? { 'Content-Type': 'application/json' } : {},
|
|
75
|
-
};
|
|
76
|
-
const req = http.request(opts, (res) => {
|
|
77
|
-
let data = '';
|
|
78
|
-
res.on('data', c => data += c);
|
|
79
|
-
res.on('end', () => {
|
|
80
|
-
try { resolve(JSON.parse(data)); }
|
|
81
|
-
catch (e) { reject(new Error(`invalid JSON: ${data}`)); }
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
req.on('error', reject);
|
|
85
|
-
if (body) req.write(JSON.stringify(body));
|
|
86
|
-
req.end();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async createTable(name, schema) {
|
|
91
|
-
return this._request('POST', `/db/${name}`, schema);
|
|
92
|
-
}
|
|
93
|
-
async dropTable(name) {
|
|
94
|
-
return this._request('DELETE', `/db/${name}`);
|
|
95
|
-
}
|
|
96
|
-
async insert(table, data) {
|
|
97
|
-
return this._request('POST', `/db/${table}/insert`, { data: Array.isArray(data) ? data : [data] });
|
|
98
|
-
}
|
|
99
|
-
async insertMany(table, data) {
|
|
100
|
-
return this._request('POST', `/db/${table}/insertMany`, { data });
|
|
101
|
-
}
|
|
102
|
-
async findById(table, id) {
|
|
103
|
-
return this._request('GET', `/db/${table}/${id}`);
|
|
104
|
-
}
|
|
105
|
-
async find(table, query = {}) {
|
|
106
|
-
return this._request('POST', `/db/${table}/find`, query);
|
|
107
|
-
}
|
|
108
|
-
async count(table) {
|
|
109
|
-
return this._request('GET', `/db/${table}/count`);
|
|
110
|
-
}
|
|
111
|
-
async updateById(table, id, data) {
|
|
112
|
-
return this._request('PUT', `/db/${table}/${id}`, { data });
|
|
113
|
-
}
|
|
114
|
-
async removeById(table, id) {
|
|
115
|
-
return this._request('DELETE', `/db/${table}/${id}`);
|
|
116
|
-
}
|
|
117
|
-
async updateByFilter(table, filter, data) {
|
|
118
|
-
return this._request('POST', `/db/${table}/update`, { filter, data });
|
|
119
|
-
}
|
|
120
|
-
async removeByFilter(table, filter) {
|
|
121
|
-
return this._request('POST', `/db/${table}/remove`, { filter });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
module.exports = { JSQL };
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const { spawn } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
function binPath() {
|
|
7
|
+
const dir = path.join(__dirname, '..', 'bin');
|
|
8
|
+
const name = process.platform === 'win32' ? 'jsql-neo-server.exe' : 'jsql-neo-server';
|
|
9
|
+
return path.join(dir, name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class JSQL {
|
|
13
|
+
constructor(opts = {}) {
|
|
14
|
+
this.host = opts.host || '127.0.0.1';
|
|
15
|
+
this.port = opts.port || 6379;
|
|
16
|
+
this.dataDir = opts.dataDir || null;
|
|
17
|
+
this._process = null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async start() {
|
|
21
|
+
if (this._process) return;
|
|
22
|
+
const bp = binPath();
|
|
23
|
+
if (!fs.existsSync(bp)) {
|
|
24
|
+
throw new Error(`jsql-neo-server binary not found at ${bp}. Run 'npm run postinstall' to build it.`);
|
|
25
|
+
}
|
|
26
|
+
const args = [];
|
|
27
|
+
if (this.dataDir) {
|
|
28
|
+
args.push('--data-dir', this.dataDir);
|
|
29
|
+
}
|
|
30
|
+
this._process = spawn(bp, args, {
|
|
31
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
32
|
+
env: {
|
|
33
|
+
...process.env,
|
|
34
|
+
JSQL_HOST: this.host,
|
|
35
|
+
JSQL_PORT: String(this.port),
|
|
36
|
+
...(this.dataDir ? { JSQL_DATA_DIR: this.dataDir } : {}),
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this._process.stdout.on('data', d => process.stdout.write(d));
|
|
40
|
+
this._process.stderr.on('data', d => process.stderr.write(d));
|
|
41
|
+
this._process.on('exit', (code) => { this._process = null; });
|
|
42
|
+
await this._waitForServer();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async stop() {
|
|
46
|
+
if (!this._process) return;
|
|
47
|
+
this._process.kill();
|
|
48
|
+
await new Promise(r => setTimeout(r, 500));
|
|
49
|
+
this._process = null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_waitForServer(retries = 20) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const tryConnect = (n) => {
|
|
55
|
+
if (n <= 0) return reject(new Error('server did not start'));
|
|
56
|
+
const req = http.get(`http://${this.host}:${this.port}/health`, (res) => {
|
|
57
|
+
if (res.statusCode === 200) resolve();
|
|
58
|
+
else setTimeout(() => tryConnect(n - 1), 200);
|
|
59
|
+
});
|
|
60
|
+
req.on('error', () => setTimeout(() => tryConnect(n - 1), 200));
|
|
61
|
+
req.setTimeout(500, () => { req.destroy(); setTimeout(() => tryConnect(n - 1), 200); });
|
|
62
|
+
};
|
|
63
|
+
tryConnect(retries);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async _request(method, path, body) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
const opts = {
|
|
70
|
+
hostname: this.host,
|
|
71
|
+
port: this.port,
|
|
72
|
+
path,
|
|
73
|
+
method,
|
|
74
|
+
headers: body ? { 'Content-Type': 'application/json' } : {},
|
|
75
|
+
};
|
|
76
|
+
const req = http.request(opts, (res) => {
|
|
77
|
+
let data = '';
|
|
78
|
+
res.on('data', c => data += c);
|
|
79
|
+
res.on('end', () => {
|
|
80
|
+
try { resolve(JSON.parse(data)); }
|
|
81
|
+
catch (e) { reject(new Error(`invalid JSON: ${data}`)); }
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
req.on('error', reject);
|
|
85
|
+
if (body) req.write(JSON.stringify(body));
|
|
86
|
+
req.end();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async createTable(name, schema) {
|
|
91
|
+
return this._request('POST', `/db/${name}`, schema);
|
|
92
|
+
}
|
|
93
|
+
async dropTable(name) {
|
|
94
|
+
return this._request('DELETE', `/db/${name}`);
|
|
95
|
+
}
|
|
96
|
+
async insert(table, data) {
|
|
97
|
+
return this._request('POST', `/db/${table}/insert`, { data: Array.isArray(data) ? data : [data] });
|
|
98
|
+
}
|
|
99
|
+
async insertMany(table, data) {
|
|
100
|
+
return this._request('POST', `/db/${table}/insertMany`, { data });
|
|
101
|
+
}
|
|
102
|
+
async findById(table, id) {
|
|
103
|
+
return this._request('GET', `/db/${table}/${id}`);
|
|
104
|
+
}
|
|
105
|
+
async find(table, query = {}) {
|
|
106
|
+
return this._request('POST', `/db/${table}/find`, query);
|
|
107
|
+
}
|
|
108
|
+
async count(table) {
|
|
109
|
+
return this._request('GET', `/db/${table}/count`);
|
|
110
|
+
}
|
|
111
|
+
async updateById(table, id, data) {
|
|
112
|
+
return this._request('PUT', `/db/${table}/${id}`, { data });
|
|
113
|
+
}
|
|
114
|
+
async removeById(table, id) {
|
|
115
|
+
return this._request('DELETE', `/db/${table}/${id}`);
|
|
116
|
+
}
|
|
117
|
+
async updateByFilter(table, filter, data) {
|
|
118
|
+
return this._request('POST', `/db/${table}/update`, { filter, data });
|
|
119
|
+
}
|
|
120
|
+
async removeByFilter(table, filter) {
|
|
121
|
+
return this._request('POST', `/db/${table}/remove`, { filter });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
module.exports = { JSQL };
|