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.
@@ -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
- class EntityModel {
21
-
22
- constructor(){
23
- this.obj = {
24
- type: null,
25
- primary : null,
26
- default : null,
27
- virtual : null,
28
- belongsTo : null,
29
- get : null,
30
- foreignKey : null,
31
- maxLength : null,
32
- nullable : false, // no
33
- unique : null
34
- }
35
- }
36
-
37
- string(){
38
- this.obj.type = "string";
39
- return this;
40
- }
41
-
42
- integer(){
43
- this.obj.type = "integer";
44
- return this;
45
- }
46
-
47
- time(){
48
- this.obj.type = "time";
49
- return this;
50
- }
51
-
52
- maxLength(amount){
53
- this.obj.maxLength = amount;
54
- return this;
55
- }
56
-
57
- // is this obj a primary key
58
- primary(){
59
- this.obj.primary = true;
60
- this.obj.nullable = false;
61
- this.obj.unique = true;
62
- return this;
63
- }
64
-
65
- // sets the default value in the DB
66
- default(value){
67
- this.obj.default = value;
68
- return this;
69
- }
70
-
71
- // get(func){
72
- // this.obj.get = func;
73
- // return this;
74
- // }
75
-
76
- unique(){
77
- this.obj.unique = true; // yes
78
- return this;
79
-
80
- }
81
-
82
- nullable(){
83
- this.obj.nullable = true; // yes
84
- return this;
85
- }
86
-
87
- notNullable(){
88
- this.obj.nullable = false; // no
89
- return this;
90
- }
91
-
92
- virtual(tableName){
93
- this.obj.virtual = true;
94
- if(tableName){
95
- this.obj.hasOne = tableName;
96
- }
97
- return this;
98
- }
99
-
100
- hasMany(name){
101
- this.obj.hasMany = name;
102
- return this;
103
- }
104
-
105
- hasOne(tableName){
106
- this.obj.hasOne = tableName;
107
- return this;
108
- }
109
-
110
- belongsTo(tableName){
111
- this.obj.foreignKey = tableName;
112
- return this
113
- }
114
-
115
- hasForeignKey(tableName){
116
- this.obj.foreignKey = tableName;
117
- return this;
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