jsql-neo 6.4.8 → 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 +1 -1
- package/index.js +1 -1
- package/lib/table.js +14 -0
- package/package.json +1 -1
- package/test/native.test.js +37 -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.4.
|
|
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
|

|
|
9
9
|

|
package/index.js
CHANGED
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
package/test/native.test.js
CHANGED
|
@@ -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 => {
|