@uql/core 3.1.0 → 3.1.2
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/CHANGELOG.md +134 -176
- package/README.md +413 -0
- package/package.json +31 -26
- package/dist/package.json +0 -131
- package/src/@types/index.d.ts +0 -1
- package/src/@types/jest.d.ts +0 -6
- package/src/browser/http/bus.spec.ts +0 -22
- package/src/browser/http/bus.ts +0 -17
- package/src/browser/http/http.spec.ts +0 -70
- package/src/browser/http/http.ts +0 -55
- package/src/browser/http/index.ts +0 -2
- package/src/browser/index.ts +0 -4
- package/src/browser/options.spec.ts +0 -37
- package/src/browser/options.ts +0 -18
- package/src/browser/querier/genericClientRepository.spec.ts +0 -105
- package/src/browser/querier/genericClientRepository.ts +0 -49
- package/src/browser/querier/httpQuerier.ts +0 -82
- package/src/browser/querier/index.ts +0 -3
- package/src/browser/querier/querier.util.spec.ts +0 -35
- package/src/browser/querier/querier.util.ts +0 -18
- package/src/browser/type/clientQuerier.ts +0 -45
- package/src/browser/type/clientQuerierPool.ts +0 -5
- package/src/browser/type/clientRepository.ts +0 -22
- package/src/browser/type/index.ts +0 -4
- package/src/browser/type/request.ts +0 -25
- package/src/dialect/abstractDialect.ts +0 -28
- package/src/dialect/abstractSqlDialect-spec.ts +0 -1309
- package/src/dialect/abstractSqlDialect.ts +0 -805
- package/src/dialect/index.ts +0 -3
- package/src/dialect/namingStrategy.spec.ts +0 -52
- package/src/dialect/queryContext.ts +0 -69
- package/src/entity/decorator/definition.spec.ts +0 -736
- package/src/entity/decorator/definition.ts +0 -265
- package/src/entity/decorator/entity.ts +0 -8
- package/src/entity/decorator/field.ts +0 -9
- package/src/entity/decorator/id.ts +0 -9
- package/src/entity/decorator/index.ts +0 -5
- package/src/entity/decorator/relation.spec.ts +0 -41
- package/src/entity/decorator/relation.ts +0 -34
- package/src/entity/index.ts +0 -1
- package/src/express/@types/express.d.ts +0 -8
- package/src/express/@types/index.d.ts +0 -1
- package/src/express/index.ts +0 -2
- package/src/express/querierMiddleware.ts +0 -217
- package/src/express/query.util.spec.ts +0 -40
- package/src/express/query.util.ts +0 -21
- package/src/index.ts +0 -9
- package/src/maria/index.ts +0 -3
- package/src/maria/mariaDialect.spec.ts +0 -207
- package/src/maria/mariaDialect.ts +0 -42
- package/src/maria/mariaQuerierPool.test.ts +0 -23
- package/src/maria/mariadbQuerier.test.ts +0 -23
- package/src/maria/mariadbQuerier.ts +0 -45
- package/src/maria/mariadbQuerierPool.ts +0 -21
- package/src/migrate/cli.ts +0 -301
- package/src/migrate/generator/index.ts +0 -4
- package/src/migrate/generator/mongoSchemaGenerator.spec.ts +0 -112
- package/src/migrate/generator/mongoSchemaGenerator.ts +0 -115
- package/src/migrate/generator/mysqlSchemaGenerator.spec.ts +0 -34
- package/src/migrate/generator/mysqlSchemaGenerator.ts +0 -92
- package/src/migrate/generator/postgresSchemaGenerator.spec.ts +0 -44
- package/src/migrate/generator/postgresSchemaGenerator.ts +0 -127
- package/src/migrate/generator/sqliteSchemaGenerator.spec.ts +0 -33
- package/src/migrate/generator/sqliteSchemaGenerator.ts +0 -81
- package/src/migrate/index.ts +0 -41
- package/src/migrate/introspection/index.ts +0 -4
- package/src/migrate/introspection/mongoIntrospector.spec.ts +0 -75
- package/src/migrate/introspection/mongoIntrospector.ts +0 -47
- package/src/migrate/introspection/mysqlIntrospector.spec.ts +0 -113
- package/src/migrate/introspection/mysqlIntrospector.ts +0 -278
- package/src/migrate/introspection/postgresIntrospector.spec.ts +0 -112
- package/src/migrate/introspection/postgresIntrospector.ts +0 -329
- package/src/migrate/introspection/sqliteIntrospector.spec.ts +0 -112
- package/src/migrate/introspection/sqliteIntrospector.ts +0 -296
- package/src/migrate/migrator-mongo.test.ts +0 -54
- package/src/migrate/migrator.spec.ts +0 -255
- package/src/migrate/migrator.test.ts +0 -94
- package/src/migrate/migrator.ts +0 -719
- package/src/migrate/namingStrategy.spec.ts +0 -22
- package/src/migrate/schemaGenerator-advanced.spec.ts +0 -138
- package/src/migrate/schemaGenerator.spec.ts +0 -190
- package/src/migrate/schemaGenerator.ts +0 -478
- package/src/migrate/storage/databaseStorage.spec.ts +0 -69
- package/src/migrate/storage/databaseStorage.ts +0 -100
- package/src/migrate/storage/index.ts +0 -2
- package/src/migrate/storage/jsonStorage.ts +0 -58
- package/src/migrate/type.ts +0 -1
- package/src/mongo/index.ts +0 -3
- package/src/mongo/mongoDialect.spec.ts +0 -251
- package/src/mongo/mongoDialect.ts +0 -238
- package/src/mongo/mongodbQuerier.test.ts +0 -45
- package/src/mongo/mongodbQuerier.ts +0 -256
- package/src/mongo/mongodbQuerierPool.test.ts +0 -25
- package/src/mongo/mongodbQuerierPool.ts +0 -24
- package/src/mysql/index.ts +0 -3
- package/src/mysql/mysql2Querier.test.ts +0 -20
- package/src/mysql/mysql2Querier.ts +0 -49
- package/src/mysql/mysql2QuerierPool.test.ts +0 -20
- package/src/mysql/mysql2QuerierPool.ts +0 -21
- package/src/mysql/mysqlDialect.spec.ts +0 -20
- package/src/mysql/mysqlDialect.ts +0 -16
- package/src/namingStrategy/defaultNamingStrategy.ts +0 -18
- package/src/namingStrategy/index.spec.ts +0 -36
- package/src/namingStrategy/index.ts +0 -2
- package/src/namingStrategy/snakeCaseNamingStrategy.ts +0 -15
- package/src/options.spec.ts +0 -41
- package/src/options.ts +0 -18
- package/src/postgres/index.ts +0 -3
- package/src/postgres/manual-types.d.ts +0 -4
- package/src/postgres/pgQuerier.test.ts +0 -25
- package/src/postgres/pgQuerier.ts +0 -45
- package/src/postgres/pgQuerierPool.test.ts +0 -28
- package/src/postgres/pgQuerierPool.ts +0 -21
- package/src/postgres/postgresDialect.spec.ts +0 -428
- package/src/postgres/postgresDialect.ts +0 -144
- package/src/querier/abstractQuerier-test.ts +0 -584
- package/src/querier/abstractQuerier.ts +0 -353
- package/src/querier/abstractQuerierPool-test.ts +0 -20
- package/src/querier/abstractQuerierPool.ts +0 -18
- package/src/querier/abstractSqlQuerier-spec.ts +0 -979
- package/src/querier/abstractSqlQuerier-test.ts +0 -21
- package/src/querier/abstractSqlQuerier.ts +0 -138
- package/src/querier/decorator/index.ts +0 -3
- package/src/querier/decorator/injectQuerier.spec.ts +0 -74
- package/src/querier/decorator/injectQuerier.ts +0 -45
- package/src/querier/decorator/serialized.spec.ts +0 -98
- package/src/querier/decorator/serialized.ts +0 -13
- package/src/querier/decorator/transactional.spec.ts +0 -240
- package/src/querier/decorator/transactional.ts +0 -56
- package/src/querier/index.ts +0 -4
- package/src/repository/genericRepository.spec.ts +0 -111
- package/src/repository/genericRepository.ts +0 -74
- package/src/repository/index.ts +0 -1
- package/src/sqlite/index.ts +0 -3
- package/src/sqlite/manual-types.d.ts +0 -4
- package/src/sqlite/sqliteDialect.spec.ts +0 -155
- package/src/sqlite/sqliteDialect.ts +0 -76
- package/src/sqlite/sqliteQuerier.spec.ts +0 -36
- package/src/sqlite/sqliteQuerier.test.ts +0 -21
- package/src/sqlite/sqliteQuerier.ts +0 -37
- package/src/sqlite/sqliteQuerierPool.test.ts +0 -12
- package/src/sqlite/sqliteQuerierPool.ts +0 -38
- package/src/test/entityMock.ts +0 -375
- package/src/test/index.ts +0 -3
- package/src/test/it.util.ts +0 -69
- package/src/test/spec.util.ts +0 -57
- package/src/type/entity.ts +0 -218
- package/src/type/index.ts +0 -9
- package/src/type/migration.ts +0 -241
- package/src/type/namingStrategy.ts +0 -17
- package/src/type/querier.ts +0 -143
- package/src/type/querierPool.ts +0 -26
- package/src/type/query.ts +0 -506
- package/src/type/repository.ts +0 -142
- package/src/type/universalQuerier.ts +0 -133
- package/src/type/utility.ts +0 -21
- package/src/util/dialect.util-extra.spec.ts +0 -96
- package/src/util/dialect.util.spec.ts +0 -23
- package/src/util/dialect.util.ts +0 -134
- package/src/util/index.ts +0 -5
- package/src/util/object.util.spec.ts +0 -29
- package/src/util/object.util.ts +0 -27
- package/src/util/raw.ts +0 -11
- package/src/util/sql.util-extra.spec.ts +0 -17
- package/src/util/sql.util.spec.ts +0 -208
- package/src/util/sql.util.ts +0 -104
- package/src/util/string.util.spec.ts +0 -46
- package/src/util/string.util.ts +0 -35
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -8
|
@@ -1,1309 +0,0 @@
|
|
|
1
|
-
import { expect } from 'bun:test';
|
|
2
|
-
import {
|
|
3
|
-
Company,
|
|
4
|
-
InventoryAdjustment,
|
|
5
|
-
Item,
|
|
6
|
-
ItemAdjustment,
|
|
7
|
-
MeasureUnit,
|
|
8
|
-
Profile,
|
|
9
|
-
type Spec,
|
|
10
|
-
Tax,
|
|
11
|
-
TaxCategory,
|
|
12
|
-
User,
|
|
13
|
-
} from '../test/index.js';
|
|
14
|
-
import type { FieldKey, QueryContext } from '../type/index.js';
|
|
15
|
-
import { raw } from '../util/index.js';
|
|
16
|
-
import type { AbstractSqlDialect } from './abstractSqlDialect.js';
|
|
17
|
-
|
|
18
|
-
export abstract class AbstractSqlDialectSpec implements Spec {
|
|
19
|
-
constructor(readonly dialect: AbstractSqlDialect) {}
|
|
20
|
-
|
|
21
|
-
protected exec(fn: (ctx: QueryContext) => void): { sql: string; values: unknown[] } {
|
|
22
|
-
const ctx = this.dialect.createContext();
|
|
23
|
-
fn(ctx);
|
|
24
|
-
return { sql: ctx.sql, values: ctx.values };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
shouldBeValidEscapeCharacter() {
|
|
28
|
-
expect(this.dialect.escapeIdChar).toBe('`');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
shouldBeginTransaction() {
|
|
32
|
-
expect(this.dialect.beginTransactionCommand).toBe('START TRANSACTION');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
shouldInsertMany() {
|
|
36
|
-
const { sql, values } = this.exec((ctx) =>
|
|
37
|
-
this.dialect.insert(ctx, User, [
|
|
38
|
-
{
|
|
39
|
-
name: 'Some name 1',
|
|
40
|
-
email: 'someemail1@example.com',
|
|
41
|
-
createdAt: 123,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: 'Some name 2',
|
|
45
|
-
email: 'someemail2@example.com',
|
|
46
|
-
createdAt: 456,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: 'Some name 3',
|
|
50
|
-
email: 'someemail3@example.com',
|
|
51
|
-
createdAt: 789,
|
|
52
|
-
},
|
|
53
|
-
]),
|
|
54
|
-
);
|
|
55
|
-
expect(sql).toBe('INSERT INTO `User` (`name`, `email`, `createdAt`) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?)');
|
|
56
|
-
expect(values).toEqual([
|
|
57
|
-
'Some name 1',
|
|
58
|
-
'someemail1@example.com',
|
|
59
|
-
123,
|
|
60
|
-
'Some name 2',
|
|
61
|
-
'someemail2@example.com',
|
|
62
|
-
456,
|
|
63
|
-
'Some name 3',
|
|
64
|
-
'someemail3@example.com',
|
|
65
|
-
789,
|
|
66
|
-
]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
shouldInsertOne() {
|
|
70
|
-
let res = this.exec((ctx) =>
|
|
71
|
-
this.dialect.insert(ctx, User, {
|
|
72
|
-
name: 'Some Name',
|
|
73
|
-
email: 'someemail@example.com',
|
|
74
|
-
createdAt: 123,
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
77
|
-
expect(res.sql).toBe('INSERT INTO `User` (`name`, `email`, `createdAt`) VALUES (?, ?, ?)');
|
|
78
|
-
expect(res.values).toEqual(['Some Name', 'someemail@example.com', 123]);
|
|
79
|
-
|
|
80
|
-
res = this.exec((ctx) =>
|
|
81
|
-
this.dialect.insert(ctx, InventoryAdjustment, {
|
|
82
|
-
date: new Date(2021, 11, 31, 23, 59, 59, 999),
|
|
83
|
-
createdAt: 123,
|
|
84
|
-
}),
|
|
85
|
-
);
|
|
86
|
-
expect(res.sql).toBe('INSERT INTO `InventoryAdjustment` (`date`, `createdAt`) VALUES (?, ?)');
|
|
87
|
-
expect(res.values[0]).toBeInstanceOf(Date);
|
|
88
|
-
expect(res.values[1]).toBe(123);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
shouldInsertWithOnInsertId() {
|
|
92
|
-
const { sql, values } = this.exec((ctx) =>
|
|
93
|
-
this.dialect.insert(ctx, TaxCategory, {
|
|
94
|
-
name: 'Some Name',
|
|
95
|
-
createdAt: 123,
|
|
96
|
-
}),
|
|
97
|
-
);
|
|
98
|
-
expect(sql).toMatch(/^INSERT INTO `TaxCategory` \(`name`, `createdAt`, `pk`\) VALUES \(\?, \?, \?\)$/);
|
|
99
|
-
expect(values[0]).toBe('Some Name');
|
|
100
|
-
expect(values[1]).toBe(123);
|
|
101
|
-
expect(values[2]).toMatch(/.+/);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
shouldUpdateWithRawString() {
|
|
105
|
-
const { sql, values } = this.exec((ctx) =>
|
|
106
|
-
this.dialect.update(
|
|
107
|
-
ctx,
|
|
108
|
-
Company,
|
|
109
|
-
{ $where: { id: 1 } },
|
|
110
|
-
{
|
|
111
|
-
kind: raw("'value'"),
|
|
112
|
-
updatedAt: 123,
|
|
113
|
-
},
|
|
114
|
-
),
|
|
115
|
-
);
|
|
116
|
-
expect(sql).toBe("UPDATE `Company` SET `kind` = 'value', `updatedAt` = ? WHERE `id` = ?");
|
|
117
|
-
expect(values).toEqual([123, 1]);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
shouldUpdateWithJsonbField() {
|
|
121
|
-
const { sql, values } = this.exec((ctx) =>
|
|
122
|
-
this.dialect.update(
|
|
123
|
-
ctx,
|
|
124
|
-
Company,
|
|
125
|
-
{ $where: { id: 1 } },
|
|
126
|
-
{
|
|
127
|
-
kind: { private: 1 },
|
|
128
|
-
updatedAt: 123,
|
|
129
|
-
},
|
|
130
|
-
),
|
|
131
|
-
);
|
|
132
|
-
expect(sql).toBe('UPDATE `Company` SET `kind` = ?, `updatedAt` = ? WHERE `id` = ?');
|
|
133
|
-
expect(values).toEqual(['{"private":1}', 123, 1]);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
shouldInsertManyWithSpecifiedIdsAndOnInsertIdAsDefault() {
|
|
137
|
-
const { sql, values } = this.exec((ctx) =>
|
|
138
|
-
this.dialect.insert(ctx, TaxCategory, [
|
|
139
|
-
{
|
|
140
|
-
name: 'Some Name A',
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
pk: '50',
|
|
144
|
-
name: 'Some Name B',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: 'Some Name C',
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
pk: '70',
|
|
151
|
-
name: 'Some Name D',
|
|
152
|
-
},
|
|
153
|
-
]),
|
|
154
|
-
);
|
|
155
|
-
expect(sql).toMatch(
|
|
156
|
-
/^INSERT INTO `TaxCategory` \(`name`, `createdAt`, `pk`\) VALUES \(\?, \?, \?\), \(\?, \?, \?\), \(\?, \?, \?\), \(\?, \?, \?\)$/,
|
|
157
|
-
);
|
|
158
|
-
expect(values[0]).toBe('Some Name A');
|
|
159
|
-
expect(values[2]).toMatch(/.+/);
|
|
160
|
-
expect(values[3]).toBe('Some Name B');
|
|
161
|
-
expect(values[5]).toBe('50');
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
shouldUpsert() {
|
|
165
|
-
const { sql, values } = this.exec((ctx) =>
|
|
166
|
-
this.dialect.upsert(
|
|
167
|
-
ctx,
|
|
168
|
-
User,
|
|
169
|
-
{ email: true },
|
|
170
|
-
{
|
|
171
|
-
name: 'Some Name',
|
|
172
|
-
email: 'someemail@example.com',
|
|
173
|
-
createdAt: 123,
|
|
174
|
-
},
|
|
175
|
-
),
|
|
176
|
-
);
|
|
177
|
-
expect(sql).toMatch(
|
|
178
|
-
/^INSERT INTO `User` \(.*`name`.*`email`.*`createdAt`.*\) VALUES \(\?, \?, \?, \?\).+ON DUPLICATE KEY UPDATE .*`name` = VALUES\(`name`\).*`createdAt` = VALUES\(`createdAt`\).*`updatedAt` = VALUES\(`updatedAt`\).*$/,
|
|
179
|
-
);
|
|
180
|
-
expect(values).toEqual(['Some Name', 'someemail@example.com', 123, expect.any(Number)]);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
shouldUpdate() {
|
|
184
|
-
const { sql, values } = this.exec((ctx) =>
|
|
185
|
-
this.dialect.update(
|
|
186
|
-
ctx,
|
|
187
|
-
User,
|
|
188
|
-
{ $where: { name: 'some', creatorId: 123 } },
|
|
189
|
-
{
|
|
190
|
-
name: 'Some Text',
|
|
191
|
-
email: 'this field should not be updated',
|
|
192
|
-
updatedAt: 321,
|
|
193
|
-
},
|
|
194
|
-
),
|
|
195
|
-
);
|
|
196
|
-
expect(sql).toBe('UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `name` = ? AND `creatorId` = ?');
|
|
197
|
-
expect(values).toEqual(['Some Text', 321, 'some', 123]);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
shouldUpdateWithAlias() {
|
|
201
|
-
const { sql, values } = this.exec((ctx) =>
|
|
202
|
-
this.dialect.update(
|
|
203
|
-
ctx,
|
|
204
|
-
Profile,
|
|
205
|
-
{ $where: { pk: 123 } },
|
|
206
|
-
{
|
|
207
|
-
picture: 'a base64 image',
|
|
208
|
-
updatedAt: 321,
|
|
209
|
-
},
|
|
210
|
-
),
|
|
211
|
-
);
|
|
212
|
-
expect(sql).toBe('UPDATE `user_profile` SET `image` = ?, `updatedAt` = ? WHERE `pk` = ?');
|
|
213
|
-
expect(values).toEqual(['a base64 image', 321, 123]);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
shouldFind() {
|
|
217
|
-
let res = this.exec((ctx) =>
|
|
218
|
-
this.dialect.find(ctx, User, {
|
|
219
|
-
$select: ['id'],
|
|
220
|
-
$where: { id: 123, name: { $ne: 'abc' } },
|
|
221
|
-
}),
|
|
222
|
-
);
|
|
223
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? AND `name` <> ?');
|
|
224
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
225
|
-
|
|
226
|
-
res = this.exec((ctx) =>
|
|
227
|
-
this.dialect.find(ctx, Profile, {
|
|
228
|
-
$select: ['pk', 'picture', 'companyId'],
|
|
229
|
-
$where: { pk: 123, picture: 'abc' },
|
|
230
|
-
}),
|
|
231
|
-
);
|
|
232
|
-
expect(res.sql).toBe(
|
|
233
|
-
'SELECT `pk`, `image` `picture`, `companyId` FROM `user_profile` WHERE `pk` = ? AND `image` = ?',
|
|
234
|
-
);
|
|
235
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
236
|
-
|
|
237
|
-
res = this.exec((ctx) =>
|
|
238
|
-
this.dialect.find(ctx, MeasureUnit, {
|
|
239
|
-
$select: ['id'],
|
|
240
|
-
$where: { id: 123, name: 'abc' },
|
|
241
|
-
}),
|
|
242
|
-
);
|
|
243
|
-
expect(res.sql).toBe('SELECT `id` FROM `MeasureUnit` WHERE `id` = ? AND `name` = ? AND `deletedAt` IS NULL');
|
|
244
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
shouldBeSecure() {
|
|
248
|
-
let res = this.exec((ctx) =>
|
|
249
|
-
this.dialect.find(ctx, User, {
|
|
250
|
-
$select: ['id', 'something' as FieldKey<User>],
|
|
251
|
-
$where: {
|
|
252
|
-
id: 1,
|
|
253
|
-
something: 1,
|
|
254
|
-
} as any,
|
|
255
|
-
$sort: {
|
|
256
|
-
id: 1,
|
|
257
|
-
something: 1,
|
|
258
|
-
} as any,
|
|
259
|
-
}),
|
|
260
|
-
);
|
|
261
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? AND `something` = ? ORDER BY `id`, `something`');
|
|
262
|
-
expect(res.values).toEqual([1, 1]);
|
|
263
|
-
|
|
264
|
-
res = this.exec((ctx) =>
|
|
265
|
-
this.dialect.insert(ctx, User, {
|
|
266
|
-
name: 'Some Name',
|
|
267
|
-
something: 'anything',
|
|
268
|
-
createdAt: 1,
|
|
269
|
-
} as any),
|
|
270
|
-
);
|
|
271
|
-
expect(res.sql).toBe('INSERT INTO `User` (`name`, `createdAt`) VALUES (?, ?)');
|
|
272
|
-
expect(res.values).toEqual(['Some Name', 1]);
|
|
273
|
-
|
|
274
|
-
res = this.exec((ctx) =>
|
|
275
|
-
this.dialect.update(
|
|
276
|
-
ctx,
|
|
277
|
-
User,
|
|
278
|
-
{
|
|
279
|
-
$where: { something: 'anything' },
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
name: 'Some Name',
|
|
283
|
-
something: 'anything',
|
|
284
|
-
updatedAt: 1,
|
|
285
|
-
} as any,
|
|
286
|
-
),
|
|
287
|
-
);
|
|
288
|
-
expect(res.sql).toBe('UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `something` = ?');
|
|
289
|
-
expect(res.values).toEqual(['Some Name', 1, 'anything']);
|
|
290
|
-
|
|
291
|
-
res = this.exec((ctx) =>
|
|
292
|
-
this.dialect.delete(ctx, User, {
|
|
293
|
-
$where: { something: 'anything' } as any,
|
|
294
|
-
}),
|
|
295
|
-
);
|
|
296
|
-
expect(res.sql).toBe('DELETE FROM `User` WHERE `something` = ?');
|
|
297
|
-
expect(res.values).toEqual(['anything']);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
shouldFind$and() {
|
|
301
|
-
let res = this.exec((ctx) =>
|
|
302
|
-
this.dialect.find(ctx, User, {
|
|
303
|
-
$select: ['id'],
|
|
304
|
-
$where: { $and: [{ id: 123, name: 'abc' }] },
|
|
305
|
-
}),
|
|
306
|
-
);
|
|
307
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? AND `name` = ?');
|
|
308
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
309
|
-
|
|
310
|
-
res = this.exec((ctx) =>
|
|
311
|
-
this.dialect.find(ctx, User, {
|
|
312
|
-
$select: { id: 1 },
|
|
313
|
-
$where: { $and: [{ id: 123 }], name: 'abc' },
|
|
314
|
-
}),
|
|
315
|
-
);
|
|
316
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? AND `name` = ?');
|
|
317
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
shouldFind$or() {
|
|
321
|
-
let res = this.exec((ctx) =>
|
|
322
|
-
this.dialect.find(ctx, User, {
|
|
323
|
-
$select: ['id'],
|
|
324
|
-
$where: { $or: [{ id: 123 }, { name: 'abc' }] },
|
|
325
|
-
}),
|
|
326
|
-
);
|
|
327
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? OR `name` = ?');
|
|
328
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
329
|
-
|
|
330
|
-
res = this.exec((ctx) =>
|
|
331
|
-
this.dialect.find(ctx, User, {
|
|
332
|
-
$select: ['id'],
|
|
333
|
-
$where: { $or: [{ id: 123 }] },
|
|
334
|
-
}),
|
|
335
|
-
);
|
|
336
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ?');
|
|
337
|
-
expect(res.values).toEqual([123]);
|
|
338
|
-
|
|
339
|
-
res = this.exec((ctx) =>
|
|
340
|
-
this.dialect.find(ctx, User, {
|
|
341
|
-
$select: { id: 1 },
|
|
342
|
-
$where: { $or: [{ id: 123, name: 'abc' }] },
|
|
343
|
-
}),
|
|
344
|
-
);
|
|
345
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? AND `name` = ?');
|
|
346
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
347
|
-
|
|
348
|
-
res = this.exec((ctx) =>
|
|
349
|
-
this.dialect.find(ctx, User, {
|
|
350
|
-
$select: ['id'],
|
|
351
|
-
$where: { $or: [{ id: 123 }], name: 'abc' },
|
|
352
|
-
}),
|
|
353
|
-
);
|
|
354
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? AND `name` = ?');
|
|
355
|
-
expect(res.values).toEqual([123, 'abc']);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
shouldFind$not() {
|
|
359
|
-
let res = this.exec((ctx) =>
|
|
360
|
-
this.dialect.find(ctx, User, {
|
|
361
|
-
$select: ['id'],
|
|
362
|
-
$where: { $not: [{ name: 'Some' }] },
|
|
363
|
-
}),
|
|
364
|
-
);
|
|
365
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE NOT `name` = ?');
|
|
366
|
-
expect(res.values).toEqual(['Some']);
|
|
367
|
-
|
|
368
|
-
res = this.exec((ctx) =>
|
|
369
|
-
this.dialect.find(ctx, Company, {
|
|
370
|
-
$select: ['id'],
|
|
371
|
-
$where: { id: { $not: 123 } },
|
|
372
|
-
}),
|
|
373
|
-
);
|
|
374
|
-
expect(res.sql).toBe('SELECT `id` FROM `Company` WHERE NOT (`id` = ?)');
|
|
375
|
-
expect(res.values).toEqual([123]);
|
|
376
|
-
|
|
377
|
-
res = this.exec((ctx) =>
|
|
378
|
-
this.dialect.find(ctx, Company, {
|
|
379
|
-
$select: ['id'],
|
|
380
|
-
$where: { id: { $not: [123, 456] } },
|
|
381
|
-
}),
|
|
382
|
-
);
|
|
383
|
-
expect(res.sql).toBe('SELECT `id` FROM `Company` WHERE NOT (`id` IN (?, ?))');
|
|
384
|
-
expect(res.values).toEqual([123, 456]);
|
|
385
|
-
|
|
386
|
-
res = this.exec((ctx) =>
|
|
387
|
-
this.dialect.find(ctx, Company, {
|
|
388
|
-
$select: ['id'],
|
|
389
|
-
$where: { id: 123, name: { $not: { $startsWith: 'a' } } },
|
|
390
|
-
}),
|
|
391
|
-
);
|
|
392
|
-
expect(res.sql).toBe('SELECT `id` FROM `Company` WHERE `id` = ? AND NOT (`name` LIKE ?)');
|
|
393
|
-
expect(res.values).toEqual([123, 'a%']);
|
|
394
|
-
|
|
395
|
-
res = this.exec((ctx) =>
|
|
396
|
-
this.dialect.find(ctx, Company, {
|
|
397
|
-
$select: ['id'],
|
|
398
|
-
$where: { name: { $not: { $startsWith: 'a', $endsWith: 'z' } } },
|
|
399
|
-
}),
|
|
400
|
-
);
|
|
401
|
-
expect(res.sql).toBe('SELECT `id` FROM `Company` WHERE NOT ((`name` LIKE ? AND `name` LIKE ?))');
|
|
402
|
-
expect(res.values).toEqual(['a%', '%z']);
|
|
403
|
-
|
|
404
|
-
res = this.exec((ctx) =>
|
|
405
|
-
this.dialect.find(ctx, User, {
|
|
406
|
-
$select: { id: true },
|
|
407
|
-
$where: { $not: [{ name: { $like: 'Some', $ne: 'Something' } }] },
|
|
408
|
-
}),
|
|
409
|
-
);
|
|
410
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE NOT (`name` LIKE ? AND `name` <> ?)');
|
|
411
|
-
expect(res.values).toEqual(['Some', 'Something']);
|
|
412
|
-
|
|
413
|
-
res = this.exec((ctx) =>
|
|
414
|
-
this.dialect.find(ctx, User, {
|
|
415
|
-
$select: { id: true },
|
|
416
|
-
$where: { $not: [{ name: 'abc' }, { creatorId: 1 }] },
|
|
417
|
-
}),
|
|
418
|
-
);
|
|
419
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE NOT (`name` = ? AND `creatorId` = ?)');
|
|
420
|
-
expect(res.values).toEqual(['abc', 1]);
|
|
421
|
-
|
|
422
|
-
res = this.exec((ctx) =>
|
|
423
|
-
this.dialect.find(ctx, Tax, {
|
|
424
|
-
$select: ['id'],
|
|
425
|
-
$where: { companyId: 1, name: { $not: { $startsWith: 'a' } } },
|
|
426
|
-
}),
|
|
427
|
-
);
|
|
428
|
-
expect(res.sql).toBe('SELECT `id` FROM `Tax` WHERE `companyId` = ? AND NOT (`name` LIKE ?)');
|
|
429
|
-
expect(res.values).toEqual([1, 'a%']);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
shouldFind$nor() {
|
|
433
|
-
let res = this.exec((ctx) =>
|
|
434
|
-
this.dialect.find(ctx, User, {
|
|
435
|
-
$select: ['id'],
|
|
436
|
-
$where: { $nor: [{ name: 'Some' }] },
|
|
437
|
-
}),
|
|
438
|
-
);
|
|
439
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE NOT `name` = ?');
|
|
440
|
-
expect(res.values).toEqual(['Some']);
|
|
441
|
-
|
|
442
|
-
res = this.exec((ctx) =>
|
|
443
|
-
this.dialect.find(ctx, User, {
|
|
444
|
-
$select: { id: true },
|
|
445
|
-
$where: { $nor: [{ name: { $like: 'Some', $ne: 'Something' } }] },
|
|
446
|
-
}),
|
|
447
|
-
);
|
|
448
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE NOT (`name` LIKE ? AND `name` <> ?)');
|
|
449
|
-
expect(res.values).toEqual(['Some', 'Something']);
|
|
450
|
-
|
|
451
|
-
res = this.exec((ctx) =>
|
|
452
|
-
this.dialect.find(ctx, User, {
|
|
453
|
-
$select: { id: true },
|
|
454
|
-
$where: { $nor: [{ name: 'abc' }, { creatorId: 1 }] },
|
|
455
|
-
}),
|
|
456
|
-
);
|
|
457
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE NOT (`name` = ? OR `creatorId` = ?)');
|
|
458
|
-
expect(res.values).toEqual(['abc', 1]);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
shouldFind$orAnd$and() {
|
|
462
|
-
const res = this.exec((ctx) =>
|
|
463
|
-
this.dialect.find(ctx, User, {
|
|
464
|
-
$select: ['id'],
|
|
465
|
-
$where: { creatorId: 1, $or: [{ name: ['a', 'b', 'c'] }, { email: 'abc@example.com' }], id: 1 },
|
|
466
|
-
}),
|
|
467
|
-
);
|
|
468
|
-
expect(res.sql).toBe(
|
|
469
|
-
'SELECT `id` FROM `User` WHERE `creatorId` = ? AND (`name` IN (?, ?, ?) OR `email` = ?) AND `id` = ?',
|
|
470
|
-
);
|
|
471
|
-
expect(res.values).toEqual([1, 'a', 'b', 'c', 'abc@example.com', 1]);
|
|
472
|
-
|
|
473
|
-
const res2 = this.exec((ctx) =>
|
|
474
|
-
this.dialect.find(ctx, User, {
|
|
475
|
-
$select: ['id'],
|
|
476
|
-
$where: {
|
|
477
|
-
creatorId: 1,
|
|
478
|
-
$or: [{ name: ['a', 'b', 'c'] }, { email: 'abc@example.com' }],
|
|
479
|
-
id: 1,
|
|
480
|
-
email: 'e',
|
|
481
|
-
},
|
|
482
|
-
}),
|
|
483
|
-
);
|
|
484
|
-
expect(res2.sql).toBe(
|
|
485
|
-
'SELECT `id` FROM `User` WHERE `creatorId` = ?' +
|
|
486
|
-
' AND (`name` IN (?, ?, ?) OR `email` = ?) AND `id` = ? AND `email` = ?',
|
|
487
|
-
);
|
|
488
|
-
expect(res2.values).toEqual([1, 'a', 'b', 'c', 'abc@example.com', 1, 'e']);
|
|
489
|
-
|
|
490
|
-
const res3 = this.exec((ctx) =>
|
|
491
|
-
this.dialect.find(ctx, User, {
|
|
492
|
-
$select: ['id'],
|
|
493
|
-
$where: {
|
|
494
|
-
creatorId: 1,
|
|
495
|
-
$or: [{ name: ['a', 'b', 'c'] }, { email: 'abc@example.com' }],
|
|
496
|
-
id: 1,
|
|
497
|
-
email: 'e',
|
|
498
|
-
},
|
|
499
|
-
$sort: { name: 1, createdAt: -1 },
|
|
500
|
-
$skip: 50,
|
|
501
|
-
$limit: 10,
|
|
502
|
-
}),
|
|
503
|
-
);
|
|
504
|
-
expect(res3.sql).toBe(
|
|
505
|
-
'SELECT `id` FROM `User` WHERE `creatorId` = ?' +
|
|
506
|
-
' AND (`name` IN (?, ?, ?) OR `email` = ?)' +
|
|
507
|
-
' AND `id` = ? AND `email` = ?' +
|
|
508
|
-
' ORDER BY `name`, `createdAt` DESC LIMIT 10 OFFSET 50',
|
|
509
|
-
);
|
|
510
|
-
expect(res3.values).toEqual([1, 'a', 'b', 'c', 'abc@example.com', 1, 'e']);
|
|
511
|
-
|
|
512
|
-
const res4 = this.exec((ctx) =>
|
|
513
|
-
this.dialect.find(ctx, User, {
|
|
514
|
-
$select: ['id'],
|
|
515
|
-
$where: {
|
|
516
|
-
$or: [
|
|
517
|
-
{
|
|
518
|
-
creatorId: 1,
|
|
519
|
-
id: 1,
|
|
520
|
-
email: 'e',
|
|
521
|
-
},
|
|
522
|
-
{ name: ['a', 'b', 'c'], email: 'abc@example.com' },
|
|
523
|
-
],
|
|
524
|
-
},
|
|
525
|
-
$sort: [
|
|
526
|
-
{ field: 'name', sort: 'asc' },
|
|
527
|
-
{ field: 'createdAt', sort: 'desc' },
|
|
528
|
-
],
|
|
529
|
-
$skip: 50,
|
|
530
|
-
$limit: 10,
|
|
531
|
-
}),
|
|
532
|
-
);
|
|
533
|
-
expect(res4.sql).toBe(
|
|
534
|
-
'SELECT `id` FROM `User` WHERE (`creatorId` = ? AND `id` = ? AND `email` = ?)' +
|
|
535
|
-
' OR (`name` IN (?, ?, ?) AND `email` = ?)' +
|
|
536
|
-
' ORDER BY `name`, `createdAt` DESC LIMIT 10 OFFSET 50',
|
|
537
|
-
);
|
|
538
|
-
expect(res4.values).toEqual([1, 1, 'e', 'a', 'b', 'c', 'abc@example.com']);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
shouldFindSingle$where() {
|
|
542
|
-
const { sql, values } = this.exec((ctx) =>
|
|
543
|
-
this.dialect.find(ctx, User, {
|
|
544
|
-
$select: ['id'],
|
|
545
|
-
$where: { name: 'some' },
|
|
546
|
-
$limit: 3,
|
|
547
|
-
}),
|
|
548
|
-
);
|
|
549
|
-
expect(sql).toBe('SELECT `id` FROM `User` WHERE `name` = ? LIMIT 3');
|
|
550
|
-
expect(values).toEqual(['some']);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
shouldFindMultipleComparisonOperators() {
|
|
554
|
-
let res = this.exec((ctx) =>
|
|
555
|
-
this.dialect.find(ctx, User, {
|
|
556
|
-
$select: ['id'],
|
|
557
|
-
$where: { $or: [{ name: { $eq: 'other', $ne: 'other unwanted' } }, { companyId: 1 }] },
|
|
558
|
-
}),
|
|
559
|
-
);
|
|
560
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE (`name` = ? AND `name` <> ?) OR `companyId` = ?');
|
|
561
|
-
expect(res.values).toEqual(['other', 'other unwanted', 1]);
|
|
562
|
-
|
|
563
|
-
res = this.exec((ctx) =>
|
|
564
|
-
this.dialect.find(ctx, User, {
|
|
565
|
-
$select: ['id'],
|
|
566
|
-
$where: { createdAt: { $gte: 123, $lte: 999 } },
|
|
567
|
-
$limit: 10,
|
|
568
|
-
}),
|
|
569
|
-
);
|
|
570
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE (`createdAt` >= ? AND `createdAt` <= ?) LIMIT 10');
|
|
571
|
-
expect(res.values).toEqual([123, 999]);
|
|
572
|
-
|
|
573
|
-
res = this.exec((ctx) =>
|
|
574
|
-
this.dialect.find(ctx, User, {
|
|
575
|
-
$select: ['id'],
|
|
576
|
-
$where: { createdAt: { $gt: 123, $lt: 999 } },
|
|
577
|
-
$limit: 10,
|
|
578
|
-
}),
|
|
579
|
-
);
|
|
580
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE (`createdAt` > ? AND `createdAt` < ?) LIMIT 10');
|
|
581
|
-
expect(res.values).toEqual([123, 999]);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
shouldFind$ne() {
|
|
585
|
-
const { sql, values } = this.exec((ctx) =>
|
|
586
|
-
this.dialect.find(ctx, User, {
|
|
587
|
-
$select: ['id'],
|
|
588
|
-
$where: { name: 'some', companyId: { $ne: 5 } },
|
|
589
|
-
$limit: 20,
|
|
590
|
-
}),
|
|
591
|
-
);
|
|
592
|
-
expect(sql).toBe('SELECT `id` FROM `User` WHERE `name` = ? AND `companyId` <> ? LIMIT 20');
|
|
593
|
-
expect(values).toEqual(['some', 5]);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
shouldFindIsNull() {
|
|
597
|
-
let res = this.exec((ctx) =>
|
|
598
|
-
this.dialect.find(ctx, User, {
|
|
599
|
-
$select: ['id'],
|
|
600
|
-
$where: { creatorId: 123, companyId: null },
|
|
601
|
-
$limit: 5,
|
|
602
|
-
}),
|
|
603
|
-
);
|
|
604
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `creatorId` = ? AND `companyId` IS NULL LIMIT 5');
|
|
605
|
-
expect(res.values).toEqual([123]);
|
|
606
|
-
|
|
607
|
-
res = this.exec((ctx) =>
|
|
608
|
-
this.dialect.find(ctx, User, {
|
|
609
|
-
$select: ['id'],
|
|
610
|
-
$where: { creatorId: 123, companyId: { $ne: null } },
|
|
611
|
-
$limit: 5,
|
|
612
|
-
}),
|
|
613
|
-
);
|
|
614
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `creatorId` = ? AND `companyId` IS NOT NULL LIMIT 5');
|
|
615
|
-
expect(res.values).toEqual([123]);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
shouldFind$in() {
|
|
619
|
-
let res = this.exec((ctx) =>
|
|
620
|
-
this.dialect.find(ctx, User, {
|
|
621
|
-
$select: ['id'],
|
|
622
|
-
$where: { name: 'some', companyId: [1, 2, 3] },
|
|
623
|
-
$limit: 10,
|
|
624
|
-
}),
|
|
625
|
-
);
|
|
626
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` = ? AND `companyId` IN (?, ?, ?) LIMIT 10');
|
|
627
|
-
expect(res.values).toEqual(['some', 1, 2, 3]);
|
|
628
|
-
|
|
629
|
-
res = this.exec((ctx) =>
|
|
630
|
-
this.dialect.find(ctx, User, {
|
|
631
|
-
$select: ['id'],
|
|
632
|
-
$where: { name: 'some', companyId: { $in: [1, 2, 3] } },
|
|
633
|
-
$limit: 10,
|
|
634
|
-
}),
|
|
635
|
-
);
|
|
636
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` = ? AND `companyId` IN (?, ?, ?) LIMIT 10');
|
|
637
|
-
expect(res.values).toEqual(['some', 1, 2, 3]);
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
shouldFind$nin() {
|
|
641
|
-
const { sql, values } = this.exec((ctx) =>
|
|
642
|
-
this.dialect.find(ctx, User, {
|
|
643
|
-
$select: ['id'],
|
|
644
|
-
$where: { name: 'some', companyId: { $nin: [1, 2, 3] } },
|
|
645
|
-
$limit: 10,
|
|
646
|
-
}),
|
|
647
|
-
);
|
|
648
|
-
expect(sql).toBe('SELECT `id` FROM `User` WHERE `name` = ? AND `companyId` NOT IN (?, ?, ?) LIMIT 10');
|
|
649
|
-
expect(values).toEqual(['some', 1, 2, 3]);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
shouldFind$selectFields() {
|
|
653
|
-
const { sql } = this.exec((ctx) => this.dialect.find(ctx, User, { $select: { id: true, company: true } }));
|
|
654
|
-
expect(sql).toBe(
|
|
655
|
-
'SELECT `User`.`id`, `company`.`id` `company_id`, `company`.`companyId` `company_companyId`, `company`.`creatorId` `company_creatorId`' +
|
|
656
|
-
', `company`.`createdAt` `company_createdAt`, `company`.`updatedAt` `company_updatedAt`' +
|
|
657
|
-
', `company`.`name` `company_name`, `company`.`description` `company_description`, `company`.`kind` `company_kind`' +
|
|
658
|
-
' FROM `User` LEFT JOIN `Company` `company` ON `company`.`id` = `User`.`companyId`',
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
shouldFind$selectOneToOne() {
|
|
663
|
-
let res = this.exec((ctx) =>
|
|
664
|
-
this.dialect.find(ctx, User, { $select: { id: true, name: true, profile: ['id', 'picture'] } }),
|
|
665
|
-
);
|
|
666
|
-
expect(res.sql).toBe(
|
|
667
|
-
'SELECT `User`.`id`, `User`.`name`, `profile`.`pk` `profile_pk`, `profile`.`image` `profile_picture` FROM `User`' +
|
|
668
|
-
' LEFT JOIN `user_profile` `profile` ON `profile`.`creatorId` = `User`.`id`',
|
|
669
|
-
);
|
|
670
|
-
|
|
671
|
-
res = this.exec((ctx) => this.dialect.find(ctx, User, { $select: { profile: true } }));
|
|
672
|
-
expect(res.sql).toBe(
|
|
673
|
-
'SELECT `User`.`id`, `profile`.`companyId` `profile_companyId`' +
|
|
674
|
-
', `profile`.`creatorId` `profile_creatorId`, `profile`.`createdAt` `profile_createdAt`' +
|
|
675
|
-
', `profile`.`updatedAt` `profile_updatedAt`' +
|
|
676
|
-
', `profile`.`pk` `profile_pk`, `profile`.`image` `profile_picture`' +
|
|
677
|
-
' FROM `User` LEFT JOIN `user_profile` `profile` ON `profile`.`creatorId` = `User`.`id`',
|
|
678
|
-
);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
shouldFind$selectManyToOne() {
|
|
682
|
-
const { sql } = this.exec((ctx) =>
|
|
683
|
-
this.dialect.find(ctx, Item, {
|
|
684
|
-
$select: {
|
|
685
|
-
id: true,
|
|
686
|
-
name: true,
|
|
687
|
-
code: true,
|
|
688
|
-
tax: { $select: ['id', 'name'], $required: true },
|
|
689
|
-
measureUnit: { $select: ['id', 'name', 'categoryId'] },
|
|
690
|
-
},
|
|
691
|
-
$limit: 100,
|
|
692
|
-
}),
|
|
693
|
-
);
|
|
694
|
-
expect(sql).toBe(
|
|
695
|
-
'SELECT `Item`.`id`, `Item`.`name`, `Item`.`code`' +
|
|
696
|
-
', `tax`.`id` `tax_id`, `tax`.`name` `tax_name`' +
|
|
697
|
-
', `measureUnit`.`id` `measureUnit_id`, `measureUnit`.`name` `measureUnit_name`, `measureUnit`.`categoryId` `measureUnit_categoryId`' +
|
|
698
|
-
' FROM `Item`' +
|
|
699
|
-
' INNER JOIN `Tax` `tax` ON `tax`.`id` = `Item`.`taxId`' +
|
|
700
|
-
' LEFT JOIN `MeasureUnit` `measureUnit` ON `measureUnit`.`id` = `Item`.`measureUnitId`' +
|
|
701
|
-
' LIMIT 100',
|
|
702
|
-
);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
shouldFind$selectWithAllFieldsAndSpecificFieldsAndWhere() {
|
|
706
|
-
const { sql, values } = this.exec((ctx) =>
|
|
707
|
-
this.dialect.find(ctx, Item, {
|
|
708
|
-
$select: {
|
|
709
|
-
id: true,
|
|
710
|
-
name: true,
|
|
711
|
-
measureUnit: { $select: ['id', 'name'], $where: { name: { $ne: 'unidad' } }, $required: true },
|
|
712
|
-
tax: ['id', 'name'],
|
|
713
|
-
},
|
|
714
|
-
$where: { salePrice: { $gte: 1000 }, name: { $istartsWith: 'A' } },
|
|
715
|
-
$sort: { tax: { name: 1 }, measureUnit: { name: 1 }, createdAt: -1 },
|
|
716
|
-
$limit: 100,
|
|
717
|
-
}),
|
|
718
|
-
);
|
|
719
|
-
expect(sql).toBe(
|
|
720
|
-
'SELECT `Item`.`id`, `Item`.`name`' +
|
|
721
|
-
', `measureUnit`.`id` `measureUnit_id`, `measureUnit`.`name` `measureUnit_name`' +
|
|
722
|
-
', `tax`.`id` `tax_id`, `tax`.`name` `tax_name`' +
|
|
723
|
-
' FROM `Item`' +
|
|
724
|
-
' INNER JOIN `MeasureUnit` `measureUnit` ON `measureUnit`.`id` = `Item`.`measureUnitId` AND `measureUnit`.`name` <> ? AND `measureUnit`.`deletedAt` IS NULL' +
|
|
725
|
-
' LEFT JOIN `Tax` `tax` ON `tax`.`id` = `Item`.`taxId`' +
|
|
726
|
-
' WHERE `Item`.`salePrice` >= ? AND `Item`.`name` LIKE ?' +
|
|
727
|
-
' ORDER BY `tax`.`name`, `measureUnit`.`name`, `Item`.`createdAt` DESC LIMIT 100',
|
|
728
|
-
);
|
|
729
|
-
expect(values).toEqual(['unidad', 1000, 'a%']);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
shouldVirtualField() {
|
|
733
|
-
let res = this.exec((ctx) =>
|
|
734
|
-
this.dialect.find(ctx, Item, {
|
|
735
|
-
$select: {
|
|
736
|
-
id: 1,
|
|
737
|
-
},
|
|
738
|
-
$where: {
|
|
739
|
-
tagsCount: { $gte: 10 },
|
|
740
|
-
},
|
|
741
|
-
}),
|
|
742
|
-
);
|
|
743
|
-
expect(res.sql).toBe(
|
|
744
|
-
'SELECT `id` FROM `Item` WHERE (SELECT COUNT(*) `count` FROM `ItemTag` WHERE `ItemTag`.`itemId` = `id`) >= ?',
|
|
745
|
-
);
|
|
746
|
-
expect(res.values).toEqual([10]);
|
|
747
|
-
|
|
748
|
-
res = this.exec((ctx) =>
|
|
749
|
-
this.dialect.find(ctx, Item, {
|
|
750
|
-
$select: {
|
|
751
|
-
id: 1,
|
|
752
|
-
name: 1,
|
|
753
|
-
code: 1,
|
|
754
|
-
tagsCount: 1,
|
|
755
|
-
measureUnit: {
|
|
756
|
-
$select: { id: 1, name: 1, categoryId: 1, category: ['name'] },
|
|
757
|
-
},
|
|
758
|
-
},
|
|
759
|
-
$limit: 100,
|
|
760
|
-
}),
|
|
761
|
-
);
|
|
762
|
-
expect(res.sql).toBe(
|
|
763
|
-
'SELECT `Item`.`id`, `Item`.`name`, `Item`.`code`' +
|
|
764
|
-
', (SELECT COUNT(*) `count` FROM `ItemTag` WHERE `ItemTag`.`itemId` = `Item`.`id`) `tagsCount`' +
|
|
765
|
-
', `measureUnit`.`id` `measureUnit_id`, `measureUnit`.`name` `measureUnit_name`, `measureUnit`.`categoryId` `measureUnit_categoryId`' +
|
|
766
|
-
', `measureUnit.category`.`id` `measureUnit_category_id`, `measureUnit.category`.`name` `measureUnit_category_name`' +
|
|
767
|
-
' FROM `Item` LEFT JOIN `MeasureUnit` `measureUnit` ON `measureUnit`.`id` = `Item`.`measureUnitId`' +
|
|
768
|
-
' LEFT JOIN `MeasureUnitCategory` `measureUnit.category` ON `measureUnit.category`.`id` = `measureUnit`.`categoryId`' +
|
|
769
|
-
' LIMIT 100',
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
shouldFind$selectDeep() {
|
|
774
|
-
let res = this.exec((ctx) =>
|
|
775
|
-
this.dialect.find(ctx, Item, {
|
|
776
|
-
$select: {
|
|
777
|
-
id: 1,
|
|
778
|
-
name: 1,
|
|
779
|
-
code: 1,
|
|
780
|
-
measureUnit: {
|
|
781
|
-
$select: { id: 1, name: 1, categoryId: 1, category: ['name'] },
|
|
782
|
-
},
|
|
783
|
-
},
|
|
784
|
-
$limit: 100,
|
|
785
|
-
}),
|
|
786
|
-
);
|
|
787
|
-
expect(res.sql).toBe(
|
|
788
|
-
'SELECT `Item`.`id`, `Item`.`name`, `Item`.`code`' +
|
|
789
|
-
', `measureUnit`.`id` `measureUnit_id`' +
|
|
790
|
-
', `measureUnit`.`name` `measureUnit_name`, `measureUnit`.`categoryId` `measureUnit_categoryId`' +
|
|
791
|
-
', `measureUnit.category`.`id` `measureUnit_category_id`, `measureUnit.category`.`name` `measureUnit_category_name`' +
|
|
792
|
-
' FROM `Item` LEFT JOIN `MeasureUnit` `measureUnit` ON `measureUnit`.`id` = `Item`.`measureUnitId`' +
|
|
793
|
-
' LEFT JOIN `MeasureUnitCategory` `measureUnit.category` ON `measureUnit.category`.`id` = `measureUnit`.`categoryId`' +
|
|
794
|
-
' LIMIT 100',
|
|
795
|
-
);
|
|
796
|
-
|
|
797
|
-
res = this.exec((ctx) =>
|
|
798
|
-
this.dialect.find(ctx, Item, {
|
|
799
|
-
$select: {
|
|
800
|
-
id: true,
|
|
801
|
-
name: true,
|
|
802
|
-
code: true,
|
|
803
|
-
measureUnit: {
|
|
804
|
-
$select: { id: true, name: true, category: { $select: { id: true, name: true } } },
|
|
805
|
-
},
|
|
806
|
-
},
|
|
807
|
-
$limit: 100,
|
|
808
|
-
}),
|
|
809
|
-
);
|
|
810
|
-
expect(res.sql).toBe(
|
|
811
|
-
'SELECT `Item`.`id`, `Item`.`name`, `Item`.`code`, `measureUnit`.`id` `measureUnit_id`' +
|
|
812
|
-
', `measureUnit`.`name` `measureUnit_name`, `measureUnit.category`.`id` `measureUnit_category_id`' +
|
|
813
|
-
', `measureUnit.category`.`name` `measureUnit_category_name`' +
|
|
814
|
-
' FROM `Item` LEFT JOIN `MeasureUnit` `measureUnit` ON `measureUnit`.`id` = `Item`.`measureUnitId`' +
|
|
815
|
-
' LEFT JOIN `MeasureUnitCategory` `measureUnit.category` ON `measureUnit.category`.`id` = `measureUnit`.`categoryId`' +
|
|
816
|
-
' LIMIT 100',
|
|
817
|
-
);
|
|
818
|
-
|
|
819
|
-
res = this.exec((ctx) =>
|
|
820
|
-
this.dialect.find(ctx, ItemAdjustment, {
|
|
821
|
-
$select: {
|
|
822
|
-
id: true,
|
|
823
|
-
buyPrice: true,
|
|
824
|
-
number: true,
|
|
825
|
-
item: {
|
|
826
|
-
$select: {
|
|
827
|
-
id: true,
|
|
828
|
-
name: true,
|
|
829
|
-
measureUnit: {
|
|
830
|
-
$select: { id: true, name: true, category: ['id', 'name'] },
|
|
831
|
-
},
|
|
832
|
-
},
|
|
833
|
-
$required: true,
|
|
834
|
-
},
|
|
835
|
-
},
|
|
836
|
-
$limit: 100,
|
|
837
|
-
}),
|
|
838
|
-
);
|
|
839
|
-
expect(res.sql).toBe(
|
|
840
|
-
'SELECT `ItemAdjustment`.`id`, `ItemAdjustment`.`buyPrice`, `ItemAdjustment`.`number`' +
|
|
841
|
-
', `item`.`id` `item_id`, `item`.`name` `item_name`' +
|
|
842
|
-
', `item.measureUnit`.`id` `item_measureUnit_id`, `item.measureUnit`.`name` `item_measureUnit_name`' +
|
|
843
|
-
', `item.measureUnit.category`.`id` `item_measureUnit_category_id`, `item.measureUnit.category`.`name` `item_measureUnit_category_name`' +
|
|
844
|
-
' FROM `ItemAdjustment`' +
|
|
845
|
-
' INNER JOIN `Item` `item` ON `item`.`id` = `ItemAdjustment`.`itemId`' +
|
|
846
|
-
' LEFT JOIN `MeasureUnit` `item.measureUnit` ON `item.measureUnit`.`id` = `item`.`measureUnitId`' +
|
|
847
|
-
' LEFT JOIN `MeasureUnitCategory` `item.measureUnit.category` ON `item.measureUnit.category`.`id` = `item.measureUnit`.`categoryId`' +
|
|
848
|
-
' LIMIT 100',
|
|
849
|
-
);
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
shouldFind$limit() {
|
|
853
|
-
let res = this.exec((ctx) =>
|
|
854
|
-
this.dialect.find(ctx, User, {
|
|
855
|
-
$select: ['id'],
|
|
856
|
-
$where: 9,
|
|
857
|
-
$limit: 1,
|
|
858
|
-
}),
|
|
859
|
-
);
|
|
860
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `id` = ? LIMIT 1');
|
|
861
|
-
expect(res.values).toEqual([9]);
|
|
862
|
-
|
|
863
|
-
res = this.exec((ctx) =>
|
|
864
|
-
this.dialect.find(ctx, User, {
|
|
865
|
-
$select: { id: 1, name: 1, creatorId: 1 },
|
|
866
|
-
$where: 9,
|
|
867
|
-
$limit: 1,
|
|
868
|
-
}),
|
|
869
|
-
);
|
|
870
|
-
expect(res.sql).toBe('SELECT `id`, `name`, `creatorId` FROM `User` WHERE `id` = ? LIMIT 1');
|
|
871
|
-
expect(res.values).toEqual([9]);
|
|
872
|
-
|
|
873
|
-
res = this.exec((ctx) =>
|
|
874
|
-
this.dialect.find(ctx, User, {
|
|
875
|
-
$select: ['id'],
|
|
876
|
-
$where: { name: 'something', creatorId: 123 },
|
|
877
|
-
$limit: 1,
|
|
878
|
-
}),
|
|
879
|
-
);
|
|
880
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` = ? AND `creatorId` = ? LIMIT 1');
|
|
881
|
-
expect(res.values).toEqual(['something', 123]);
|
|
882
|
-
|
|
883
|
-
res = this.exec((ctx) =>
|
|
884
|
-
this.dialect.find(ctx, User, {
|
|
885
|
-
$select: ['id', 'name', 'creatorId'],
|
|
886
|
-
$limit: 25,
|
|
887
|
-
}),
|
|
888
|
-
);
|
|
889
|
-
expect(res.sql).toBe('SELECT `id`, `name`, `creatorId` FROM `User` LIMIT 25');
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
shouldFind$skip() {
|
|
893
|
-
const res = this.exec((ctx) =>
|
|
894
|
-
this.dialect.find(ctx, User, {
|
|
895
|
-
$select: { id: 1, name: 1, creatorId: 1 },
|
|
896
|
-
$skip: 30,
|
|
897
|
-
}),
|
|
898
|
-
);
|
|
899
|
-
expect(res.sql).toBe('SELECT `id`, `name`, `creatorId` FROM `User` OFFSET 30');
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
shouldFind$select() {
|
|
903
|
-
let res = this.exec((ctx) => this.dialect.find(ctx, User, { $select: { password: false } }));
|
|
904
|
-
expect(res.sql).toBe(
|
|
905
|
-
'SELECT `id`, `companyId`, `creatorId`, `createdAt`, `updatedAt`, `name`, `email` FROM `User`',
|
|
906
|
-
);
|
|
907
|
-
|
|
908
|
-
res = this.exec((ctx) => this.dialect.find(ctx, User, { $select: { name: 0, password: 0 } }));
|
|
909
|
-
expect(res.sql).toBe('SELECT `id`, `companyId`, `creatorId`, `createdAt`, `updatedAt`, `email` FROM `User`');
|
|
910
|
-
|
|
911
|
-
res = this.exec((ctx) => this.dialect.find(ctx, User, { $select: { id: 1, name: 1, password: 0 } }));
|
|
912
|
-
expect(res.sql).toBe('SELECT `id`, `name` FROM `User`');
|
|
913
|
-
|
|
914
|
-
res = this.exec((ctx) => this.dialect.find(ctx, User, { $select: { id: 1, name: 0, password: 0 } }));
|
|
915
|
-
expect(res.sql).toBe('SELECT `id` FROM `User`');
|
|
916
|
-
|
|
917
|
-
res = this.exec((ctx) =>
|
|
918
|
-
this.dialect.find(ctx, User, {
|
|
919
|
-
$select: [raw('*'), raw('LOG10(numberOfVotes + 1) * 287014.5873982681 + createdAt', 'hotness')],
|
|
920
|
-
$where: { name: 'something' },
|
|
921
|
-
}),
|
|
922
|
-
);
|
|
923
|
-
expect(res.sql).toBe(
|
|
924
|
-
'SELECT *, LOG10(numberOfVotes + 1) * 287014.5873982681 + createdAt `hotness` FROM `User` WHERE `name` = ?',
|
|
925
|
-
);
|
|
926
|
-
expect(res.values).toEqual(['something']);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
shouldDelete() {
|
|
930
|
-
let res = this.exec((ctx) => this.dialect.delete(ctx, User, { $where: 123 }));
|
|
931
|
-
expect(res.sql).toBe('DELETE FROM `User` WHERE `id` = ?');
|
|
932
|
-
expect(res.values).toEqual([123]);
|
|
933
|
-
|
|
934
|
-
expect(() => this.exec((ctx) => this.dialect.delete(ctx, User, { $where: 123 }, { softDelete: true }))).toThrow(
|
|
935
|
-
"'User' has not enabled 'softDelete'",
|
|
936
|
-
);
|
|
937
|
-
|
|
938
|
-
res = this.exec((ctx) => this.dialect.delete(ctx, User, { $where: 123 }, { softDelete: false }));
|
|
939
|
-
expect(res.sql).toBe('DELETE FROM `User` WHERE `id` = ?');
|
|
940
|
-
expect(res.values).toEqual([123]);
|
|
941
|
-
|
|
942
|
-
res = this.exec((ctx) => this.dialect.delete(ctx, MeasureUnit, { $where: 123 }));
|
|
943
|
-
expect(res.sql).toMatch(/^UPDATE `MeasureUnit` SET `deletedAt` = \? WHERE `id` = \? AND `deletedAt` IS NULL$/);
|
|
944
|
-
expect(res.values).toEqual([expect.any(Number), 123]);
|
|
945
|
-
|
|
946
|
-
res = this.exec((ctx) => this.dialect.delete(ctx, MeasureUnit, { $where: 123 }, { softDelete: true }));
|
|
947
|
-
expect(res.sql).toMatch(/^UPDATE `MeasureUnit` SET `deletedAt` = \? WHERE `id` = \? AND `deletedAt` IS NULL$/);
|
|
948
|
-
expect(res.values).toEqual([expect.any(Number), 123]);
|
|
949
|
-
|
|
950
|
-
res = this.exec((ctx) => this.dialect.delete(ctx, MeasureUnit, { $where: 123 }, { softDelete: false }));
|
|
951
|
-
expect(res.sql).toBe('DELETE FROM `MeasureUnit` WHERE `id` = ?');
|
|
952
|
-
expect(res.values).toEqual([123]);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
shouldFind$selectRaw() {
|
|
956
|
-
let res = this.exec((ctx) =>
|
|
957
|
-
this.dialect.find(ctx, User, {
|
|
958
|
-
$select: [raw(() => 'createdAt', 'hotness')],
|
|
959
|
-
$where: { name: 'something' },
|
|
960
|
-
}),
|
|
961
|
-
);
|
|
962
|
-
expect(res.sql).toBe('SELECT createdAt `hotness` FROM `User` WHERE `name` = ?');
|
|
963
|
-
expect(res.values).toEqual(['something']);
|
|
964
|
-
|
|
965
|
-
res = this.exec((ctx) =>
|
|
966
|
-
this.dialect.find(ctx, User, {
|
|
967
|
-
$select: [raw('*'), raw('LOG10(numberOfVotes + 1) * 287014.5873982681 + createdAt', 'hotness')],
|
|
968
|
-
$where: { name: 'something' },
|
|
969
|
-
}),
|
|
970
|
-
);
|
|
971
|
-
expect(res.sql).toBe(
|
|
972
|
-
'SELECT *, LOG10(numberOfVotes + 1) * 287014.5873982681 + createdAt `hotness` FROM `User` WHERE `name` = ?',
|
|
973
|
-
);
|
|
974
|
-
expect(res.values).toEqual(['something']);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
shouldFind$whereRaw() {
|
|
978
|
-
let res = this.exec((ctx) =>
|
|
979
|
-
this.dialect.find(ctx, Item, {
|
|
980
|
-
$select: ['creatorId'],
|
|
981
|
-
$where: { $and: [{ companyId: 1 }, raw('SUM(salePrice) > 500')] },
|
|
982
|
-
}),
|
|
983
|
-
);
|
|
984
|
-
expect(res.sql).toBe('SELECT `creatorId` FROM `Item` WHERE `companyId` = ? AND SUM(salePrice) > 500');
|
|
985
|
-
expect(res.values).toEqual([1]);
|
|
986
|
-
|
|
987
|
-
res = this.exec((ctx) =>
|
|
988
|
-
this.dialect.find(ctx, Item, {
|
|
989
|
-
$select: ['id'],
|
|
990
|
-
$where: { $or: [{ companyId: 1 }, 5, raw('SUM(salePrice) > 500')] },
|
|
991
|
-
}),
|
|
992
|
-
);
|
|
993
|
-
expect(res.sql).toBe('SELECT `id` FROM `Item` WHERE `companyId` = ? OR `id` = ? OR SUM(salePrice) > 500');
|
|
994
|
-
expect(res.values).toEqual([1, 5]);
|
|
995
|
-
|
|
996
|
-
res = this.exec((ctx) =>
|
|
997
|
-
this.dialect.find(ctx, Item, {
|
|
998
|
-
$select: ['id'],
|
|
999
|
-
$where: { $or: [1, raw('SUM(salePrice) > 500')] },
|
|
1000
|
-
}),
|
|
1001
|
-
);
|
|
1002
|
-
expect(res.sql).toBe('SELECT `id` FROM `Item` WHERE `id` = ? OR SUM(salePrice) > 500');
|
|
1003
|
-
expect(res.values).toEqual([1]);
|
|
1004
|
-
|
|
1005
|
-
res = this.exec((ctx) =>
|
|
1006
|
-
this.dialect.find(ctx, Item, {
|
|
1007
|
-
$select: ['id'],
|
|
1008
|
-
$where: { $or: [raw('SUM(salePrice) > 500'), 1, { companyId: 1 }] },
|
|
1009
|
-
}),
|
|
1010
|
-
);
|
|
1011
|
-
expect(res.sql).toBe('SELECT `id` FROM `Item` WHERE SUM(salePrice) > 500 OR `id` = ? OR `companyId` = ?');
|
|
1012
|
-
expect(res.values).toEqual([1, 1]);
|
|
1013
|
-
|
|
1014
|
-
res = this.exec((ctx) =>
|
|
1015
|
-
this.dialect.find(ctx, Item, {
|
|
1016
|
-
$select: ['id'],
|
|
1017
|
-
$where: { $and: [raw('SUM(salePrice) > 500')] },
|
|
1018
|
-
}),
|
|
1019
|
-
);
|
|
1020
|
-
expect(res.sql).toBe('SELECT `id` FROM `Item` WHERE SUM(salePrice) > 500');
|
|
1021
|
-
|
|
1022
|
-
res = this.exec((ctx) =>
|
|
1023
|
-
this.dialect.find(ctx, Item, {
|
|
1024
|
-
$select: ['id'],
|
|
1025
|
-
$where: raw('SUM(salePrice) > 500'),
|
|
1026
|
-
}),
|
|
1027
|
-
);
|
|
1028
|
-
expect(res.sql).toBe('SELECT `id` FROM `Item` WHERE SUM(salePrice) > 500');
|
|
1029
|
-
|
|
1030
|
-
res = this.exec((ctx) =>
|
|
1031
|
-
this.dialect.find(ctx, Item, {
|
|
1032
|
-
$select: ['creatorId'],
|
|
1033
|
-
$where: { $or: [[1, 2], { code: 'abc' }] },
|
|
1034
|
-
}),
|
|
1035
|
-
);
|
|
1036
|
-
expect(res.sql).toBe('SELECT `creatorId` FROM `Item` WHERE `id` IN (?, ?) OR `code` = ?');
|
|
1037
|
-
expect(res.values).toEqual([1, 2, 'abc']);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
shouldFind$startsWith() {
|
|
1041
|
-
let res = this.exec((ctx) =>
|
|
1042
|
-
this.dialect.find(ctx, User, {
|
|
1043
|
-
$select: ['id'],
|
|
1044
|
-
$where: { name: { $startsWith: 'Some' } },
|
|
1045
|
-
$sort: [
|
|
1046
|
-
{ field: 'name', sort: 'asc' },
|
|
1047
|
-
{ field: 'createdAt', sort: 'desc' },
|
|
1048
|
-
],
|
|
1049
|
-
$skip: 0,
|
|
1050
|
-
$limit: 50,
|
|
1051
|
-
}),
|
|
1052
|
-
);
|
|
1053
|
-
expect(res.sql).toBe(
|
|
1054
|
-
'SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `createdAt` DESC LIMIT 50 OFFSET 0',
|
|
1055
|
-
);
|
|
1056
|
-
expect(res.values).toEqual(['Some%']);
|
|
1057
|
-
|
|
1058
|
-
res = this.exec((ctx) =>
|
|
1059
|
-
this.dialect.find(ctx, User, {
|
|
1060
|
-
$select: { id: true },
|
|
1061
|
-
$where: { name: { $startsWith: 'Some', $ne: 'Something' } },
|
|
1062
|
-
$sort: { name: 1, id: -1 },
|
|
1063
|
-
$skip: 0,
|
|
1064
|
-
$limit: 50,
|
|
1065
|
-
}),
|
|
1066
|
-
);
|
|
1067
|
-
expect(res.sql).toBe(
|
|
1068
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1069
|
-
);
|
|
1070
|
-
expect(res.values).toEqual(['Some%', 'Something']);
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
shouldFind$istartsWith() {
|
|
1074
|
-
let res = this.exec((ctx) =>
|
|
1075
|
-
this.dialect.find(ctx, User, {
|
|
1076
|
-
$select: ['id'],
|
|
1077
|
-
$where: { name: { $istartsWith: 'Some' } },
|
|
1078
|
-
$sort: { name: 1, id: -1 },
|
|
1079
|
-
$skip: 0,
|
|
1080
|
-
$limit: 50,
|
|
1081
|
-
}),
|
|
1082
|
-
);
|
|
1083
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1084
|
-
expect(res.values).toEqual(['some%']);
|
|
1085
|
-
|
|
1086
|
-
res = this.exec((ctx) =>
|
|
1087
|
-
this.dialect.find(ctx, User, {
|
|
1088
|
-
$select: { id: true },
|
|
1089
|
-
$where: { name: { $istartsWith: 'Some', $ne: 'Something' } },
|
|
1090
|
-
$sort: { name: 1, id: -1 },
|
|
1091
|
-
$skip: 0,
|
|
1092
|
-
$limit: 50,
|
|
1093
|
-
}),
|
|
1094
|
-
);
|
|
1095
|
-
expect(res.sql).toBe(
|
|
1096
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1097
|
-
);
|
|
1098
|
-
expect(res.values).toEqual(['some%', 'Something']);
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
shouldFind$endsWith() {
|
|
1102
|
-
let res = this.exec((ctx) =>
|
|
1103
|
-
this.dialect.find(ctx, User, {
|
|
1104
|
-
$select: ['id'],
|
|
1105
|
-
$where: { name: { $endsWith: 'Some' } },
|
|
1106
|
-
$sort: { name: 1, id: -1 },
|
|
1107
|
-
$skip: 0,
|
|
1108
|
-
$limit: 50,
|
|
1109
|
-
}),
|
|
1110
|
-
);
|
|
1111
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1112
|
-
expect(res.values).toEqual(['%Some']);
|
|
1113
|
-
|
|
1114
|
-
res = this.exec((ctx) =>
|
|
1115
|
-
this.dialect.find(ctx, User, {
|
|
1116
|
-
$select: ['id'],
|
|
1117
|
-
$where: { name: { $endsWith: 'Some', $ne: 'Something' } },
|
|
1118
|
-
$sort: { name: 1, id: -1 },
|
|
1119
|
-
$skip: 0,
|
|
1120
|
-
$limit: 50,
|
|
1121
|
-
}),
|
|
1122
|
-
);
|
|
1123
|
-
expect(res.sql).toBe(
|
|
1124
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1125
|
-
);
|
|
1126
|
-
expect(res.values).toEqual(['%Some', 'Something']);
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
shouldFind$iendsWith() {
|
|
1130
|
-
let res = this.exec((ctx) =>
|
|
1131
|
-
this.dialect.find(ctx, User, {
|
|
1132
|
-
$select: ['id'],
|
|
1133
|
-
$where: { name: { $iendsWith: 'Some' } },
|
|
1134
|
-
$sort: { name: 1, id: -1 },
|
|
1135
|
-
$skip: 0,
|
|
1136
|
-
$limit: 50,
|
|
1137
|
-
}),
|
|
1138
|
-
);
|
|
1139
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1140
|
-
expect(res.values).toEqual(['%some']);
|
|
1141
|
-
|
|
1142
|
-
res = this.exec((ctx) =>
|
|
1143
|
-
this.dialect.find(ctx, User, {
|
|
1144
|
-
$select: ['id'],
|
|
1145
|
-
$where: { name: { $iendsWith: 'Some', $ne: 'Something' } },
|
|
1146
|
-
$sort: { name: 1, id: -1 },
|
|
1147
|
-
$skip: 0,
|
|
1148
|
-
$limit: 50,
|
|
1149
|
-
}),
|
|
1150
|
-
);
|
|
1151
|
-
expect(res.sql).toBe(
|
|
1152
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1153
|
-
);
|
|
1154
|
-
expect(res.values).toEqual(['%some', 'Something']);
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
shouldFind$includes() {
|
|
1158
|
-
let res = this.exec((ctx) =>
|
|
1159
|
-
this.dialect.find(ctx, User, {
|
|
1160
|
-
$select: ['id'],
|
|
1161
|
-
$where: { name: { $includes: 'Some' } },
|
|
1162
|
-
$sort: { name: 1, id: -1 },
|
|
1163
|
-
$skip: 0,
|
|
1164
|
-
$limit: 50,
|
|
1165
|
-
}),
|
|
1166
|
-
);
|
|
1167
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1168
|
-
expect(res.values).toEqual(['%Some%']);
|
|
1169
|
-
|
|
1170
|
-
res = this.exec((ctx) =>
|
|
1171
|
-
this.dialect.find(ctx, User, {
|
|
1172
|
-
$select: ['id'],
|
|
1173
|
-
$where: { name: { $includes: 'Some', $ne: 'Something' } },
|
|
1174
|
-
$sort: { name: 1, id: -1 },
|
|
1175
|
-
$skip: 0,
|
|
1176
|
-
$limit: 50,
|
|
1177
|
-
}),
|
|
1178
|
-
);
|
|
1179
|
-
expect(res.sql).toBe(
|
|
1180
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1181
|
-
);
|
|
1182
|
-
expect(res.values).toEqual(['%Some%', 'Something']);
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
shouldFind$iincludes() {
|
|
1186
|
-
let res = this.exec((ctx) =>
|
|
1187
|
-
this.dialect.find(ctx, User, {
|
|
1188
|
-
$select: ['id'],
|
|
1189
|
-
$where: { name: { $iincludes: 'Some' } },
|
|
1190
|
-
$sort: { name: 1, id: -1 },
|
|
1191
|
-
$skip: 0,
|
|
1192
|
-
$limit: 50,
|
|
1193
|
-
}),
|
|
1194
|
-
);
|
|
1195
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1196
|
-
expect(res.values).toEqual(['%some%']);
|
|
1197
|
-
|
|
1198
|
-
res = this.exec((ctx) =>
|
|
1199
|
-
this.dialect.find(ctx, User, {
|
|
1200
|
-
$select: ['id'],
|
|
1201
|
-
$where: { name: { $iincludes: 'Some', $ne: 'Something' } },
|
|
1202
|
-
$sort: { name: 1, id: -1 },
|
|
1203
|
-
$skip: 0,
|
|
1204
|
-
$limit: 50,
|
|
1205
|
-
}),
|
|
1206
|
-
);
|
|
1207
|
-
expect(res.sql).toBe(
|
|
1208
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1209
|
-
);
|
|
1210
|
-
expect(res.values).toEqual(['%some%', 'Something']);
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
shouldFind$like() {
|
|
1214
|
-
let res = this.exec((ctx) =>
|
|
1215
|
-
this.dialect.find(ctx, User, {
|
|
1216
|
-
$select: ['id'],
|
|
1217
|
-
$where: { name: { $like: 'Some' } },
|
|
1218
|
-
$sort: { name: 1, id: -1 },
|
|
1219
|
-
$skip: 0,
|
|
1220
|
-
$limit: 50,
|
|
1221
|
-
}),
|
|
1222
|
-
);
|
|
1223
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1224
|
-
expect(res.values).toEqual(['Some']);
|
|
1225
|
-
|
|
1226
|
-
res = this.exec((ctx) =>
|
|
1227
|
-
this.dialect.find(ctx, User, {
|
|
1228
|
-
$select: { id: true },
|
|
1229
|
-
$where: { name: { $like: 'Some', $ne: 'Something' } },
|
|
1230
|
-
$sort: { name: 1, id: -1 },
|
|
1231
|
-
$skip: 0,
|
|
1232
|
-
$limit: 50,
|
|
1233
|
-
}),
|
|
1234
|
-
);
|
|
1235
|
-
expect(res.sql).toBe(
|
|
1236
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1237
|
-
);
|
|
1238
|
-
expect(res.values).toEqual(['Some', 'Something']);
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
shouldFind$ilike() {
|
|
1242
|
-
let res = this.exec((ctx) =>
|
|
1243
|
-
this.dialect.find(ctx, User, {
|
|
1244
|
-
$select: ['id'],
|
|
1245
|
-
$where: { name: { $ilike: 'Some' } },
|
|
1246
|
-
$sort: { name: 1, id: -1 },
|
|
1247
|
-
$skip: 0,
|
|
1248
|
-
$limit: 50,
|
|
1249
|
-
}),
|
|
1250
|
-
);
|
|
1251
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` LIKE ? ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0');
|
|
1252
|
-
expect(res.values).toEqual(['some']);
|
|
1253
|
-
|
|
1254
|
-
res = this.exec((ctx) =>
|
|
1255
|
-
this.dialect.find(ctx, User, {
|
|
1256
|
-
$select: { id: 1 },
|
|
1257
|
-
$where: { name: { $ilike: 'Some', $ne: 'Something' } },
|
|
1258
|
-
$sort: { name: 1, id: -1 },
|
|
1259
|
-
$skip: 0,
|
|
1260
|
-
$limit: 50,
|
|
1261
|
-
}),
|
|
1262
|
-
);
|
|
1263
|
-
expect(res.sql).toBe(
|
|
1264
|
-
'SELECT `id` FROM `User` WHERE (`name` LIKE ? AND `name` <> ?) ORDER BY `name`, `id` DESC LIMIT 50 OFFSET 0',
|
|
1265
|
-
);
|
|
1266
|
-
expect(res.values).toEqual(['some', 'Something']);
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
shouldFind$regex() {
|
|
1270
|
-
const res = this.exec((ctx) =>
|
|
1271
|
-
this.dialect.find(ctx, User, {
|
|
1272
|
-
$select: ['id'],
|
|
1273
|
-
$where: { name: { $regex: '^some' } },
|
|
1274
|
-
}),
|
|
1275
|
-
);
|
|
1276
|
-
expect(res.sql).toBe('SELECT `id` FROM `User` WHERE `name` REGEXP ?');
|
|
1277
|
-
expect(res.values).toEqual(['^some']);
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
shouldFind$text() {
|
|
1281
|
-
let res = this.exec((ctx) =>
|
|
1282
|
-
this.dialect.find(ctx, Item, {
|
|
1283
|
-
$select: { id: true },
|
|
1284
|
-
$where: { $text: { $fields: ['name', 'description'], $value: 'some text' }, companyId: 1 },
|
|
1285
|
-
$limit: 30,
|
|
1286
|
-
}),
|
|
1287
|
-
);
|
|
1288
|
-
expect(res.sql).toBe(
|
|
1289
|
-
'SELECT `id` FROM `Item` WHERE MATCH(`name`, `description`) AGAINST(?) AND `companyId` = ? LIMIT 30',
|
|
1290
|
-
);
|
|
1291
|
-
expect(res.values).toEqual(['some text', 1]);
|
|
1292
|
-
|
|
1293
|
-
res = this.exec((ctx) =>
|
|
1294
|
-
this.dialect.find(ctx, User, {
|
|
1295
|
-
$select: { id: 1 },
|
|
1296
|
-
$where: {
|
|
1297
|
-
$text: { $fields: ['name'], $value: 'something' },
|
|
1298
|
-
name: { $ne: 'other unwanted' },
|
|
1299
|
-
companyId: 1,
|
|
1300
|
-
},
|
|
1301
|
-
$limit: 10,
|
|
1302
|
-
}),
|
|
1303
|
-
);
|
|
1304
|
-
expect(res.sql).toBe(
|
|
1305
|
-
'SELECT `id` FROM `User` WHERE MATCH(`name`) AGAINST(?) AND `name` <> ? AND `companyId` = ? LIMIT 10',
|
|
1306
|
-
);
|
|
1307
|
-
expect(res.values).toEqual(['something', 'other unwanted', 1]);
|
|
1308
|
-
}
|
|
1309
|
-
}
|