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,105 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/* global describe, it, expect, beforeAll */
|
|
6
|
+
|
|
7
|
+
const { Utils, ConnectionBase } = require('../../lib');
|
|
8
|
+
|
|
9
|
+
describe('Utils::query', () => {
|
|
10
|
+
describe('parseFilterFieldAndOperator', function() {
|
|
11
|
+
it('should be able to parse a field', function() {
|
|
12
|
+
expect(Utils.parseFilterFieldAndOperator(' test ')).toEqual({
|
|
13
|
+
field: 'test',
|
|
14
|
+
operator: '=',
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should be able to parse field and operator', function() {
|
|
19
|
+
expect(Utils.parseFilterFieldAndOperator('test=')).toEqual({
|
|
20
|
+
field: 'test',
|
|
21
|
+
operator: '=',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(Utils.parseFilterFieldAndOperator('test !=')).toEqual({
|
|
25
|
+
field: 'test',
|
|
26
|
+
operator: '!=',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(Utils.parseFilterFieldAndOperator('test>')).toEqual({
|
|
30
|
+
field: 'test',
|
|
31
|
+
operator: '>',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(Utils.parseFilterFieldAndOperator(' test >= ')).toEqual({
|
|
35
|
+
field: 'test',
|
|
36
|
+
operator: '>=',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(Utils.parseFilterFieldAndOperator('test<')).toEqual({
|
|
40
|
+
field: 'test',
|
|
41
|
+
operator: '<',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(Utils.parseFilterFieldAndOperator('test<=')).toEqual({
|
|
45
|
+
field: 'test',
|
|
46
|
+
operator: '<=',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(Utils.parseFilterFieldAndOperator('test><')).toEqual({
|
|
50
|
+
field: 'test',
|
|
51
|
+
operator: '><',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(Utils.parseFilterFieldAndOperator('test<>')).toEqual({
|
|
55
|
+
field: 'test',
|
|
56
|
+
operator: '<>',
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(Utils.parseFilterFieldAndOperator('test*')).toEqual({
|
|
60
|
+
field: 'test',
|
|
61
|
+
operator: '*',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(Utils.parseFilterFieldAndOperator('test!*')).toEqual({
|
|
65
|
+
field: 'test',
|
|
66
|
+
operator: '!*',
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should throw an error without a field', function() {
|
|
71
|
+
expect(() => Utils.parseFilterFieldAndOperator(' != ')).toThrow(new Error('generateQueryFromFilter: "field" is blank'));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should throw an error with a bad operator', function() {
|
|
75
|
+
expect(() => Utils.parseFilterFieldAndOperator(' test !! ')).toThrow(new Error('generateQueryFromFilter: Unknown operator "!!"'));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('generateQueryFromFilter', function() {
|
|
80
|
+
let connection;
|
|
81
|
+
let User;
|
|
82
|
+
|
|
83
|
+
beforeAll(async () => {
|
|
84
|
+
try {
|
|
85
|
+
connection = new ConnectionBase({
|
|
86
|
+
bindModels: false,
|
|
87
|
+
models: require('../support/models'),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
let models = connection.getModels();
|
|
91
|
+
User = models.User;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Error in beforeAll: ', error);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should throw an error on a bad operator for an array value', function() {
|
|
98
|
+
expect(() => Utils.generateQueryFromFilter(connection, User, { 'lastName>': [ 'derp' ] })).toThrow(new Error('Invalid array value for operator ">"'));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should throw an error on a bad operator for a NULL value', function() {
|
|
102
|
+
expect(() => Utils.generateQueryFromFilter(connection, User, { 'firstName>': null })).toThrow(new Error('Invalid "NULL" value for operator ">"'));
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|