jsql-neo 6.8.25 → 6.8.27
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/README.md +1 -1
- package/bin/jsql +12 -1
- package/index.d.ts +23 -7
- package/index.js +17 -2
- package/lib/cache.js +9 -1
- package/lib/columnar_fast.js +13 -2
- package/lib/database.js +284 -71
- package/lib/errors.js +2 -0
- package/lib/migrate.js +44 -4
- package/lib/mongo_server.js +153 -15
- package/lib/multiserver.js +4 -1
- package/lib/mysql_server.js +132 -19
- package/lib/nedb_compat.js +18 -1
- package/lib/objectid.js +15 -0
- package/lib/pg_server.js +159 -27
- package/lib/redis_server.js +44 -20
- package/lib/sql.js +266 -36
- package/lib/sqlite_compat.js +3 -0
- package/lib/table.js +92 -5
- package/lib/web_ui.js +16 -12
- package/lib/xql/index.js +0 -0
- package/package.json +2 -2
- package/test/alter-table.test.js +1 -1
- package/test/columnar-vector.test.js +2 -1
- package/test/issue-188-237.test.js +5 -2
- package/test/issue-259-264.test.js +5 -1
- package/test/issue-271-283.test.js +6 -2
- package/test/issue-272-311.test.js +2 -1
- package/test/issue-279-306.test.js +2 -1
- package/test/issue-327-418.test.js +133 -0
- package/test/issue-329-346.test.js +116 -0
- package/test/issue-331-345.test.js +49 -0
- package/test/issue-341-419.test.js +134 -0
- package/test/issue-352-386.test.js +251 -0
- package/test/issue-355-366.test.js +77 -0
- package/test/issue-357-365.test.js +89 -0
- package/test/issue-369-394.test.js +304 -0
- package/test/issue-372-387.test.js +182 -0
- package/test/issue-383-402.test.js +83 -0
- package/test/issue-395-430.test.js +227 -0
- package/test/issue-445-449.test.js +271 -0
- package/test/issue-450-454.test.js +202 -0
- package/test/issue-455-459.test.js +348 -0
- package/test/issue-460-464.test.js +195 -0
- package/test/issue-465-469.test.js +201 -0
- package/test/issue-471.test.js +150 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> **One engine to rule them all** — a Rust-powered embedded database that speaks your language:
|
|
4
4
|
> MySQL, PostgreSQL, MongoDB, Redis, SQL, TypeScript, **and the browser**.
|
|
5
5
|
|
|
6
|
-
> **v6.8.
|
|
6
|
+
> **v6.8.27** — stable release · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|

|
package/bin/jsql
CHANGED
|
@@ -241,7 +241,13 @@ const cli = (yaggs || require('./yaggs-fallback').buildYaggsFallback(_pkg))({
|
|
|
241
241
|
if (!table || !outFile) throw new Error('Usage: jsql export <table> <file.json|csv> [--db <path>]');
|
|
242
242
|
const db = new Database(argv.db || './db.json', { autoSave: false });
|
|
243
243
|
await db.loadDatabase ? db.loadDatabase() : null;
|
|
244
|
-
|
|
244
|
+
let bytes;
|
|
245
|
+
try {
|
|
246
|
+
bytes = await migrate.exportToFile(db, table, outFile);
|
|
247
|
+
} finally {
|
|
248
|
+
// #355:CLI 是一次性进程,不 close 会留下 .lock,30 秒内第二条命令直接撞锁。
|
|
249
|
+
if (typeof db.close === 'function') await db.close();
|
|
250
|
+
}
|
|
245
251
|
if (argv.json) console.log(JSON.stringify({ ok: true, table, file: outFile, bytes }));
|
|
246
252
|
else console.log(`Exported '${table}' (${bytes} bytes) to ${outFile}`);
|
|
247
253
|
} catch (e) { fail(e); }
|
|
@@ -260,6 +266,7 @@ const cli = (yaggs || require('./yaggs-fallback').buildYaggsFallback(_pkg))({
|
|
|
260
266
|
await db.loadDatabase ? db.loadDatabase() : null;
|
|
261
267
|
const ext = path.extname(file).toLowerCase();
|
|
262
268
|
let result;
|
|
269
|
+
try {
|
|
263
270
|
if (ext === '.sql') {
|
|
264
271
|
result = await migrate.importDumpFile(db, file, { strict: !!argv.strict });
|
|
265
272
|
} else if (ext === '.json') {
|
|
@@ -273,6 +280,10 @@ const cli = (yaggs || require('./yaggs-fallback').buildYaggsFallback(_pkg))({
|
|
|
273
280
|
} else {
|
|
274
281
|
throw new Error('Unsupported file type: ' + ext);
|
|
275
282
|
}
|
|
283
|
+
} finally {
|
|
284
|
+
// #355:导入完成即释放锁,否则连续两条 CLI 命令会互相撞 .lock。
|
|
285
|
+
if (typeof db.close === 'function') await db.close();
|
|
286
|
+
}
|
|
276
287
|
if (argv.json) {
|
|
277
288
|
console.log(JSON.stringify({ ok: true, ...result }));
|
|
278
289
|
} else {
|
package/index.d.ts
CHANGED
|
@@ -295,6 +295,7 @@ declare namespace JSQLNeo {
|
|
|
295
295
|
allowComments?: boolean;
|
|
296
296
|
safety?: boolean;
|
|
297
297
|
maxStatements?: number;
|
|
298
|
+
allowStacked?: boolean;
|
|
298
299
|
session?: Record<string, unknown>;
|
|
299
300
|
/** 5.5.0+:原生 `?` 占位符绑定值(与 applyParams 的数组入参二选一) */
|
|
300
301
|
params?: unknown[];
|
|
@@ -334,13 +335,29 @@ declare namespace JSQLNeo {
|
|
|
334
335
|
export function transform(ast: unknown, fn: (node: unknown) => unknown): unknown;
|
|
335
336
|
|
|
336
337
|
export interface DatabaseOptions {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
338
|
+
mode?: 'memory' | 'hybrid' | 'disk';
|
|
339
|
+
autoSave?: boolean;
|
|
340
|
+
autoSaveInterval?: number;
|
|
341
|
+
memReserveMB?: number;
|
|
342
|
+
flushInterval?: number;
|
|
343
|
+
evictInterval?: number;
|
|
344
|
+
encryptKey?: string;
|
|
345
|
+
versioning?: boolean;
|
|
346
|
+
wal?: boolean;
|
|
347
|
+
walCheckpointOps?: number;
|
|
348
|
+
isolationLevel?: 'READ_COMMITTED' | 'REPEATABLE_READ';
|
|
349
|
+
slowQueryThreshold?: number;
|
|
350
|
+
fileLock?: boolean;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface DatastoreOptions {
|
|
354
|
+
filename?: string;
|
|
355
|
+
database?: unknown;
|
|
356
|
+
engine?: unknown;
|
|
340
357
|
}
|
|
341
358
|
|
|
342
359
|
export class Database {
|
|
343
|
-
constructor(options?: DatabaseOptions);
|
|
360
|
+
constructor(filePath?: string, options?: DatabaseOptions);
|
|
344
361
|
createTable(name: string, schema: Schema): Promise<unknown>;
|
|
345
362
|
insert(table: string, data: Record<string, unknown>): Promise<unknown>;
|
|
346
363
|
find(table: string, filter?: Record<string, unknown>): Promise<Row[]>;
|
|
@@ -348,8 +365,7 @@ declare namespace JSQLNeo {
|
|
|
348
365
|
prepare(sql: string): PreparedStatement;
|
|
349
366
|
query(sql: string, paramsOrOpts?: unknown[] | SQLOptions, opts?: SQLOptions): Promise<SQLResult>;
|
|
350
367
|
update(table: string, filter: Record<string, unknown>, data: Record<string, unknown>): Promise<number>;
|
|
351
|
-
|
|
352
|
-
findOne(table: string, filter?: Record<string, unknown>): Promise<Row | null>;
|
|
368
|
+
removeWhere(table: string, filter: Record<string, unknown>): Promise<number>;
|
|
353
369
|
count(table: string): Promise<number>;
|
|
354
370
|
getTables(): Promise<string[]>;
|
|
355
371
|
dropTable(name: string): Promise<void>;
|
|
@@ -425,7 +441,7 @@ declare namespace JSQLNeo {
|
|
|
425
441
|
}
|
|
426
442
|
|
|
427
443
|
export class Datastore {
|
|
428
|
-
constructor(options?:
|
|
444
|
+
constructor(options?: DatastoreOptions);
|
|
429
445
|
insert(docs: unknown): Promise<unknown>;
|
|
430
446
|
find(query?: unknown): Promise<unknown[]>;
|
|
431
447
|
update(query: unknown, update: unknown): Promise<number>;
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSQL-NEO v6.8.
|
|
2
|
+
* JSQL-NEO v6.8.27 — Rust-Powered Embedded Database (WASM + HTTP)
|
|
3
3
|
*
|
|
4
4
|
* @example
|
|
5
5
|
* const jsql = require('jsql-neo');
|
|
@@ -129,8 +129,23 @@ function injectMySQLCompat(mod) {
|
|
|
129
129
|
return touched;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
// #327:公共导出的 JSQL 此前直接挂纯内存的 WasmClient.JSQL,`path`/`mode`
|
|
133
|
+
// 被静默丢弃 —— README 主推的 `new JSQL({ path, mode: 'disk' })` 进程退出即全丢。
|
|
134
|
+
// 这里保持构造签名与 API 不变:disk/持久化模式且存在带落盘能力的回退实现时,
|
|
135
|
+
// 转交该实现;其余情况仍走原 WASM/JS 引擎,不统一两套引擎。
|
|
136
|
+
function JSQL(opts) {
|
|
137
|
+
const o = (typeof opts === 'string') ? { path: opts } : (opts || {});
|
|
138
|
+
const wantDisk = !!o.path && o.path !== ':memory:' && (o.mode || 'disk') !== 'memory';
|
|
139
|
+
if (wantDisk && NativeClient._DiskFallbackJSQL) {
|
|
140
|
+
return new NativeClient._DiskFallbackJSQL(opts);
|
|
141
|
+
}
|
|
142
|
+
return new WasmClient.JSQL(opts);
|
|
143
|
+
}
|
|
144
|
+
// 保留原型引用习惯(instanceof 链与原 WASM 实现一致)
|
|
145
|
+
JSQL.prototype = WasmClient.JSQL.prototype;
|
|
146
|
+
|
|
132
147
|
module.exports = {
|
|
133
|
-
JSQL
|
|
148
|
+
JSQL,
|
|
134
149
|
// jsql 1.0.0 怀旧兼容层(同步 createTable/dropTable + db.<表名> 属性)
|
|
135
150
|
// 用法:const { Database } = require('jsql-neo/compat/v1');
|
|
136
151
|
compatV1: require('./lib/compat/v1'),
|
package/lib/cache.js
CHANGED
|
@@ -17,7 +17,15 @@ class Cache {
|
|
|
17
17
|
this._startTTLCleaner();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
set(key, value) {
|
|
20
|
+
set(key, value) {
|
|
21
|
+
const k = String(key);
|
|
22
|
+
this._getData().set(k, String(value));
|
|
23
|
+
// #382:普通 SET 必须清除既有 TTL(Redis 语义),否则新值会继承旧过期时间,
|
|
24
|
+
// 甚至已过期但尚未清理的键被“复活”。
|
|
25
|
+
this._getExpires().delete(k);
|
|
26
|
+
this._dirty = true;
|
|
27
|
+
return 'OK';
|
|
28
|
+
}
|
|
21
29
|
get(key) {
|
|
22
30
|
const k = String(key);
|
|
23
31
|
if (this._isExpired(k)) return null;
|
package/lib/columnar_fast.js
CHANGED
|
@@ -14,6 +14,17 @@ function colNameOf(node) {
|
|
|
14
14
|
return node.type === 'column' ? node.name : null;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* #469:聚合输出列名,与行存命名规则一致 —— 保留实参 / `*`:
|
|
19
|
+
* COUNT(v)、COUNT(*)、MIN(s),不得退化为 COUNT()。
|
|
20
|
+
*/
|
|
21
|
+
function aggLabel(fn, col) {
|
|
22
|
+
let arg;
|
|
23
|
+
if (col == null || col.type === 'star' || col.type === '*') arg = '*';
|
|
24
|
+
else arg = colNameOf(col) || '*';
|
|
25
|
+
return fn + '(' + arg + ')';
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
/**
|
|
18
29
|
* 把 WHERE 编译成「命中行下标数组」。
|
|
19
30
|
* 只支持 `列 OP 字面量` 以及它们的 AND 组合;其它(OR / LIKE / 函数 / 子查询 /
|
|
@@ -196,7 +207,7 @@ function aggregate(statement, data) {
|
|
|
196
207
|
default: return null;
|
|
197
208
|
}
|
|
198
209
|
outRow.push(v);
|
|
199
|
-
outCols.push(c.alias || (fn
|
|
210
|
+
outCols.push(c.alias || aggLabel(fn, argNode));
|
|
200
211
|
}
|
|
201
212
|
return { type: 'select', columns: outCols, rows: [outRow] };
|
|
202
213
|
}
|
|
@@ -339,7 +350,7 @@ function groupBy(statement, data) {
|
|
|
339
350
|
outRows.push(row);
|
|
340
351
|
}
|
|
341
352
|
const outCols = cols.map(c => c.alias || (c.aggregate
|
|
342
|
-
? String(c.aggregate).toUpperCase()
|
|
353
|
+
? aggLabel(String(c.aggregate).toUpperCase(), c.column)
|
|
343
354
|
: colNameOf(c.scalar || c.expr)));
|
|
344
355
|
|
|
345
356
|
// ORDER BY:在分组结果上排序 —— 组数通常远小于行数,代价很低。
|