mythix-orm 1.0.1

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.
Files changed (124) hide show
  1. package/.eslintrc.js +94 -0
  2. package/.vscode/launch.json +34 -0
  3. package/.vscode/settings.json +10 -0
  4. package/LICENSE +21 -0
  5. package/README.md +15 -0
  6. package/lib/connection/connection-base.js +877 -0
  7. package/lib/connection/index.js +11 -0
  8. package/lib/connection/literals/average-literal.js +14 -0
  9. package/lib/connection/literals/count-literal.js +18 -0
  10. package/lib/connection/literals/distinct-literal.js +14 -0
  11. package/lib/connection/literals/index.js +23 -0
  12. package/lib/connection/literals/literal-base.js +62 -0
  13. package/lib/connection/literals/literal-field-base.js +45 -0
  14. package/lib/connection/literals/literal.js +11 -0
  15. package/lib/connection/literals/max-literal.js +14 -0
  16. package/lib/connection/literals/min-literal.js +14 -0
  17. package/lib/connection/literals/sum-literal.js +14 -0
  18. package/lib/connection/query-generator-base.js +864 -0
  19. package/lib/errors/base-error.js +14 -0
  20. package/lib/errors/connection/access-denied-error.js +13 -0
  21. package/lib/errors/connection/connection-acquire-timeout-error.js +13 -0
  22. package/lib/errors/connection/connection-refused-error.js +13 -0
  23. package/lib/errors/connection/connection-timed-out-error.js +13 -0
  24. package/lib/errors/connection/host-not-found-error.js +13 -0
  25. package/lib/errors/connection/host-not-reachable-error.js +13 -0
  26. package/lib/errors/connection/index.js +19 -0
  27. package/lib/errors/connection/invalid-connection-error.js +13 -0
  28. package/lib/errors/connection-base-error.js +13 -0
  29. package/lib/errors/database/exclusion-constraint-error.js +13 -0
  30. package/lib/errors/database/foreign-key-constraint-error.js +13 -0
  31. package/lib/errors/database/index.js +13 -0
  32. package/lib/errors/database/timeout-error.js +13 -0
  33. package/lib/errors/database/unknown-constraint-error.js +13 -0
  34. package/lib/errors/database-base-error.js +17 -0
  35. package/lib/errors/index.js +44 -0
  36. package/lib/field.js +18 -0
  37. package/lib/index.js +43 -0
  38. package/lib/model.js +1374 -0
  39. package/lib/proxy-class/index.js +3 -0
  40. package/lib/proxy-class/proxy-class.js +269 -0
  41. package/lib/query-engine/field-scope.js +99 -0
  42. package/lib/query-engine/index.js +13 -0
  43. package/lib/query-engine/model-scope.js +198 -0
  44. package/lib/query-engine/query-engine-base.js +325 -0
  45. package/lib/query-engine/query-engine.js +212 -0
  46. package/lib/types/concrete/bigint-type.js +62 -0
  47. package/lib/types/concrete/blob-type.js +46 -0
  48. package/lib/types/concrete/boolean-type.js +41 -0
  49. package/lib/types/concrete/char-type.js +39 -0
  50. package/lib/types/concrete/date-type.js +87 -0
  51. package/lib/types/concrete/datetime-type.js +92 -0
  52. package/lib/types/concrete/float-type.js +47 -0
  53. package/lib/types/concrete/foreign-key-type.js +208 -0
  54. package/lib/types/concrete/index.js +53 -0
  55. package/lib/types/concrete/integer-type.js +51 -0
  56. package/lib/types/concrete/string-type.js +44 -0
  57. package/lib/types/concrete/text-type.js +44 -0
  58. package/lib/types/concrete/uuid-base.js +77 -0
  59. package/lib/types/concrete/uuid-v1-type.js +99 -0
  60. package/lib/types/concrete/uuid-v3-type.js +108 -0
  61. package/lib/types/concrete/uuid-v4-type.js +90 -0
  62. package/lib/types/concrete/uuid-v5-type.js +108 -0
  63. package/lib/types/concrete/xid-type.js +58 -0
  64. package/lib/types/helpers/default-helpers.js +127 -0
  65. package/lib/types/helpers/index.js +35 -0
  66. package/lib/types/index.js +94 -0
  67. package/lib/types/type.js +244 -0
  68. package/lib/types/virtual/index.js +14 -0
  69. package/lib/types/virtual/model-type.js +141 -0
  70. package/lib/types/virtual/models-type.js +264 -0
  71. package/lib/types/virtual/relational-type-base.js +323 -0
  72. package/lib/utils/index.js +65 -0
  73. package/lib/utils/misc-utils.js +73 -0
  74. package/lib/utils/model-utils.js +704 -0
  75. package/lib/utils/query-utils.js +186 -0
  76. package/package.json +63 -0
  77. package/playground/test01.js +15 -0
  78. package/spec/connection/connection-base-spec.js +126 -0
  79. package/spec/connection/literals/average-literal-spec.js +45 -0
  80. package/spec/connection/literals/count-literal-spec.js +42 -0
  81. package/spec/connection/literals/distinct-literal-spec.js +42 -0
  82. package/spec/connection/literals/literal-spec.js +26 -0
  83. package/spec/connection/literals/max-literal-spec.js +42 -0
  84. package/spec/connection/literals/min-literal-spec.js +42 -0
  85. package/spec/connection/literals/sum-literal-spec.js +42 -0
  86. package/spec/helpers/default-helpers-spec.js +108 -0
  87. package/spec/model-spec.js +736 -0
  88. package/spec/proxy-class/proxy-class-spec.js +173 -0
  89. package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_chain_query_conditions-001.snapshot +94 -0
  90. package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_construct_a_query_context_with_a_model_call-001.snapshot +35 -0
  91. package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_construct_a_query_context_with_a_model_sub-001.snapshot +35 -0
  92. package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_set_a_default_scope_on_a_model-001.snapshot +57 -0
  93. package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_unscope_default_scope_on_a_model-001.snapshot +35 -0
  94. package/spec/query-engine/query-engine-spec.js +99 -0
  95. package/spec/support/jasmine.json +13 -0
  96. package/spec/support/models/blob-test-model.js +19 -0
  97. package/spec/support/models/extended-user-model.js +38 -0
  98. package/spec/support/models/index.js +27 -0
  99. package/spec/support/models/number-model.js +24 -0
  100. package/spec/support/models/role-model.js +26 -0
  101. package/spec/support/models/role-thing-model.js +41 -0
  102. package/spec/support/models/scoped-user-model.js +13 -0
  103. package/spec/support/models/time-model.js +36 -0
  104. package/spec/support/models/user-model.js +70 -0
  105. package/spec/support/models/user-role-model.js +36 -0
  106. package/spec/support/models/user-thing-model.js +46 -0
  107. package/spec/support/models/validation-test-model.js +40 -0
  108. package/spec/support/snapshots.js +293 -0
  109. package/spec/support/test-helpers.js +13 -0
  110. package/spec/types/concrete/bigint-type-spec.js +84 -0
  111. package/spec/types/concrete/boolean-type-spec.js +83 -0
  112. package/spec/types/concrete/date-type-spec.js +85 -0
  113. package/spec/types/concrete/datetime-type-spec.js +87 -0
  114. package/spec/types/concrete/float-type-spec.js +71 -0
  115. package/spec/types/concrete/foreign-key-type-spec.js +64 -0
  116. package/spec/types/concrete/integer-type-spec.js +71 -0
  117. package/spec/types/concrete/string-type-spec.js +91 -0
  118. package/spec/types/concrete/uuid-v1-type-spec.js +73 -0
  119. package/spec/types/concrete/uuid-v4-type-spec.js +65 -0
  120. package/spec/types/type-spec.js +101 -0
  121. package/spec/types/virtual/model-types-spec.js +401 -0
  122. package/spec/utils/misc-utils-spec.js +61 -0
  123. package/spec/utils/model-utils-spec.js +55 -0
  124. package/spec/utils/query-utils-spec.js +105 -0
@@ -0,0 +1,325 @@
1
+ 'use strict';
2
+
3
+ const ProxyClass = require('../proxy-class');
4
+
5
+ let uuid = 1;
6
+
7
+ function generateID() {
8
+ return uuid++;
9
+ }
10
+
11
+ class QueryEngineBase extends ProxyClass {
12
+ static generateID() {
13
+ return uuid++;
14
+ }
15
+
16
+ static isQueryContext(value) {
17
+ return !!(value && value.isQueryContext);
18
+ }
19
+
20
+ static isQuery(value) {
21
+ if (!value)
22
+ return false;
23
+
24
+ if (value instanceof QueryEngineBase)
25
+ return true;
26
+
27
+ if (value._isQueryEngine)
28
+ return true;
29
+
30
+ if (typeof value._getRawQueryContext === 'function')
31
+ return true;
32
+
33
+ return false;
34
+ }
35
+
36
+ static queryContextType(queryContext) {
37
+ let contextParams = {
38
+ hasCondition: false,
39
+ hasField: false,
40
+ hasModel: false,
41
+ };
42
+
43
+ if (!queryContext)
44
+ return contextParams;
45
+
46
+ if (queryContext.condition)
47
+ contextParams.hasCondition = true;
48
+
49
+ if (queryContext.fieldName)
50
+ contextParams.hasField = true;
51
+
52
+ if (queryContext.Model)
53
+ contextParams.hasModel = true;
54
+
55
+ return contextParams;
56
+ }
57
+
58
+ getModelScopeClass() {
59
+ return this.getQueryEngineScope().getModelScopeClass();
60
+ }
61
+
62
+ getFieldScopeClass() {
63
+ return this.getQueryEngineScope().getFieldScopeClass();
64
+ }
65
+
66
+ _inheritContext(context, name, ...args) {
67
+ let newContext = Object.assign(
68
+ Object.create(context),
69
+ { value: undefined },
70
+ ...args,
71
+ {
72
+ contextID: generateID(),
73
+ },
74
+ );
75
+
76
+ if (name) {
77
+ newContext[`${name}Context`] = newContext;
78
+ newContext['currentScopeName'] = name;
79
+ }
80
+
81
+ return newContext;
82
+ }
83
+
84
+ _fetchScope(...scopeNames) {
85
+ let context = this._getRawQueryContext();
86
+
87
+ for (let i = 0, il = scopeNames.length; i < il; i++) {
88
+ let scopeName = scopeNames[i];
89
+ if (scopeName === 'queryEngine') {
90
+ return this._newQueryEngineScope();
91
+ } else if (scopeName === 'model') {
92
+ let Model = context.Model;
93
+ if (!Model)
94
+ continue;
95
+
96
+ return this._newModelScope(Model);
97
+ } else if (scopeName === 'field') {
98
+ let Field = context.Field;
99
+ if (!Field)
100
+ continue;
101
+
102
+ return this._newFieldScope(context.Field);
103
+ }
104
+ }
105
+
106
+ return this;
107
+ }
108
+
109
+ _newQueryEngineScope() {
110
+ const QueryEngine = this.getQueryEngineClass();
111
+ let context = this.currentContext;
112
+ let newContext = this._inheritContext(context, 'queryEngine');
113
+ let newScope = new QueryEngine(newContext);
114
+
115
+ return newScope;
116
+ }
117
+
118
+ _newModelScope(Model) {
119
+ let ModelScopeClass = this.getModelScopeClass();
120
+ let modelName = Model.getModelName();
121
+ let context = this.currentContext;
122
+ let extra = {};
123
+
124
+ if (!context.rootModel) {
125
+ extra.rootModelName = modelName;
126
+ extra.rootModel = Model;
127
+ }
128
+
129
+ // Ensure that the specified model
130
+ // is the same dialect as the query
131
+ let modelConnection = Model._getConnection();
132
+ let dialect;
133
+
134
+ if (modelConnection) {
135
+ dialect = modelConnection.dialect;
136
+ if (context.dialect && context.dialect !== dialect)
137
+ throw new Error(`QueryEngine: Model "${Model.getModelName()}" is on a different connection dialect than the current query dialect of "${context.dialect}". You can not match different connection dialects in the same query.`);
138
+ }
139
+
140
+ if (!dialect) {
141
+ let connection = this.getConnection();
142
+ if (connection)
143
+ dialect = connection.dialect;
144
+ }
145
+
146
+ let newContext = this._inheritContext(context, 'model', { operator: 'MODEL', Model, modelName, dialect }, extra);
147
+ let newScope = new ModelScopeClass(newContext);
148
+
149
+ // We shouldn't add this scope if this is
150
+ // already the current model of the scope
151
+ if (context.Model !== Model)
152
+ context.queryRoot.push(newContext);
153
+
154
+ // But we always need to return the scope
155
+ // for the proxy to work properly
156
+ return newScope;
157
+ }
158
+
159
+ _newFieldScope(Field) {
160
+ let fieldName = Field.fieldName;
161
+ let context = this.currentContext;
162
+ let FieldScopeClass = this.getFieldScopeClass();
163
+ let extra = {};
164
+
165
+ if (!context.rootField) {
166
+ extra.rootFieldName = fieldName;
167
+ extra.rootField = Field;
168
+ }
169
+
170
+ let newContext = this._inheritContext(context, 'field', { operator: 'FIELD', fieldName, Field }, extra);
171
+ let newScope = new FieldScopeClass(newContext);
172
+
173
+ // We shouldn't add this scope if this is
174
+ // already the current field of the scope
175
+ if (context.Field !== Field)
176
+ context.queryRoot.push(newContext);
177
+
178
+ // But we always need to return the scope
179
+ // for the proxy to work properly
180
+ return newScope;
181
+ }
182
+
183
+ constructor(context) {
184
+ super();
185
+
186
+ this._isQueryEngine = true;
187
+
188
+ if (!context)
189
+ throw new TypeError('QueryEngineBase::constructor: "context" required.');
190
+
191
+ if (!context.rootContext) {
192
+ context._isQueryEngine = true;
193
+ context.rootContext = context;
194
+ }
195
+
196
+ if (!context.queryRoot)
197
+ context.queryRoot = [];
198
+
199
+ if (!('and' in context))
200
+ context.and = true;
201
+
202
+ if (!('or' in context))
203
+ context.or = false;
204
+
205
+ // console.log(`Creating new ${this.constructor.name} scope: `, context, Object.getPrototypeOf(context));
206
+
207
+ let queryRoot = context.queryRoot;
208
+ Object.defineProperties(this, {
209
+ queryRoot: {
210
+ writable: false,
211
+ enumberable: false,
212
+ configurable: true,
213
+ value: queryRoot,
214
+ },
215
+ currentContext: {
216
+ enumberable: false,
217
+ configurable: true,
218
+ get: () => {
219
+ let currentContext = queryRoot[queryRoot.length - 1];
220
+ return currentContext || context;
221
+ },
222
+ set: () => {},
223
+ },
224
+ });
225
+ }
226
+
227
+ _getTopContextID() {
228
+ return this.currentContext.contextID;
229
+ }
230
+
231
+ _getRawQueryContext() {
232
+ return this.currentContext;
233
+ }
234
+
235
+ _getRawQuery() {
236
+ return this.currentContext.queryRoot;
237
+ }
238
+
239
+ _isLastPartControl() {
240
+ let queryParts = this._getRawQuery();
241
+ let lastPart = queryParts[queryParts.length - 1];
242
+
243
+ if (Object.prototype.hasOwnProperty.call(lastPart, 'control') && lastPart.control === true)
244
+ return true;
245
+
246
+ return false;
247
+ }
248
+
249
+ _isLastPartCondition() {
250
+ let queryParts = this._getRawQuery();
251
+ let lastPart = queryParts[queryParts.length - 1];
252
+
253
+ if (Object.prototype.hasOwnProperty.call(lastPart, 'condition') && lastPart.condition === true)
254
+ return true;
255
+
256
+ return false;
257
+ }
258
+
259
+ _debugQuery() {
260
+ let query = this._getRawQuery();
261
+ for (let i = 0, il = query.length; i < il; i++) {
262
+ let queryPart = query[i];
263
+ let operator = queryPart.operator;
264
+
265
+ if (operator === 'MODEL')
266
+ console.log(`MODEL -> ${queryPart.Model.getModelName()}`);
267
+ else if (operator === 'FIELD')
268
+ console.log(`FIELD -> ${queryPart.Field.fieldName}`);
269
+ else
270
+ console.log(`${operator} -> ${queryPart.value}`);
271
+ }
272
+
273
+ }
274
+
275
+ _addToQuery(queryPart, _context) {
276
+ let context = _context || this._getRawQueryContext();
277
+ let queryRoot = context.queryRoot;
278
+
279
+ queryRoot.push(
280
+ this._inheritContext(
281
+ context,
282
+ null,
283
+ queryPart,
284
+ ),
285
+ );
286
+ }
287
+
288
+ getConnection() {
289
+ return this.currentContext.connection;
290
+ }
291
+
292
+ getModel(modelName) {
293
+ let connection = this.getConnection();
294
+ let Model = (connection && connection.getModel(modelName));
295
+
296
+ if (!Model) {
297
+ let models = this.currentContext.models;
298
+ if (models)
299
+ Model = models[modelName];
300
+ }
301
+
302
+ return Model;
303
+ }
304
+
305
+ getQueryEngineScope() {
306
+ return this.currentContext.queryEngineScope;
307
+ }
308
+
309
+ getQueryEngineClass() {
310
+ return this.currentContext.queryEngineScope.constructor;
311
+ }
312
+
313
+ clone() {
314
+ const Klass = this.constructor;
315
+ let context = this._getRawQueryContext();
316
+ let queryRootCopy = this._getRawQuery().slice();
317
+ let newContext = Object.assign(Object.create(context), { queryRoot: queryRootCopy });
318
+
319
+ queryRootCopy.push(newContext);
320
+
321
+ return new Klass(newContext);
322
+ }
323
+ }
324
+
325
+ module.exports = QueryEngineBase;
@@ -0,0 +1,212 @@
1
+ 'use strict';
2
+
3
+ const Nife = require('nife');
4
+ const ProxyClass = require('../proxy-class');
5
+ const QueryEngineBase = require('./query-engine-base');
6
+ const ModelScope = require('./model-scope');
7
+ const FieldScope = require('./field-scope');
8
+ const Utils = require('../utils');
9
+
10
+ class QueryEngine extends QueryEngineBase {
11
+ getModelScopeClass() {
12
+ return ModelScope;
13
+ }
14
+
15
+ getFieldScopeClass() {
16
+ return FieldScope;
17
+ }
18
+
19
+ constructor(_context) {
20
+ let context = Object.assign(
21
+ Object.create(_context || {}),
22
+ {
23
+ currentScopeName: 'queryEngine',
24
+ isQueryContext: true,
25
+ contextID: QueryEngineBase.generateID(),
26
+ },
27
+ );
28
+
29
+ super(context);
30
+
31
+ context.queryEngineScope = this;
32
+ }
33
+
34
+ Model(modelName) {
35
+ let model = this.getModel(modelName);
36
+ if (!model)
37
+ throw new Error(`QueryEngine::Model: Requested model "${modelName}" not found.`);
38
+
39
+ return this._newModelScope(model);
40
+ }
41
+
42
+ unscoped(context) {
43
+ let QueryEngineClass = this.constructor;
44
+ let currentContext = context || this.currentContext;
45
+ let queryEngine = new QueryEngineClass({
46
+ connection: currentContext.connection,
47
+ });
48
+
49
+ if (currentContext.rootModelName)
50
+ queryEngine = queryEngine[currentContext.rootModelName];
51
+
52
+ return queryEngine;
53
+ }
54
+
55
+ toString(...args) {
56
+ if (args.length === 0)
57
+ return `${this.constructor.name} {}`;
58
+
59
+ let connection = args[0];
60
+ let queryGenerator = connection.getQueryGenerator();
61
+
62
+ return queryGenerator.generateSelectStatement(this, args[1]);
63
+ }
64
+
65
+ toSQL(options) {
66
+ let connection = this.getConnection();
67
+ return this.toString(connection, options);
68
+ }
69
+
70
+ MERGE(_queryEngine) {
71
+ let queryEngine = _queryEngine;
72
+ if (!queryEngine)
73
+ return this;
74
+
75
+ let thisQueryContext = this._getRawQueryContext();
76
+ if (!QueryEngine.isQuery(queryEngine) && Nife.instanceOf(queryEngine, 'array', 'object', 'map', 'set'))
77
+ queryEngine = Utils.generateQueryFromFilter(this.getConnection(), thisQueryContext.rootModel, queryEngine);
78
+
79
+ let sourceQuery = queryEngine._getRawQuery();
80
+ let currentModel = thisQueryContext.Model;
81
+
82
+ for (let i = 0, il = sourceQuery.length; i < il; i++) {
83
+ let queryPart = sourceQuery[i];
84
+ let mergeContext = Utils.objectAssignSpecial(queryPart, null, [
85
+ // Skip the following keys
86
+ // as they are provided by the
87
+ // parent queryEngine
88
+ 'connection',
89
+ 'contextID',
90
+ 'fieldContext',
91
+ 'isQueryContext',
92
+ 'modelContext',
93
+ 'queryEngineScope',
94
+ 'queryRoot',
95
+ 'rootContext',
96
+ 'rootModel',
97
+ 'rootModelName',
98
+ ]);
99
+
100
+ // Skip unneeded duplicate model entries
101
+ if (mergeContext.operator === 'MODEL') {
102
+ if (mergeContext.Model === currentModel)
103
+ continue;
104
+
105
+ currentModel = mergeContext.Model;
106
+ }
107
+
108
+ this._addToQuery(Object.assign({
109
+ Model: queryPart.Model,
110
+ modelName: queryPart.modelName,
111
+ Field: queryPart.Field,
112
+ fieldName: queryPart.fieldName,
113
+ }, mergeContext));
114
+ }
115
+
116
+ return this;
117
+ }
118
+
119
+ all(options) {
120
+ let connection = this.getConnection(options && options.connection);
121
+
122
+ if (options && options.stream)
123
+ return connection.select(this, options);
124
+ else
125
+ return Utils.collect(connection.select(this, options));
126
+ }
127
+
128
+ async first(_limit, options) {
129
+ let limit = (_limit == null) ? 1 : _limit;
130
+ let connection = this.getConnection(options && options.connection);
131
+ let query = this.clone().LIMIT(limit);
132
+
133
+ let result = await Utils.collect(connection.select(query, options));
134
+ return (_limit == null) ? result[0] : result;
135
+ }
136
+
137
+ async last(_limit, options) {
138
+ let limit = (_limit == null) ? 1 : _limit;
139
+ let connection = this.getConnection(options && options.connection);
140
+ let query = this.clone().LIMIT(limit);
141
+
142
+ let result = await Utils.collect(connection.select(query, Object.assign({}, options || {}, { reverseOrder: true })));
143
+ return (_limit == null) ? result[0] : result.reverse();
144
+ }
145
+
146
+ async update(attributes, options) {
147
+ let connection = this.getConnection(options && options.connection);
148
+ return await connection.updateAll(this, attributes, options);
149
+ }
150
+
151
+ async destroy(options) {
152
+ let connection = this.getConnection(options && options.connection);
153
+ return await connection.destroy(this, options);
154
+ }
155
+
156
+ async average(field, options) {
157
+ let connection = this.getConnection(options && options.connection);
158
+ return await connection.average(this, field, options);
159
+ }
160
+
161
+ async count(field, options) {
162
+ let connection = this.getConnection(options && options.connection);
163
+ return await connection.count(this, field, options);
164
+ }
165
+
166
+ async min(field, options) {
167
+ let connection = this.getConnection(options && options.connection);
168
+ return await connection.min(this, field, options);
169
+ }
170
+
171
+ async max(field, options) {
172
+ let connection = this.getConnection(options && options.connection);
173
+ return await connection.max(this, field, options);
174
+ }
175
+
176
+ async sum(field, options) {
177
+ let connection = this.getConnection(options && options.connection);
178
+ return await connection.sum(this, field, options);
179
+ }
180
+
181
+ async pluck(fields, options) {
182
+ let connection = this.getConnection(options && options.connection);
183
+ return await connection.pluck(this, fields, options);
184
+ }
185
+
186
+ async exists(options) {
187
+ let connection = this.getConnection(options && options.connection);
188
+ return await connection.exists(this, options);
189
+ }
190
+
191
+ [ProxyClass.MISSING](target, prop) {
192
+ if (prop === 'debug') {
193
+ this.currentContext.rootContext.debug = true;
194
+ return this._fetchScope('model', 'queryEngine');
195
+ }
196
+
197
+ let model = this.getModel(prop);
198
+ if (model) {
199
+ return this._newModelScope(model).__call(function(...args) {
200
+ let fieldName = args.find((arg) => (arg && arg.constructor && !arg.constructor._isMythixConnection));
201
+ if (!fieldName)
202
+ return this;
203
+
204
+ return this.Field(fieldName);
205
+ });
206
+ }
207
+
208
+ return this[prop];
209
+ }
210
+ }
211
+
212
+ module.exports = QueryEngine;
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const Nife = require('nife');
4
+ const Type = require('../type');
5
+ const { AUTO_INCREMENT } = require('../helpers/default-helpers');
6
+
7
+ class BigIntType extends Type {
8
+ static Default = {
9
+ AUTO_INCREMENT,
10
+ };
11
+
12
+ static getDisplayName() {
13
+ return 'BIGINT';
14
+ }
15
+
16
+ getDisplayName() {
17
+ return this.constructor.getDisplayName();
18
+ }
19
+
20
+ constructor(length, _options) {
21
+ let options = _options || {};
22
+
23
+ super(length, options);
24
+
25
+ this.length = length || null;
26
+
27
+ Object.defineProperties(this, {
28
+ '_options': {
29
+ writable: true,
30
+ enumberable: false,
31
+ configurable: true,
32
+ value: options,
33
+ },
34
+ });
35
+ }
36
+
37
+ castToType({ value }) {
38
+ if (value == null)
39
+ return value;
40
+
41
+ let castValue = BigInt(value);
42
+ if (this._options.strict === true)
43
+ return castValue;
44
+
45
+ return Number(castValue).valueOf();
46
+ }
47
+
48
+ isValidValue(value) {
49
+ return (Nife.instanceOf(value, 'number', 'bigint') && isFinite(value));
50
+ }
51
+
52
+ toString(connection) {
53
+ return (connection)
54
+ ? this.toConnectionType(connection)
55
+ : `BIGINT${(this.length != null) ? `(${this.length})` : ''}`;
56
+ }
57
+ }
58
+
59
+ module.exports = {
60
+ BIGINT: Type.wrapConstructor(BigIntType),
61
+ BigIntType,
62
+ };
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ /* global Buffer */
4
+
5
+ const Type = require('../type');
6
+
7
+ class BlobType extends Type {
8
+ static getDisplayName() {
9
+ return 'BLOB';
10
+ }
11
+
12
+ getDisplayName() {
13
+ return this.constructor.getDisplayName();
14
+ }
15
+
16
+ constructor(length) {
17
+ super(length);
18
+
19
+ this.length = length || null;
20
+ }
21
+
22
+ castToType({ value }) {
23
+ if (value == null)
24
+ return value;
25
+
26
+ if (!Buffer.isBuffer(value))
27
+ throw new TypeError(`BlobType::castToType: Value provided ("${value}") can not be cast into a Buffer. Please provide a Buffer directly.`);
28
+
29
+ return value;
30
+ }
31
+
32
+ isValidValue(value) {
33
+ return Buffer.isBuffer(value);
34
+ }
35
+
36
+ toString(connection) {
37
+ return (connection)
38
+ ? this.toConnectionType(connection)
39
+ : 'BLOB';
40
+ }
41
+ }
42
+
43
+ module.exports = {
44
+ BLOB: Type.wrapConstructor(BlobType),
45
+ BlobType,
46
+ };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ const Type = require('../type');
4
+
5
+ class BooleanType extends Type {
6
+ static getDisplayName() {
7
+ return 'BOOLEAN';
8
+ }
9
+
10
+ getDisplayName() {
11
+ return this.constructor.getDisplayName();
12
+ }
13
+
14
+ castToType({ value }) {
15
+ if (value == null)
16
+ return value;
17
+
18
+ if (value === 'true')
19
+ return true;
20
+
21
+ if (value === 'false')
22
+ return false;
23
+
24
+ return !!value;
25
+ }
26
+
27
+ isValidValue(value) {
28
+ return (value === true || value === false);
29
+ }
30
+
31
+ toString(connection) {
32
+ return (connection)
33
+ ? this.toConnectionType(connection)
34
+ : 'BOOLEAN';
35
+ }
36
+ }
37
+
38
+ module.exports = {
39
+ BOOLEAN: Type.wrapConstructor(BooleanType),
40
+ BooleanType,
41
+ };