jsql-neo 6.4.7 → 6.4.9

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 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.4.7** — official release build · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
6
+ > **v6.4.9** — official release build · [github.com/vexify-org/JSQL-neo](https://github.com/vexify-org/JSQL-neo) · [jsql.vexify.top](https://jsql.vexify.top)
7
7
 
8
8
  ![Engines](https://img.shields.io/badge/engines-Native%20%7C%20WASM%20%7C%20Pure%20JS-7ee787)
9
9
  ![MySQL](https://img.shields.io/badge/protocol-MySQL%20compatible-1f6feb)
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * JSQL-NEO v6.4.7 — Rust-Powered Embedded Database (WASM + HTTP)
2
+ * JSQL-NEO v6.4.9 — Rust-Powered Embedded Database (WASM + HTTP)
3
3
  *
4
4
  * @example
5
5
  * const jsql = require('jsql-neo');
@@ -802,6 +802,14 @@ class JSQL {
802
802
  if (!schema) return;
803
803
  const fields = Object.keys(schema).filter(f => schema[f] && (schema[f].primaryKey || schema[f].unique));
804
804
  if (!fields.length) return;
805
+ // 只在**确实要改主键 / UNIQUE 列**时才做冲突检查。
806
+ // UPDATE t SET age = 30 WHERE id = 1 —— age 不是主键,不可能造成键冲突。
807
+ //
808
+ // 此前先把整表 jsqlFind 一遍(limit 1000000 = 20 万行全量 JSON 化),再进
809
+ // 循环逐字段 find/some。updateById 于是在 20 万行的表上要 250~500ms ——
810
+ // 比读整张表还贵,而它本来只需要定位一行。
811
+ const touched = fields.filter(f => Object.prototype.hasOwnProperty.call(data, f));
812
+ if (!touched.length) return;
805
813
  const raw = this._n('jsqlFind', table, '{}', 1000000, 0);
806
814
  const all = safeParse(raw);
807
815
  if (!Array.isArray(all)) return;
package/lib/table.js CHANGED
@@ -146,6 +146,20 @@ class Table {
146
146
  this._dateFields = {}; // { fieldName: 'date'|'datetime'|'timestamp' }
147
147
 
148
148
  for (const [field, def] of Object.entries(schema)) {
149
+ // schema 字段名归一化:驼峰 primaryKey/autoIncrement 与下划线
150
+ // primary_key/auto_increment 两种写法都要认。
151
+ //
152
+ // 此前这里只认驼峰,而 native_client 在交给 Rust 之前会归一化
153
+ // (lib/native_client.js 里 primary_key → primaryKey)。结果:
154
+ // README 与官方示例用的下划线写法,在 native 下正常,在纯 JS 下
155
+ // **静默失效** —— 自增 id 不生成,find({id:1}) 永远返回空,
156
+ // 而且不报任何错。这是纯 JS 与 native 的行为分歧。
157
+ if (def && typeof def === 'object' && !Array.isArray(def)) {
158
+ if (def.primary_key !== undefined && def.primaryKey === undefined) def.primaryKey = def.primary_key;
159
+ if (def.auto_increment !== undefined && def.autoIncrement === undefined) def.autoIncrement = def.auto_increment;
160
+ if (def.primary_key !== undefined) delete def.primary_key;
161
+ if (def.auto_increment !== undefined) delete def.auto_increment;
162
+ }
149
163
  const isPk = !!(def.primaryKey || def.primary === true);
150
164
  if (isPk) this._primaryKey = field;
151
165
  if (def.autoIncrement) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "6.4.7",
3
+ "version": "6.4.9",
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
  "types": "index.d.ts",
@@ -151,6 +151,43 @@ function ok(name, cond, extra) {
151
151
  await db.stop();
152
152
  }
153
153
 
154
+ /* ---- schema 字段名下划线写法:两引擎必须一致(静默正确性 bug)---- */
155
+ /*
156
+ * README 与官方示例用下划线写法(primary_key / auto_increment)。
157
+ * native_client 交给 Rust 前会归一化,纯 JS 的 table.js 此前不认 ——
158
+ * 结果纯 JS 下自增 id 根本不生成、find({id:1}) 永远空,且**不报任何错**。
159
+ */
160
+ {
161
+ const SNAKE = { id: { type: 'integer', primary_key: true, auto_increment: true }, name: { type: 'string' } };
162
+
163
+ // native
164
+ {
165
+ const d = new JSQL();
166
+ await d.start();
167
+ await d.createTable('snk', SNAKE);
168
+ await d.insert('snk', [{ name: 'a' }, { name: 'b' }]);
169
+ await new Promise(r => setTimeout(r, 200));
170
+ const rows = await d.find('snk', {});
171
+ const first = rows.find(r => r.name === 'a');
172
+ ok('schema 下划线写法 · native:自增 id 生成', !!(first && first.id !== undefined), rows);
173
+ const got = await d.findById('snk', first && first.id);
174
+ ok('schema 下划线写法 · native:findById 命中', !!(got && got.name === 'a'), got);
175
+ await d.stop();
176
+ }
177
+
178
+ // pure JS
179
+ {
180
+ const Database = require(path.join(ROOT, 'lib', 'database'));
181
+ const d = new Database(':memory:');
182
+ await d.createTable('snk', SNAKE);
183
+ await d.insert('snk', [{ name: 'a' }, { name: 'b' }]);
184
+ const rows = await d.find('snk', {});
185
+ const first = rows.find(r => r.name === 'a');
186
+ ok('schema 下划线写法 · pure-js:自增 id 生成', !!(first && first.id !== undefined), rows);
187
+ const got = await d.findById('snk', first && first.id);
188
+ ok('schema 下划线写法 · pure-js:findById 命中', !!(got && got.name === 'a'), got);
189
+ }
190
+ }
154
191
  console.log(`\n${passed} passed, ${failed} failed`);
155
192
  process.exit(failed ? 1 : 0);
156
193
  })().catch(e => {