mythix-orm 1.11.4 → 1.11.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/lib/connection/connection-base.js +10 -0
- package/lib/connection/literals/average-literal.js +4 -0
- package/lib/connection/literals/count-literal.js +4 -0
- package/lib/connection/literals/literal-base.js +15 -0
- package/lib/connection/literals/literal-field-base.js +6 -0
- package/lib/connection/literals/max-literal.js +4 -0
- package/lib/connection/literals/min-literal.js +4 -0
- package/lib/connection/literals/sum-literal.js +4 -0
- package/lib/connection/query-generator-base.js +2 -8
- package/lib/model.js +6 -4
- package/lib/query-engine/model-scope.js +2 -0
- package/lib/utils/async-store.js +19 -20
- package/package.json +1 -1
|
@@ -280,6 +280,16 @@ class ConnectionBase extends EventEmitter {
|
|
|
280
280
|
return new QueryGeneratorBase(this);
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
stackAssign(obj, ..._args) {
|
|
284
|
+
let newObj = Object.create(obj || {});
|
|
285
|
+
let args = _args.filter(Boolean);
|
|
286
|
+
|
|
287
|
+
if (args.length > 0)
|
|
288
|
+
Object.assign(newObj, ...args);
|
|
289
|
+
|
|
290
|
+
return newObj;
|
|
291
|
+
}
|
|
292
|
+
|
|
283
293
|
/// This method is an internal method that parses
|
|
284
294
|
/// the "lock mode" options passed to a call to
|
|
285
295
|
/// <see>Connection.transaction</see>.
|
|
@@ -43,6 +43,14 @@ class LiteralBase {
|
|
|
43
43
|
return (this.isLiteral(value) && value.constructor && value.constructor.name === this.name);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
static isAggregate() {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
isAggregate() {
|
|
51
|
+
return this.constructor.isAggregate();
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
constructor(literal, options) {
|
|
47
55
|
Object.defineProperties(this, {
|
|
48
56
|
'literal': {
|
|
@@ -87,6 +95,9 @@ class LiteralBase {
|
|
|
87
95
|
if (LiteralBase.isLiteral(definition))
|
|
88
96
|
return definition;
|
|
89
97
|
|
|
98
|
+
if (!definition.fieldNames)
|
|
99
|
+
return definition;
|
|
100
|
+
|
|
90
101
|
let field = connection.getField(definition.fieldNames[0], definition.modelName);
|
|
91
102
|
if (!field) {
|
|
92
103
|
if (definition.fieldNames[0] && definition.modelName) {
|
|
@@ -109,6 +120,10 @@ class LiteralBase {
|
|
|
109
120
|
toString() {
|
|
110
121
|
return this.literal;
|
|
111
122
|
}
|
|
123
|
+
|
|
124
|
+
valueOf() {
|
|
125
|
+
return this.literal;
|
|
126
|
+
}
|
|
112
127
|
}
|
|
113
128
|
|
|
114
129
|
module.exports = LiteralBase;
|
|
@@ -20,6 +20,8 @@ class LiteralFieldBase extends LiteralBase {
|
|
|
20
20
|
} catch (error) {
|
|
21
21
|
if (isRequired)
|
|
22
22
|
throw error;
|
|
23
|
+
|
|
24
|
+
definition = fullyQualifiedName;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -47,6 +49,10 @@ class LiteralFieldBase extends LiteralBase {
|
|
|
47
49
|
|
|
48
50
|
return this.definitionToField(connection, this.definition);
|
|
49
51
|
}
|
|
52
|
+
|
|
53
|
+
valueOf() {
|
|
54
|
+
return this.definition;
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
module.exports = LiteralFieldBase;
|
|
@@ -15,14 +15,8 @@ class QueryGeneratorBase {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
stackAssign(obj, ...
|
|
19
|
-
|
|
20
|
-
let args = _args.filter(Boolean);
|
|
21
|
-
|
|
22
|
-
if (args.length > 0)
|
|
23
|
-
Object.assign(newObj, ...args);
|
|
24
|
-
|
|
25
|
-
return newObj;
|
|
18
|
+
stackAssign(obj, ...args) {
|
|
19
|
+
return this.connection.stackAssign(obj, ...args);
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
escape(...args) {
|
package/lib/model.js
CHANGED
|
@@ -450,14 +450,16 @@ class Model {
|
|
|
450
450
|
/// a connection to your models. This will allow you to provide a
|
|
451
451
|
/// connection directly when you create the model, which can make
|
|
452
452
|
/// interacting with the model less tiresome. i.e. `new Model(null, { connection })`.
|
|
453
|
-
_getConnection(
|
|
453
|
+
_getConnection(_connection) {
|
|
454
|
+
let connection = _connection;
|
|
454
455
|
if (connection)
|
|
455
456
|
return connection;
|
|
456
457
|
|
|
457
|
-
|
|
458
|
-
|
|
458
|
+
connection = this.constructor._getConnection();
|
|
459
|
+
if (connection)
|
|
460
|
+
return connection;
|
|
459
461
|
|
|
460
|
-
return this.
|
|
462
|
+
return this._connection;
|
|
461
463
|
}
|
|
462
464
|
|
|
463
465
|
static getConnection(_connection) {
|
|
@@ -353,6 +353,8 @@ class ModelScope extends QueryEngineBase {
|
|
|
353
353
|
distinctValue = new DistinctLiteral(`${fullyQualifiedName.Model.getModelName()}:${fullyQualifiedName.fieldName}`);
|
|
354
354
|
} else if (LiteralBase.isLiteral(fullyQualifiedName)) {
|
|
355
355
|
distinctValue = new DistinctLiteral(fullyQualifiedName);
|
|
356
|
+
} else if (!fullyQualifiedName) {
|
|
357
|
+
distinctValue = null;
|
|
356
358
|
} else {
|
|
357
359
|
throw new TypeError(`QueryEngine::ModelScope::DISTINCT: Invalid value provided [${(fullyQualifiedName) ? fullyQualifiedName.toString() : fullyQualifiedName}]. All values provided must be strings, fields, or literals.`);
|
|
358
360
|
}
|
package/lib/utils/async-store.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
let globalAsyncStore;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
let globalAsyncStore = global._mythixGlobalAsyncLocalStore;
|
|
4
|
+
|
|
5
|
+
if (!globalAsyncStore) {
|
|
6
|
+
try {
|
|
7
|
+
const { AsyncLocalStorage } = require('async_hooks');
|
|
8
|
+
global._mythixGlobalAsyncLocalStore = globalAsyncStore = new AsyncLocalStorage();
|
|
9
|
+
} catch (error) {
|
|
10
|
+
global._mythixGlobalAsyncLocalStore = globalAsyncStore = {
|
|
11
|
+
getStore: () => undefined,
|
|
12
|
+
run: (context, callback) => callback(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
function getContextStore() {
|
|
@@ -40,16 +42,13 @@ function setContextValue(key, value) {
|
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
function runInContext(context, callback) {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
45
|
+
return globalAsyncStore.run(
|
|
46
|
+
{
|
|
47
|
+
parent: globalAsyncStore.getStore(),
|
|
48
|
+
context,
|
|
49
|
+
},
|
|
50
|
+
callback,
|
|
51
|
+
);
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
module.exports = {
|