masterrecord 1.1.5 → 1.1.6
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 +14 -0
- package/Entity/entityModelBuilder.js +7 -7
- package/Entity/entityTrackerModel.js +15 -15
- package/Migrations/cli.js +126 -121
- package/Migrations/migrationMySQLQuery.js +21 -27
- package/Migrations/migrationPostgresQuery.js +16 -16
- package/Migrations/migrationSQLiteQuery.js +14 -14
- package/Migrations/migrations.js +41 -45
- package/Migrations/schema.js +3 -3
- package/QueryLanguage/queryMethods.js +26 -26
- package/QueryLanguage/queryScript.js +28 -28
- package/SQLLiteEngine.js +116 -118
- package/Tools.js +19 -19
- package/context.js +1 -1
- package/mySQLEngine.js +3 -3
- package/package.json +9 -2
- package/postgresEngine.js +6 -6
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,15 +38,15 @@ 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 (
|
|
49
|
+
for (const key in model) {
|
|
50
50
|
if (model.hasOwnProperty(key)) {
|
|
51
51
|
if(model[key].primary){
|
|
52
52
|
if(model[key].primary === true){
|
|
@@ -58,7 +58,7 @@ class Tools{
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
static findForeignTable(name, model){
|
|
61
|
-
for (
|
|
61
|
+
for (const key in model) {
|
|
62
62
|
if (model.hasOwnProperty(key)) {
|
|
63
63
|
if(model[key].foreignTable){
|
|
64
64
|
if(model[key].foreignTable === name){
|
|
@@ -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,10 +127,10 @@ class Tools{
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
static removePrimarykeyandVirtual(currentModel, modelEntity){
|
|
130
|
-
|
|
130
|
+
const newCurrentModel = Object.create(currentModel);
|
|
131
131
|
|
|
132
|
-
for(
|
|
133
|
-
|
|
132
|
+
for(const entity in modelEntity) {
|
|
133
|
+
const currentEntity = modelEntity[entity];
|
|
134
134
|
if (modelEntity.hasOwnProperty(entity)) {
|
|
135
135
|
if(currentEntity.primary === true){
|
|
136
136
|
delete newCurrentModel[`_${entity}`];
|
|
@@ -146,8 +146,8 @@ class Tools{
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
static getEntity(name, modelEntity){
|
|
149
|
-
for(
|
|
150
|
-
|
|
149
|
+
for(const entity in modelEntity) {
|
|
150
|
+
const currentEntity = modelEntity[entity];
|
|
151
151
|
if (modelEntity.hasOwnProperty(entity)) {
|
|
152
152
|
if(currentEntity.__name === name){
|
|
153
153
|
return currentEntity;
|
|
@@ -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
|
@@ -1069,7 +1069,7 @@ class context {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
1071
1071
|
// Normalize type — require explicit type, no silent inference
|
|
1072
|
-
|
|
1072
|
+
const type = (options.type || '').toString().toLowerCase();
|
|
1073
1073
|
if (!type) {
|
|
1074
1074
|
throw new ConfigurationError(
|
|
1075
1075
|
'Database type is required. Please specify type: "sqlite", "mysql", or "postgres" in your configuration.',
|
package/mySQLEngine.js
CHANGED
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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
|
@@ -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
|
|
|
@@ -795,7 +795,7 @@ class postgresEngine {
|
|
|
795
795
|
const $that = this;
|
|
796
796
|
const columnNames = [];
|
|
797
797
|
const params = [];
|
|
798
|
-
|
|
798
|
+
const paramIndex = 1;
|
|
799
799
|
|
|
800
800
|
for (const column in modelEntity) {
|
|
801
801
|
if (column.indexOf("__") === -1) {
|