@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
package/src/type/query.ts
DELETED
|
@@ -1,506 +0,0 @@
|
|
|
1
|
-
import type { FieldKey, IdValue, Key, RelationKey } from './entity.js';
|
|
2
|
-
import type { BooleanLike, ExpandScalar, Scalar, Type, Unpacked } from './utility.js';
|
|
3
|
-
|
|
4
|
-
export type QueryOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* use or omit `softDelete` attribute.
|
|
7
|
-
*/
|
|
8
|
-
softDelete?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* prefix the query with this.
|
|
11
|
-
*/
|
|
12
|
-
prefix?: string;
|
|
13
|
-
/**
|
|
14
|
-
* automatically infer the prefix for the query.
|
|
15
|
-
*/
|
|
16
|
-
autoPrefix?: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type QuerySelectOptions = {
|
|
20
|
-
/**
|
|
21
|
-
* prefix the query with this.
|
|
22
|
-
*/
|
|
23
|
-
prefix?: string;
|
|
24
|
-
/**
|
|
25
|
-
* automatically add the prefix for the alias.
|
|
26
|
-
*/
|
|
27
|
-
autoPrefixAlias?: boolean;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* query selection as an array.
|
|
32
|
-
*/
|
|
33
|
-
export type QuerySelectArray<E> = (Key<E> | QueryRaw)[];
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* query selection as a map.
|
|
37
|
-
*/
|
|
38
|
-
export type QuerySelectMap<E> = QuerySelectFieldMap<E> | QuerySelectRelationMap<E>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* query selection.
|
|
42
|
-
*/
|
|
43
|
-
export type QuerySelect<E> = QuerySelectArray<E> | QuerySelectMap<E>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* query selection of fields as a map.
|
|
47
|
-
*/
|
|
48
|
-
export type QuerySelectFieldMap<E> = {
|
|
49
|
-
[K in FieldKey<E>]?: BooleanLike;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* query conflict paths map.
|
|
54
|
-
*/
|
|
55
|
-
export type QueryConflictPathsMap<E> = {
|
|
56
|
-
[K in FieldKey<E>]?: true;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* query conflict paths.
|
|
61
|
-
*/
|
|
62
|
-
export type QueryConflictPaths<E> = QueryConflictPathsMap<E>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* query selection of relations as a map.
|
|
66
|
-
*/
|
|
67
|
-
export type QuerySelectRelationMap<E> = {
|
|
68
|
-
[K in RelationKey<E>]?: BooleanLike | Key<Unpacked<E[K]>>[] | QuerySelectRelationOptions<E[K]>;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* options to select a relation.
|
|
73
|
-
*/
|
|
74
|
-
export type QuerySelectRelationOptions<E> = (E extends unknown[] ? Query<Unpacked<E>> : QueryUnique<Unpacked<E>>) & {
|
|
75
|
-
$required?: boolean;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* options for full-text-search operator.
|
|
80
|
-
*/
|
|
81
|
-
export type QueryTextSearchOptions<E> = {
|
|
82
|
-
/**
|
|
83
|
-
* text to search for.
|
|
84
|
-
*/
|
|
85
|
-
$value: string;
|
|
86
|
-
/**
|
|
87
|
-
* list of fields to search on.
|
|
88
|
-
*/
|
|
89
|
-
$fields?: FieldKey<E>[];
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* comparison by fields.
|
|
94
|
-
*/
|
|
95
|
-
export type QueryWhereFieldMap<E> = { [K in FieldKey<E>]?: QueryWhereFieldValue<E[K]> };
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* complex operators.
|
|
99
|
-
*/
|
|
100
|
-
export type QueryWhereMap<E> = QueryWhereFieldMap<E> & QueryWhereRootOperator<E>;
|
|
101
|
-
|
|
102
|
-
export type QueryWhereRootOperator<E> = {
|
|
103
|
-
/**
|
|
104
|
-
* joins query clauses with a logical `AND`, returns records that match all the clauses.
|
|
105
|
-
*/
|
|
106
|
-
$and?: QueryWhereArray<E>;
|
|
107
|
-
/**
|
|
108
|
-
* joins query clauses with a logical `OR`, returns records that match any of the clauses.
|
|
109
|
-
*/
|
|
110
|
-
$or?: QueryWhereArray<E>;
|
|
111
|
-
/**
|
|
112
|
-
* joins query clauses with a logical `AND`, returns records that do not match all the clauses.
|
|
113
|
-
*/
|
|
114
|
-
$not?: QueryWhereArray<E>;
|
|
115
|
-
/**
|
|
116
|
-
* joins query clauses with a logical `OR`, returns records that do not match any of the clauses.
|
|
117
|
-
*/
|
|
118
|
-
$nor?: QueryWhereArray<E>;
|
|
119
|
-
/**
|
|
120
|
-
* whether the specified fields match against a full-text search of the given string.
|
|
121
|
-
*/
|
|
122
|
-
$text?: QueryTextSearchOptions<E>;
|
|
123
|
-
/**
|
|
124
|
-
* whether the record exists in the given sub-query.
|
|
125
|
-
*/
|
|
126
|
-
$exists?: QueryRaw;
|
|
127
|
-
/**
|
|
128
|
-
* whether the record does not exists in the given sub-query.
|
|
129
|
-
*/
|
|
130
|
-
$nexists?: QueryRaw;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export type QueryWhereFieldOperatorMap<T> = {
|
|
134
|
-
/**
|
|
135
|
-
* whether a value is equal to the given value.
|
|
136
|
-
*/
|
|
137
|
-
$eq?: ExpandScalar<T>;
|
|
138
|
-
/**
|
|
139
|
-
* whether a value is not equal to the given value.
|
|
140
|
-
*/
|
|
141
|
-
$ne?: ExpandScalar<T>;
|
|
142
|
-
/**
|
|
143
|
-
* negates the given comparison.
|
|
144
|
-
*/
|
|
145
|
-
$not?: QueryWhereFieldValue<T>;
|
|
146
|
-
/**
|
|
147
|
-
* whether a value is less than the given value.
|
|
148
|
-
*/
|
|
149
|
-
$lt?: ExpandScalar<T>;
|
|
150
|
-
/**
|
|
151
|
-
* whether a value is less than or equal to the given value.
|
|
152
|
-
*/
|
|
153
|
-
$lte?: ExpandScalar<T>;
|
|
154
|
-
/**
|
|
155
|
-
* whether a value is greater than the given value.
|
|
156
|
-
*/
|
|
157
|
-
$gt?: ExpandScalar<T>;
|
|
158
|
-
/**
|
|
159
|
-
* whether a value is greater than or equal to the given value.
|
|
160
|
-
*/
|
|
161
|
-
$gte?: ExpandScalar<T>;
|
|
162
|
-
/**
|
|
163
|
-
* whether a string begins with the given string (case sensitive).
|
|
164
|
-
*/
|
|
165
|
-
$startsWith?: string;
|
|
166
|
-
/**
|
|
167
|
-
* whether a string begins with the given string (case insensitive).
|
|
168
|
-
*/
|
|
169
|
-
$istartsWith?: string;
|
|
170
|
-
/**
|
|
171
|
-
* whether a string ends with the given string (case sensitive).
|
|
172
|
-
*/
|
|
173
|
-
$endsWith?: string;
|
|
174
|
-
/**
|
|
175
|
-
* whether a string ends with the given string (case insensitive).
|
|
176
|
-
*/
|
|
177
|
-
$iendsWith?: string;
|
|
178
|
-
/**
|
|
179
|
-
* whether a string is contained within the given string (case sensitive).
|
|
180
|
-
*/
|
|
181
|
-
$includes?: string;
|
|
182
|
-
/**
|
|
183
|
-
* whether a string is contained within the given string (case insensitive).
|
|
184
|
-
*/
|
|
185
|
-
$iincludes?: string;
|
|
186
|
-
/**
|
|
187
|
-
* whether a string fulfills the given pattern (case sensitive).
|
|
188
|
-
*/
|
|
189
|
-
$like?: string;
|
|
190
|
-
/**
|
|
191
|
-
* whether a string fulfills the given pattern (case insensitive).
|
|
192
|
-
*/
|
|
193
|
-
$ilike?: string;
|
|
194
|
-
/**
|
|
195
|
-
* whether a string matches the given regular expression.
|
|
196
|
-
*/
|
|
197
|
-
$regex?: string;
|
|
198
|
-
/**
|
|
199
|
-
* whether a value matches any of the given values.
|
|
200
|
-
*/
|
|
201
|
-
$in?: ExpandScalar<T>[];
|
|
202
|
-
/**
|
|
203
|
-
* whether a value does not match any of the given values.
|
|
204
|
-
*/
|
|
205
|
-
$nin?: ExpandScalar<T>[];
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Value for a field comparison.
|
|
210
|
-
*/
|
|
211
|
-
export type QueryWhereFieldValue<T> = T | T[] | QueryWhereFieldOperatorMap<T> | QueryRaw;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* query single filter.
|
|
215
|
-
*/
|
|
216
|
-
export type QueryWhereSingle<E> = IdValue<E> | IdValue<E>[] | QueryWhereMap<E> | QueryRaw;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* query filter array.
|
|
220
|
-
*/
|
|
221
|
-
export type QueryWhereArray<E> = QueryWhereSingle<E>[];
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* query filter.
|
|
225
|
-
*/
|
|
226
|
-
export type QueryWhere<E> = QueryWhereSingle<E> | QueryWhereArray<E>;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* direction for the sort.
|
|
230
|
-
*/
|
|
231
|
-
export type QuerySortDirection = -1 | 1 | 'asc' | 'desc';
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* sort by tuples
|
|
235
|
-
*/
|
|
236
|
-
export type QuerySortTuples<E> = [FieldKey<E>, QuerySortDirection][];
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* sort by objects.
|
|
240
|
-
*/
|
|
241
|
-
export type QuerySortObjects<E> = { field: FieldKey<E>; sort: QuerySortDirection }[];
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* sort by fields.
|
|
245
|
-
*/
|
|
246
|
-
export type QuerySortFieldMap<E> = {
|
|
247
|
-
[K in FieldKey<E>]?: QuerySortDirection;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* sort by relations fields.
|
|
252
|
-
*/
|
|
253
|
-
export type QuerySortRelationMap<E> = {
|
|
254
|
-
[K in RelationKey<E>]?: QuerySortMap<Unpacked<E[K]>>;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* sort by map.
|
|
259
|
-
*/
|
|
260
|
-
export type QuerySortMap<E> = QuerySortFieldMap<E> | QuerySortRelationMap<E>;
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* sort options.
|
|
264
|
-
*/
|
|
265
|
-
export type QuerySort<E> = QuerySortMap<E> | QuerySortTuples<E> | QuerySortObjects<E>;
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* pager options.
|
|
269
|
-
*/
|
|
270
|
-
export type QueryPager = {
|
|
271
|
-
/**
|
|
272
|
-
* Index from where start the search
|
|
273
|
-
*/
|
|
274
|
-
$skip?: number;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Max number of records to retrieve
|
|
278
|
-
*/
|
|
279
|
-
$limit?: number;
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* search options.
|
|
284
|
-
*/
|
|
285
|
-
export type QuerySearch<E> = {
|
|
286
|
-
/**
|
|
287
|
-
* filtering options.
|
|
288
|
-
*/
|
|
289
|
-
$where?: QueryWhere<E>;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* sorting options.
|
|
293
|
-
*/
|
|
294
|
-
$sort?: QuerySort<E>;
|
|
295
|
-
} & QueryPager;
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* criteria one options.
|
|
299
|
-
*/
|
|
300
|
-
export type QuerySearchOne<E> = Omit<QuerySearch<E>, '$limit'>;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* query options.
|
|
304
|
-
*/
|
|
305
|
-
export type Query<E> = {
|
|
306
|
-
/**
|
|
307
|
-
* selection options.
|
|
308
|
-
*/
|
|
309
|
-
$select?: QuerySelect<E>;
|
|
310
|
-
} & QuerySearch<E>;
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* options to get a single record.
|
|
314
|
-
*/
|
|
315
|
-
export type QueryOne<E> = Omit<Query<E>, '$limit'>;
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* options to get an unique record.
|
|
319
|
-
*/
|
|
320
|
-
export type QueryUnique<E> = Pick<QueryOne<E>, '$select' | '$where'>;
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* stringified query.
|
|
324
|
-
*/
|
|
325
|
-
export type QueryStringified = {
|
|
326
|
-
[K in keyof Query<unknown>]?: string;
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* result of an update operation.
|
|
331
|
-
*/
|
|
332
|
-
export type QueryUpdateResult = {
|
|
333
|
-
/**
|
|
334
|
-
* number of affected records.
|
|
335
|
-
*/
|
|
336
|
-
changes?: number;
|
|
337
|
-
/**
|
|
338
|
-
* the inserted IDs.
|
|
339
|
-
*/
|
|
340
|
-
ids?: number[] | string[];
|
|
341
|
-
/**
|
|
342
|
-
* first inserted ID.
|
|
343
|
-
*/
|
|
344
|
-
firstId?: number | string;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* options for the `raw` function.
|
|
349
|
-
*/
|
|
350
|
-
export type QueryRawFnOptions = {
|
|
351
|
-
/**
|
|
352
|
-
* the current dialect.
|
|
353
|
-
*/
|
|
354
|
-
dialect?: QueryDialect;
|
|
355
|
-
/**
|
|
356
|
-
* the prefix.
|
|
357
|
-
*/
|
|
358
|
-
prefix?: string;
|
|
359
|
-
/**
|
|
360
|
-
* the escaped prefix.
|
|
361
|
-
*/
|
|
362
|
-
escapedPrefix?: string;
|
|
363
|
-
/**
|
|
364
|
-
* the query context.
|
|
365
|
-
*/
|
|
366
|
-
ctx?: QueryContext;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* a `raw` function
|
|
371
|
-
*/
|
|
372
|
-
export type QueryRawFn = (opts?: QueryRawFnOptions) => void | Scalar;
|
|
373
|
-
|
|
374
|
-
export class QueryRaw {
|
|
375
|
-
constructor(
|
|
376
|
-
readonly value: Scalar | QueryRawFn,
|
|
377
|
-
readonly alias?: string,
|
|
378
|
-
) {}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* comparison options.
|
|
383
|
-
*/
|
|
384
|
-
export type QueryComparisonOptions = QueryOptions & {
|
|
385
|
-
/**
|
|
386
|
-
* use precedence for the comparison or not.
|
|
387
|
-
*/
|
|
388
|
-
usePrecedence?: boolean;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* query filter options.
|
|
393
|
-
*/
|
|
394
|
-
export type QueryWhereOptions = QueryComparisonOptions & {
|
|
395
|
-
/**
|
|
396
|
-
* clause to be used in the filter.
|
|
397
|
-
*/
|
|
398
|
-
clause?: 'WHERE' | false;
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
export interface QueryContext {
|
|
402
|
-
append(sql: string): this;
|
|
403
|
-
addValue(value: unknown): this;
|
|
404
|
-
pushValue(value: unknown): this;
|
|
405
|
-
readonly sql: string;
|
|
406
|
-
readonly values: unknown[];
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export interface QueryDialect {
|
|
410
|
-
/**
|
|
411
|
-
* obtains the records matching the given search parameters.
|
|
412
|
-
* @param ctx the query context
|
|
413
|
-
* @param entity the target entity
|
|
414
|
-
* @param q the criteria options
|
|
415
|
-
* @param opts the query options
|
|
416
|
-
*/
|
|
417
|
-
find<E>(ctx: QueryContext, entity: Type<E>, q: Query<E>, opts?: QueryOptions): void;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* counts the number of records matching the given search parameters.
|
|
421
|
-
* @param ctx the query context
|
|
422
|
-
* @param entity the target entity
|
|
423
|
-
* @param q the criteria options
|
|
424
|
-
* @param opts the query options
|
|
425
|
-
*/
|
|
426
|
-
count<E>(ctx: QueryContext, entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): void;
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* insert records.
|
|
430
|
-
* @param ctx the query context
|
|
431
|
-
* @param entity the target entity
|
|
432
|
-
* @param payload the payload
|
|
433
|
-
* @param opts the query options
|
|
434
|
-
*/
|
|
435
|
-
insert<E>(ctx: QueryContext, entity: Type<E>, payload: E | E[], opts?: QueryOptions): void;
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* update records.
|
|
439
|
-
* @param ctx the query context
|
|
440
|
-
* @param entity the target entity
|
|
441
|
-
* @param q the criteria options
|
|
442
|
-
* @param payload
|
|
443
|
-
* @param opts the query options
|
|
444
|
-
*/
|
|
445
|
-
update<E>(ctx: QueryContext, entity: Type<E>, q: QuerySearch<E>, payload: E, opts?: QueryOptions): void;
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* upsert records.
|
|
449
|
-
* @param ctx the query context
|
|
450
|
-
* @param entity the target entity
|
|
451
|
-
* @param conflictPaths the conflict paths
|
|
452
|
-
* @param payload
|
|
453
|
-
*/
|
|
454
|
-
upsert<E>(ctx: QueryContext, entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E): void;
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* delete records.
|
|
458
|
-
* @param ctx the query context
|
|
459
|
-
* @param entity the target entity
|
|
460
|
-
* @param q the criteria options
|
|
461
|
-
* @param opts the query options
|
|
462
|
-
*/
|
|
463
|
-
delete<E>(ctx: QueryContext, entity: Type<E>, q: QuerySearch<E>, opts?: QueryOptions): void;
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* escape an identifier.
|
|
467
|
-
* @param val the value to be escaped
|
|
468
|
-
* @param forbidQualified don't escape dots
|
|
469
|
-
* @param addDot use a dot as suffix
|
|
470
|
-
*/
|
|
471
|
-
escapeId(val: string, forbidQualified?: boolean, addDot?: boolean): string;
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* escape a value.
|
|
475
|
-
* @param val the value to escape
|
|
476
|
-
*/
|
|
477
|
-
escape(val: unknown): string;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* add a value to the query.
|
|
481
|
-
* @param values the values array
|
|
482
|
-
* @param value the value to add
|
|
483
|
-
*/
|
|
484
|
-
addValue(values: unknown[], value: unknown): string;
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* create a new query context.
|
|
488
|
-
*/
|
|
489
|
-
createContext(): QueryContext;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Minimal dialect interface exposing escapeIdChar for SQL operations
|
|
494
|
-
*/
|
|
495
|
-
export interface SqlQueryDialect extends QueryDialect {
|
|
496
|
-
/**
|
|
497
|
-
* the escape character for identifiers.
|
|
498
|
-
*/
|
|
499
|
-
readonly escapeIdChar: '"' | '`';
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Get the placeholder for a parameter at the given index (1-based).
|
|
503
|
-
* Default: '?' for MySQL/MariaDB/SQLite, '$n' for PostgreSQL.
|
|
504
|
-
*/
|
|
505
|
-
placeholder(index: number): string;
|
|
506
|
-
}
|
package/src/type/repository.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { IdValue } from './entity.js';
|
|
2
|
-
import type { Query, QueryConflictPaths, QueryOne, QueryOptions, QuerySearch, QueryUpdateResult } from './query.js';
|
|
3
|
-
import type { UniversalQuerier } from './universalQuerier.js';
|
|
4
|
-
import type { Type } from './utility.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A `repository` allows to interact with the datasource to perform persistence operations on a specific entity.
|
|
8
|
-
*/
|
|
9
|
-
export type UniversalRepository<E> = {
|
|
10
|
-
/**
|
|
11
|
-
* the `entity` class to which this `repository` is linked to.
|
|
12
|
-
*/
|
|
13
|
-
readonly entity: Type<E>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* the `querier` instance to which this `repository` is linked to.
|
|
17
|
-
*/
|
|
18
|
-
readonly querier: UniversalQuerier;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* obtains the record with the given primary key.
|
|
22
|
-
* @param id the primary key value
|
|
23
|
-
* @param q the criteria options
|
|
24
|
-
*/
|
|
25
|
-
findOneById(id: IdValue<E>, q?: QueryOne<E>): Promise<unknown>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* obtains the first record matching the given search parameters.
|
|
29
|
-
* @param q the criteria options
|
|
30
|
-
*/
|
|
31
|
-
findOne(q: QueryOne<E>): Promise<unknown>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* obtains the records matching the given search parameters.
|
|
35
|
-
* @param q the criteria options
|
|
36
|
-
*/
|
|
37
|
-
findMany(q: Query<E>): Promise<unknown>;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* obtains the records matching the given search parameters,
|
|
41
|
-
* also counts the number of matches ignoring pagination.
|
|
42
|
-
* @param q the criteria options
|
|
43
|
-
*/
|
|
44
|
-
findManyAndCount(q: Query<E>): Promise<unknown>;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* counts the number of records matching the given search parameters.
|
|
48
|
-
* @param q the search options
|
|
49
|
-
*/
|
|
50
|
-
count(q: QuerySearch<E>): Promise<unknown>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* inserts a record.
|
|
54
|
-
* @param payload the data to be persisted
|
|
55
|
-
*/
|
|
56
|
-
insertOne(payload: E): Promise<unknown>;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Inserts many records.
|
|
60
|
-
* @param entity the entity to persist on
|
|
61
|
-
* @param payload the data to be persisted
|
|
62
|
-
*/
|
|
63
|
-
insertMany?(payload: E[]): Promise<unknown>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* updates a record partially.
|
|
67
|
-
* @param id the primary key of the record to be updated
|
|
68
|
-
* @param payload the data to be persisted
|
|
69
|
-
*/
|
|
70
|
-
updateOneById(id: IdValue<E>, payload: E): Promise<unknown>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* updates many records partially.
|
|
74
|
-
* @param qm the criteria to look for the records
|
|
75
|
-
* @param payload the data to be persisted
|
|
76
|
-
*/
|
|
77
|
-
updateMany?(qm: QuerySearch<E>, payload: E): Promise<unknown>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Insert or update a record given a search criteria.
|
|
81
|
-
* @param conflictPaths the keys to use for the unique search.
|
|
82
|
-
* @param payload the data to insert or update.
|
|
83
|
-
*/
|
|
84
|
-
upsertOne?(conflictPaths: QueryConflictPaths<E>, payload: E): Promise<unknown>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Insert or update a record.
|
|
88
|
-
* @param payload the data to be persisted
|
|
89
|
-
*/
|
|
90
|
-
saveOne(payload: E): Promise<unknown>;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* insert or update records.
|
|
94
|
-
* @param payload the data to be persisted
|
|
95
|
-
*/
|
|
96
|
-
saveMany?(payload: E[]): Promise<unknown>;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* delete or SoftDelete a record.
|
|
100
|
-
* @param id the primary key of the record
|
|
101
|
-
*/
|
|
102
|
-
deleteOneById(id: IdValue<E>, opts?: QueryOptions): Promise<unknown>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* delete or SoftDelete records.
|
|
106
|
-
* @param qm the criteria to look for the records
|
|
107
|
-
*/
|
|
108
|
-
deleteMany(qm: QuerySearch<E>, opts?: QueryOptions): Promise<unknown>;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* base contract for the backend repositories.
|
|
113
|
-
*/
|
|
114
|
-
export interface Repository<E> extends UniversalRepository<E> {
|
|
115
|
-
findOneById(id: IdValue<E>, q?: QueryOne<E>): Promise<E>;
|
|
116
|
-
|
|
117
|
-
findOne(qm: QueryOne<E>): Promise<E>;
|
|
118
|
-
|
|
119
|
-
findMany(qm: Query<E>): Promise<E[]>;
|
|
120
|
-
|
|
121
|
-
findManyAndCount(qm: Query<E>): Promise<[E[], number]>;
|
|
122
|
-
|
|
123
|
-
count(q?: QuerySearch<E>): Promise<number>;
|
|
124
|
-
|
|
125
|
-
insertOne(payload: E): Promise<IdValue<E>>;
|
|
126
|
-
|
|
127
|
-
insertMany(payload: E[]): Promise<IdValue<E>[]>;
|
|
128
|
-
|
|
129
|
-
updateOneById(id: IdValue<E>, payload: E): Promise<number>;
|
|
130
|
-
|
|
131
|
-
updateMany(qm: QuerySearch<E>, payload: E): Promise<number>;
|
|
132
|
-
|
|
133
|
-
upsertOne(conflictPaths: QueryConflictPaths<E>, payload: E): Promise<QueryUpdateResult>;
|
|
134
|
-
|
|
135
|
-
saveOne(payload: E): Promise<IdValue<E>>;
|
|
136
|
-
|
|
137
|
-
saveMany?(payload: E[]): Promise<IdValue<E>[]>;
|
|
138
|
-
|
|
139
|
-
deleteOneById(id: IdValue<E>, opts?: QueryOptions): Promise<number>;
|
|
140
|
-
|
|
141
|
-
deleteMany(qm: QuerySearch<E>, opts?: QueryOptions): Promise<number>;
|
|
142
|
-
}
|