@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,979 +0,0 @@
|
|
|
1
|
-
import { expect, jest } from 'bun:test';
|
|
2
|
-
import {
|
|
3
|
-
clearTables,
|
|
4
|
-
createTables,
|
|
5
|
-
dropTables,
|
|
6
|
-
InventoryAdjustment,
|
|
7
|
-
Item,
|
|
8
|
-
MeasureUnit,
|
|
9
|
-
type Spec,
|
|
10
|
-
Tag,
|
|
11
|
-
User,
|
|
12
|
-
} from '../test/index.js';
|
|
13
|
-
import type { QuerierPool } from '../type/index.js';
|
|
14
|
-
import { raw } from '../util/index.js';
|
|
15
|
-
import type { AbstractSqlQuerier } from './abstractSqlQuerier.js';
|
|
16
|
-
|
|
17
|
-
export abstract class AbstractSqlQuerierSpec implements Spec {
|
|
18
|
-
querier: AbstractSqlQuerier;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
readonly pool: QuerierPool<AbstractSqlQuerier>,
|
|
22
|
-
readonly idType: string,
|
|
23
|
-
) {}
|
|
24
|
-
|
|
25
|
-
async beforeAll() {
|
|
26
|
-
this.querier = await this.pool.getQuerier();
|
|
27
|
-
await dropTables(this.querier);
|
|
28
|
-
await createTables(this.querier, this.idType);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async beforeEach() {
|
|
32
|
-
this.querier = await this.pool.getQuerier();
|
|
33
|
-
await clearTables(this.querier);
|
|
34
|
-
jest.spyOn(this.querier, 'all');
|
|
35
|
-
jest.spyOn(this.querier, 'run');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async afterEach() {
|
|
39
|
-
if (this.querier.hasOpenTransaction) {
|
|
40
|
-
await this.querier.rollbackTransaction();
|
|
41
|
-
}
|
|
42
|
-
await this.querier.release();
|
|
43
|
-
jest.restoreAllMocks();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async afterAll() {
|
|
47
|
-
await this.pool.end();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async shouldFindOneById() {
|
|
51
|
-
await this.querier.findOneById(User, 1);
|
|
52
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
53
|
-
1,
|
|
54
|
-
'SELECT `id`, `companyId`, `creatorId`, `createdAt`, `updatedAt`, `name`, `email` FROM `User` WHERE `id` = ? LIMIT 1',
|
|
55
|
-
[1],
|
|
56
|
-
);
|
|
57
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
58
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async shouldFindOne() {
|
|
62
|
-
await this.querier.findOne(User, { $select: ['id', 'name'], $where: { companyId: 123 } });
|
|
63
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
64
|
-
1,
|
|
65
|
-
'SELECT `id`, `name` FROM `User` WHERE `companyId` = ? LIMIT 1',
|
|
66
|
-
[123],
|
|
67
|
-
);
|
|
68
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
69
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async shouldFindOneAndSelectOneToMany() {
|
|
73
|
-
await this.querier.insertOne(InventoryAdjustment, {
|
|
74
|
-
id: 1,
|
|
75
|
-
description: 'something a',
|
|
76
|
-
createdAt: 1,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
80
|
-
1,
|
|
81
|
-
'INSERT INTO `InventoryAdjustment` (`id`, `description`, `createdAt`) VALUES (?, ?, ?)',
|
|
82
|
-
[1, 'something a', 1],
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
await this.querier.findOne(InventoryAdjustment, {
|
|
86
|
-
$select: { id: true, description: true, itemAdjustments: { $where: { id: [5, 6, 7] } } },
|
|
87
|
-
$where: { id: 1 },
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
91
|
-
1,
|
|
92
|
-
'SELECT `InventoryAdjustment`.`id`, `InventoryAdjustment`.`description` FROM `InventoryAdjustment` WHERE `InventoryAdjustment`.`id` = ? LIMIT 1',
|
|
93
|
-
[1],
|
|
94
|
-
);
|
|
95
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
96
|
-
2,
|
|
97
|
-
'SELECT `id`, `companyId`, `creatorId`, `createdAt`, `updatedAt`, `itemId`, `number`, `buyPrice`, `storehouseId`' +
|
|
98
|
-
', `inventoryAdjustmentId` FROM `ItemAdjustment` WHERE `id` IN (?, ?, ?) AND `inventoryAdjustmentId` IN (?)',
|
|
99
|
-
[5, 6, 7, 1],
|
|
100
|
-
);
|
|
101
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
102
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async shouldVirtualField() {
|
|
106
|
-
await this.querier.findMany(Item, {
|
|
107
|
-
$select: { id: 1 },
|
|
108
|
-
$where: {
|
|
109
|
-
tagsCount: { $gte: 10 },
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
expect(this.querier.all).toHaveBeenCalledWith(
|
|
114
|
-
'SELECT `id` FROM `Item` WHERE (SELECT COUNT(*) `count` FROM `ItemTag` WHERE `ItemTag`.`itemId` = `id`) >= ?',
|
|
115
|
-
[10],
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
119
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
120
|
-
jest.clearAllMocks();
|
|
121
|
-
|
|
122
|
-
await this.querier.findMany(Item, {
|
|
123
|
-
$select: {
|
|
124
|
-
id: 1,
|
|
125
|
-
name: 1,
|
|
126
|
-
code: 1,
|
|
127
|
-
tagsCount: 1,
|
|
128
|
-
measureUnit: {
|
|
129
|
-
$select: { id: 1, name: 1, categoryId: 1, category: ['name'] },
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
$limit: 100,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
expect(this.querier.all).toHaveBeenCalledWith(
|
|
136
|
-
'SELECT `Item`.`id`, `Item`.`name`, `Item`.`code`' +
|
|
137
|
-
', (SELECT COUNT(*) `count` FROM `ItemTag` WHERE `ItemTag`.`itemId` = `Item`.`id`) `tagsCount`' +
|
|
138
|
-
', `measureUnit`.`id` `measureUnit_id`, `measureUnit`.`name` `measureUnit_name`, `measureUnit`.`categoryId` `measureUnit_categoryId`' +
|
|
139
|
-
', `measureUnit.category`.`id` `measureUnit_category_id`, `measureUnit.category`.`name` `measureUnit_category_name`' +
|
|
140
|
-
' FROM `Item` LEFT JOIN `MeasureUnit` `measureUnit` ON `measureUnit`.`id` = `Item`.`measureUnitId`' +
|
|
141
|
-
' LEFT JOIN `MeasureUnitCategory` `measureUnit.category` ON `measureUnit.category`.`id` = `measureUnit`.`categoryId`' +
|
|
142
|
-
' LIMIT 100',
|
|
143
|
-
[],
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
147
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
148
|
-
|
|
149
|
-
jest.clearAllMocks();
|
|
150
|
-
|
|
151
|
-
await this.querier.findMany(Tag, {
|
|
152
|
-
$select: {
|
|
153
|
-
id: 1,
|
|
154
|
-
itemsCount: 1,
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
expect(this.querier.all).toHaveBeenCalledWith(
|
|
159
|
-
'SELECT `id`, (SELECT COUNT(*) `count` FROM `ItemTag` WHERE `ItemTag`.`tagId` = `id`) `itemsCount` FROM `Tag`',
|
|
160
|
-
[],
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
164
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async shouldFind$exists() {
|
|
168
|
-
await this.querier.findMany(Item, {
|
|
169
|
-
$select: {
|
|
170
|
-
id: 1,
|
|
171
|
-
},
|
|
172
|
-
$where: {
|
|
173
|
-
$exists: raw(({ ctx, dialect, escapedPrefix }) => {
|
|
174
|
-
dialect.find(ctx, User, {
|
|
175
|
-
$select: ['id'],
|
|
176
|
-
$where: {
|
|
177
|
-
companyId: raw(({ ctx: innerCtx }) => {
|
|
178
|
-
innerCtx.append(escapedPrefix + dialect.escapeId('companyId'));
|
|
179
|
-
}),
|
|
180
|
-
},
|
|
181
|
-
});
|
|
182
|
-
}),
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
expect(this.querier.all).toHaveBeenCalledWith(
|
|
187
|
-
'SELECT `id` FROM `Item` WHERE EXISTS (SELECT `id` FROM `User` WHERE `companyId` = `Item`.`companyId`)',
|
|
188
|
-
[],
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
192
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async shouldFind$nexists() {
|
|
196
|
-
await this.querier.findMany(Item, {
|
|
197
|
-
$select: { id: 1 },
|
|
198
|
-
$where: {
|
|
199
|
-
$nexists: raw(({ ctx, dialect, escapedPrefix }) => {
|
|
200
|
-
dialect.find(ctx, User, {
|
|
201
|
-
$select: ['id'],
|
|
202
|
-
$where: {
|
|
203
|
-
companyId: raw(({ ctx: innerCtx }) => {
|
|
204
|
-
innerCtx.append(escapedPrefix + dialect.escapeId('companyId'));
|
|
205
|
-
}),
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
}),
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
expect(this.querier.all).toHaveBeenCalledWith(
|
|
213
|
-
'SELECT `id` FROM `Item` WHERE NOT EXISTS (SELECT `id` FROM `User` WHERE `companyId` = `Item`.`companyId`)',
|
|
214
|
-
[],
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
218
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async shouldFindOneAndSelectOneToManyOnly() {
|
|
222
|
-
await this.querier.insertMany(InventoryAdjustment, [
|
|
223
|
-
{
|
|
224
|
-
id: 123,
|
|
225
|
-
createdAt: 1,
|
|
226
|
-
},
|
|
227
|
-
{ id: 456, createdAt: 1 },
|
|
228
|
-
]);
|
|
229
|
-
|
|
230
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
231
|
-
1,
|
|
232
|
-
'INSERT INTO `InventoryAdjustment` (`id`, `createdAt`) VALUES (?, ?), (?, ?)',
|
|
233
|
-
[123, 1, 456, 1],
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
await this.querier.findMany(InventoryAdjustment, {
|
|
237
|
-
$select: { itemAdjustments: ['id', 'buyPrice', 'itemId', 'creatorId', 'createdAt'] },
|
|
238
|
-
$where: { createdAt: 1 },
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
242
|
-
1,
|
|
243
|
-
'SELECT `InventoryAdjustment`.`id` FROM `InventoryAdjustment` WHERE `InventoryAdjustment`.`createdAt` = ?',
|
|
244
|
-
[1],
|
|
245
|
-
);
|
|
246
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
247
|
-
2,
|
|
248
|
-
'SELECT `id`, `buyPrice`, `itemId`, `creatorId`, `createdAt`, `inventoryAdjustmentId`' +
|
|
249
|
-
' FROM `ItemAdjustment` WHERE `inventoryAdjustmentId` IN (?, ?)',
|
|
250
|
-
[123, 456],
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
254
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
async shouldFindOneAndSelectOneToManyWithSpecifiedFields() {
|
|
258
|
-
await this.querier.insertMany(InventoryAdjustment, [
|
|
259
|
-
{
|
|
260
|
-
description: 'something a',
|
|
261
|
-
createdAt: 1,
|
|
262
|
-
itemAdjustments: [
|
|
263
|
-
{ buyPrice: 1, createdAt: 1 },
|
|
264
|
-
{ buyPrice: 1, createdAt: 1 },
|
|
265
|
-
],
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
description: 'something b',
|
|
269
|
-
createdAt: 1,
|
|
270
|
-
itemAdjustments: [
|
|
271
|
-
{ id: 1, buyPrice: 1, updatedAt: 1 },
|
|
272
|
-
{ buyPrice: 1, createdAt: 1 },
|
|
273
|
-
],
|
|
274
|
-
},
|
|
275
|
-
]);
|
|
276
|
-
|
|
277
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
278
|
-
1,
|
|
279
|
-
'INSERT INTO `InventoryAdjustment` (`description`, `createdAt`) VALUES (?, ?), (?, ?)',
|
|
280
|
-
['something a', 1, 'something b', 1],
|
|
281
|
-
);
|
|
282
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
283
|
-
2,
|
|
284
|
-
'INSERT INTO `ItemAdjustment` (`buyPrice`, `createdAt`, `inventoryAdjustmentId`) VALUES (?, ?, ?), (?, ?, ?)',
|
|
285
|
-
[1, 1, 1, 1, 1, 1],
|
|
286
|
-
);
|
|
287
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
288
|
-
3,
|
|
289
|
-
'INSERT INTO `ItemAdjustment` (`buyPrice`, `createdAt`, `inventoryAdjustmentId`) VALUES (?, ?, ?)',
|
|
290
|
-
[1, 1, 2],
|
|
291
|
-
);
|
|
292
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
293
|
-
4,
|
|
294
|
-
'UPDATE `ItemAdjustment` SET `buyPrice` = ?, `updatedAt` = ?, `inventoryAdjustmentId` = ? WHERE `id` = ?',
|
|
295
|
-
[1, 1, 2, 1],
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
await this.querier.findMany(InventoryAdjustment, {
|
|
299
|
-
$select: { id: true, itemAdjustments: { $select: ['buyPrice'], $skip: 1, $limit: 2 } },
|
|
300
|
-
$where: { createdAt: 1 },
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
304
|
-
1,
|
|
305
|
-
'SELECT `InventoryAdjustment`.`id` FROM `InventoryAdjustment` WHERE `InventoryAdjustment`.`createdAt` = ?',
|
|
306
|
-
[1],
|
|
307
|
-
);
|
|
308
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
309
|
-
2,
|
|
310
|
-
'SELECT `buyPrice`, `inventoryAdjustmentId` FROM `ItemAdjustment` WHERE `inventoryAdjustmentId` IN (?, ?) LIMIT 2 OFFSET 1',
|
|
311
|
-
[1, 2],
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
315
|
-
expect(this.querier.run).toHaveBeenCalledTimes(4);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
async shouldFindManyAndSelectOneToMany() {
|
|
319
|
-
await this.querier.insertMany(InventoryAdjustment, [
|
|
320
|
-
{ id: 123, description: 'something a', createdAt: 1 },
|
|
321
|
-
{ id: 456, description: 'something b', createdAt: 1 },
|
|
322
|
-
]);
|
|
323
|
-
|
|
324
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
325
|
-
1,
|
|
326
|
-
'INSERT INTO `InventoryAdjustment` (`id`, `description`, `createdAt`) VALUES (?, ?, ?), (?, ?, ?)',
|
|
327
|
-
[123, 'something a', 1, 456, 'something b', 1],
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
await this.querier.findMany(InventoryAdjustment, {
|
|
331
|
-
$select: { id: true, itemAdjustments: true },
|
|
332
|
-
$where: { createdAt: 1 },
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
336
|
-
1,
|
|
337
|
-
'SELECT `InventoryAdjustment`.`id` FROM `InventoryAdjustment` WHERE `InventoryAdjustment`.`createdAt` = ?',
|
|
338
|
-
[1],
|
|
339
|
-
);
|
|
340
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
341
|
-
2,
|
|
342
|
-
'SELECT `id`, `companyId`, `creatorId`, `createdAt`, `updatedAt`, `itemId`, `number`, `buyPrice`, `storehouseId`' +
|
|
343
|
-
', `inventoryAdjustmentId` FROM `ItemAdjustment` WHERE `inventoryAdjustmentId` IN (?, ?)',
|
|
344
|
-
[123, 456],
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
348
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
async shouldFindOneAndSelectManyToMany() {
|
|
352
|
-
await this.querier.insertOne(Item, { id: 123, createdAt: 1 });
|
|
353
|
-
|
|
354
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
355
|
-
1,
|
|
356
|
-
'INSERT INTO `Item` (`id`, `createdAt`) VALUES (?, ?)',
|
|
357
|
-
[123, 1],
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
await this.querier.findOne(Item, {
|
|
361
|
-
$select: { id: true, createdAt: true, tags: ['id'] },
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
365
|
-
1,
|
|
366
|
-
'SELECT `Item`.`id`, `Item`.`createdAt` FROM `Item` LIMIT 1',
|
|
367
|
-
[],
|
|
368
|
-
);
|
|
369
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
370
|
-
2,
|
|
371
|
-
'SELECT `ItemTag`.`id`, `ItemTag`.`itemId`, `tag`.`id` `tag_id`' +
|
|
372
|
-
' FROM `ItemTag` INNER JOIN `Tag` `tag` ON `tag`.`id` = `ItemTag`.`tagId`' +
|
|
373
|
-
' WHERE `ItemTag`.`itemId` IN (?)',
|
|
374
|
-
[123],
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
378
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
async shouldFindOneByIdAndSelectManyToMany() {
|
|
382
|
-
await this.querier.insertOne(Item, { id: 123, createdAt: 1 });
|
|
383
|
-
|
|
384
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
385
|
-
1,
|
|
386
|
-
'INSERT INTO `Item` (`id`, `createdAt`) VALUES (?, ?)',
|
|
387
|
-
[123, 1],
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
await this.querier.findOneById(Item, 123, {
|
|
391
|
-
$select: { id: 1, createdAt: 1, tags: ['id'] },
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
395
|
-
1,
|
|
396
|
-
'SELECT `Item`.`id`, `Item`.`createdAt` FROM `Item` WHERE `Item`.`id` = ? LIMIT 1',
|
|
397
|
-
[123],
|
|
398
|
-
);
|
|
399
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
400
|
-
2,
|
|
401
|
-
'SELECT `ItemTag`.`id`, `ItemTag`.`itemId`, `tag`.`id` `tag_id`' +
|
|
402
|
-
' FROM `ItemTag` INNER JOIN `Tag` `tag` ON `tag`.`id` = `ItemTag`.`tagId`' +
|
|
403
|
-
' WHERE `ItemTag`.`itemId` IN (?)',
|
|
404
|
-
[123],
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
408
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
async shouldFindManyAndCount() {
|
|
412
|
-
await this.querier.findManyAndCount(User, {
|
|
413
|
-
$select: { id: true, name: true },
|
|
414
|
-
$where: { companyId: 123 },
|
|
415
|
-
$sort: { createdAt: -1 },
|
|
416
|
-
$skip: 50,
|
|
417
|
-
$limit: 100,
|
|
418
|
-
});
|
|
419
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
420
|
-
1,
|
|
421
|
-
'SELECT `id`, `name` FROM `User` WHERE `companyId` = ? ORDER BY `createdAt` DESC LIMIT 100 OFFSET 50',
|
|
422
|
-
[123],
|
|
423
|
-
);
|
|
424
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
425
|
-
2,
|
|
426
|
-
'SELECT COUNT(*) `count` FROM `User` WHERE `companyId` = ?',
|
|
427
|
-
[123],
|
|
428
|
-
);
|
|
429
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
430
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
async shouldInsertManyEmpty() {
|
|
434
|
-
const res1 = await this.querier.insertMany(User, []);
|
|
435
|
-
expect(this.querier.run).not.toHaveBeenCalled();
|
|
436
|
-
expect(this.querier.all).not.toHaveBeenCalled();
|
|
437
|
-
expect(res1).toEqual([]);
|
|
438
|
-
|
|
439
|
-
const res2 = await this.querier.insertMany(User, undefined);
|
|
440
|
-
expect(this.querier.run).not.toHaveBeenCalled();
|
|
441
|
-
expect(this.querier.all).not.toHaveBeenCalled();
|
|
442
|
-
expect(res2).toEqual([]);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
async shouldInsertOne() {
|
|
446
|
-
await this.querier.insertOne(User, { companyId: 123, createdAt: 1 });
|
|
447
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
448
|
-
1,
|
|
449
|
-
'INSERT INTO `User` (`companyId`, `createdAt`) VALUES (?, ?)',
|
|
450
|
-
[123, 1],
|
|
451
|
-
);
|
|
452
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
453
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
async shouldInsertOneAndCascadeOneToOne() {
|
|
457
|
-
await this.querier.insertOne(User, {
|
|
458
|
-
name: 'some name',
|
|
459
|
-
createdAt: 1,
|
|
460
|
-
profile: { picture: 'abc', createdAt: 1 },
|
|
461
|
-
});
|
|
462
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `User` (`name`, `createdAt`) VALUES (?, ?)', [
|
|
463
|
-
'some name',
|
|
464
|
-
1,
|
|
465
|
-
]);
|
|
466
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
467
|
-
2,
|
|
468
|
-
'INSERT INTO `user_profile` (`image`, `createdAt`, `creatorId`) VALUES (?, ?, ?)',
|
|
469
|
-
['abc', 1, 1],
|
|
470
|
-
);
|
|
471
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
472
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
async shouldInsertOneAndCascadeManyToOne() {
|
|
476
|
-
await this.querier.insertOne(MeasureUnit, {
|
|
477
|
-
name: 'Centimeter',
|
|
478
|
-
createdAt: 123,
|
|
479
|
-
category: { name: 'Metric', createdAt: 123 },
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
483
|
-
1,
|
|
484
|
-
'INSERT INTO `MeasureUnit` (`name`, `createdAt`) VALUES (?, ?)',
|
|
485
|
-
['Centimeter', 123],
|
|
486
|
-
);
|
|
487
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
488
|
-
2,
|
|
489
|
-
'INSERT INTO `MeasureUnitCategory` (`name`, `createdAt`) VALUES (?, ?)',
|
|
490
|
-
['Metric', 123],
|
|
491
|
-
);
|
|
492
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
493
|
-
3,
|
|
494
|
-
expect.stringMatching(
|
|
495
|
-
/^UPDATE `MeasureUnit` SET `categoryId` = \?, `updatedAt` = \? WHERE `id` = \? AND `deletedAt` IS NULL$/,
|
|
496
|
-
),
|
|
497
|
-
[1, expect.any(Number), 1],
|
|
498
|
-
);
|
|
499
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
500
|
-
expect(this.querier.run).toHaveBeenCalledTimes(3);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
async shouldInsertOneAndCascadeOneToMany() {
|
|
504
|
-
await this.querier.insertOne(InventoryAdjustment, {
|
|
505
|
-
description: 'some description',
|
|
506
|
-
createdAt: 1,
|
|
507
|
-
itemAdjustments: [
|
|
508
|
-
{ buyPrice: 50, createdAt: 1 },
|
|
509
|
-
{ buyPrice: 300, createdAt: 1 },
|
|
510
|
-
],
|
|
511
|
-
});
|
|
512
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
513
|
-
1,
|
|
514
|
-
'INSERT INTO `InventoryAdjustment` (`description`, `createdAt`) VALUES (?, ?)',
|
|
515
|
-
['some description', 1],
|
|
516
|
-
);
|
|
517
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
518
|
-
2,
|
|
519
|
-
'INSERT INTO `ItemAdjustment` (`buyPrice`, `createdAt`, `inventoryAdjustmentId`) VALUES (?, ?, ?), (?, ?, ?)',
|
|
520
|
-
[50, 1, 1, 300, 1, 1],
|
|
521
|
-
);
|
|
522
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
523
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
async shouldUpdateMany() {
|
|
527
|
-
await this.querier.updateMany(User, { $where: { companyId: 4 } }, { name: 'Hola', updatedAt: 1 });
|
|
528
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
529
|
-
1,
|
|
530
|
-
'UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `companyId` = ?',
|
|
531
|
-
['Hola', 1, 4],
|
|
532
|
-
);
|
|
533
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
534
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
async shouldUpdateOneById() {
|
|
538
|
-
await this.querier.updateOneById(User, 5, { companyId: 123, updatedAt: 1 });
|
|
539
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
540
|
-
1,
|
|
541
|
-
'UPDATE `User` SET `companyId` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
542
|
-
[123, 1, 5],
|
|
543
|
-
);
|
|
544
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
545
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
async shouldUpdateOneByIdAndCascadeOneToOne() {
|
|
549
|
-
await this.querier.insertOne(User, { createdAt: 1 });
|
|
550
|
-
|
|
551
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `User` (`createdAt`) VALUES (?)', [1]);
|
|
552
|
-
|
|
553
|
-
await this.querier.updateOneById(User, 1, {
|
|
554
|
-
name: 'something',
|
|
555
|
-
updatedAt: 1,
|
|
556
|
-
profile: { picture: 'xyz', createdAt: 1 },
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
560
|
-
2,
|
|
561
|
-
'UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
562
|
-
['something', 1, 1],
|
|
563
|
-
);
|
|
564
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
565
|
-
3,
|
|
566
|
-
'INSERT INTO `user_profile` (`image`, `createdAt`, `creatorId`) VALUES (?, ?, ?)',
|
|
567
|
-
['xyz', 1, 1],
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `User` WHERE `id` = ?', [1]);
|
|
571
|
-
|
|
572
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
573
|
-
expect(this.querier.run).toHaveBeenCalledTimes(3);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
async shouldUpdateOneByIdAndCascadeOneToOneNull() {
|
|
577
|
-
await this.querier.insertOne(User, { createdAt: 1 });
|
|
578
|
-
|
|
579
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `User` (`createdAt`) VALUES (?)', [1]);
|
|
580
|
-
|
|
581
|
-
await this.querier.updateOneById(User, 1, {
|
|
582
|
-
name: 'something',
|
|
583
|
-
updatedAt: 1,
|
|
584
|
-
profile: null,
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
588
|
-
2,
|
|
589
|
-
'UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
590
|
-
['something', 1, 1],
|
|
591
|
-
);
|
|
592
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `User` WHERE `id` = ?', [1]);
|
|
593
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(2, 'SELECT `pk` FROM `user_profile` WHERE `creatorId` = ?', [1]);
|
|
594
|
-
|
|
595
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
596
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
async shouldUpdateOneByIdAndCascadeOneToMany() {
|
|
600
|
-
await this.querier.insertOne(InventoryAdjustment, { createdAt: 1 });
|
|
601
|
-
|
|
602
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
603
|
-
1,
|
|
604
|
-
'INSERT INTO `InventoryAdjustment` (`createdAt`) VALUES (?)',
|
|
605
|
-
[1],
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
await this.querier.updateOneById(InventoryAdjustment, 1, {
|
|
609
|
-
description: 'some description',
|
|
610
|
-
updatedAt: 1,
|
|
611
|
-
itemAdjustments: [
|
|
612
|
-
{ buyPrice: 50, createdAt: 1 },
|
|
613
|
-
{ buyPrice: 300, createdAt: 1 },
|
|
614
|
-
],
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
618
|
-
2,
|
|
619
|
-
'UPDATE `InventoryAdjustment` SET `description` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
620
|
-
['some description', 1, 1],
|
|
621
|
-
);
|
|
622
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `InventoryAdjustment` WHERE `id` = ?', [1]);
|
|
623
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
624
|
-
2,
|
|
625
|
-
'SELECT `id` FROM `ItemAdjustment` WHERE `inventoryAdjustmentId` = ?',
|
|
626
|
-
[1],
|
|
627
|
-
);
|
|
628
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
629
|
-
3,
|
|
630
|
-
'INSERT INTO `ItemAdjustment` (`buyPrice`, `createdAt`, `inventoryAdjustmentId`) VALUES (?, ?, ?), (?, ?, ?)',
|
|
631
|
-
[50, 1, 1, 300, 1, 1],
|
|
632
|
-
);
|
|
633
|
-
|
|
634
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
635
|
-
expect(this.querier.run).toHaveBeenCalledTimes(3);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
async shouldUpdateOneByIdAndCascadeOneToManyNull() {
|
|
639
|
-
await this.querier.insertOne(InventoryAdjustment, { createdAt: 1 });
|
|
640
|
-
|
|
641
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
642
|
-
1,
|
|
643
|
-
'INSERT INTO `InventoryAdjustment` (`createdAt`) VALUES (?)',
|
|
644
|
-
[1],
|
|
645
|
-
);
|
|
646
|
-
|
|
647
|
-
await this.querier.updateOneById(InventoryAdjustment, 1, {
|
|
648
|
-
description: 'some description',
|
|
649
|
-
updatedAt: 1,
|
|
650
|
-
itemAdjustments: null,
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
654
|
-
2,
|
|
655
|
-
'UPDATE `InventoryAdjustment` SET `description` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
656
|
-
['some description', 1, 1],
|
|
657
|
-
);
|
|
658
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `InventoryAdjustment` WHERE `id` = ?', [1]);
|
|
659
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
660
|
-
2,
|
|
661
|
-
'SELECT `id` FROM `ItemAdjustment` WHERE `inventoryAdjustmentId` = ?',
|
|
662
|
-
[1],
|
|
663
|
-
);
|
|
664
|
-
|
|
665
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
666
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
async shouldUpdateManyAndCascadeOneToManyNull() {
|
|
670
|
-
await this.querier.insertOne(InventoryAdjustment, { companyId: 1, createdAt: 1 });
|
|
671
|
-
|
|
672
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
673
|
-
1,
|
|
674
|
-
'INSERT INTO `InventoryAdjustment` (`companyId`, `createdAt`) VALUES (?, ?)',
|
|
675
|
-
[1, 1],
|
|
676
|
-
);
|
|
677
|
-
|
|
678
|
-
await this.querier.updateMany(
|
|
679
|
-
InventoryAdjustment,
|
|
680
|
-
{ $where: { companyId: 1 } },
|
|
681
|
-
{
|
|
682
|
-
description: 'some description',
|
|
683
|
-
updatedAt: 1,
|
|
684
|
-
itemAdjustments: null,
|
|
685
|
-
},
|
|
686
|
-
);
|
|
687
|
-
|
|
688
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
689
|
-
2,
|
|
690
|
-
'UPDATE `InventoryAdjustment` SET `description` = ?, `updatedAt` = ? WHERE `companyId` = ?',
|
|
691
|
-
['some description', 1, 1],
|
|
692
|
-
);
|
|
693
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
694
|
-
1,
|
|
695
|
-
'SELECT `id` FROM `InventoryAdjustment` WHERE `companyId` = ?',
|
|
696
|
-
[1],
|
|
697
|
-
);
|
|
698
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
699
|
-
2,
|
|
700
|
-
'SELECT `id` FROM `ItemAdjustment` WHERE `inventoryAdjustmentId` = ?',
|
|
701
|
-
[1],
|
|
702
|
-
);
|
|
703
|
-
|
|
704
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
705
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
async shouldInsertOneAndCascadeManyToManyInserts() {
|
|
709
|
-
await this.querier.insertOne(Item, {
|
|
710
|
-
name: 'item one',
|
|
711
|
-
createdAt: 1,
|
|
712
|
-
tags: [
|
|
713
|
-
{
|
|
714
|
-
name: 'tag one',
|
|
715
|
-
createdAt: 1,
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
name: 'tag two',
|
|
719
|
-
createdAt: 1,
|
|
720
|
-
},
|
|
721
|
-
],
|
|
722
|
-
});
|
|
723
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `Item` (`name`, `createdAt`) VALUES (?, ?)', [
|
|
724
|
-
'item one',
|
|
725
|
-
1,
|
|
726
|
-
]);
|
|
727
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
728
|
-
2,
|
|
729
|
-
'INSERT INTO `Tag` (`name`, `createdAt`) VALUES (?, ?), (?, ?)',
|
|
730
|
-
['tag one', 1, 'tag two', 1],
|
|
731
|
-
);
|
|
732
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
733
|
-
3,
|
|
734
|
-
'INSERT INTO `ItemTag` (`itemId`, `tagId`) VALUES (?, ?), (?, ?)',
|
|
735
|
-
[1, 1, 1, 2],
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
739
|
-
expect(this.querier.run).toHaveBeenCalledTimes(3);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
async shouldUpdateAndCascadeManyToManyInserts() {
|
|
743
|
-
const id = await this.querier.insertOne(Item, { createdAt: 1 });
|
|
744
|
-
|
|
745
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `Item` (`createdAt`) VALUES (?)', [1]);
|
|
746
|
-
|
|
747
|
-
await this.querier.updateOneById(Item, id, {
|
|
748
|
-
name: 'item one',
|
|
749
|
-
updatedAt: 1,
|
|
750
|
-
tags: [
|
|
751
|
-
{
|
|
752
|
-
name: 'tag one',
|
|
753
|
-
createdAt: 1,
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
name: 'tag two',
|
|
757
|
-
createdAt: 1,
|
|
758
|
-
},
|
|
759
|
-
],
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
763
|
-
2,
|
|
764
|
-
'UPDATE `Item` SET `name` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
765
|
-
['item one', 1, 1],
|
|
766
|
-
);
|
|
767
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `Item` WHERE `id` = ?', [1]);
|
|
768
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
769
|
-
3,
|
|
770
|
-
'INSERT INTO `Tag` (`name`, `createdAt`) VALUES (?, ?), (?, ?)',
|
|
771
|
-
['tag one', 1, 'tag two', 1],
|
|
772
|
-
);
|
|
773
|
-
|
|
774
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(2, 'SELECT `id` FROM `ItemTag` WHERE `itemId` = ?', [1]);
|
|
775
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
776
|
-
4,
|
|
777
|
-
'INSERT INTO `ItemTag` (`itemId`, `tagId`) VALUES (?, ?), (?, ?)',
|
|
778
|
-
[1, 1, 1, 2],
|
|
779
|
-
);
|
|
780
|
-
|
|
781
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
782
|
-
expect(this.querier.run).toHaveBeenCalledTimes(4);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
async shouldUpdateAndCascadeManyToManyLinks() {
|
|
786
|
-
const id = await this.querier.insertOne(Item, { createdAt: 1 });
|
|
787
|
-
|
|
788
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `Item` (`createdAt`) VALUES (?)', [1]);
|
|
789
|
-
|
|
790
|
-
await this.querier.updateOneById(Item, id, {
|
|
791
|
-
name: 'item one',
|
|
792
|
-
tags: [{ id: 22 }, { id: 33 }],
|
|
793
|
-
updatedAt: 1,
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
797
|
-
2,
|
|
798
|
-
'UPDATE `Item` SET `name` = ?, `updatedAt` = ? WHERE `id` = ?',
|
|
799
|
-
['item one', 1, 1],
|
|
800
|
-
);
|
|
801
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `Item` WHERE `id` = ?', [1]);
|
|
802
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(2, 'SELECT `id` FROM `ItemTag` WHERE `itemId` = ?', [1]);
|
|
803
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
804
|
-
3,
|
|
805
|
-
'INSERT INTO `ItemTag` (`itemId`, `tagId`) VALUES (?, ?), (?, ?)',
|
|
806
|
-
[1, 22, 1, 33],
|
|
807
|
-
);
|
|
808
|
-
|
|
809
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
810
|
-
expect(this.querier.run).toHaveBeenCalledTimes(3);
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
async shouldDeleteOneAndCascadeManyToManyDeletes() {
|
|
814
|
-
await this.shouldInsertOneAndCascadeManyToManyInserts();
|
|
815
|
-
|
|
816
|
-
jest.clearAllMocks();
|
|
817
|
-
|
|
818
|
-
await this.querier.deleteOneById(Item, 1);
|
|
819
|
-
|
|
820
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `Item` WHERE `id` = ?', [1]);
|
|
821
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(2, 'SELECT `id` FROM `ItemTag` WHERE `itemId` IN (?)', [1]);
|
|
822
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'DELETE FROM `Item` WHERE `id` IN (?)', [1]);
|
|
823
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(2, 'DELETE FROM `ItemTag` WHERE `id` IN (?, ?)', [1, 2]);
|
|
824
|
-
|
|
825
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
826
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
async shouldDeleteOneAndNoCascadeManyToManyDeletes() {
|
|
830
|
-
await this.shouldInsertOneAndCascadeManyToManyInserts();
|
|
831
|
-
|
|
832
|
-
jest.clearAllMocks();
|
|
833
|
-
|
|
834
|
-
await this.querier.deleteOneById(Tag, 1);
|
|
835
|
-
|
|
836
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `Tag` WHERE `id` = ?', [1]);
|
|
837
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'DELETE FROM `Tag` WHERE `id` IN (?)', [1]);
|
|
838
|
-
|
|
839
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
840
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
async shouldDeleteOneById() {
|
|
844
|
-
const id = await this.querier.insertOne(User, { createdAt: 1, profile: { createdAt: 1 } });
|
|
845
|
-
|
|
846
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `User` (`createdAt`) VALUES (?)', [1]);
|
|
847
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(
|
|
848
|
-
2,
|
|
849
|
-
'INSERT INTO `user_profile` (`createdAt`, `creatorId`) VALUES (?, ?)',
|
|
850
|
-
[1, 1],
|
|
851
|
-
);
|
|
852
|
-
|
|
853
|
-
await this.querier.deleteOneById(User, id);
|
|
854
|
-
|
|
855
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(3, 'DELETE FROM `User` WHERE `id` IN (?)', [1]);
|
|
856
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(4, 'DELETE FROM `user_profile` WHERE `pk` IN (?)', [1]);
|
|
857
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `User` WHERE `id` = ?', [1]);
|
|
858
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(2, 'SELECT `pk` FROM `user_profile`', []);
|
|
859
|
-
|
|
860
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
861
|
-
expect(this.querier.run).toHaveBeenCalledTimes(4);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
async shouldDeleteMany() {
|
|
865
|
-
await this.querier.insertOne(User, { createdAt: 123 });
|
|
866
|
-
|
|
867
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(1, 'INSERT INTO `User` (`createdAt`) VALUES (?)', [123]);
|
|
868
|
-
|
|
869
|
-
await this.querier.deleteMany(User, { $where: { createdAt: 123 } });
|
|
870
|
-
|
|
871
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(1, 'SELECT `id` FROM `User` WHERE `createdAt` = ?', [123]);
|
|
872
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(2, 'SELECT `pk` FROM `user_profile`', []);
|
|
873
|
-
expect(this.querier.run).toHaveBeenNthCalledWith(2, 'DELETE FROM `User` WHERE `id` IN (?)', [1]);
|
|
874
|
-
|
|
875
|
-
expect(this.querier.all).toHaveBeenCalledTimes(2);
|
|
876
|
-
expect(this.querier.run).toHaveBeenCalledTimes(2);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
async shouldCount() {
|
|
880
|
-
await this.querier.count(User, { $where: { companyId: 123 } });
|
|
881
|
-
expect(this.querier.all).toHaveBeenNthCalledWith(
|
|
882
|
-
1,
|
|
883
|
-
'SELECT COUNT(*) `count` FROM `User` WHERE `companyId` = ?',
|
|
884
|
-
[123],
|
|
885
|
-
);
|
|
886
|
-
expect(this.querier.all).toHaveBeenCalledTimes(1);
|
|
887
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
async shouldUseTransaction() {
|
|
891
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
892
|
-
await this.querier.beginTransaction();
|
|
893
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
894
|
-
await this.querier.updateOneById(User, 5, { name: 'Hola', updatedAt: 1 });
|
|
895
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
896
|
-
await this.querier.commitTransaction();
|
|
897
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
898
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
899
|
-
expect(this.querier.run).toHaveBeenCalledWith('UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `id` = ?', [
|
|
900
|
-
'Hola',
|
|
901
|
-
1,
|
|
902
|
-
5,
|
|
903
|
-
]);
|
|
904
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
async shouldUseTransactionCallback() {
|
|
908
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
909
|
-
await this.querier.transaction(async () => {
|
|
910
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
911
|
-
await this.querier.updateOneById(User, 5, { name: 'Hola', updatedAt: 1 });
|
|
912
|
-
});
|
|
913
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
914
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
915
|
-
expect(this.querier.run).toHaveBeenCalledWith('UPDATE `User` SET `name` = ?, `updatedAt` = ? WHERE `id` = ?', [
|
|
916
|
-
'Hola',
|
|
917
|
-
1,
|
|
918
|
-
5,
|
|
919
|
-
]);
|
|
920
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
async shouldThrowIfRollbackIfErrorInCallback() {
|
|
924
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
925
|
-
const prom = this.querier.transaction(async () => {
|
|
926
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
927
|
-
throw new Error('some error');
|
|
928
|
-
});
|
|
929
|
-
await expect(prom).rejects.toThrow('some error');
|
|
930
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
931
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
932
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
async shouldThrowIfTransactionIsPending() {
|
|
936
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
937
|
-
await this.querier.beginTransaction();
|
|
938
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
939
|
-
await expect(this.querier.beginTransaction()).rejects.toThrow('pending transaction');
|
|
940
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
941
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
942
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
async shouldThrowIfCommitWithNoPendingTransaction() {
|
|
946
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
947
|
-
await expect(this.querier.commitTransaction()).rejects.toThrow('not a pending transaction');
|
|
948
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
949
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
950
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
async shouldThrowIfRollbackWithNoPendingTransaction() {
|
|
954
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
955
|
-
await expect(this.querier.rollbackTransaction()).rejects.toThrow('not a pending transaction');
|
|
956
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
957
|
-
expect(this.querier.run).toHaveBeenCalledTimes(0);
|
|
958
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
async shouldThrowIfReleaseWithPendingTransaction() {
|
|
962
|
-
expect(this.querier.hasOpenTransaction).toBeFalsy();
|
|
963
|
-
await this.querier.beginTransaction();
|
|
964
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
965
|
-
await this.querier.updateOneById(User, 5, { name: 'some name' });
|
|
966
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
967
|
-
await expect(this.querier.release()).rejects.toThrow('pending transaction');
|
|
968
|
-
expect(this.querier.hasOpenTransaction).toBe(true);
|
|
969
|
-
expect(this.querier.run).toHaveBeenCalledTimes(1);
|
|
970
|
-
expect(this.querier.all).toHaveBeenCalledTimes(0);
|
|
971
|
-
await this.querier.rollbackTransaction();
|
|
972
|
-
await this.querier.release();
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
async shouldBeIdempotentRelease() {
|
|
976
|
-
await this.querier.release();
|
|
977
|
-
await expect(this.querier.release()).resolves.toBeUndefined();
|
|
978
|
-
}
|
|
979
|
-
}
|