masterrecord 0.0.47 → 0.0.49
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/Entity/entityModel.js +18 -7
- package/Entity/entityTrackerModel.js +3 -3
- package/Migrations/cli.js +116 -10
- package/Migrations/migrationMySQLQuery.js +299 -0
- package/Migrations/migrationTemplate.js +7 -7
- package/Migrations/migrations.js +44 -6
- package/Migrations/schema.js +93 -38
- package/QueryLanguage/queryMethods.js +25 -0
- package/context.js +32 -24
- package/insertManager.js +22 -15
- package/mySQLEngine.js +124 -41
- package/mySQLSyncConnect.js +39 -0
- package/package.json +3 -2
package/Migrations/migrations.js
CHANGED
|
@@ -76,7 +76,10 @@ class Migrations{
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
#findUpdatedColumns(tables){
|
|
79
|
+
|
|
80
|
+
|
|
79
81
|
tables.forEach(function (item, index) {
|
|
82
|
+
|
|
80
83
|
var UD = diff.updatedDiff(item.old, item.new);
|
|
81
84
|
const isEmpty = Object.keys(UD).length === 0;
|
|
82
85
|
if(!isEmpty){
|
|
@@ -111,8 +114,15 @@ class Migrations{
|
|
|
111
114
|
});
|
|
112
115
|
|
|
113
116
|
if(columnNotFound === false){
|
|
114
|
-
// this means it did not find the column
|
|
115
|
-
|
|
117
|
+
// this means it did not find the column
|
|
118
|
+
|
|
119
|
+
if(item.new[key].type !== "hasOne" && item.new[key].type !== "hasMany" && item.new[key].type !== "hasManyThrough"){
|
|
120
|
+
// if you have to create a new table no need to create the columns
|
|
121
|
+
if(item.newTables.length === 0){
|
|
122
|
+
item.newColumns.push(value);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
|
|
@@ -142,7 +152,9 @@ class Migrations{
|
|
|
142
152
|
|
|
143
153
|
// build table to build new migration snapshot
|
|
144
154
|
#buildMigrationObject(oldSchema, newSchema){
|
|
155
|
+
|
|
145
156
|
var tables = this.#organizeSchemaByTables(oldSchema, newSchema);
|
|
157
|
+
|
|
146
158
|
tables = this.#findNewTables(tables);
|
|
147
159
|
tables = this.#findNewColumns(tables);
|
|
148
160
|
tables = this.#findDeletedColumns(tables);
|
|
@@ -163,6 +175,30 @@ class Migrations{
|
|
|
163
175
|
}
|
|
164
176
|
}
|
|
165
177
|
|
|
178
|
+
// remove hasMany and hasOne and hasManyThrough
|
|
179
|
+
cleanEntities(entities){
|
|
180
|
+
var newEntity = [];
|
|
181
|
+
for (let i = 0; i < entities.length; i++) {
|
|
182
|
+
var entity = entities[i];
|
|
183
|
+
var newObj = {}
|
|
184
|
+
|
|
185
|
+
for (let key in entity) {
|
|
186
|
+
if (entity.hasOwnProperty(key)) {
|
|
187
|
+
|
|
188
|
+
if(entity[key].type !== "hasOne" && entity[key].type !== "hasMany" && entity[key].type !== "hasManyThrough"){
|
|
189
|
+
// if(entity[key].relationshipType == "belongsTo" ){
|
|
190
|
+
// entity[key].name = entity[key].foreignKey;
|
|
191
|
+
// }
|
|
192
|
+
newObj[key] = entity[key];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
newEntity.push(newObj);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return newEntity;
|
|
200
|
+
}
|
|
201
|
+
|
|
166
202
|
createSnapShot(snap){
|
|
167
203
|
|
|
168
204
|
var dbFolder = `${snap.executedLocation}/db`;
|
|
@@ -191,10 +227,11 @@ class Migrations{
|
|
|
191
227
|
}
|
|
192
228
|
}
|
|
193
229
|
|
|
194
|
-
//
|
|
230
|
+
// validate if schema has changed based on new and old
|
|
195
231
|
buildUpObject(oldSchema, newSchema){
|
|
196
232
|
var tableObj = {}
|
|
197
|
-
var tables = this.#buildMigrationObject(oldSchema, newSchema);
|
|
233
|
+
var tables = this.#buildMigrationObject(oldSchema, newSchema);
|
|
234
|
+
|
|
198
235
|
tables.forEach(function (item, index) {
|
|
199
236
|
// add new columns for table
|
|
200
237
|
var columnInfo = tables[index];
|
|
@@ -219,9 +256,9 @@ class Migrations{
|
|
|
219
256
|
|
|
220
257
|
if(item.new === null){
|
|
221
258
|
columnInfo.old.tableName = item.name;
|
|
222
|
-
tableObj[
|
|
259
|
+
tableObj["new"] = columnInfo.old;
|
|
223
260
|
}
|
|
224
|
-
|
|
261
|
+
|
|
225
262
|
tableObj.___table = item;
|
|
226
263
|
});
|
|
227
264
|
return tableObj;
|
|
@@ -230,6 +267,7 @@ class Migrations{
|
|
|
230
267
|
template(name, oldSchema, newSchema){
|
|
231
268
|
var MT = new MigrationTemplate(name);
|
|
232
269
|
var tables = this.#buildMigrationObject(oldSchema, newSchema);
|
|
270
|
+
|
|
233
271
|
tables.forEach(function (item, index) {
|
|
234
272
|
if(item.old === null){
|
|
235
273
|
MT.createTable("up", column, item.name);
|
package/Migrations/schema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// version 0.0.
|
|
1
|
+
// version 0.0.4
|
|
2
2
|
class schema{
|
|
3
3
|
|
|
4
4
|
constructor(context){
|
|
@@ -7,80 +7,135 @@ class schema{
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
init(table){
|
|
10
|
-
|
|
10
|
+
if(table){
|
|
11
|
+
this.fullTable = table.___table;
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
// create obj to convert into create sql
|
|
14
16
|
addColumn(table){
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
17
|
+
// todo need to work on add column for mysql
|
|
18
|
+
if(table){
|
|
19
|
+
if(this.context.isSQLite){
|
|
20
|
+
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
21
|
+
var queryBuilder = new sqliteQuery();
|
|
22
|
+
var queryObj = queryBuilder.alterColumn(this.fullTable.new, table);
|
|
23
|
+
for (var key in queryObj) {
|
|
24
|
+
var query = queryObj[key];
|
|
25
|
+
this.context._execute(query);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(this.context.isMySQL){
|
|
30
|
+
var sqlquery = require("./migrationMySQLQuery");
|
|
31
|
+
var queryBuilder = new sqlquery();
|
|
32
|
+
table.realDataType = queryBuilder.typeManager(table.type);
|
|
33
|
+
var query = queryBuilder.addColum(table);
|
|
21
34
|
this.context._execute(query);
|
|
22
35
|
}
|
|
23
36
|
}
|
|
37
|
+
|
|
24
38
|
// add column to database
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
dropColumn(table){
|
|
28
|
-
if(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
if(table){
|
|
43
|
+
if(this.fullTable){
|
|
44
|
+
// drop column
|
|
45
|
+
if(this.context.isSQLite){
|
|
46
|
+
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
47
|
+
var queryBuilder = new sqliteQuery();
|
|
48
|
+
var query = queryBuilder.dropColumn(table);
|
|
49
|
+
this.context._execute(query);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if(this.context.isMySQL){
|
|
53
|
+
var sqlquery = require("./migrationMySQLQuery");
|
|
54
|
+
var queryBuilder = new sqlquery();
|
|
55
|
+
var query = queryBuilder.dropColumn(table);
|
|
56
|
+
this.context._execute(query);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}else{
|
|
60
|
+
console.log("Must call the addTable function.");
|
|
35
61
|
}
|
|
36
|
-
}else{
|
|
37
|
-
console.log("Must call the addTable function.");
|
|
38
62
|
}
|
|
39
63
|
}
|
|
40
64
|
|
|
41
65
|
createTable(table){
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
66
|
+
|
|
67
|
+
if(table){
|
|
68
|
+
if(this.context.isSQLite){
|
|
69
|
+
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
70
|
+
var queryBuilder = new sqliteQuery();
|
|
71
|
+
var query = queryBuilder.createTable(table);
|
|
72
|
+
this.context._execute(query);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if(this.context.isMySQL){
|
|
76
|
+
var sqlquery = require("./migrationMySQLQuery");
|
|
77
|
+
var queryBuilder = new sqlquery();
|
|
78
|
+
var query = queryBuilder.createTable(table);
|
|
79
|
+
this.context._execute(query);
|
|
80
|
+
}
|
|
81
|
+
}else{
|
|
82
|
+
console.log("Table that your trying to create is undefined. PLease check if there are any changes that need to be made");
|
|
47
83
|
}
|
|
48
84
|
}
|
|
49
85
|
|
|
50
86
|
|
|
51
87
|
dropTable(table){
|
|
52
|
-
if(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
88
|
+
if(table){
|
|
89
|
+
if(this.context.isSQLite){
|
|
90
|
+
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
91
|
+
var queryBuilder = new sqliteQuery();
|
|
92
|
+
var query = queryBuilder.dropTable(table.__name);
|
|
93
|
+
this.context._execute(query);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if(this.context.isMySQL){
|
|
97
|
+
var sqlquery = require("./migrationMySQLQuery");
|
|
98
|
+
var queryBuilder = new sqlquery();
|
|
99
|
+
var query = queryBuilder.dropTable(table.__name);
|
|
100
|
+
this.context._execute(query);
|
|
101
|
+
}
|
|
57
102
|
}
|
|
58
103
|
}
|
|
59
104
|
|
|
60
105
|
|
|
61
106
|
//"dbo.People", "Location"
|
|
62
107
|
alterColumn(table){
|
|
63
|
-
if(
|
|
64
|
-
if(this.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var
|
|
108
|
+
if(table){
|
|
109
|
+
if(this.fullTable){
|
|
110
|
+
if(this.context.isSQLite){
|
|
111
|
+
var sqliteQuery = require("./migrationSQLiteQuery");
|
|
112
|
+
var queryBuilder = new sqliteQuery();
|
|
113
|
+
var queryObj = queryBuilder.alterColumn(this.fullTable.new, table);
|
|
114
|
+
for (var key in queryObj) {
|
|
115
|
+
var query = queryObj[key];
|
|
116
|
+
this.context._execute(query);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if(this.context.isMySQL){
|
|
121
|
+
var sqlquery = require("./migrationMySQLQuery");
|
|
122
|
+
var queryBuilder = new sqlquery();
|
|
123
|
+
var query = queryBuilder.alterColumn(table);
|
|
70
124
|
this.context._execute(query);
|
|
71
125
|
}
|
|
126
|
+
|
|
127
|
+
}else{
|
|
128
|
+
console.log("Must call the addTable function.");
|
|
72
129
|
}
|
|
73
|
-
}else{
|
|
74
|
-
console.log("Must call the addTable function.");
|
|
75
130
|
}
|
|
76
131
|
}
|
|
77
132
|
|
|
78
133
|
renameColumn(){
|
|
79
|
-
|
|
134
|
+
// TODO
|
|
80
135
|
}
|
|
81
136
|
|
|
82
137
|
seed(){
|
|
83
|
-
|
|
138
|
+
// TODO
|
|
84
139
|
}
|
|
85
140
|
|
|
86
141
|
}
|
|
@@ -198,6 +198,14 @@ class queryMethods{
|
|
|
198
198
|
this.__reset();
|
|
199
199
|
return val;
|
|
200
200
|
}
|
|
201
|
+
|
|
202
|
+
if(this.__context.isMySQL){
|
|
203
|
+
// trying to match string select and relace with select Count(*);
|
|
204
|
+
var entityValue = this.__context._SQLEngine.getCount(this.__queryObject, this.__entity, this.__context);
|
|
205
|
+
var val = entityValue[Object.keys(entityValue)[0]];
|
|
206
|
+
this.__reset();
|
|
207
|
+
return val;
|
|
208
|
+
}
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
single(){
|
|
@@ -207,6 +215,13 @@ class queryMethods{
|
|
|
207
215
|
this.__reset();
|
|
208
216
|
return sing;
|
|
209
217
|
}
|
|
218
|
+
|
|
219
|
+
if(this.__context.isMySQL){
|
|
220
|
+
var entityValue = this.__context._SQLEngine.get(this.__queryObject.script, this.__entity, this.__context);
|
|
221
|
+
var sing = this.__singleEntityBuilder(entityValue[0]);
|
|
222
|
+
this.__reset();
|
|
223
|
+
return sing;
|
|
224
|
+
}
|
|
210
225
|
}
|
|
211
226
|
|
|
212
227
|
toList(){
|
|
@@ -219,6 +234,16 @@ class queryMethods{
|
|
|
219
234
|
this.__reset();
|
|
220
235
|
return toLi;
|
|
221
236
|
}
|
|
237
|
+
|
|
238
|
+
if(this.__context.isMySQL){
|
|
239
|
+
if(this.__queryObject.script.entityMap.length === 0){
|
|
240
|
+
this.__queryObject.skipClause( this.__entity.__name);
|
|
241
|
+
}
|
|
242
|
+
var entityValue = this.__context._SQLEngine.all(this.__queryObject.script, this.__entity, this.__context);
|
|
243
|
+
var toLi = this.__multipleEntityBuilder(entityValue);
|
|
244
|
+
this.__reset();
|
|
245
|
+
return toLi;
|
|
246
|
+
}
|
|
222
247
|
}
|
|
223
248
|
|
|
224
249
|
// ------------------------------- FUNCTIONS THAT UPDATE SQL START FROM HERE -----------------------------------------------------
|
package/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Version 0.0.
|
|
1
|
+
// Version 0.0.6
|
|
2
2
|
|
|
3
3
|
var modelBuilder = require('./Entity/entityModelBuilder');
|
|
4
4
|
var query = require('masterrecord/QueryLanguage/queryMethods');
|
|
@@ -9,6 +9,8 @@ var insertManager = require('./insertManager');
|
|
|
9
9
|
var deleteManager = require('./deleteManager');
|
|
10
10
|
var globSearch = require("glob");
|
|
11
11
|
var fs = require('fs');
|
|
12
|
+
const appRoot = require('app-root-path');
|
|
13
|
+
const MySQLClient = require('masterrecord/mySQLSyncConnect');
|
|
12
14
|
|
|
13
15
|
class context {
|
|
14
16
|
_isModelValid = {
|
|
@@ -19,14 +21,14 @@ class context {
|
|
|
19
21
|
__builderEntities = [];
|
|
20
22
|
__trackedEntities = [];
|
|
21
23
|
__relationshipModels = [];
|
|
22
|
-
|
|
24
|
+
__environment = "";
|
|
23
25
|
__name = "";
|
|
24
26
|
isSQLite = false;
|
|
25
27
|
isMySQL = false;
|
|
26
28
|
isPostgres = false;
|
|
27
29
|
|
|
28
30
|
constructor(){
|
|
29
|
-
this.
|
|
31
|
+
this. __environment = process.env.master;
|
|
30
32
|
this.__name = this.constructor.name;
|
|
31
33
|
this._SQLEngine = "";
|
|
32
34
|
}
|
|
@@ -67,12 +69,11 @@ class context {
|
|
|
67
69
|
*/
|
|
68
70
|
__mysqlInit(env, sqlName){
|
|
69
71
|
try{
|
|
70
|
-
|
|
71
|
-
const mysql = require(sqlName);
|
|
72
|
-
const connection =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this._MYSQLEngine = new MYSQLEngine();
|
|
72
|
+
|
|
73
|
+
//const mysql = require(sqlName);
|
|
74
|
+
const connection = new MySQLClient(env);
|
|
75
|
+
this._SQLEngine = new MYSQLEngine();
|
|
76
|
+
this._SQLEngine.__name = sqlName;
|
|
76
77
|
return connection;
|
|
77
78
|
|
|
78
79
|
}
|
|
@@ -124,7 +125,7 @@ class context {
|
|
|
124
125
|
useSqlite(rootFolderLocation){
|
|
125
126
|
this.isSQLite = true;
|
|
126
127
|
var root = process.cwd();
|
|
127
|
-
var envType = this.
|
|
128
|
+
var envType = this.__environment;
|
|
128
129
|
var contextName = this.__name;
|
|
129
130
|
var file = this.__findSettings(root, rootFolderLocation, envType);
|
|
130
131
|
var settings = require(file.file);
|
|
@@ -156,16 +157,25 @@ class context {
|
|
|
156
157
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
useMySql(
|
|
160
|
-
|
|
160
|
+
useMySql(rootFolderLocation){
|
|
161
|
+
|
|
161
162
|
this.isMySQL = true;
|
|
162
|
-
|
|
163
|
-
this.
|
|
163
|
+
var envType = this.__environment;
|
|
164
|
+
var contextName = this.__name;
|
|
165
|
+
var root = appRoot.path;
|
|
166
|
+
var file = this.__findSettings(root, rootFolderLocation, envType);
|
|
167
|
+
var settings = require(file.file);
|
|
168
|
+
var options = settings[contextName];
|
|
169
|
+
|
|
170
|
+
if(options === undefined){
|
|
171
|
+
console.log("settings missing context name settings");
|
|
172
|
+
throw error("settings missing context name settings");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.db = this.__mysqlInit(options, "mysql2");
|
|
176
|
+
this._SQLEngine.setDB(this.db, "mysql");
|
|
164
177
|
return this;
|
|
165
|
-
|
|
166
|
-
else{
|
|
167
|
-
console.log("database options not defined - Master Record");
|
|
168
|
-
}
|
|
178
|
+
|
|
169
179
|
}
|
|
170
180
|
|
|
171
181
|
|
|
@@ -224,7 +234,7 @@ class context {
|
|
|
224
234
|
this._SQLEngine.endTransaction();
|
|
225
235
|
}
|
|
226
236
|
if(this.isMySQL){
|
|
227
|
-
this._SQLEngine.startTransaction();
|
|
237
|
+
//this._SQLEngine.startTransaction();
|
|
228
238
|
for (var model in tracked) {
|
|
229
239
|
var currentModel = tracked[model];
|
|
230
240
|
switch(currentModel.__state) {
|
|
@@ -256,7 +266,7 @@ class context {
|
|
|
256
266
|
}
|
|
257
267
|
}
|
|
258
268
|
this.__clearErrorHandler();
|
|
259
|
-
this._SQLEngine.endTransaction();
|
|
269
|
+
//this._SQLEngine.endTransaction();
|
|
260
270
|
}
|
|
261
271
|
}
|
|
262
272
|
else{
|
|
@@ -266,7 +276,7 @@ class context {
|
|
|
266
276
|
|
|
267
277
|
catch(error){
|
|
268
278
|
this.__clearErrorHandler();
|
|
269
|
-
this._SQLEngine.errorTransaction();
|
|
279
|
+
//this._SQLEngine.errorTransaction();
|
|
270
280
|
console.log("error", error);
|
|
271
281
|
this.__clearTracked();
|
|
272
282
|
throw error;
|
|
@@ -278,9 +288,7 @@ class context {
|
|
|
278
288
|
|
|
279
289
|
|
|
280
290
|
_execute(query){
|
|
281
|
-
|
|
282
|
-
this._SQLEngine._execute(query);
|
|
283
|
-
}
|
|
291
|
+
this._SQLEngine._execute(query);
|
|
284
292
|
}
|
|
285
293
|
|
|
286
294
|
// __track(model){
|
package/insertManager.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
// version 0.0.4
|
|
3
3
|
var tools = require('./Tools');
|
|
4
|
+
var queryScript = require('masterrecord/QueryLanguage/queryScript');
|
|
4
5
|
|
|
5
6
|
class InsertManager {
|
|
6
7
|
|
|
@@ -8,6 +9,7 @@ class InsertManager {
|
|
|
8
9
|
this._SQLEngine = sqlEngine;
|
|
9
10
|
this._errorModel = errorModel;
|
|
10
11
|
this._allEntities = allEntities;
|
|
12
|
+
this.__queryObject = new queryScript();
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
init(currentModel){
|
|
@@ -27,8 +29,10 @@ class InsertManager {
|
|
|
27
29
|
var primaryKey = tools.getPrimaryKeyObject(currentModel.__entity);
|
|
28
30
|
// return all fields that have auto and dont have a value to the current model on insert
|
|
29
31
|
if(currentModel.__entity[primaryKey].auto === true){
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
+
var query = `select * from ${currentModel.__entity.__name} where ${primaryKey} = ${ SQL.id }`;
|
|
33
|
+
var jj = this.__queryObject.raw(query);
|
|
34
|
+
var getQueryModel = this._SQLEngine.get(jj, currentModel.__entity, currentModel.__context );
|
|
35
|
+
currentModel[primaryKey] = getQueryModel[0][primaryKey];
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
const modelKeys = Object.keys(currentModel);
|
|
@@ -79,7 +83,7 @@ class InsertManager {
|
|
|
79
83
|
belongsToInsert(currentModel, modelEntity){
|
|
80
84
|
var $that = this;
|
|
81
85
|
for(var entity in modelEntity) {
|
|
82
|
-
if(modelEntity[entity].
|
|
86
|
+
if(modelEntity[entity].relationshipType === "belongsTo"){
|
|
83
87
|
var foreignKey = modelEntity[entity].foreignKey === undefined ? modelEntity[entity].name : modelEntity[entity].foreignKey;
|
|
84
88
|
var newPropertyModel = currentModel[foreignKey];
|
|
85
89
|
// check if model is a an object. If so insert the child first then the parent.
|
|
@@ -113,21 +117,24 @@ class InsertManager {
|
|
|
113
117
|
|
|
114
118
|
// SKIP belongs too
|
|
115
119
|
if(currentEntity.type !== "belongsTo" && currentEntity.type !== "hasMany"){
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
if(currentEntity.relationshipType !== "belongsTo"){
|
|
121
|
+
// primary is always null in an insert so validation insert must be null
|
|
122
|
+
if(currentEntity.nullable === false && !currentEntity.primary){
|
|
123
|
+
// if it doesnt have a get method then call error
|
|
124
|
+
if(currentEntity.set === undefined){
|
|
125
|
+
if(currentModel[entity] === undefined || currentModel[entity] === null || currentModel[entity] === "" ){
|
|
126
|
+
this._errorModel.isValid = false;
|
|
127
|
+
var errorMessage = `Entity ${currentModel.__entity.__name} column ${entity} is a required Field`;
|
|
128
|
+
this._errorModel.errors.push(errorMessage);
|
|
129
|
+
throw errorMessage;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else{
|
|
133
|
+
currentRealModel[entity] = currentEntity.set(currentModel[entity]);
|
|
125
134
|
}
|
|
126
|
-
}
|
|
127
|
-
else{
|
|
128
|
-
currentRealModel[entity] = currentEntity.set(currentModel[entity]);
|
|
129
135
|
}
|
|
130
136
|
}
|
|
137
|
+
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
|