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.
- package/.eslintrc.js +94 -0
- package/.vscode/launch.json +34 -0
- package/.vscode/settings.json +10 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/lib/connection/connection-base.js +877 -0
- package/lib/connection/index.js +11 -0
- package/lib/connection/literals/average-literal.js +14 -0
- package/lib/connection/literals/count-literal.js +18 -0
- package/lib/connection/literals/distinct-literal.js +14 -0
- package/lib/connection/literals/index.js +23 -0
- package/lib/connection/literals/literal-base.js +62 -0
- package/lib/connection/literals/literal-field-base.js +45 -0
- package/lib/connection/literals/literal.js +11 -0
- package/lib/connection/literals/max-literal.js +14 -0
- package/lib/connection/literals/min-literal.js +14 -0
- package/lib/connection/literals/sum-literal.js +14 -0
- package/lib/connection/query-generator-base.js +864 -0
- package/lib/errors/base-error.js +14 -0
- package/lib/errors/connection/access-denied-error.js +13 -0
- package/lib/errors/connection/connection-acquire-timeout-error.js +13 -0
- package/lib/errors/connection/connection-refused-error.js +13 -0
- package/lib/errors/connection/connection-timed-out-error.js +13 -0
- package/lib/errors/connection/host-not-found-error.js +13 -0
- package/lib/errors/connection/host-not-reachable-error.js +13 -0
- package/lib/errors/connection/index.js +19 -0
- package/lib/errors/connection/invalid-connection-error.js +13 -0
- package/lib/errors/connection-base-error.js +13 -0
- package/lib/errors/database/exclusion-constraint-error.js +13 -0
- package/lib/errors/database/foreign-key-constraint-error.js +13 -0
- package/lib/errors/database/index.js +13 -0
- package/lib/errors/database/timeout-error.js +13 -0
- package/lib/errors/database/unknown-constraint-error.js +13 -0
- package/lib/errors/database-base-error.js +17 -0
- package/lib/errors/index.js +44 -0
- package/lib/field.js +18 -0
- package/lib/index.js +43 -0
- package/lib/model.js +1374 -0
- package/lib/proxy-class/index.js +3 -0
- package/lib/proxy-class/proxy-class.js +269 -0
- package/lib/query-engine/field-scope.js +99 -0
- package/lib/query-engine/index.js +13 -0
- package/lib/query-engine/model-scope.js +198 -0
- package/lib/query-engine/query-engine-base.js +325 -0
- package/lib/query-engine/query-engine.js +212 -0
- package/lib/types/concrete/bigint-type.js +62 -0
- package/lib/types/concrete/blob-type.js +46 -0
- package/lib/types/concrete/boolean-type.js +41 -0
- package/lib/types/concrete/char-type.js +39 -0
- package/lib/types/concrete/date-type.js +87 -0
- package/lib/types/concrete/datetime-type.js +92 -0
- package/lib/types/concrete/float-type.js +47 -0
- package/lib/types/concrete/foreign-key-type.js +208 -0
- package/lib/types/concrete/index.js +53 -0
- package/lib/types/concrete/integer-type.js +51 -0
- package/lib/types/concrete/string-type.js +44 -0
- package/lib/types/concrete/text-type.js +44 -0
- package/lib/types/concrete/uuid-base.js +77 -0
- package/lib/types/concrete/uuid-v1-type.js +99 -0
- package/lib/types/concrete/uuid-v3-type.js +108 -0
- package/lib/types/concrete/uuid-v4-type.js +90 -0
- package/lib/types/concrete/uuid-v5-type.js +108 -0
- package/lib/types/concrete/xid-type.js +58 -0
- package/lib/types/helpers/default-helpers.js +127 -0
- package/lib/types/helpers/index.js +35 -0
- package/lib/types/index.js +94 -0
- package/lib/types/type.js +244 -0
- package/lib/types/virtual/index.js +14 -0
- package/lib/types/virtual/model-type.js +141 -0
- package/lib/types/virtual/models-type.js +264 -0
- package/lib/types/virtual/relational-type-base.js +323 -0
- package/lib/utils/index.js +65 -0
- package/lib/utils/misc-utils.js +73 -0
- package/lib/utils/model-utils.js +704 -0
- package/lib/utils/query-utils.js +186 -0
- package/package.json +63 -0
- package/playground/test01.js +15 -0
- package/spec/connection/connection-base-spec.js +126 -0
- package/spec/connection/literals/average-literal-spec.js +45 -0
- package/spec/connection/literals/count-literal-spec.js +42 -0
- package/spec/connection/literals/distinct-literal-spec.js +42 -0
- package/spec/connection/literals/literal-spec.js +26 -0
- package/spec/connection/literals/max-literal-spec.js +42 -0
- package/spec/connection/literals/min-literal-spec.js +42 -0
- package/spec/connection/literals/sum-literal-spec.js +42 -0
- package/spec/helpers/default-helpers-spec.js +108 -0
- package/spec/model-spec.js +736 -0
- package/spec/proxy-class/proxy-class-spec.js +173 -0
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_chain_query_conditions-001.snapshot +94 -0
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_construct_a_query_context_with_a_model_call-001.snapshot +35 -0
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_construct_a_query_context_with_a_model_sub-001.snapshot +35 -0
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_set_a_default_scope_on_a_model-001.snapshot +57 -0
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_unscope_default_scope_on_a_model-001.snapshot +35 -0
- package/spec/query-engine/query-engine-spec.js +99 -0
- package/spec/support/jasmine.json +13 -0
- package/spec/support/models/blob-test-model.js +19 -0
- package/spec/support/models/extended-user-model.js +38 -0
- package/spec/support/models/index.js +27 -0
- package/spec/support/models/number-model.js +24 -0
- package/spec/support/models/role-model.js +26 -0
- package/spec/support/models/role-thing-model.js +41 -0
- package/spec/support/models/scoped-user-model.js +13 -0
- package/spec/support/models/time-model.js +36 -0
- package/spec/support/models/user-model.js +70 -0
- package/spec/support/models/user-role-model.js +36 -0
- package/spec/support/models/user-thing-model.js +46 -0
- package/spec/support/models/validation-test-model.js +40 -0
- package/spec/support/snapshots.js +293 -0
- package/spec/support/test-helpers.js +13 -0
- package/spec/types/concrete/bigint-type-spec.js +84 -0
- package/spec/types/concrete/boolean-type-spec.js +83 -0
- package/spec/types/concrete/date-type-spec.js +85 -0
- package/spec/types/concrete/datetime-type-spec.js +87 -0
- package/spec/types/concrete/float-type-spec.js +71 -0
- package/spec/types/concrete/foreign-key-type-spec.js +64 -0
- package/spec/types/concrete/integer-type-spec.js +71 -0
- package/spec/types/concrete/string-type-spec.js +91 -0
- package/spec/types/concrete/uuid-v1-type-spec.js +73 -0
- package/spec/types/concrete/uuid-v4-type-spec.js +65 -0
- package/spec/types/type-spec.js +101 -0
- package/spec/types/virtual/model-types-spec.js +401 -0
- package/spec/utils/misc-utils-spec.js +61 -0
- package/spec/utils/model-utils-spec.js +55 -0
- package/spec/utils/query-utils-spec.js +105 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
4
|
+
|
|
5
|
+
class AverageLiteral extends LiteralFieldBase {
|
|
6
|
+
toString(connection) {
|
|
7
|
+
if (!connection)
|
|
8
|
+
return `${this.constructor.name} {}`;
|
|
9
|
+
|
|
10
|
+
return connection.literalToString(this);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = AverageLiteral;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
4
|
+
|
|
5
|
+
class CountLiteral extends LiteralFieldBase {
|
|
6
|
+
static isFieldRequired() {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
toString(connection) {
|
|
11
|
+
if (!connection)
|
|
12
|
+
return `${this.constructor.name} {}`;
|
|
13
|
+
|
|
14
|
+
return connection.literalToString(this);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = CountLiteral;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
4
|
+
|
|
5
|
+
class DistinctLiteral extends LiteralFieldBase {
|
|
6
|
+
toString(connection) {
|
|
7
|
+
if (!connection)
|
|
8
|
+
return `${this.constructor.name} {}`;
|
|
9
|
+
|
|
10
|
+
return connection.literalToString(this);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = DistinctLiteral;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralBase = require('./literal-base');
|
|
4
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
5
|
+
const Literal = require('./literal');
|
|
6
|
+
const AverageLiteral = require('./average-literal');
|
|
7
|
+
const CountLiteral = require('./count-literal');
|
|
8
|
+
const MaxLiteral = require('./max-literal');
|
|
9
|
+
const MinLiteral = require('./min-literal');
|
|
10
|
+
const DistinctLiteral = require('./distinct-literal');
|
|
11
|
+
const SumLiteral = require('./sum-literal');
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
LiteralBase,
|
|
15
|
+
LiteralFieldBase,
|
|
16
|
+
Literal,
|
|
17
|
+
AverageLiteral,
|
|
18
|
+
CountLiteral,
|
|
19
|
+
MaxLiteral,
|
|
20
|
+
MinLiteral,
|
|
21
|
+
DistinctLiteral,
|
|
22
|
+
SumLiteral,
|
|
23
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ModelUtils = require('../../utils/model-utils');
|
|
4
|
+
|
|
5
|
+
class LiteralBase {
|
|
6
|
+
constructor(literal, options) {
|
|
7
|
+
Object.defineProperties(this, {
|
|
8
|
+
'literal': {
|
|
9
|
+
writable: true,
|
|
10
|
+
enumberable: false,
|
|
11
|
+
configurable: true,
|
|
12
|
+
value: literal,
|
|
13
|
+
},
|
|
14
|
+
'options': {
|
|
15
|
+
writable: true,
|
|
16
|
+
enumberable: false,
|
|
17
|
+
configurable: true,
|
|
18
|
+
value: options || {},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fullyQualifiedNameToDefinition(fullyQualifiedName) {
|
|
24
|
+
if (fullyQualifiedName instanceof LiteralBase)
|
|
25
|
+
return fullyQualifiedName;
|
|
26
|
+
|
|
27
|
+
if (!fullyQualifiedName)
|
|
28
|
+
throw new TypeError(`${this.constructor.name}::fullyQualifiedNameToDefinition: Unable to find field for fully qualified name "${fullyQualifiedName}".`);
|
|
29
|
+
|
|
30
|
+
let definition;
|
|
31
|
+
if (fullyQualifiedName.Model && fullyQualifiedName.fieldName) {
|
|
32
|
+
definition = {
|
|
33
|
+
modelName: fullyQualifiedName.Model.getModelName(),
|
|
34
|
+
fieldNames: [ fullyQualifiedName.fieldName ],
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
definition = ModelUtils.parseQualifiedName(fullyQualifiedName);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!definition || !definition.modelName || !definition.fieldNames.length)
|
|
41
|
+
throw new TypeError(`${this.constructor.name}::fullyQualifiedNameToDefinition: Unable to find field for fully qualified name "${fullyQualifiedName}".`);
|
|
42
|
+
|
|
43
|
+
return definition;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
definitionToField(connection, definition) {
|
|
47
|
+
if (definition instanceof LiteralBase)
|
|
48
|
+
return definition;
|
|
49
|
+
|
|
50
|
+
let field = connection.getField(definition.fieldNames[0], definition.modelName);
|
|
51
|
+
if (!field)
|
|
52
|
+
throw new Error(`${this.constructor.name}::definitionToField: Unable to locate field "${definition.modelName}"."${definition.fieldNames[0]}".`);
|
|
53
|
+
|
|
54
|
+
return field;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
toString() {
|
|
58
|
+
return this.literal;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = LiteralBase;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Nife = require('nife');
|
|
4
|
+
const LiteralBase = require('./literal-base');
|
|
5
|
+
|
|
6
|
+
class LiteralFieldBase extends LiteralBase {
|
|
7
|
+
static isFieldRequired() {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
constructor(fullyQualifiedName) {
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
let isRequired = this.constructor.isFieldRequired();
|
|
15
|
+
let definition;
|
|
16
|
+
|
|
17
|
+
if (isRequired || fullyQualifiedName) {
|
|
18
|
+
try {
|
|
19
|
+
definition = this.fullyQualifiedNameToDefinition(fullyQualifiedName);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (isRequired)
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Object.defineProperties(this, {
|
|
27
|
+
'definition': {
|
|
28
|
+
writable: true,
|
|
29
|
+
enumberable: false,
|
|
30
|
+
configurable: true,
|
|
31
|
+
value: definition,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getFullyQualifiedFieldName() {
|
|
37
|
+
let definition = this.definition || {};
|
|
38
|
+
if (!definition.modelName || Nife.isEmpty(definition.fieldNames))
|
|
39
|
+
return;
|
|
40
|
+
|
|
41
|
+
return `${definition.modelName}:${definition.fieldNames[0]}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = LiteralFieldBase;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
4
|
+
|
|
5
|
+
class MaxLiteral extends LiteralFieldBase {
|
|
6
|
+
toString(connection) {
|
|
7
|
+
if (!connection)
|
|
8
|
+
return `${this.constructor.name} {}`;
|
|
9
|
+
|
|
10
|
+
return connection.literalToString(this);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = MaxLiteral;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
4
|
+
|
|
5
|
+
class MinLiteral extends LiteralFieldBase {
|
|
6
|
+
toString(connection) {
|
|
7
|
+
if (!connection)
|
|
8
|
+
return `${this.constructor.name} {}`;
|
|
9
|
+
|
|
10
|
+
return connection.literalToString(this);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = MinLiteral;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const LiteralFieldBase = require('./literal-field-base');
|
|
4
|
+
|
|
5
|
+
class SumLiteral extends LiteralFieldBase {
|
|
6
|
+
toString(connection) {
|
|
7
|
+
if (!connection)
|
|
8
|
+
return `${this.constructor.name} {}`;
|
|
9
|
+
|
|
10
|
+
return connection.literalToString(this);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = SumLiteral;
|