masterrecord 1.1.5 → 1.1.7
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 +26 -0
- package/Cache/RedisQueryCache.js +1 -1
- package/Entity/entityModelBuilder.js +8 -8
- package/Entity/entityTrackerModel.js +19 -19
- package/Migrations/cli.js +127 -123
- package/Migrations/migrationMySQLQuery.js +21 -27
- package/Migrations/migrationPostgresQuery.js +16 -16
- package/Migrations/migrationSQLiteQuery.js +14 -15
- package/Migrations/migrationTemplate.js +6 -6
- package/Migrations/migrations.js +66 -70
- package/Migrations/schema.js +3 -3
- package/QueryLanguage/queryMethods.js +27 -28
- package/QueryLanguage/queryScript.js +35 -37
- package/SQLLiteEngine.js +122 -123
- package/Tools.js +23 -23
- package/context.js +4 -5
- package/deleteManager.js +0 -1
- package/insertManager.js +1 -1
- package/mySQLEngine.js +16 -10
- package/package.json +9 -2
- package/postgresEngine.js +25 -18
- package/postgresSyncConnect.js +2 -2
package/Tools.js
CHANGED
|
@@ -19,9 +19,9 @@ class Tools{
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
static returnEntityList(list, entityList ){
|
|
22
|
-
|
|
23
|
-
for(
|
|
24
|
-
|
|
22
|
+
const newList = [];
|
|
23
|
+
for(let max = 0; max < list.length; max++ ){
|
|
24
|
+
const ent = entityList[list[max]];
|
|
25
25
|
if(ent){
|
|
26
26
|
if(ent.relationshipType === "hasMany" || ent.relationshipType === "hasOne"){
|
|
27
27
|
newList.push(ent.name);
|
|
@@ -38,16 +38,16 @@ class Tools{
|
|
|
38
38
|
// this will remove everthing from back slash amount
|
|
39
39
|
static removeBackwardSlashSection(string, amount, type){
|
|
40
40
|
type = type === undefined ? "\\" : type;
|
|
41
|
-
|
|
42
|
-
for(
|
|
41
|
+
const stringArray = string.split(type);
|
|
42
|
+
for(let i = 0; i < amount; i++){
|
|
43
43
|
stringArray.pop();
|
|
44
44
|
}
|
|
45
45
|
return stringArray.join(type);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
static getPrimaryKeyObject(model){
|
|
49
|
-
for (
|
|
50
|
-
if (
|
|
49
|
+
for (const key in model) {
|
|
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
|
|
@@ -58,8 +58,8 @@ class Tools{
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
static findForeignTable(name, model){
|
|
61
|
-
for (
|
|
62
|
-
if (
|
|
61
|
+
for (const key in model) {
|
|
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];
|
|
@@ -85,7 +85,7 @@ class Tools{
|
|
|
85
85
|
|
|
86
86
|
static clearAllProto(proto){
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
const newproto = {}
|
|
89
89
|
if(proto.__proto__ ){
|
|
90
90
|
// Include non-enumerable own properties so we don't lose values defined via getters
|
|
91
91
|
const keys = Object.getOwnPropertyNames(proto);
|
|
@@ -127,11 +127,11 @@ class Tools{
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
static removePrimarykeyandVirtual(currentModel, modelEntity){
|
|
130
|
-
|
|
130
|
+
const newCurrentModel = Object.create(currentModel);
|
|
131
131
|
|
|
132
|
-
for(
|
|
133
|
-
|
|
134
|
-
if (
|
|
132
|
+
for(const entity in modelEntity) {
|
|
133
|
+
const currentEntity = modelEntity[entity];
|
|
134
|
+
if (Object.prototype.hasOwnProperty.call(modelEntity, entity)) {
|
|
135
135
|
if(currentEntity.primary === true){
|
|
136
136
|
delete newCurrentModel[`_${entity}`];
|
|
137
137
|
}
|
|
@@ -146,9 +146,9 @@ class Tools{
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
static getEntity(name, modelEntity){
|
|
149
|
-
for(
|
|
150
|
-
|
|
151
|
-
if (
|
|
149
|
+
for(const entity in modelEntity) {
|
|
150
|
+
const currentEntity = modelEntity[entity];
|
|
151
|
+
if (Object.prototype.hasOwnProperty.call(modelEntity, entity)) {
|
|
152
152
|
if(currentEntity.__name === name){
|
|
153
153
|
return currentEntity;
|
|
154
154
|
}
|
|
@@ -168,14 +168,14 @@ class Tools{
|
|
|
168
168
|
|
|
169
169
|
// return randome letter that is not the skip letter
|
|
170
170
|
static getRandomLetter(length, skip){
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
let result = '';
|
|
172
|
+
const characters = 'abcdefghijklmnopqrstuvwxyz';
|
|
173
|
+
const charactersLength = characters.length;
|
|
174
174
|
|
|
175
|
-
for (
|
|
175
|
+
for ( let i = 0; i < length; i++ ) {
|
|
176
176
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
177
177
|
if(skip){
|
|
178
|
-
for (
|
|
178
|
+
for ( let b = 0; b < skip.length; b++ ) {
|
|
179
179
|
if(result === skip[i].entity){
|
|
180
180
|
result = "";
|
|
181
181
|
i--;
|
|
@@ -192,7 +192,7 @@ class Tools{
|
|
|
192
192
|
|
|
193
193
|
static convertEntityToSelectParameterString(obj){
|
|
194
194
|
// todo: loop throgh object and append string with comma to
|
|
195
|
-
|
|
195
|
+
let mainString = "";
|
|
196
196
|
const entries = Object.keys(obj);
|
|
197
197
|
for (const key of entries) {
|
|
198
198
|
// Skip lifecycle hooks - they are not database columns
|
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';
|
|
@@ -1069,7 +1068,7 @@ class context {
|
|
|
1069
1068
|
}
|
|
1070
1069
|
|
|
1071
1070
|
// Normalize type — require explicit type, no silent inference
|
|
1072
|
-
|
|
1071
|
+
const type = (options.type || '').toString().toLowerCase();
|
|
1073
1072
|
if (!type) {
|
|
1074
1073
|
throw new ConfigurationError(
|
|
1075
1074
|
'Database type is required. Please specify type: "sqlite", "mysql", or "postgres" in your configuration.',
|
|
@@ -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;
|
|
@@ -472,7 +472,7 @@ class MySQLEngine {
|
|
|
472
472
|
const includeQueries = [];
|
|
473
473
|
const $that = this;
|
|
474
474
|
|
|
475
|
-
for (
|
|
475
|
+
for (const part in query.include) {
|
|
476
476
|
const includeEntity = query.include[part];
|
|
477
477
|
if (includeEntity) {
|
|
478
478
|
const parentObj = includeEntity[query.parentName];
|
|
@@ -537,7 +537,7 @@ class MySQLEngine {
|
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
let func = expr.func;
|
|
540
|
-
|
|
540
|
+
const arg = expr.arg;
|
|
541
541
|
if ((!func && typeof arg === 'undefined')) {
|
|
542
542
|
return null;
|
|
543
543
|
}
|
|
@@ -613,7 +613,7 @@ class MySQLEngine {
|
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
getEntity(name, maps) {
|
|
616
|
-
for (
|
|
616
|
+
for (const item in maps) {
|
|
617
617
|
const map = maps[item];
|
|
618
618
|
if (tools.capitalizeFirstLetter(name) === map.name) {
|
|
619
619
|
return map.entity;
|
|
@@ -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.7",
|
|
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",
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
"node": ">=20.0.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"test": "node --test test/ Migrations/pathUtils.test.js"
|
|
52
|
+
"test": "node --test test/ Migrations/pathUtils.test.js",
|
|
53
|
+
"lint": "eslint . --fix",
|
|
54
|
+
"lint:check": "eslint ."
|
|
53
55
|
},
|
|
54
56
|
"author": "Alexandr Rich",
|
|
55
57
|
"license": "MIT",
|
|
@@ -76,5 +78,10 @@
|
|
|
76
78
|
"mysql2": "^3.11.5",
|
|
77
79
|
"app-root-path": "^3.1.0",
|
|
78
80
|
"better-sqlite3": "^12.6.2"
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@eslint/js": "^9.17.0",
|
|
84
|
+
"eslint": "^9.17.0",
|
|
85
|
+
"globals": "^15.14.0"
|
|
79
86
|
}
|
|
80
87
|
}
|
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 ...
|
|
@@ -462,12 +462,12 @@ class postgresEngine {
|
|
|
462
462
|
const entity = this.getEntity(query.parentName, query.entityMap);
|
|
463
463
|
const andList = [];
|
|
464
464
|
|
|
465
|
-
for (
|
|
465
|
+
for (const entityPart in andEntity) {
|
|
466
466
|
const itemEntity = andEntity[entityPart];
|
|
467
|
-
for (
|
|
467
|
+
for (const table in itemEntity[query.parentName]) {
|
|
468
468
|
const item = itemEntity[query.parentName][table];
|
|
469
469
|
const expressions = [];
|
|
470
|
-
for (
|
|
470
|
+
for (const exp in item.expressions) {
|
|
471
471
|
// Use the field name verbatim for SQL emission so it
|
|
472
472
|
// matches the actual column case. The capitalized form
|
|
473
473
|
// is only useful for the navigational-relationship
|
|
@@ -530,7 +530,7 @@ class postgresEngine {
|
|
|
530
530
|
const item = whereEntity[query.parentName].query;
|
|
531
531
|
const conditions = [];
|
|
532
532
|
|
|
533
|
-
for (
|
|
533
|
+
for (const exp in item.expressions) {
|
|
534
534
|
// Use the field name verbatim for SQL emission. See buildAnd for full rationale.
|
|
535
535
|
const originalField = item.expressions[exp].field;
|
|
536
536
|
const capitalized = tools.capitalizeFirstLetter(originalField);
|
|
@@ -643,7 +643,7 @@ class postgresEngine {
|
|
|
643
643
|
const dirtyFields = model.__dirtyFields;
|
|
644
644
|
let paramIndex = 1;
|
|
645
645
|
|
|
646
|
-
for (
|
|
646
|
+
for (const column in dirtyFields) {
|
|
647
647
|
const fieldName = dirtyFields[column];
|
|
648
648
|
const entityDef = model.__entity[fieldName];
|
|
649
649
|
|
|
@@ -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
|
-
let 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
|
|