masterrecord 0.0.23 → 0.0.24
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 +128 -120
- package/Entity/EntityModelBuilder.js +63 -63
- package/Entity/EntityTrackerModel.js +42 -42
- package/Masterrecord.js +173 -178
- package/Migrations/cli.js +105 -105
- package/Migrations/migrationTemplate.js +63 -63
- package/Migrations/migrations.js +46 -22
- package/Migrations/schema.js +42 -42
- package/QueryLanguage/_Expression.js +321 -321
- package/QueryLanguage/_LogicalQuery.js +22 -22
- package/QueryLanguage/_OperatorList.js +87 -87
- package/QueryLanguage/_QueryModel.js +441 -441
- package/QueryLanguage/_Tokenization.js +172 -172
- package/QueryLanguage/__Query.js +385 -385
- package/QueryLanguage/_simpleQuery.js +183 -183
- package/QueryLanguage/queryBuilder.js +51 -51
- package/{SQLEngine.js → SQLiteEngine.js} +56 -52
- package/Tools.js +55 -55
- package/package.json +27 -27
package/Entity/EntityModel.js
CHANGED
|
@@ -1,121 +1,129 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
:binary
|
|
4
|
-
:boolean
|
|
5
|
-
:date
|
|
6
|
-
:datetime
|
|
7
|
-
:decimal
|
|
8
|
-
:float
|
|
9
|
-
:integer
|
|
10
|
-
:bigint
|
|
11
|
-
:primary_key
|
|
12
|
-
:references
|
|
13
|
-
:string
|
|
14
|
-
:text
|
|
15
|
-
:time
|
|
16
|
-
:timestamp
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.obj.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.obj.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
:binary
|
|
4
|
+
:boolean
|
|
5
|
+
:date
|
|
6
|
+
:datetime
|
|
7
|
+
:decimal
|
|
8
|
+
:float
|
|
9
|
+
:integer
|
|
10
|
+
:bigint
|
|
11
|
+
:primary_key
|
|
12
|
+
:references
|
|
13
|
+
:string
|
|
14
|
+
:text
|
|
15
|
+
:time
|
|
16
|
+
:timestamp
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
// version 1.0.15
|
|
20
|
+
|
|
21
|
+
class EntityModel {
|
|
22
|
+
|
|
23
|
+
constructor(){
|
|
24
|
+
this.obj = {
|
|
25
|
+
type: null,
|
|
26
|
+
primary : null,
|
|
27
|
+
default : null,
|
|
28
|
+
virtual : null,
|
|
29
|
+
belongsTo : null,
|
|
30
|
+
get : null,
|
|
31
|
+
foreignKey : null,
|
|
32
|
+
maxLength : null,
|
|
33
|
+
nullable : false, // no
|
|
34
|
+
unique : null,
|
|
35
|
+
autoIncrement : false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
string(){
|
|
40
|
+
this.obj.type = "string";
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
integer(){
|
|
45
|
+
this.obj.type = "integer";
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
time(){
|
|
50
|
+
this.obj.type = "time";
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
maxLength(amount){
|
|
55
|
+
this.obj.maxLength = amount;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// is this obj a primary key
|
|
60
|
+
primary(){
|
|
61
|
+
this.obj.primary = true;
|
|
62
|
+
this.obj.nullable = false;
|
|
63
|
+
this.obj.unique = true;
|
|
64
|
+
this.obj.autoIncrement = true;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// sets the default value in the DB
|
|
69
|
+
default(value){
|
|
70
|
+
this.obj.default = value;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// get(func){
|
|
75
|
+
// this.obj.get = func;
|
|
76
|
+
// return this;
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
unique(){
|
|
80
|
+
this.obj.unique = true; // yes
|
|
81
|
+
return this;
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
autoIncrement(){
|
|
86
|
+
this.obj.autoIncrement = true;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
nullable(){
|
|
91
|
+
this.obj.nullable = true; // yes
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
notNullable(){
|
|
96
|
+
this.obj.nullable = false; // no
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
virtual(tableName){
|
|
101
|
+
this.obj.virtual = true;
|
|
102
|
+
if(tableName){
|
|
103
|
+
this.obj.hasOne = tableName;
|
|
104
|
+
}
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
hasMany(name){
|
|
109
|
+
this.obj.hasMany = name;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
hasOne(tableName){
|
|
114
|
+
this.obj.hasOne = tableName;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
belongsTo(tableName){
|
|
119
|
+
this.obj.foreignKey = tableName;
|
|
120
|
+
return this
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
hasForeignKey(tableName){
|
|
124
|
+
this.obj.foreignKey = tableName;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
121
129
|
module.exports = EntityModel;
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
var modelDB = require('./EntityModel');
|
|
2
|
-
|
|
3
|
-
// creates new instance if entity model and calls inner functions to build out a valid entity
|
|
4
|
-
class EntityModelBuilder {
|
|
5
|
-
|
|
6
|
-
static init(model){
|
|
7
|
-
var mod = new model(); //create new instance of Entity Model
|
|
8
|
-
var obj = {};
|
|
9
|
-
var methodNamesArray = Object.getOwnPropertyNames( mod.__proto__ );
|
|
10
|
-
var constructorIndex = methodNamesArray.indexOf("constructor");
|
|
11
|
-
// remove contructor method
|
|
12
|
-
if (constructorIndex > -1) {
|
|
13
|
-
methodNamesArray.splice(constructorIndex, 1);
|
|
14
|
-
}
|
|
15
|
-
// loop through all method names in the entity model
|
|
16
|
-
for (var i = 0; i < methodNamesArray.length; i++) {
|
|
17
|
-
let MDB = new modelDB(); // create a new instance of entity Model class
|
|
18
|
-
mod[methodNamesArray[i]](MDB);
|
|
19
|
-
this.cleanNull(MDB.obj); // remove objects that are null or undefined
|
|
20
|
-
if(Object.keys(MDB.obj).length === 0){
|
|
21
|
-
MDB.obj.virtual = true;
|
|
22
|
-
}
|
|
23
|
-
MDB.obj.name = methodNamesArray[i];
|
|
24
|
-
obj[methodNamesArray[i]] = MDB.obj;
|
|
25
|
-
}
|
|
26
|
-
return obj;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static cleanNull(obj) {
|
|
30
|
-
for (var propName in obj) {
|
|
31
|
-
if (obj[propName]) {
|
|
32
|
-
delete obj[propName];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static selectColumnQuery(objectLiteral){
|
|
38
|
-
var arr = "";
|
|
39
|
-
for(var keys = Object.keys(model), i = 0, end = keys.length; i < end; i++) {
|
|
40
|
-
var key = keys[i], value = model[key];
|
|
41
|
-
if(value.virtual === undefined){
|
|
42
|
-
arr += key + ",";
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
let cleaned = arr.substring(0, arr.length - 1);
|
|
46
|
-
return cleaned;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// who calls this? What does this do?
|
|
50
|
-
static callAllGets(data, model){
|
|
51
|
-
console.log("callAllGets");
|
|
52
|
-
for(var keys = Object.keys(model), i = 0, end = keys.length; i < end; i++) {
|
|
53
|
-
var key = keys[i], value = model[key];
|
|
54
|
-
if(value.get){
|
|
55
|
-
data[key] = value.get(data);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return data;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
1
|
+
var modelDB = require('./EntityModel');
|
|
2
|
+
|
|
3
|
+
// creates new instance if entity model and calls inner functions to build out a valid entity
|
|
4
|
+
class EntityModelBuilder {
|
|
5
|
+
|
|
6
|
+
static init(model){
|
|
7
|
+
var mod = new model(); //create new instance of Entity Model
|
|
8
|
+
var obj = {};
|
|
9
|
+
var methodNamesArray = Object.getOwnPropertyNames( mod.__proto__ );
|
|
10
|
+
var constructorIndex = methodNamesArray.indexOf("constructor");
|
|
11
|
+
// remove contructor method
|
|
12
|
+
if (constructorIndex > -1) {
|
|
13
|
+
methodNamesArray.splice(constructorIndex, 1);
|
|
14
|
+
}
|
|
15
|
+
// loop through all method names in the entity model
|
|
16
|
+
for (var i = 0; i < methodNamesArray.length; i++) {
|
|
17
|
+
let MDB = new modelDB(); // create a new instance of entity Model class
|
|
18
|
+
mod[methodNamesArray[i]](MDB);
|
|
19
|
+
this.cleanNull(MDB.obj); // remove objects that are null or undefined
|
|
20
|
+
if(Object.keys(MDB.obj).length === 0){
|
|
21
|
+
MDB.obj.virtual = true;
|
|
22
|
+
}
|
|
23
|
+
MDB.obj.name = methodNamesArray[i];
|
|
24
|
+
obj[methodNamesArray[i]] = MDB.obj;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static cleanNull(obj) {
|
|
30
|
+
for (var propName in obj) {
|
|
31
|
+
if (obj[propName]) {
|
|
32
|
+
delete obj[propName];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static selectColumnQuery(objectLiteral){
|
|
38
|
+
var arr = "";
|
|
39
|
+
for(var keys = Object.keys(model), i = 0, end = keys.length; i < end; i++) {
|
|
40
|
+
var key = keys[i], value = model[key];
|
|
41
|
+
if(value.virtual === undefined){
|
|
42
|
+
arr += key + ",";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
let cleaned = arr.substring(0, arr.length - 1);
|
|
46
|
+
return cleaned;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// who calls this? What does this do?
|
|
50
|
+
static callAllGets(data, model){
|
|
51
|
+
console.log("callAllGets");
|
|
52
|
+
for(var keys = Object.keys(model), i = 0, end = keys.length; i < end; i++) {
|
|
53
|
+
var key = keys[i], value = model[key];
|
|
54
|
+
if(value.get){
|
|
55
|
+
data[key] = value.get(data);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
64
|
module.exports = EntityModelBuilder;
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
class EntityTrackerModel {
|
|
2
|
-
constructor () {
|
|
3
|
-
this.__ID = Math.floor((Math.random() * 100000) + 1);;
|
|
4
|
-
this.__dirtyFields = [];
|
|
5
|
-
this.__state = "track";
|
|
6
|
-
this.__entity = null;
|
|
7
|
-
this.__name = null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// entity states https://docs.microsoft.com/en-us/dotnet/api/system.data.entitystate?view=netframework-4.7.2
|
|
11
|
-
|
|
12
|
-
// start tracking model
|
|
13
|
-
build(modelValue, currentEntity){
|
|
14
|
-
this.__proto__ = {};
|
|
15
|
-
const modelFields = Object.entries(modelValue); /// return array of objects
|
|
16
|
-
var modelClass = this; // build entity with models
|
|
17
|
-
modelClass.__entity = currentEntity;
|
|
18
|
-
modelClass.__name = currentEntity.__name;
|
|
19
|
-
|
|
20
|
-
for (const [modelField, modelFieldValue] of modelFields) { // loop through database values
|
|
21
|
-
// set the value dynamiclly
|
|
22
|
-
if(currentEntity[modelField]){ // current entity has a value then add
|
|
23
|
-
modelClass["_" + modelField] = modelFieldValue;
|
|
24
|
-
|
|
25
|
-
// Setter
|
|
26
|
-
this.__proto__.__defineSetter__(modelField, function(value){
|
|
27
|
-
modelClass.__state = "modified";
|
|
28
|
-
modelClass.__dirtyFields.push(modelField);
|
|
29
|
-
// Then it will add name to dirty fields
|
|
30
|
-
this["_" + modelField] = value;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Getter
|
|
34
|
-
this.__proto__.__defineGetter__(modelField, function(){
|
|
35
|
-
return this["_" + modelField];
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return modelClass;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
1
|
+
class EntityTrackerModel {
|
|
2
|
+
constructor () {
|
|
3
|
+
this.__ID = Math.floor((Math.random() * 100000) + 1);;
|
|
4
|
+
this.__dirtyFields = [];
|
|
5
|
+
this.__state = "track";
|
|
6
|
+
this.__entity = null;
|
|
7
|
+
this.__name = null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// entity states https://docs.microsoft.com/en-us/dotnet/api/system.data.entitystate?view=netframework-4.7.2
|
|
11
|
+
|
|
12
|
+
// start tracking model
|
|
13
|
+
build(modelValue, currentEntity){
|
|
14
|
+
this.__proto__ = {};
|
|
15
|
+
const modelFields = Object.entries(modelValue); /// return array of objects
|
|
16
|
+
var modelClass = this; // build entity with models
|
|
17
|
+
modelClass.__entity = currentEntity;
|
|
18
|
+
modelClass.__name = currentEntity.__name;
|
|
19
|
+
|
|
20
|
+
for (const [modelField, modelFieldValue] of modelFields) { // loop through database values
|
|
21
|
+
// set the value dynamiclly
|
|
22
|
+
if(currentEntity[modelField]){ // current entity has a value then add
|
|
23
|
+
modelClass["_" + modelField] = modelFieldValue;
|
|
24
|
+
|
|
25
|
+
// Setter
|
|
26
|
+
this.__proto__.__defineSetter__(modelField, function(value){
|
|
27
|
+
modelClass.__state = "modified";
|
|
28
|
+
modelClass.__dirtyFields.push(modelField);
|
|
29
|
+
// Then it will add name to dirty fields
|
|
30
|
+
this["_" + modelField] = value;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Getter
|
|
34
|
+
this.__proto__.__defineGetter__(modelField, function(){
|
|
35
|
+
return this["_" + modelField];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return modelClass;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
43
|
module.exports = EntityTrackerModel
|