masterrecord 1.1.6 → 1.1.8
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/CHANGES.md +28 -0
- package/Cache/RedisQueryCache.js +1 -1
- package/Entity/entityModelBuilder.js +1 -1
- package/Entity/entityTrackerModel.js +30 -5
- package/Migrations/cli.js +2 -3
- package/Migrations/migrationSQLiteQuery.js +0 -1
- package/Migrations/migrationTemplate.js +6 -6
- package/Migrations/migrations.js +25 -25
- package/QueryLanguage/queryMethods.js +17 -3
- package/QueryLanguage/queryScript.js +7 -9
- package/SQLLiteEngine.js +7 -6
- package/Tools.js +4 -4
- package/context.js +3 -4
- package/deleteManager.js +0 -1
- package/insertManager.js +1 -1
- package/mySQLEngine.js +13 -7
- package/package.json +1 -1
- package/postgresEngine.js +20 -13
- package/postgresSyncConnect.js +2 -2
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# MasterRecord Changelog
|
|
2
2
|
|
|
3
|
+
## v1.1.8 — entity internals/methods are non-enumerable (fixes spread/JSON data loss)
|
|
4
|
+
|
|
5
|
+
**Bug:** entity instances exposed their internals (`__entity`, `__context`, `__ID`, `__dirtyFields`, `__state`, `__name`) and helper methods (`toJSON`, `toObject`, `save`, `delete`, `reload`, `clone`) as **enumerable** own properties (attached by object literal / plain assignment). So spreading or `Object.assign`-ing an entity:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
const w = await ctx.Workspace.where(x => x.id == $$, id).single();
|
|
9
|
+
const out = { ...w, role: 'owner' };
|
|
10
|
+
JSON.stringify(out); // before: {"id":28,"name":"..."} — `role` silently dropped
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Two failure modes: (1) the **copied `toJSON`** ran on the plain object and rebuilt output from the original columns only, silently discarding any key the caller added; (2) `__context` (the whole DB context) leaked into the copy and could make `JSON.stringify` throw on its circular structure. `Object.keys(entity)` also returned methods + internals.
|
|
14
|
+
|
|
15
|
+
**Fix:** internals and helper/hook methods are now defined non-enumerable in both entity-construction paths — `Entity/entityTrackerModel.build()` (queried entities) and `QueryLanguage/queryMethods.new()` (new entities). Column accessors stay enumerable (and the FTS `__rank` column too). `{ ...entity, extra }` now serializes correctly and `Object.keys(entity)` returns only columns.
|
|
16
|
+
|
|
17
|
+
**Engine coverage:** the fix is in shared, engine-agnostic hydration code — all entities (SQLite, MySQL, Postgres) are built through the same `build()` / `new()`. (Regression test runs on SQLite; the code path is identical for the other engines.)
|
|
18
|
+
|
|
19
|
+
## v1.1.7 — clear remaining safe lint errors (0 errors)
|
|
20
|
+
|
|
21
|
+
Follow-up to 1.1.6. ESLint now reports **0 errors** (192 `no-var`/`no-redeclare` warnings remain, intentionally deferred — see below). No runtime behavior changes; full test suite green (same single pre-existing `count-no-from-audit` failure).
|
|
22
|
+
|
|
23
|
+
- **`no-prototype-builtins` (9):** `obj.hasOwnProperty(k)` → `Object.prototype.hasOwnProperty.call(obj, k)`.
|
|
24
|
+
- **`no-case-declarations` (23):** wrapped `switch`-`case` bodies that declare `const`/`let` in blocks (SQLite/MySQL/Postgres engines).
|
|
25
|
+
- **`no-unused-vars` (61):** removed genuinely-unused imports/locals (verified safe — e.g. an unused `PostgresEngine` import in `context.js`, which builds the PG engine via `PostgresClient`/`__postgresInit`, and an unused `tools` import in `deleteManager.js`), prefixed unused params/catch bindings with `_`.
|
|
26
|
+
- **`eqeqeq` (12):** switched the rule to `'smart'` (permits the `x == null` null-or-undefined idiom) and converted the lambda-DSL string comparisons in `queryScript` to `===`.
|
|
27
|
+
- **`prefer-const` (2):** in `queryScript`.
|
|
28
|
+
|
|
29
|
+
**Deferred (now `warn`, not `error`):** `no-var` (123) and `no-redeclare` (69). These live in legacy var-heavy engine internals; mechanically converting them across the MySQL/Postgres code paths — which the local test run (SQLite only) does not exercise — risks silent regressions. Tracked for a dedicated, individually-verified pass.
|
|
30
|
+
|
|
3
31
|
## v1.1.6 — lint-driven bug fixes + ESLint tooling
|
|
4
32
|
|
|
5
33
|
Set up ESLint (flat config, eslint 9 + `globals.node`) with a `lint`/`lint:check` script and ran it across the codebase. Beyond the mechanical `var`→`const`/`let` autofix (safe; full test suite still green), the lint surfaced several genuine bugs, now fixed:
|
package/Cache/RedisQueryCache.js
CHANGED
|
@@ -73,7 +73,7 @@ class EntityModelBuilder {
|
|
|
73
73
|
throw new Error(`compositeIndexes must be an array`);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
return indexes.map((index,
|
|
76
|
+
return indexes.map((index, _i) => {
|
|
77
77
|
// Simple array: ['col1', 'col2'] -> auto-generate name
|
|
78
78
|
if (Array.isArray(index)) {
|
|
79
79
|
const colNames = index.join('_');
|
|
@@ -222,7 +222,7 @@ class EntityTrackerModel {
|
|
|
222
222
|
// This is the FASTEST method - direct access to plain data storage
|
|
223
223
|
if (this._values && typeof this._values === 'object') {
|
|
224
224
|
for (const key in this._values) {
|
|
225
|
-
if (
|
|
225
|
+
if (Object.prototype.hasOwnProperty.call(this._values, key)) {
|
|
226
226
|
plain[key] = this._values[key];
|
|
227
227
|
}
|
|
228
228
|
}
|
|
@@ -240,7 +240,7 @@ class EntityTrackerModel {
|
|
|
240
240
|
if (!isRelationship) {
|
|
241
241
|
try {
|
|
242
242
|
plain[fieldName] = this[fieldName];
|
|
243
|
-
} catch (
|
|
243
|
+
} catch (_e) {
|
|
244
244
|
// Skip fields that throw errors when accessed
|
|
245
245
|
}
|
|
246
246
|
}
|
|
@@ -275,7 +275,7 @@ class EntityTrackerModel {
|
|
|
275
275
|
_visited: visited
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
|
-
} catch (
|
|
278
|
+
} catch (_e) {
|
|
279
279
|
// Skip relationships that throw errors when accessed
|
|
280
280
|
}
|
|
281
281
|
}
|
|
@@ -392,6 +392,31 @@ class EntityTrackerModel {
|
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
// Make internal metadata (`__*`) and helper/hook methods
|
|
396
|
+
// non-enumerable. They are attached by plain assignment / object
|
|
397
|
+
// literal above, which makes them enumerable own properties — so
|
|
398
|
+
// `{ ...entity }` / `Object.assign({}, entity)` would copy them.
|
|
399
|
+
// Two concrete bugs that causes:
|
|
400
|
+
// 1. The copied `toJSON` runs on the spread object and rebuilds
|
|
401
|
+
// output from the original columns only, silently dropping any
|
|
402
|
+
// key the caller added (`{ ...w, role }` serialized without
|
|
403
|
+
// `role`).
|
|
404
|
+
// 2. `__context` (the whole DB context) leaks into the spread and
|
|
405
|
+
// makes `JSON.stringify` throw on its circular structure.
|
|
406
|
+
// Column accessors are defined with `enumerable: true` and stay
|
|
407
|
+
// enumerable; relationship getters are already non-enumerable.
|
|
408
|
+
for (const key of Object.keys(modelClass)) {
|
|
409
|
+
const desc = Object.getOwnPropertyDescriptor(modelClass, key);
|
|
410
|
+
// Only touch DATA properties (internals + methods). Skip accessor
|
|
411
|
+
// properties — those are the column getters (defined enumerable +
|
|
412
|
+
// non-configurable, so redefining them throws), including the FTS
|
|
413
|
+
// `__rank` column, which should stay enumerable/serializable.
|
|
414
|
+
if (!desc || !('value' in desc)) continue;
|
|
415
|
+
if (key.startsWith('__') || typeof desc.value === 'function') {
|
|
416
|
+
Object.defineProperty(modelClass, key, { enumerable: false });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
395
420
|
return modelClass;
|
|
396
421
|
}
|
|
397
422
|
|
|
@@ -423,7 +448,7 @@ class EntityTrackerModel {
|
|
|
423
448
|
const $that = this;
|
|
424
449
|
// loop though current entity and add only relationship models to this list
|
|
425
450
|
const entityFields = Object.entries(currentEntity);
|
|
426
|
-
for (const [entityField,
|
|
451
|
+
for (const [entityField, _entityFieldValue] of entityFields) { // loop through entity values
|
|
427
452
|
|
|
428
453
|
if($that._isRelationship(currentEntity[entityField])){
|
|
429
454
|
|
|
@@ -492,7 +517,7 @@ class EntityTrackerModel {
|
|
|
492
517
|
try{
|
|
493
518
|
const joiningEntity = this.__context[tools.capitalize(entityName)];
|
|
494
519
|
const entityFieldJoinName = currentEntity[entityField].foreignTable === undefined? entityField : currentEntity[entityField].foreignTable;
|
|
495
|
-
const
|
|
520
|
+
const _thirdEntity = this.__context[tools.capitalize(entityFieldJoinName)];
|
|
496
521
|
const firstJoiningID = joiningEntity.__entity[this.__entity.__name].foreignTable;
|
|
497
522
|
const secondJoiningID = Object.values(joiningEntity.__entity).find(e => e.foreignTable === ent.__name);
|
|
498
523
|
if(firstJoiningID && secondJoiningID )
|
package/Migrations/cli.js
CHANGED
|
@@ -51,7 +51,6 @@ function __getMigrationTimestamp(file){
|
|
|
51
51
|
const __MIGRATIONS_TABLE__ = '_masterrecord_migrations';
|
|
52
52
|
|
|
53
53
|
async function __ensureMigrationsTable(ctx){
|
|
54
|
-
const engine = ctx._SQLEngine;
|
|
55
54
|
if (ctx.isSQLite) {
|
|
56
55
|
await ctx._execute(`CREATE TABLE IF NOT EXISTS [${__MIGRATIONS_TABLE__}] (
|
|
57
56
|
migration_name TEXT PRIMARY KEY,
|
|
@@ -127,7 +126,7 @@ async function __cleanupAndExit(contextInstance, exitCode = 0) {
|
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
|
|
130
|
-
const [,, ...
|
|
129
|
+
const [,, ..._args] = process.argv
|
|
131
130
|
|
|
132
131
|
|
|
133
132
|
|
|
@@ -179,7 +178,7 @@ program.option('-V', 'output the version');
|
|
|
179
178
|
.action(async function(contextFileName){
|
|
180
179
|
const executedLocation = process.cwd();
|
|
181
180
|
contextFileName = contextFileName.toLowerCase();
|
|
182
|
-
const
|
|
181
|
+
const _migration = new Migration();
|
|
183
182
|
let contextInstance = null;
|
|
184
183
|
try{
|
|
185
184
|
const files = globSync(`**/*${contextFileName}_contextSnapShot.json`, { cwd: executedLocation, dot: true, windowsPathsNoEscape: true, nocase: true });
|
|
@@ -258,7 +258,6 @@ class migrationSQLiteQuery {
|
|
|
258
258
|
createFullTextIndex(info){
|
|
259
259
|
const ftsTable = info.ftsTableName || `${info.tableName}_fts`;
|
|
260
260
|
const cols = info.columns.join(', ');
|
|
261
|
-
const insertCols = info.columns.map(c => `[${c}]`).join(', ');
|
|
262
261
|
const newCols = info.columns.map(c => `new.[${c}]`).join(', ');
|
|
263
262
|
const oldCols = info.columns.map(c => `old.[${c}]`).join(', ');
|
|
264
263
|
|
|
@@ -37,7 +37,7 @@ export default ${this.name};
|
|
|
37
37
|
`;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
alterColumn(type, name,
|
|
40
|
+
alterColumn(type, name, _parent){
|
|
41
41
|
if(type === "up"){
|
|
42
42
|
this.#up += os.EOL + ` await this.alterColumn(table.${name});`
|
|
43
43
|
}
|
|
@@ -54,7 +54,7 @@ export default ${this.name};
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
addColumn(type, name,
|
|
57
|
+
addColumn(type, name, _parent){
|
|
58
58
|
if(type === "up"){
|
|
59
59
|
this.#up += os.EOL + ` await this.addColumn(table.${name});`
|
|
60
60
|
}
|
|
@@ -73,7 +73,7 @@ export default ${this.name};
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
dropColumn(type, name,
|
|
76
|
+
dropColumn(type, name, _parent){
|
|
77
77
|
if(type === "up"){
|
|
78
78
|
this.#up += os.EOL + ` await this.dropColumn(table.${name});`
|
|
79
79
|
}
|
|
@@ -83,7 +83,7 @@ export default ${this.name};
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
createIndex(type, indexInfo){
|
|
86
|
-
const
|
|
86
|
+
const _indexName = indexInfo.indexName === true
|
|
87
87
|
? `idx_${indexInfo.tableName.toLowerCase()}_${indexInfo.columnName.toLowerCase()}`
|
|
88
88
|
: indexInfo.indexName;
|
|
89
89
|
|
|
@@ -102,7 +102,7 @@ export default ${this.name};
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
dropIndex(type, indexInfo){
|
|
105
|
-
const
|
|
105
|
+
const _indexName = indexInfo.indexName === true
|
|
106
106
|
? `idx_${indexInfo.tableName.toLowerCase()}_${indexInfo.columnName.toLowerCase()}`
|
|
107
107
|
: indexInfo.indexName;
|
|
108
108
|
|
|
@@ -277,7 +277,7 @@ export default ${this.name};
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
const pkValue = rollback.value;
|
|
280
|
-
const
|
|
280
|
+
const _pkKey = rollback.key || 'id';
|
|
281
281
|
|
|
282
282
|
// Generate delete code with error handling
|
|
283
283
|
this.#down += os.EOL + ` try {`;
|
package/Migrations/migrations.js
CHANGED
|
@@ -19,7 +19,7 @@ class Migrations{
|
|
|
19
19
|
const seenTableNames = new Set(); // Track processed table names to prevent duplicates
|
|
20
20
|
|
|
21
21
|
if(oldSchema.length === 0){
|
|
22
|
-
newSchema.forEach(function (item,
|
|
22
|
+
newSchema.forEach(function (item, _index) {
|
|
23
23
|
const tableName = item["__name"];
|
|
24
24
|
|
|
25
25
|
// Skip if we've already processed this table name
|
|
@@ -47,7 +47,7 @@ class Migrations{
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
else{
|
|
50
|
-
newSchema.forEach(function (item,
|
|
50
|
+
newSchema.forEach(function (item, _index) {
|
|
51
51
|
const tableName = item["__name"];
|
|
52
52
|
|
|
53
53
|
// Skip if we've already processed this table name
|
|
@@ -72,7 +72,7 @@ class Migrations{
|
|
|
72
72
|
newSeedData : []
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
oldSchema.forEach(function (oldItem,
|
|
75
|
+
oldSchema.forEach(function (oldItem, _index) {
|
|
76
76
|
const oldItemName = oldItem["__name"];
|
|
77
77
|
if(table.name === oldItemName){
|
|
78
78
|
table.old = oldItem;
|
|
@@ -87,7 +87,7 @@ class Migrations{
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
#findDeletedColumns(tables){
|
|
90
|
-
tables.forEach(function (item,
|
|
90
|
+
tables.forEach(function (item, _index) {
|
|
91
91
|
let deletedColumn = null;
|
|
92
92
|
if(item.new && item.old){
|
|
93
93
|
Object.keys(item.old).forEach(function (key) {
|
|
@@ -111,7 +111,7 @@ class Migrations{
|
|
|
111
111
|
#findUpdatedColumns(tables){
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
tables.forEach(function (item,
|
|
114
|
+
tables.forEach(function (item, _index) {
|
|
115
115
|
|
|
116
116
|
const UD = diff.updatedDiff(item.old, item.new);
|
|
117
117
|
const isEmpty = Object.keys(UD).length === 0;
|
|
@@ -131,7 +131,7 @@ class Migrations{
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
#findNewColumns(tables){
|
|
134
|
-
tables.forEach(function (item,
|
|
134
|
+
tables.forEach(function (item, _index) {
|
|
135
135
|
if(item.new && item.old){
|
|
136
136
|
Object.keys(item.new).forEach(function (key) {
|
|
137
137
|
if(typeof item.new[key] === "object"){
|
|
@@ -170,7 +170,7 @@ class Migrations{
|
|
|
170
170
|
|
|
171
171
|
#findNewTables(tables){
|
|
172
172
|
// find new tables
|
|
173
|
-
tables.forEach(function (item,
|
|
173
|
+
tables.forEach(function (item, _index) {
|
|
174
174
|
if(item.new && item.old){
|
|
175
175
|
if(Object.keys(item.old).length === 0){
|
|
176
176
|
item.newTables.push(item);
|
|
@@ -201,7 +201,7 @@ class Migrations{
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
#findNewIndexes(tables){
|
|
204
|
-
tables.forEach(function (item,
|
|
204
|
+
tables.forEach(function (item, _index) {
|
|
205
205
|
// Skip new tables — createTable() in schema.js already creates their indexes
|
|
206
206
|
if(item.newTables && item.newTables.length > 0) return;
|
|
207
207
|
|
|
@@ -248,7 +248,7 @@ class Migrations{
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
#findDeletedIndexes(tables){
|
|
251
|
-
tables.forEach(function (item,
|
|
251
|
+
tables.forEach(function (item, _index) {
|
|
252
252
|
if(item.new && item.old){
|
|
253
253
|
Object.keys(item.old).forEach(function (key) {
|
|
254
254
|
if(typeof item.old[key] === "object" && item.old[key].indexes){
|
|
@@ -292,7 +292,7 @@ class Migrations{
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
#findNewCompositeIndexes(tables) {
|
|
295
|
-
tables.forEach(function (item,
|
|
295
|
+
tables.forEach(function (item, _index) {
|
|
296
296
|
// Skip new tables — createTable() in schema.js already creates their composite indexes
|
|
297
297
|
if(item.newTables && item.newTables.length > 0) return;
|
|
298
298
|
|
|
@@ -320,7 +320,7 @@ class Migrations{
|
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
#findDeletedCompositeIndexes(tables) {
|
|
323
|
-
tables.forEach(function (item,
|
|
323
|
+
tables.forEach(function (item, _index) {
|
|
324
324
|
if (item.new && item.old) {
|
|
325
325
|
const newComposite = item.new.__compositeIndexes || [];
|
|
326
326
|
const oldComposite = item.old.__compositeIndexes || [];
|
|
@@ -393,7 +393,7 @@ class Migrations{
|
|
|
393
393
|
const newObj = {}
|
|
394
394
|
|
|
395
395
|
for (const key in entity) {
|
|
396
|
-
if (
|
|
396
|
+
if (Object.prototype.hasOwnProperty.call(entity, key)) {
|
|
397
397
|
|
|
398
398
|
if(entity[key].type !== "hasOne" && entity[key].type !== "hasMany" && entity[key].type !== "hasManyThrough"){
|
|
399
399
|
// if(entity[key].relationshipType == "belongsTo" ){
|
|
@@ -464,21 +464,21 @@ class Migrations{
|
|
|
464
464
|
// this.createTable(table.TableName) can safely access it.
|
|
465
465
|
tableObj[item.name] = columnInfo.new;
|
|
466
466
|
|
|
467
|
-
item.newTables.forEach(function (
|
|
467
|
+
item.newTables.forEach(function (_column, _ind) {
|
|
468
468
|
tableObj[item.name] = columnInfo.new;
|
|
469
469
|
});
|
|
470
470
|
|
|
471
|
-
item.newColumns.forEach(function (column,
|
|
471
|
+
item.newColumns.forEach(function (column, _ind) {
|
|
472
472
|
columnInfo.new[column].tableName = item.name;
|
|
473
473
|
tableObj[column] = columnInfo.new[column];
|
|
474
474
|
});
|
|
475
475
|
|
|
476
|
-
item.deletedColumns.forEach(function (column,
|
|
476
|
+
item.deletedColumns.forEach(function (column, _ind) {
|
|
477
477
|
columnInfo.old[column].tableName = item.name;
|
|
478
478
|
tableObj[column] = columnInfo.old[column];
|
|
479
479
|
});
|
|
480
480
|
|
|
481
|
-
item.updatedColumns.forEach(function (column,
|
|
481
|
+
item.updatedColumns.forEach(function (column, _ind) {
|
|
482
482
|
tableObj[column.table.name] = column;
|
|
483
483
|
});
|
|
484
484
|
|
|
@@ -521,30 +521,30 @@ class Migrations{
|
|
|
521
521
|
}
|
|
522
522
|
const tables = this.#buildMigrationObject(oldSchema, newSchema, newSeedData);
|
|
523
523
|
|
|
524
|
-
tables.forEach(function (item,
|
|
524
|
+
tables.forEach(function (item, _index) {
|
|
525
525
|
// (Whole-table create/drop is handled below via item.newTables /
|
|
526
526
|
// item.deletedColumns. The previous `if (item.old === null)` /
|
|
527
527
|
// `if (item.new === null)` branches here referenced an undefined
|
|
528
528
|
// `column` and never ran — old/new are always {} or an object,
|
|
529
529
|
// never null — so they were dead, broken code and were removed.)
|
|
530
530
|
|
|
531
|
-
item.newTables.forEach(function (
|
|
531
|
+
item.newTables.forEach(function (_column, _ind) {
|
|
532
532
|
MT.createTable("up", item.name);
|
|
533
533
|
MT.dropTable("down", item.name);
|
|
534
534
|
});
|
|
535
535
|
|
|
536
536
|
// add new columns for table
|
|
537
|
-
item.newColumns.forEach(function (column,
|
|
537
|
+
item.newColumns.forEach(function (column, _index) {
|
|
538
538
|
MT.addColumn("up", column, item.name);
|
|
539
539
|
MT.dropColumn("down", column, item.name);
|
|
540
540
|
});
|
|
541
541
|
|
|
542
|
-
item.deletedColumns.forEach(function (column,
|
|
542
|
+
item.deletedColumns.forEach(function (column, _index) {
|
|
543
543
|
MT.dropColumn("up", column, item.name);
|
|
544
544
|
MT.addColumn("down",column, item.name);
|
|
545
545
|
});
|
|
546
546
|
|
|
547
|
-
item.updatedColumns.forEach(function (column,
|
|
547
|
+
item.updatedColumns.forEach(function (column, _index) {
|
|
548
548
|
const isEmpty = Object.keys(column).length === 0;
|
|
549
549
|
if(!isEmpty){
|
|
550
550
|
MT.alterColumn("up", column.table.name, item.name);
|
|
@@ -552,19 +552,19 @@ class Migrations{
|
|
|
552
552
|
}
|
|
553
553
|
});
|
|
554
554
|
|
|
555
|
-
item.newIndexes.forEach(function (indexInfo,
|
|
555
|
+
item.newIndexes.forEach(function (indexInfo, _index) {
|
|
556
556
|
MT.createIndex("up", indexInfo);
|
|
557
557
|
});
|
|
558
558
|
|
|
559
|
-
item.deletedIndexes.forEach(function (indexInfo,
|
|
559
|
+
item.deletedIndexes.forEach(function (indexInfo, _index) {
|
|
560
560
|
MT.dropIndex("up", indexInfo);
|
|
561
561
|
});
|
|
562
562
|
|
|
563
|
-
item.newCompositeIndexes.forEach(function (indexInfo,
|
|
563
|
+
item.newCompositeIndexes.forEach(function (indexInfo, _index) {
|
|
564
564
|
MT.createCompositeIndex("up", indexInfo);
|
|
565
565
|
});
|
|
566
566
|
|
|
567
|
-
item.deletedCompositeIndexes.forEach(function (indexInfo,
|
|
567
|
+
item.deletedCompositeIndexes.forEach(function (indexInfo, _index) {
|
|
568
568
|
MT.dropCompositeIndex("up", indexInfo);
|
|
569
569
|
});
|
|
570
570
|
|
|
@@ -601,7 +601,6 @@ class queryMethods{
|
|
|
601
601
|
};
|
|
602
602
|
|
|
603
603
|
// Set up property setters for all entity fields
|
|
604
|
-
const $that = this;
|
|
605
604
|
for (const fieldName in this.__entity) {
|
|
606
605
|
if(!fieldName.startsWith("__")){
|
|
607
606
|
const field = this.__entity[fieldName];
|
|
@@ -802,7 +801,7 @@ class queryMethods{
|
|
|
802
801
|
if (!isRelationship) {
|
|
803
802
|
try {
|
|
804
803
|
plain[fieldName] = this[fieldName];
|
|
805
|
-
} catch (
|
|
804
|
+
} catch (_e) {
|
|
806
805
|
// Skip fields that throw errors when accessed
|
|
807
806
|
}
|
|
808
807
|
}
|
|
@@ -836,7 +835,7 @@ class queryMethods{
|
|
|
836
835
|
_visited: visited
|
|
837
836
|
});
|
|
838
837
|
}
|
|
839
|
-
} catch (
|
|
838
|
+
} catch (_e) {
|
|
840
839
|
// Skip relationships that throw errors when accessed
|
|
841
840
|
}
|
|
842
841
|
}
|
|
@@ -969,6 +968,21 @@ class queryMethods{
|
|
|
969
968
|
}
|
|
970
969
|
}
|
|
971
970
|
|
|
971
|
+
// Make internal metadata (`__*`) and helper/hook methods
|
|
972
|
+
// non-enumerable so that `{ ...entity }` / `Object.assign` copy only
|
|
973
|
+
// column values — see the matching note in entityTrackerModel.build().
|
|
974
|
+
// Without this, the copied `toJSON` silently drops caller-added keys
|
|
975
|
+
// on serialize and `__context` leaks (circular JSON).
|
|
976
|
+
for (const key of Object.keys(newEntity)) {
|
|
977
|
+
const desc = Object.getOwnPropertyDescriptor(newEntity, key);
|
|
978
|
+
// Only DATA properties (internals + methods); skip accessor
|
|
979
|
+
// (column) getters, which are non-configurable.
|
|
980
|
+
if (!desc || !('value' in desc)) continue;
|
|
981
|
+
if (key.startsWith('__') || typeof desc.value === 'function') {
|
|
982
|
+
Object.defineProperty(newEntity, key, { enumerable: false });
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
|
|
972
986
|
return newEntity;
|
|
973
987
|
}
|
|
974
988
|
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
import tools from '../Tools.js';
|
|
4
4
|
import QueryParameters from './queryParameters.js';
|
|
5
5
|
|
|
6
|
-
const LOG_OPERATORS_REGEX = /(\|\|)|(&&)/;
|
|
7
|
-
|
|
8
6
|
// Escape special regex characters so user-supplied names can be safely
|
|
9
7
|
// interpolated into RegExp constructors (prevents "Unmatched ')'" etc.)
|
|
10
8
|
function escapeRegExp(str) {
|
|
@@ -245,11 +243,11 @@ class queryScript{
|
|
|
245
243
|
|
|
246
244
|
|
|
247
245
|
splitGroupsByLogicalOperators(text) {
|
|
248
|
-
|
|
246
|
+
const parts = {};
|
|
249
247
|
const part = {query : text, name : "query"}
|
|
250
248
|
|
|
251
249
|
//tmp = this.splitByLogicalOperators(part.query, entityRegExp)
|
|
252
|
-
tmp = this.extractInside(part.query, part.name);
|
|
250
|
+
const tmp = this.extractInside(part.query, part.name);
|
|
253
251
|
if(tmp){
|
|
254
252
|
part.inside = tmp;
|
|
255
253
|
parts[part.name] = part;
|
|
@@ -441,17 +439,17 @@ class queryScript{
|
|
|
441
439
|
if ((match = segment.match(exprPartRegExp))) {
|
|
442
440
|
fields = match[1].split(".");
|
|
443
441
|
func = (match[2] ? fields[fields.length - 1] : (match[3] || "exists"));
|
|
444
|
-
if (func
|
|
442
|
+
if (func === "==" || func === "===") {
|
|
445
443
|
func = "=";
|
|
446
444
|
}
|
|
447
|
-
else if (func
|
|
445
|
+
else if (func === "!==") {
|
|
448
446
|
func = "!=";
|
|
449
447
|
}
|
|
450
448
|
arg = match[2] || match[4];
|
|
451
|
-
if (arg
|
|
452
|
-
arg = arg
|
|
449
|
+
if (arg === "true" || arg === "false") {
|
|
450
|
+
arg = arg === "true";
|
|
453
451
|
}
|
|
454
|
-
else if (arg && arg.charAt(0)
|
|
452
|
+
else if (arg && arg.charAt(0) === arg.charAt(arg.length - 1) && (arg.charAt(0) === "'" || arg.charAt(0) === '"')) {
|
|
455
453
|
arg = arg.slice(1, -1);
|
|
456
454
|
}
|
|
457
455
|
part.entity = entity;
|
package/SQLLiteEngine.js
CHANGED
|
@@ -168,7 +168,7 @@ class SQLLiteEngine {
|
|
|
168
168
|
}catch(_){ return Promise.resolve([]); }
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
async getCount(queryObject, entity,
|
|
171
|
+
async getCount(queryObject, entity, _context){
|
|
172
172
|
const query = queryObject.script;
|
|
173
173
|
const queryString = {};
|
|
174
174
|
try {
|
|
@@ -242,7 +242,7 @@ class SQLLiteEngine {
|
|
|
242
242
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
buildCount(query,
|
|
245
|
+
buildCount(query, _mainQuery){
|
|
246
246
|
const entity = this.getEntity(query.parentName, query.entityMap);
|
|
247
247
|
if(query.count){
|
|
248
248
|
if(query.count !== "none"){
|
|
@@ -257,7 +257,7 @@ class SQLLiteEngine {
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
buildQuery(query, entity, context,
|
|
260
|
+
buildQuery(query, entity, context, _limit){
|
|
261
261
|
|
|
262
262
|
const queryObject = {};
|
|
263
263
|
queryObject.entity = this.getEntity(entity.__name, query.entityMap);
|
|
@@ -324,7 +324,6 @@ class SQLLiteEngine {
|
|
|
324
324
|
|
|
325
325
|
buildOrderBy(query, entity){
|
|
326
326
|
// ORDER BY column1, column2, ... ASC|DESC;
|
|
327
|
-
const $that = this;
|
|
328
327
|
let orderByType = "ASC";
|
|
329
328
|
let orderByEntity = query.orderBy;
|
|
330
329
|
let strQuery = "";
|
|
@@ -759,7 +758,7 @@ class SQLLiteEngine {
|
|
|
759
758
|
}
|
|
760
759
|
// TODO Boolean value is a string with a letter
|
|
761
760
|
switch(type){
|
|
762
|
-
case "belongsTo" :
|
|
761
|
+
case "belongsTo" : {
|
|
763
762
|
const foreignKey = model.__entity[dirtyFields[column]].foreignKey;
|
|
764
763
|
let fkValue = model[dirtyFields[column]];
|
|
765
764
|
// 🔥 NEW: Validate foreign key type
|
|
@@ -772,6 +771,7 @@ class SQLLiteEngine {
|
|
|
772
771
|
// dirty fields must not wipe the accumulated SET clause.
|
|
773
772
|
argument = argument === null ? `${foreignKey} = ${fkValue},` : `${argument} ${foreignKey} = ${fkValue},`;
|
|
774
773
|
break;
|
|
774
|
+
}
|
|
775
775
|
case "integer" :
|
|
776
776
|
//model.__entity[dirtyFields[column]].skipGetFunction = true;
|
|
777
777
|
var columneValue = model[`_${dirtyFields[column]}`];
|
|
@@ -875,7 +875,7 @@ class SQLLiteEngine {
|
|
|
875
875
|
|
|
876
876
|
// Build parameterized SET clause
|
|
877
877
|
switch(type){
|
|
878
|
-
case "belongsTo":
|
|
878
|
+
case "belongsTo": {
|
|
879
879
|
const foreignKey = model.__entity[dirtyFields[column]].foreignKey;
|
|
880
880
|
let fkValue = model[dirtyFields[column]];
|
|
881
881
|
|
|
@@ -895,6 +895,7 @@ class SQLLiteEngine {
|
|
|
895
895
|
sqlParts.push(`[${foreignKey}] = ?`);
|
|
896
896
|
params.push(model[fore]);
|
|
897
897
|
break;
|
|
898
|
+
}
|
|
898
899
|
case "integer":
|
|
899
900
|
var intValue = model["_" + dirtyFields[column]];
|
|
900
901
|
|
package/Tools.js
CHANGED
|
@@ -47,7 +47,7 @@ class Tools{
|
|
|
47
47
|
|
|
48
48
|
static getPrimaryKeyObject(model){
|
|
49
49
|
for (const key in model) {
|
|
50
|
-
if (
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(model, key)) {
|
|
51
51
|
if(model[key].primary){
|
|
52
52
|
if(model[key].primary === true){
|
|
53
53
|
return key
|
|
@@ -59,7 +59,7 @@ class Tools{
|
|
|
59
59
|
|
|
60
60
|
static findForeignTable(name, model){
|
|
61
61
|
for (const key in model) {
|
|
62
|
-
if (
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(model, key)) {
|
|
63
63
|
if(model[key].foreignTable){
|
|
64
64
|
if(model[key].foreignTable === name){
|
|
65
65
|
return model[key];
|
|
@@ -131,7 +131,7 @@ class Tools{
|
|
|
131
131
|
|
|
132
132
|
for(const entity in modelEntity) {
|
|
133
133
|
const currentEntity = modelEntity[entity];
|
|
134
|
-
if (
|
|
134
|
+
if (Object.prototype.hasOwnProperty.call(modelEntity, entity)) {
|
|
135
135
|
if(currentEntity.primary === true){
|
|
136
136
|
delete newCurrentModel[`_${entity}`];
|
|
137
137
|
}
|
|
@@ -148,7 +148,7 @@ class Tools{
|
|
|
148
148
|
static getEntity(name, modelEntity){
|
|
149
149
|
for(const entity in modelEntity) {
|
|
150
150
|
const currentEntity = modelEntity[entity];
|
|
151
|
-
if (
|
|
151
|
+
if (Object.prototype.hasOwnProperty.call(modelEntity, entity)) {
|
|
152
152
|
if(currentEntity.__name === name){
|
|
153
153
|
return currentEntity;
|
|
154
154
|
}
|
package/context.js
CHANGED
|
@@ -19,7 +19,6 @@ import query from './QueryLanguage/queryMethods.js';
|
|
|
19
19
|
import tools from './Tools.js';
|
|
20
20
|
import SQLLiteEngine from './SQLLiteEngine.js';
|
|
21
21
|
import MySQLEngine from './mySQLEngine.js';
|
|
22
|
-
import PostgresEngine from './postgresEngine.js';
|
|
23
22
|
import insertManager from './insertManager.js';
|
|
24
23
|
import deleteManager from './deleteManager.js';
|
|
25
24
|
import { globSync } from 'glob';
|
|
@@ -2059,7 +2058,7 @@ class context {
|
|
|
2059
2058
|
const entity = EntityClass.new();
|
|
2060
2059
|
// Copy properties from data object to entity
|
|
2061
2060
|
for (const key in item) {
|
|
2062
|
-
if (
|
|
2061
|
+
if (Object.prototype.hasOwnProperty.call(item, key)) {
|
|
2063
2062
|
entity[key] = item[key];
|
|
2064
2063
|
}
|
|
2065
2064
|
}
|
|
@@ -2112,7 +2111,7 @@ class context {
|
|
|
2112
2111
|
|
|
2113
2112
|
// Apply updates to entity
|
|
2114
2113
|
for (const key in update) {
|
|
2115
|
-
if (
|
|
2114
|
+
if (Object.prototype.hasOwnProperty.call(update, key) && key !== 'id') {
|
|
2116
2115
|
entity[key] = update[key];
|
|
2117
2116
|
}
|
|
2118
2117
|
}
|
|
@@ -2249,7 +2248,7 @@ class context {
|
|
|
2249
2248
|
* });
|
|
2250
2249
|
*/
|
|
2251
2250
|
static async closeAll() {
|
|
2252
|
-
for (const [
|
|
2251
|
+
for (const [_key, entry] of _pools) {
|
|
2253
2252
|
try {
|
|
2254
2253
|
if (entry.promise) {
|
|
2255
2254
|
// Wait for pending init to complete, then close it
|
package/deleteManager.js
CHANGED
package/insertManager.js
CHANGED
|
@@ -337,7 +337,7 @@ class InsertManager {
|
|
|
337
337
|
for (const entity of Object.keys(entityModel)) {
|
|
338
338
|
const currentEntity = entityModel[entity];
|
|
339
339
|
|
|
340
|
-
if (!
|
|
340
|
+
if (!Object.prototype.hasOwnProperty.call(entityModel, entity)) {
|
|
341
341
|
continue;
|
|
342
342
|
}
|
|
343
343
|
|
package/mySQLEngine.js
CHANGED
|
@@ -163,7 +163,7 @@ class MySQLEngine {
|
|
|
163
163
|
* method (expects a lambda), not a SQL wrapper; the return value was the
|
|
164
164
|
* queryScript object and running it as SQL produced "[object Object]".
|
|
165
165
|
*/
|
|
166
|
-
async getCount(queryObject, entity,
|
|
166
|
+
async getCount(queryObject, entity, _context) {
|
|
167
167
|
const query = queryObject.script;
|
|
168
168
|
try {
|
|
169
169
|
let sql;
|
|
@@ -713,7 +713,7 @@ class MySQLEngine {
|
|
|
713
713
|
}
|
|
714
714
|
|
|
715
715
|
switch (type) {
|
|
716
|
-
case "belongsTo":
|
|
716
|
+
case "belongsTo": {
|
|
717
717
|
const foreignKey = model.__entity[dirtyFields[column]].foreignKey;
|
|
718
718
|
let fkValue = model[dirtyFields[column]];
|
|
719
719
|
try {
|
|
@@ -730,8 +730,9 @@ class MySQLEngine {
|
|
|
730
730
|
sqlParts.push(`\`${foreignKey}\` = ?`);
|
|
731
731
|
params.push(model[fore]);
|
|
732
732
|
break;
|
|
733
|
+
}
|
|
733
734
|
|
|
734
|
-
case "integer":
|
|
735
|
+
case "integer": {
|
|
735
736
|
let intValue = model["_" + dirtyFields[column]];
|
|
736
737
|
try {
|
|
737
738
|
intValue = FieldTransformer.toDatabase(intValue, model.__entity[dirtyFields[column]], model.__entity.__name, dirtyFields[column]);
|
|
@@ -746,8 +747,9 @@ class MySQLEngine {
|
|
|
746
747
|
sqlParts.push(`\`${dirtyFields[column]}\` = ?`);
|
|
747
748
|
params.push(intValue);
|
|
748
749
|
break;
|
|
750
|
+
}
|
|
749
751
|
|
|
750
|
-
case "string":
|
|
752
|
+
case "string": {
|
|
751
753
|
let strValue = model["_" + dirtyFields[column]];
|
|
752
754
|
try {
|
|
753
755
|
strValue = FieldTransformer.toDatabase(strValue, model.__entity[dirtyFields[column]], model.__entity.__name, dirtyFields[column]);
|
|
@@ -762,8 +764,9 @@ class MySQLEngine {
|
|
|
762
764
|
sqlParts.push(`\`${dirtyFields[column]}\` = ?`);
|
|
763
765
|
params.push(strValue);
|
|
764
766
|
break;
|
|
767
|
+
}
|
|
765
768
|
|
|
766
|
-
case "boolean":
|
|
769
|
+
case "boolean": {
|
|
767
770
|
let boolValue = model["_" + dirtyFields[column]];
|
|
768
771
|
try {
|
|
769
772
|
boolValue = FieldTransformer.toDatabase(boolValue, model.__entity[dirtyFields[column]], model.__entity.__name, dirtyFields[column]);
|
|
@@ -780,8 +783,9 @@ class MySQLEngine {
|
|
|
780
783
|
sqlParts.push(`\`${dirtyFields[column]}\` = ?`);
|
|
781
784
|
params.push(bool);
|
|
782
785
|
break;
|
|
786
|
+
}
|
|
783
787
|
|
|
784
|
-
case "time":
|
|
788
|
+
case "time": {
|
|
785
789
|
let timeValue = model["_" + dirtyFields[column]];
|
|
786
790
|
try {
|
|
787
791
|
timeValue = FieldTransformer.toDatabase(timeValue, model.__entity[dirtyFields[column]], model.__entity.__name, dirtyFields[column]);
|
|
@@ -796,6 +800,7 @@ class MySQLEngine {
|
|
|
796
800
|
sqlParts.push(`\`${dirtyFields[column]}\` = ?`);
|
|
797
801
|
params.push(timeValue);
|
|
798
802
|
break;
|
|
803
|
+
}
|
|
799
804
|
|
|
800
805
|
case "hasMany":
|
|
801
806
|
sqlParts.push(`\`${dirtyFields[column]}\` = ?`);
|
|
@@ -872,7 +877,7 @@ class MySQLEngine {
|
|
|
872
877
|
params.push(fieldColumn);
|
|
873
878
|
} else {
|
|
874
879
|
switch (modelEntity[column].type) {
|
|
875
|
-
case "belongsTo":
|
|
880
|
+
case "belongsTo": {
|
|
876
881
|
const fieldObject = tools.findTrackedObject(fields.__context.__trackedEntities, column);
|
|
877
882
|
if (Object.keys(fieldObject).length > 0) {
|
|
878
883
|
const primaryKey = tools.getPrimaryKeyObject(fieldObject.__entity);
|
|
@@ -882,6 +887,7 @@ class MySQLEngine {
|
|
|
882
887
|
params.push(fieldColumn);
|
|
883
888
|
}
|
|
884
889
|
break;
|
|
890
|
+
}
|
|
885
891
|
}
|
|
886
892
|
}
|
|
887
893
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./MasterRecord.js",
|
package/postgresEngine.js
CHANGED
|
@@ -215,7 +215,7 @@ class postgresEngine {
|
|
|
215
215
|
/**
|
|
216
216
|
* SELECT COUNT
|
|
217
217
|
*/
|
|
218
|
-
async getCount(queryObject, entity,
|
|
218
|
+
async getCount(queryObject, entity, _context) {
|
|
219
219
|
const query = queryObject.script;
|
|
220
220
|
try {
|
|
221
221
|
let queryString;
|
|
@@ -225,7 +225,7 @@ class postgresEngine {
|
|
|
225
225
|
if (query.count === undefined) {
|
|
226
226
|
query.count = "none";
|
|
227
227
|
}
|
|
228
|
-
const
|
|
228
|
+
const _entityAlias = this.getEntity(entity.__name, query.entityMap);
|
|
229
229
|
// Include buildAnd so chained .and() calls survive into the
|
|
230
230
|
// COUNT SQL. Without this they were silently dropped.
|
|
231
231
|
queryString = {
|
|
@@ -325,8 +325,8 @@ class postgresEngine {
|
|
|
325
325
|
/**
|
|
326
326
|
* Build complete SELECT query with parameters
|
|
327
327
|
*/
|
|
328
|
-
buildQuery(query, entity,
|
|
329
|
-
const
|
|
328
|
+
buildQuery(query, entity, _context) {
|
|
329
|
+
const _entityStr = this.getEntity(entity.__name, query.entityMap);
|
|
330
330
|
const params = query.parameters ? query.parameters.getParams() : [];
|
|
331
331
|
|
|
332
332
|
// Standard SQL clause order: SELECT ... FROM ... WHERE ... AND ... ORDER BY ... LIMIT ... OFFSET ...
|
|
@@ -667,7 +667,7 @@ class postgresEngine {
|
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
switch (type) {
|
|
670
|
-
case "belongsTo":
|
|
670
|
+
case "belongsTo": {
|
|
671
671
|
const foreignKey = model.__entity[dirtyFields[column]].foreignKey;
|
|
672
672
|
let fkValue = model[dirtyFields[column]];
|
|
673
673
|
// Apply toDatabase transformer
|
|
@@ -686,8 +686,9 @@ class postgresEngine {
|
|
|
686
686
|
sqlParts.push(`${$that._q(foreignKey)} = $${paramIndex++}`);
|
|
687
687
|
params.push(model[fore]);
|
|
688
688
|
break;
|
|
689
|
+
}
|
|
689
690
|
|
|
690
|
-
case "integer":
|
|
691
|
+
case "integer": {
|
|
691
692
|
let intValue = model["_" + dirtyFields[column]];
|
|
692
693
|
// Apply toDatabase transformer
|
|
693
694
|
try {
|
|
@@ -704,8 +705,9 @@ class postgresEngine {
|
|
|
704
705
|
sqlParts.push(`${$that._q(dirtyFields[column])} = $${paramIndex++}`);
|
|
705
706
|
params.push(intValue);
|
|
706
707
|
break;
|
|
708
|
+
}
|
|
707
709
|
|
|
708
|
-
case "string":
|
|
710
|
+
case "string": {
|
|
709
711
|
let strValue = model["_" + dirtyFields[column]];
|
|
710
712
|
// Apply toDatabase transformer
|
|
711
713
|
try {
|
|
@@ -722,8 +724,9 @@ class postgresEngine {
|
|
|
722
724
|
sqlParts.push(`${$that._q(dirtyFields[column])} = $${paramIndex++}`);
|
|
723
725
|
params.push(strValue);
|
|
724
726
|
break;
|
|
727
|
+
}
|
|
725
728
|
|
|
726
|
-
case "boolean":
|
|
729
|
+
case "boolean": {
|
|
727
730
|
let boolValue = model["_" + dirtyFields[column]];
|
|
728
731
|
// Apply toDatabase transformer
|
|
729
732
|
try {
|
|
@@ -740,8 +743,9 @@ class postgresEngine {
|
|
|
740
743
|
sqlParts.push(`${$that._q(dirtyFields[column])} = $${paramIndex++}`);
|
|
741
744
|
params.push(boolValue);
|
|
742
745
|
break;
|
|
746
|
+
}
|
|
743
747
|
|
|
744
|
-
case "time":
|
|
748
|
+
case "time": {
|
|
745
749
|
let timeValue = model["_" + dirtyFields[column]];
|
|
746
750
|
// Apply toDatabase transformer
|
|
747
751
|
try {
|
|
@@ -758,6 +762,7 @@ class postgresEngine {
|
|
|
758
762
|
sqlParts.push(`${$that._q(dirtyFields[column])} = $${paramIndex++}`);
|
|
759
763
|
params.push(timeValue);
|
|
760
764
|
break;
|
|
765
|
+
}
|
|
761
766
|
|
|
762
767
|
case "hasMany":
|
|
763
768
|
sqlParts.push(`${$that._q(dirtyFields[column])} = $${paramIndex++}`);
|
|
@@ -795,7 +800,6 @@ class postgresEngine {
|
|
|
795
800
|
const $that = this;
|
|
796
801
|
const columnNames = [];
|
|
797
802
|
const params = [];
|
|
798
|
-
const paramIndex = 1;
|
|
799
803
|
|
|
800
804
|
for (const column in modelEntity) {
|
|
801
805
|
if (column.indexOf("__") === -1) {
|
|
@@ -893,21 +897,23 @@ class postgresEngine {
|
|
|
893
897
|
return String(value);
|
|
894
898
|
|
|
895
899
|
case 'integer':
|
|
896
|
-
case 'int':
|
|
900
|
+
case 'int': {
|
|
897
901
|
const intVal = parseInt(value, 10);
|
|
898
902
|
if (isNaN(intVal)) {
|
|
899
903
|
throw new Error(`Field '${entityName}.${fieldName}' must be an integer, got: ${value}`);
|
|
900
904
|
}
|
|
901
905
|
return intVal;
|
|
906
|
+
}
|
|
902
907
|
|
|
903
908
|
case 'float':
|
|
904
909
|
case 'double':
|
|
905
|
-
case 'decimal':
|
|
910
|
+
case 'decimal': {
|
|
906
911
|
const floatVal = parseFloat(value);
|
|
907
912
|
if (isNaN(floatVal)) {
|
|
908
913
|
throw new Error(`Field '${entityName}.${fieldName}' must be a number, got: ${value}`);
|
|
909
914
|
}
|
|
910
915
|
return floatVal;
|
|
916
|
+
}
|
|
911
917
|
|
|
912
918
|
case 'boolean':
|
|
913
919
|
case 'bool':
|
|
@@ -918,7 +924,7 @@ class postgresEngine {
|
|
|
918
924
|
|
|
919
925
|
case 'date':
|
|
920
926
|
case 'datetime':
|
|
921
|
-
case 'timestamp':
|
|
927
|
+
case 'timestamp': {
|
|
922
928
|
if (value instanceof Date) {
|
|
923
929
|
return value;
|
|
924
930
|
}
|
|
@@ -927,6 +933,7 @@ class postgresEngine {
|
|
|
927
933
|
throw new Error(`Field '${entityName}.${fieldName}' must be a valid date, got: ${value}`);
|
|
928
934
|
}
|
|
929
935
|
return dateVal;
|
|
936
|
+
}
|
|
930
937
|
|
|
931
938
|
case 'json':
|
|
932
939
|
case 'jsonb':
|
package/postgresSyncConnect.js
CHANGED
|
@@ -70,11 +70,11 @@ class PostgresSyncConnect {
|
|
|
70
70
|
this.engine.setDB(this.pool, 'postgres');
|
|
71
71
|
|
|
72
72
|
// Set up error handlers
|
|
73
|
-
this.pool.on('error', (err,
|
|
73
|
+
this.pool.on('error', (err, _client) => {
|
|
74
74
|
console.error('Unexpected PostgreSQL error:', err);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
this.pool.on('connect', (
|
|
77
|
+
this.pool.on('connect', (_client) => {
|
|
78
78
|
console.log('New PostgreSQL client connected');
|
|
79
79
|
});
|
|
80
80
|
|