@ts-awesome/orm 1.8.0-rc.0 → 2.0.0-alpha.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/dist/builder.d.ts +1 -9
- package/dist/builder.js.map +1 -1
- package/dist/compiler.d.ts +55 -0
- package/dist/compiler.js +481 -0
- package/dist/compiler.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/intermediate.d.ts +9 -1
- package/dist/operators.js +2 -2
- package/dist/operators.js.map +1 -1
- package/dist/reader.js +1 -0
- package/dist/reader.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +31 -1
- package/tests/builder.spec.ts +0 -1084
- package/tests/executor.spec.ts +0 -24
- package/tests/function-operators.spec.js +0 -172
- package/tests/models.ts +0 -100
- package/tests/prototype-operations.spec.js +0 -346
- package/tests/reader.spec.ts +0 -164
package/tests/executor.spec.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {NamedParameter} from "../src/wrappers";
|
|
2
|
-
import {TestExecutor} from "../src/test-driver";
|
|
3
|
-
|
|
4
|
-
describe('BaseExecutor', () => {
|
|
5
|
-
|
|
6
|
-
it('named params', async () => {
|
|
7
|
-
const sqlName = 'test';
|
|
8
|
-
const namedParam = new NamedParameter(sqlName);
|
|
9
|
-
|
|
10
|
-
const executor = new TestExecutor();
|
|
11
|
-
|
|
12
|
-
executor.mapper = (query) => {
|
|
13
|
-
expect(query).toBeDefined()
|
|
14
|
-
expect(query.params).toBeDefined()
|
|
15
|
-
expect(query.params[sqlName]).toBe(123)
|
|
16
|
-
return []
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
executor.setNamedParameter(namedParam, 123)
|
|
20
|
-
|
|
21
|
-
await executor.execute({});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
})
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
const {SupportedOperations, Operandable, FunctionCall, ColumnWrapper} = require("../dist/wrappers");
|
|
2
|
-
const {and, or, not, all, any, exists, avg, sum, count, max, min, asc, desc, of, alias} = require('../dist/operators');
|
|
3
|
-
|
|
4
|
-
describe('Operators should return correct intermediate query', () => {
|
|
5
|
-
const operandable = SupportedOperations.eq.call([1, 2, 3], 5);
|
|
6
|
-
const testTable = {
|
|
7
|
-
tableName: 'table_name',
|
|
8
|
-
fields: new Map([
|
|
9
|
-
['test_field', {name: 'test_field'}],
|
|
10
|
-
['another_field', {name: 'another_field'}]
|
|
11
|
-
])
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
it('Asc operator', () => {
|
|
15
|
-
const result = asc(operandable);
|
|
16
|
-
expect(result).toStrictEqual({...operandable, _order: 'ASC', _nulls: undefined});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('Asc operator', () => {
|
|
20
|
-
const result = asc(operandable, 'LAST');
|
|
21
|
-
expect(result).toStrictEqual({...operandable, _order: 'ASC', _nulls: 'LAST'});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('Desc operator', () => {
|
|
25
|
-
const result = desc(operandable);
|
|
26
|
-
expect(result).toStrictEqual({...operandable, _order: 'DESC', _nulls: undefined});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('Desc operator', () => {
|
|
30
|
-
const result = desc(operandable, 'FIRST');
|
|
31
|
-
expect(result).toStrictEqual({...operandable, _order: 'DESC', _nulls: 'FIRST'});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('Of operator', () => {
|
|
35
|
-
const field = 'test_field';
|
|
36
|
-
const result = of(testTable, field);
|
|
37
|
-
|
|
38
|
-
expect(result).toBeInstanceOf(ColumnWrapper);
|
|
39
|
-
expect(result._column).toStrictEqual({table: testTable.tableName, name: 'test_field'})
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('Of operator should throw error if given filed does not exists', () => {
|
|
43
|
-
const field = 'nonexistent_field';
|
|
44
|
-
|
|
45
|
-
expect(() => {
|
|
46
|
-
of(testTable, field);
|
|
47
|
-
}).toThrowError(`Field '${field}' should be annotated with @dbField() or @dbManyField()`);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('Alias operator', () => {
|
|
51
|
-
const name = 'some_name';
|
|
52
|
-
const result = alias(operandable, name);
|
|
53
|
-
|
|
54
|
-
expect(result._alias).toBe(name);
|
|
55
|
-
expect(result._operands).toStrictEqual([operandable]);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('Operators should return correct Operandable intermediate query', () => {
|
|
60
|
-
|
|
61
|
-
const firstOperand = true;
|
|
62
|
-
const secondOperand = false;
|
|
63
|
-
const subquery = {
|
|
64
|
-
_type: 'SELECT',
|
|
65
|
-
_table: {
|
|
66
|
-
tableName: 'test_table',
|
|
67
|
-
fields: new Map([['test_field', 'test value']])
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
it('And operator', () => {
|
|
72
|
-
const result = and(firstOperand, secondOperand);
|
|
73
|
-
|
|
74
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
75
|
-
expect(result._operator).toBe('AND');
|
|
76
|
-
expect(result._operands).toStrictEqual([firstOperand, secondOperand]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('Or operator', () => {
|
|
80
|
-
const result = or(firstOperand, secondOperand);
|
|
81
|
-
|
|
82
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
83
|
-
expect(result._operator).toBe('OR');
|
|
84
|
-
expect(result._operands).toStrictEqual([firstOperand, secondOperand]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('Not operator', () => {
|
|
88
|
-
const condition = false;
|
|
89
|
-
const result = not(condition);
|
|
90
|
-
|
|
91
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
92
|
-
expect(result._operator).toBe('NOT');
|
|
93
|
-
expect(result._operands).toStrictEqual([condition]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('All operator', () => {
|
|
97
|
-
const result = all(subquery);
|
|
98
|
-
|
|
99
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
100
|
-
expect(result._operator).toBe('ALL');
|
|
101
|
-
expect(result._operands).toStrictEqual([subquery]);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('Any operator', () => {
|
|
105
|
-
const result = any(subquery);
|
|
106
|
-
|
|
107
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
108
|
-
expect(result._operator).toBe('ANY');
|
|
109
|
-
expect(result._operands).toStrictEqual([subquery]);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('Exists operator', () => {
|
|
113
|
-
const result = exists(subquery);
|
|
114
|
-
|
|
115
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
116
|
-
expect(result._operator).toBe('EXISTS');
|
|
117
|
-
expect(result._operands).toStrictEqual([subquery]);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('Operands should return correct FunctionalCall intermediate query', ()=> {
|
|
122
|
-
|
|
123
|
-
const operandable = SupportedOperations.eq.call([1, 2, 3], 5);
|
|
124
|
-
|
|
125
|
-
it('Avg operator', () => {
|
|
126
|
-
const result = avg(operandable);
|
|
127
|
-
|
|
128
|
-
expect(result).toBeInstanceOf(FunctionCall);
|
|
129
|
-
expect(result._func).toBe('AVG');
|
|
130
|
-
expect(result._args).toStrictEqual([operandable]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('Sum operator', () => {
|
|
134
|
-
const result = sum(operandable);
|
|
135
|
-
|
|
136
|
-
expect(result).toBeInstanceOf(FunctionCall);
|
|
137
|
-
expect(result._func).toBe('SUM');
|
|
138
|
-
expect(result._args).toStrictEqual([operandable]);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('Count operator', () => {
|
|
142
|
-
const result = count(operandable);
|
|
143
|
-
|
|
144
|
-
expect(result).toBeInstanceOf(FunctionCall);
|
|
145
|
-
expect(result._func).toBe('COUNT');
|
|
146
|
-
expect(result._args).toStrictEqual([operandable]);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('Count operator should return * if value was not provided', () => {
|
|
150
|
-
const result = count();
|
|
151
|
-
|
|
152
|
-
expect(result).toBeInstanceOf(FunctionCall);
|
|
153
|
-
expect(result._func).toBe('COUNT');
|
|
154
|
-
expect(result._args).toStrictEqual(['*']);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('Max operator', () => {
|
|
158
|
-
const result = max(operandable);
|
|
159
|
-
|
|
160
|
-
expect(result).toBeInstanceOf(FunctionCall);
|
|
161
|
-
expect(result._func).toBe('MAX');
|
|
162
|
-
expect(result._args).toStrictEqual([operandable]);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('Min operator', () => {
|
|
166
|
-
const result = min(operandable);
|
|
167
|
-
|
|
168
|
-
expect(result).toBeInstanceOf(FunctionCall);
|
|
169
|
-
expect(result._func).toBe('MIN');
|
|
170
|
-
expect(result._args).toStrictEqual([operandable]);
|
|
171
|
-
});
|
|
172
|
-
});
|
package/tests/models.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {dbField, dbTable, IDbField, dbFilterField, and, Select, DbValueType,
|
|
2
|
-
IOperandable, cast, FunctionCall, Branded} from '../src';
|
|
3
|
-
|
|
4
|
-
const UUID: IDbField = {}
|
|
5
|
-
|
|
6
|
-
export type PersonId = Branded<number, 'PersonId'>;
|
|
7
|
-
export type PersonUid = Branded<string, 'PersonUid'>;
|
|
8
|
-
|
|
9
|
-
@dbTable('Person', [{name: 'idx', fields: ['id']}])
|
|
10
|
-
export class Person {
|
|
11
|
-
@dbField({
|
|
12
|
-
primaryKey: true,
|
|
13
|
-
autoIncrement: true
|
|
14
|
-
})
|
|
15
|
-
id!: PersonId;
|
|
16
|
-
|
|
17
|
-
@dbField({
|
|
18
|
-
kind: UUID
|
|
19
|
-
})
|
|
20
|
-
uid?: PersonUid;
|
|
21
|
-
|
|
22
|
-
@dbField name!: string;
|
|
23
|
-
@dbField age!: number;
|
|
24
|
-
@dbField city!: string;
|
|
25
|
-
|
|
26
|
-
@dbField({sensitive: true, nullable: true})
|
|
27
|
-
password?: string;
|
|
28
|
-
|
|
29
|
-
@dbFilterField({
|
|
30
|
-
table: 'employee',
|
|
31
|
-
keyField: 'person',
|
|
32
|
-
valueField: 'title',
|
|
33
|
-
})
|
|
34
|
-
profiles?: string[];
|
|
35
|
-
|
|
36
|
-
@dbFilterField(primary => Select(Tag)
|
|
37
|
-
.columns((x) => [x.name])
|
|
38
|
-
.join(TagPerson, (a ,b) => and(a.id.eq(b.tag), b.person.eq(primary)))
|
|
39
|
-
)
|
|
40
|
-
tags?: string[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type TagId = Branded<number, 'TagId'>;
|
|
44
|
-
|
|
45
|
-
@dbTable('Tag')
|
|
46
|
-
export class Tag {
|
|
47
|
-
@dbField({
|
|
48
|
-
primaryKey: true,
|
|
49
|
-
autoIncrement: true
|
|
50
|
-
})
|
|
51
|
-
public id!: TagId;
|
|
52
|
-
|
|
53
|
-
@dbField public name!: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@dbTable('TagPerson')
|
|
57
|
-
export class TagPerson {
|
|
58
|
-
@dbField({
|
|
59
|
-
primaryKey: true,
|
|
60
|
-
})
|
|
61
|
-
public person!: PersonId;
|
|
62
|
-
@dbField({
|
|
63
|
-
primaryKey: true,
|
|
64
|
-
})
|
|
65
|
-
public tag!: TagId;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@dbTable('Employee')
|
|
69
|
-
export class Employee {
|
|
70
|
-
@dbField personId!: PersonId;
|
|
71
|
-
@dbField company!: string;
|
|
72
|
-
@dbField salary!: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const EMAIL: IDbField = {
|
|
76
|
-
reader(value: DbValueType) {
|
|
77
|
-
return typeof value === 'string' ? value.toLowerCase() : value
|
|
78
|
-
},
|
|
79
|
-
writer(value): DbValueType {
|
|
80
|
-
return typeof value === 'string' ? value.toLowerCase() : value
|
|
81
|
-
},
|
|
82
|
-
readQuery(name: IOperandable<string>): IOperandable<string> {
|
|
83
|
-
return cast(name as never, 'Email');
|
|
84
|
-
},
|
|
85
|
-
writeQuery(name: IOperandable<string>): IOperandable<string> {
|
|
86
|
-
return cast(name as never, 'Email');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type MailingListId = Branded<number, 'MailingListId'>;
|
|
91
|
-
|
|
92
|
-
export class MailingList {
|
|
93
|
-
@dbField({
|
|
94
|
-
primaryKey: true,
|
|
95
|
-
autoIncrement: true
|
|
96
|
-
})
|
|
97
|
-
public id!: MailingListId;
|
|
98
|
-
@dbField public name!: string;
|
|
99
|
-
@dbField({kind: EMAIL}) email!: string;
|
|
100
|
-
}
|
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
const {SupportedOperations, Operandable} = require("../src/wrappers");
|
|
2
|
-
|
|
3
|
-
describe('Operations should return correct intermediate query', () => {
|
|
4
|
-
|
|
5
|
-
const thisData = [1, 2, 3, 4, 5];
|
|
6
|
-
const givenValue = 5;
|
|
7
|
-
|
|
8
|
-
it('Equal operation', () => {
|
|
9
|
-
const result = SupportedOperations.eq.call(thisData, givenValue);
|
|
10
|
-
|
|
11
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
12
|
-
expect(result._operator).toBe('=');
|
|
13
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('Not equal operation', () => {
|
|
17
|
-
const result = SupportedOperations.neq.call(thisData, givenValue);
|
|
18
|
-
|
|
19
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
20
|
-
expect(result._operator).toBe('<>');
|
|
21
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('LIKE operation', () => {
|
|
25
|
-
const result = SupportedOperations.like.call(thisData, givenValue);
|
|
26
|
-
|
|
27
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
28
|
-
expect(result._operator).toBe('LIKE');
|
|
29
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('IN operation', () => {
|
|
33
|
-
const result = SupportedOperations.in.call(thisData, givenValue);
|
|
34
|
-
|
|
35
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
36
|
-
expect(result._operator).toBe('IN');
|
|
37
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('HAS operation', () => {
|
|
41
|
-
const result = SupportedOperations.has.call(thisData, givenValue);
|
|
42
|
-
|
|
43
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
44
|
-
expect(result._operator).toBe('IN');
|
|
45
|
-
expect(result._operands).toStrictEqual([givenValue, thisData]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('BETWEEN operation', () => {
|
|
49
|
-
const lowerGivenValue = 5;
|
|
50
|
-
const highGivenValue = 10;
|
|
51
|
-
const result = SupportedOperations.between.call(thisData, lowerGivenValue, highGivenValue);
|
|
52
|
-
|
|
53
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
54
|
-
expect(result._operator).toBe('BETWEEN');
|
|
55
|
-
expect(result._operands).toStrictEqual([thisData, lowerGivenValue, highGivenValue]);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('GREATER THAN operation', () => {
|
|
59
|
-
const result = SupportedOperations.gt.call(thisData, givenValue);
|
|
60
|
-
|
|
61
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
62
|
-
expect(result._operator).toBe('>');
|
|
63
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('GREATER THAN EQUAL operation', () => {
|
|
67
|
-
const result = SupportedOperations.gte.call(thisData, givenValue);
|
|
68
|
-
|
|
69
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
70
|
-
expect(result._operator).toBe('>=');
|
|
71
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('LOWER THAN operation', () => {
|
|
75
|
-
const result = SupportedOperations.lt.call(thisData, givenValue);
|
|
76
|
-
|
|
77
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
78
|
-
expect(result._operator).toBe('<');
|
|
79
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('LOWER THAN EQUAL operation', () => {
|
|
83
|
-
const result = SupportedOperations.lte.call(thisData, givenValue);
|
|
84
|
-
|
|
85
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
86
|
-
expect(result._operator).toBe('<=');
|
|
87
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('ADD operation', () => {
|
|
91
|
-
const result = SupportedOperations.add.call(thisData, givenValue);
|
|
92
|
-
|
|
93
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
94
|
-
expect(result._operator).toBe('+');
|
|
95
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('SUBTRACTION operation', () => {
|
|
99
|
-
const result = SupportedOperations.sub.call(thisData, givenValue);
|
|
100
|
-
|
|
101
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
102
|
-
expect(result._operator).toBe('-');
|
|
103
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('MULTIPLY operation', () => {
|
|
107
|
-
const result = SupportedOperations.mul.call(thisData, givenValue);
|
|
108
|
-
|
|
109
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
110
|
-
expect(result._operator).toBe('*');
|
|
111
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('DIVISION operation', () => {
|
|
115
|
-
const result = SupportedOperations.div.call(thisData, givenValue);
|
|
116
|
-
|
|
117
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
118
|
-
expect(result._operator).toBe('/');
|
|
119
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('MODULO operation', () => {
|
|
123
|
-
const result = SupportedOperations.mod.call(thisData, givenValue);
|
|
124
|
-
|
|
125
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
126
|
-
expect(result._operator).toBe('%');
|
|
127
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('AND operation', () => {
|
|
131
|
-
const result = SupportedOperations.and.call(thisData, givenValue);
|
|
132
|
-
|
|
133
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
134
|
-
expect(result._operator).toBe('&');
|
|
135
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('OR operation', () => {
|
|
139
|
-
const result = SupportedOperations.or.call(thisData, givenValue);
|
|
140
|
-
|
|
141
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
142
|
-
expect(result._operator).toBe('|');
|
|
143
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('XOR operation', () => {
|
|
147
|
-
const result = SupportedOperations.xor.call(thisData, givenValue);
|
|
148
|
-
|
|
149
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
150
|
-
expect(result._operator).toBe('^');
|
|
151
|
-
expect(result._operands).toStrictEqual([thisData, givenValue]);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('Operations should return correct intermediate query if given value is subquery', () => {
|
|
156
|
-
|
|
157
|
-
const thisData = [1, 2, 3, 4, 5];
|
|
158
|
-
const givenValue = 5;
|
|
159
|
-
const subQueryGivenValue = SupportedOperations.eq.call(thisData, givenValue);
|
|
160
|
-
|
|
161
|
-
it('Equal operation', () => {
|
|
162
|
-
const result = SupportedOperations.eq.call(thisData, subQueryGivenValue);
|
|
163
|
-
|
|
164
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
165
|
-
expect(result._operator).toBe('=');
|
|
166
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
167
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('Not equal operation', () => {
|
|
171
|
-
const result = SupportedOperations.eq.call(thisData, subQueryGivenValue);
|
|
172
|
-
|
|
173
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
174
|
-
expect(result._operator).toBe('=');
|
|
175
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
176
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('LIKE operation', () => {
|
|
180
|
-
const result = SupportedOperations.like.call(thisData, subQueryGivenValue);
|
|
181
|
-
|
|
182
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
183
|
-
expect(result._operator).toBe('LIKE');
|
|
184
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
185
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('IN operation', () => {
|
|
189
|
-
const result = SupportedOperations.in.call(thisData, subQueryGivenValue);
|
|
190
|
-
|
|
191
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
192
|
-
expect(result._operator).toBe('IN');
|
|
193
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
194
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('HAS operation', () => {
|
|
198
|
-
const result = SupportedOperations.has.call(thisData, subQueryGivenValue);
|
|
199
|
-
|
|
200
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
201
|
-
expect(result._operator).toBe('IN');
|
|
202
|
-
expect(result._operands[0]).toBeInstanceOf(Operandable);
|
|
203
|
-
expect(result._operands).toStrictEqual([subQueryGivenValue, thisData]);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('BETWEEN operation', () => {
|
|
207
|
-
const result = SupportedOperations.between.call(thisData, subQueryGivenValue, subQueryGivenValue);
|
|
208
|
-
|
|
209
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
210
|
-
expect(result._operator).toBe('BETWEEN');
|
|
211
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
212
|
-
expect(result._operands[2]).toBeInstanceOf(Operandable);
|
|
213
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue, subQueryGivenValue]);
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('GREATER THAN operation', () => {
|
|
217
|
-
const result = SupportedOperations.gt.call(thisData, subQueryGivenValue);
|
|
218
|
-
|
|
219
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
220
|
-
expect(result._operator).toBe('>');
|
|
221
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
222
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('GREATER THAN EQUAL operation', () => {
|
|
226
|
-
const result = SupportedOperations.gte.call(thisData, subQueryGivenValue);
|
|
227
|
-
|
|
228
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
229
|
-
expect(result._operator).toBe('>=');
|
|
230
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
231
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('LOWER THAN operation', () => {
|
|
235
|
-
const result = SupportedOperations.lt.call(thisData, subQueryGivenValue);
|
|
236
|
-
|
|
237
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
238
|
-
expect(result._operator).toBe('<');
|
|
239
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
240
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('LOWER THAN EQUAL operation', () => {
|
|
244
|
-
const result = SupportedOperations.lte.call(thisData, subQueryGivenValue);
|
|
245
|
-
|
|
246
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
247
|
-
expect(result._operator).toBe('<=');
|
|
248
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
249
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('ADD operation', () => {
|
|
253
|
-
const result = SupportedOperations.add.call(thisData, subQueryGivenValue);
|
|
254
|
-
|
|
255
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
256
|
-
expect(result._operator).toBe('+');
|
|
257
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
258
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('SUBTRACTION operation', () => {
|
|
262
|
-
const result = SupportedOperations.sub.call(thisData, subQueryGivenValue);
|
|
263
|
-
|
|
264
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
265
|
-
expect(result._operator).toBe('-');
|
|
266
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
267
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('MULTIPLY operation', () => {
|
|
271
|
-
const result = SupportedOperations.mul.call(thisData, subQueryGivenValue);
|
|
272
|
-
|
|
273
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
274
|
-
expect(result._operator).toBe('*');
|
|
275
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
276
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('DIVISION operation', () => {
|
|
280
|
-
const result = SupportedOperations.div.call(thisData, subQueryGivenValue);
|
|
281
|
-
|
|
282
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
283
|
-
expect(result._operator).toBe('/');
|
|
284
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
285
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('MODULO operation', () => {
|
|
289
|
-
const result = SupportedOperations.mod.call(thisData, subQueryGivenValue);
|
|
290
|
-
|
|
291
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
292
|
-
expect(result._operator).toBe('%');
|
|
293
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
294
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
it('AND operation', () => {
|
|
298
|
-
const result = SupportedOperations.and.call(thisData, subQueryGivenValue);
|
|
299
|
-
|
|
300
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
301
|
-
expect(result._operator).toBe('&');
|
|
302
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
303
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('OR operation', () => {
|
|
307
|
-
const result = SupportedOperations.or.call(thisData, subQueryGivenValue);
|
|
308
|
-
|
|
309
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
310
|
-
expect(result._operator).toBe('|');
|
|
311
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
312
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('XOR operation', () => {
|
|
316
|
-
const result = SupportedOperations.xor.call(thisData, subQueryGivenValue);
|
|
317
|
-
|
|
318
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
319
|
-
expect(result._operator).toBe('^');
|
|
320
|
-
expect(result._operands[1]).toBeInstanceOf(Operandable);
|
|
321
|
-
expect(result._operands).toStrictEqual([thisData, subQueryGivenValue]);
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
describe('Operations should correct process null value', () => {
|
|
326
|
-
|
|
327
|
-
const thisData = [1, 2, 3, 4, 5];
|
|
328
|
-
|
|
329
|
-
it('Equal operation', () => {
|
|
330
|
-
const givenValue = null;
|
|
331
|
-
const result = SupportedOperations.eq.call(thisData, givenValue);
|
|
332
|
-
|
|
333
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
334
|
-
expect(result._operator).toBe('IS');
|
|
335
|
-
expect(result._operands).toStrictEqual([thisData, 'NULL']);
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it('A non-equal operation', () => {
|
|
339
|
-
const givenValue = null;
|
|
340
|
-
const result = SupportedOperations.neq.call(thisData, givenValue);
|
|
341
|
-
|
|
342
|
-
expect(result).toBeInstanceOf(Operandable);
|
|
343
|
-
expect(result._operator).toBe('IS NOT');
|
|
344
|
-
expect(result._operands).toStrictEqual([thisData, 'NULL']);
|
|
345
|
-
});
|
|
346
|
-
});
|