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,108 @@
|
|
|
1
|
+
/* eslint-disable new-cap */
|
|
2
|
+
/* eslint-disable no-magic-numbers */
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/* global describe, it, expect */
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
FLAG_ON_INITIALIZE,
|
|
10
|
+
FLAG_ON_INSERT,
|
|
11
|
+
FLAG_ON_UPDATE,
|
|
12
|
+
FLAG_ON_STORE,
|
|
13
|
+
FLAG_LITERAL,
|
|
14
|
+
FLAG_REMOTE,
|
|
15
|
+
defaultValueFlags,
|
|
16
|
+
AUTO_INCREMENT,
|
|
17
|
+
DATETIME_NOW,
|
|
18
|
+
DATE_NOW,
|
|
19
|
+
} = require('../../lib/types/helpers/default-helpers');
|
|
20
|
+
|
|
21
|
+
describe('DefaultHelpers', () => {
|
|
22
|
+
it('can set initialize flag on a default method', () => {
|
|
23
|
+
let func = defaultValueFlags(function() {});
|
|
24
|
+
expect(func.mythixFlags).toEqual(FLAG_ON_INITIALIZE);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('can set create flag on a default method', () => {
|
|
28
|
+
let func = defaultValueFlags(function() {}, { onInsert: true });
|
|
29
|
+
expect(func.mythixFlags).toEqual(FLAG_ON_INSERT);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('can set update flag on a default method', () => {
|
|
33
|
+
let func = defaultValueFlags(function() {}, { onUpdate: true });
|
|
34
|
+
expect(func.mythixFlags).toEqual(FLAG_ON_UPDATE);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('can set store flag on a default method', () => {
|
|
38
|
+
let func = defaultValueFlags(function() {}, { onStore: true });
|
|
39
|
+
expect(func.mythixFlags).toEqual(FLAG_ON_STORE);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('can set remote flag on a default method', () => {
|
|
43
|
+
let func = defaultValueFlags(function() {}, { literal: true });
|
|
44
|
+
expect(func.mythixFlags).toEqual(FLAG_LITERAL);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('can remove initialize flag on a default method', () => {
|
|
48
|
+
let func = defaultValueFlags(function() {}, { onInitialize: false });
|
|
49
|
+
expect(func.mythixFlags).toEqual(0);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('AUTO_INCREMENT', () => {
|
|
53
|
+
it('should have the correct flags set', () => {
|
|
54
|
+
expect(AUTO_INCREMENT.mythixFlags).toEqual(FLAG_LITERAL | FLAG_REMOTE);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should call connection to get value', () => {
|
|
58
|
+
let context = {
|
|
59
|
+
connection: {
|
|
60
|
+
getDefaultFieldValue: (type) => {
|
|
61
|
+
return type;
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
let connectionDefaultType = AUTO_INCREMENT(context);
|
|
67
|
+
expect(connectionDefaultType).toEqual('AUTO_INCREMENT');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('DATETIME_NOW', () => {
|
|
72
|
+
it('should have the correct flags set', () => {
|
|
73
|
+
expect(DATETIME_NOW.mythixFlags).toEqual(FLAG_LITERAL | FLAG_REMOTE);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should call connection to get value', () => {
|
|
77
|
+
let context = {
|
|
78
|
+
connection: {
|
|
79
|
+
getDefaultFieldValue: (type) => {
|
|
80
|
+
return type;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let connectionDefaultType = DATETIME_NOW(context);
|
|
86
|
+
expect(connectionDefaultType).toEqual('DATETIME_NOW');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('DATE_NOW', () => {
|
|
91
|
+
it('should have the correct flags set', () => {
|
|
92
|
+
expect(DATE_NOW.mythixFlags).toEqual(FLAG_LITERAL | FLAG_REMOTE);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should call connection to get value', () => {
|
|
96
|
+
let context = {
|
|
97
|
+
connection: {
|
|
98
|
+
getDefaultFieldValue: (type) => {
|
|
99
|
+
return type;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
let connectionDefaultType = DATE_NOW(context);
|
|
105
|
+
expect(connectionDefaultType).toEqual('DATE_NOW');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|