knex 0.21.20 → 0.21.21
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 +6 -0
- package/CONTRIBUTING.md +184 -184
- package/LICENSE +22 -22
- package/README.md +95 -95
- package/bin/cli.js +414 -414
- package/bin/utils/cli-config-utils.js +151 -151
- package/bin/utils/constants.js +7 -7
- package/bin/utils/migrationsLister.js +37 -37
- package/knex.js +8 -8
- package/lib/client.js +413 -413
- package/lib/config-resolver.js +61 -61
- package/lib/constants.js +44 -44
- package/lib/dialects/mssql/index.js +390 -390
- package/lib/dialects/mssql/query/compiler.js +444 -444
- package/lib/dialects/mssql/schema/columncompiler.js +103 -103
- package/lib/dialects/mssql/schema/compiler.js +59 -59
- package/lib/dialects/mssql/schema/tablecompiler.js +245 -245
- package/lib/dialects/mssql/transaction.js +97 -97
- package/lib/dialects/mysql/index.js +191 -191
- package/lib/dialects/mysql/query/compiler.js +142 -142
- package/lib/dialects/mysql/schema/columncompiler.js +171 -171
- package/lib/dialects/mysql/schema/compiler.js +60 -60
- package/lib/dialects/mysql/schema/tablecompiler.js +262 -262
- package/lib/dialects/mysql/transaction.js +48 -48
- package/lib/dialects/mysql2/index.js +35 -35
- package/lib/dialects/mysql2/transaction.js +46 -46
- package/lib/dialects/oracle/DEAD_CODE.md +5 -5
- package/lib/dialects/oracle/formatter.js +20 -20
- package/lib/dialects/oracle/index.js +79 -79
- package/lib/dialects/oracle/query/compiler.js +327 -327
- package/lib/dialects/oracle/schema/columnbuilder.js +18 -18
- package/lib/dialects/oracle/schema/columncompiler.js +139 -139
- package/lib/dialects/oracle/schema/compiler.js +81 -81
- package/lib/dialects/oracle/schema/tablecompiler.js +165 -165
- package/lib/dialects/oracle/schema/trigger.js +126 -126
- package/lib/dialects/oracle/utils.js +86 -86
- package/lib/dialects/oracledb/index.js +489 -489
- package/lib/dialects/oracledb/query/compiler.js +363 -363
- package/lib/dialects/oracledb/schema/columncompiler.js +35 -35
- package/lib/dialects/oracledb/transaction.js +76 -76
- package/lib/dialects/oracledb/utils.js +14 -14
- package/lib/dialects/postgres/index.js +319 -319
- package/lib/dialects/postgres/query/compiler.js +206 -206
- package/lib/dialects/postgres/schema/columncompiler.js +125 -125
- package/lib/dialects/postgres/schema/compiler.js +109 -109
- package/lib/dialects/postgres/schema/tablecompiler.js +183 -183
- package/lib/dialects/redshift/index.js +73 -73
- package/lib/dialects/redshift/query/compiler.js +119 -119
- package/lib/dialects/redshift/schema/columnbuilder.js +20 -20
- package/lib/dialects/redshift/schema/columncompiler.js +60 -60
- package/lib/dialects/redshift/schema/compiler.js +14 -14
- package/lib/dialects/redshift/schema/tablecompiler.js +123 -123
- package/lib/dialects/redshift/transaction.js +18 -18
- package/lib/dialects/sqlite3/formatter.js +21 -21
- package/lib/dialects/sqlite3/index.js +169 -169
- package/lib/dialects/sqlite3/query/compiler.js +222 -222
- package/lib/dialects/sqlite3/schema/columncompiler.js +27 -27
- package/lib/dialects/sqlite3/schema/compiler.js +49 -49
- package/lib/dialects/sqlite3/schema/ddl.js +525 -525
- package/lib/dialects/sqlite3/schema/tablecompiler.js +238 -238
- package/lib/formatter.js +295 -295
- package/lib/functionhelper.js +14 -14
- package/lib/helpers.js +92 -92
- package/lib/index.js +3 -3
- package/lib/interface.js +115 -115
- package/lib/knex.js +42 -42
- package/lib/logger.js +76 -76
- package/lib/migrate/MigrationGenerator.js +82 -82
- package/lib/migrate/Migrator.js +611 -611
- package/lib/migrate/configuration-merger.js +60 -60
- package/lib/migrate/migrate-stub.js +17 -17
- package/lib/migrate/migration-list-resolver.js +36 -36
- package/lib/migrate/sources/fs-migrations.js +99 -99
- package/lib/migrate/stub/cjs.stub +15 -15
- package/lib/migrate/stub/coffee.stub +13 -13
- package/lib/migrate/stub/eg.stub +14 -14
- package/lib/migrate/stub/js.stub +15 -15
- package/lib/migrate/stub/knexfile-coffee.stub +34 -34
- package/lib/migrate/stub/knexfile-eg.stub +43 -43
- package/lib/migrate/stub/knexfile-js.stub +44 -44
- package/lib/migrate/stub/knexfile-ls.stub +35 -35
- package/lib/migrate/stub/knexfile-ts.stub +44 -44
- package/lib/migrate/stub/ls.stub +14 -14
- package/lib/migrate/stub/ts.stub +21 -21
- package/lib/migrate/table-creator.js +67 -67
- package/lib/migrate/table-resolver.js +27 -27
- package/lib/query/builder.js +1372 -1372
- package/lib/query/compiler.js +889 -889
- package/lib/query/constants.js +13 -13
- package/lib/query/joinclause.js +263 -263
- package/lib/query/methods.js +92 -92
- package/lib/query/string.js +190 -190
- package/lib/raw.js +188 -188
- package/lib/ref.js +39 -39
- package/lib/runner.js +285 -285
- package/lib/schema/builder.js +82 -82
- package/lib/schema/columnbuilder.js +117 -117
- package/lib/schema/columncompiler.js +177 -177
- package/lib/schema/compiler.js +101 -101
- package/lib/schema/helpers.js +51 -51
- package/lib/schema/tablebuilder.js +288 -288
- package/lib/schema/tablecompiler.js +296 -296
- package/lib/seed/Seeder.js +203 -203
- package/lib/seed/seed-stub.js +13 -13
- package/lib/seed/stub/coffee.stub +9 -9
- package/lib/seed/stub/eg.stub +11 -11
- package/lib/seed/stub/js.stub +13 -13
- package/lib/seed/stub/ls.stub +11 -11
- package/lib/seed/stub/ts.stub +13 -13
- package/lib/transaction.js +363 -363
- package/lib/util/batchInsert.js +59 -59
- package/lib/util/delay.js +6 -6
- package/lib/util/fake-client.js +9 -9
- package/lib/util/finally-mixin.js +13 -13
- package/lib/util/fs.js +76 -76
- package/lib/util/import-file.js +13 -13
- package/lib/util/is-module-type.js +14 -14
- package/lib/util/is.js +32 -32
- package/lib/util/make-knex.js +338 -338
- package/lib/util/nanoid.js +29 -29
- package/lib/util/noop.js +1 -1
- package/lib/util/parse-connection.js +66 -66
- package/lib/util/save-async-stack.js +14 -14
- package/lib/util/template.js +52 -52
- package/lib/util/timeout.js +29 -29
- package/lib/util/timestamp.js +16 -16
- package/package.json +1 -1
- package/scripts/build.js +125 -125
- package/scripts/docker-compose.yml +111 -111
- package/scripts/next-release-howto.md +24 -24
- package/scripts/release.sh +34 -34
- package/scripts/runkit-example.js +34 -34
- package/scripts/stress-test/README.txt +18 -18
- package/scripts/stress-test/docker-compose.yml +47 -47
- package/scripts/stress-test/knex-stress-test.js +196 -196
- package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +145 -145
- package/scripts/stress-test/mysql2-sudden-exit-without-error.js +100 -100
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +184 -184
- package/types/index.d.ts +2249 -2249
- package/types/result.d.ts +27 -27
- package/types/tables.d.ts +4 -4
package/types/index.d.ts
CHANGED
|
@@ -1,2249 +1,2249 @@
|
|
|
1
|
-
// Originally based on contributions to DefinitelyTyped:
|
|
2
|
-
// Definitions by: Qubo <https://github.com/tkQubo>
|
|
3
|
-
// Pablo Rodríguez <https://github.com/MeLlamoPablo>
|
|
4
|
-
// Matt R. Wilson <https://github.com/mastermatt>
|
|
5
|
-
// Satana Charuwichitratana <https://github.com/micksatana>
|
|
6
|
-
// Shrey Jain <https://github.com/shreyjain1994>
|
|
7
|
-
// TypeScript Version: 3.7
|
|
8
|
-
|
|
9
|
-
import tarn = require('tarn');
|
|
10
|
-
import events = require('events');
|
|
11
|
-
import stream = require('stream');
|
|
12
|
-
import ResultTypes = require('./result');
|
|
13
|
-
|
|
14
|
-
import { Tables } from './tables';
|
|
15
|
-
|
|
16
|
-
import { ConnectionOptions } from "tls";
|
|
17
|
-
import { Stream } from "stream";
|
|
18
|
-
|
|
19
|
-
// # Generic type-level utilities
|
|
20
|
-
|
|
21
|
-
// If T is object then make it a partial otherwise fallback to any
|
|
22
|
-
//
|
|
23
|
-
// This is primarily to prevent type incompatibilities where target can be unknown.
|
|
24
|
-
// While unknown can be assigned to any, Partial<unknown> can't be.
|
|
25
|
-
type SafePartial<T> = Partial<AnyOrUnknownToOther<T, {}>>;
|
|
26
|
-
|
|
27
|
-
type MaybeArray<T> = T | T[];
|
|
28
|
-
|
|
29
|
-
type StrKey<T> = string & keyof T;
|
|
30
|
-
|
|
31
|
-
// If T is unknown then convert to any, else retain original
|
|
32
|
-
type UnknownToAny<T> = unknown extends T ? any : T;
|
|
33
|
-
type AnyToUnknown<T> = unknown extends T ? unknown : T;
|
|
34
|
-
type AnyOrUnknownToOther<T1, T2> = unknown extends T1 ? T2 : T1;
|
|
35
|
-
|
|
36
|
-
// Intersection conditionally applied only when TParams is non-empty
|
|
37
|
-
// This is primarily to keep the signatures more intuitive.
|
|
38
|
-
type AugmentParams<TTarget, TParams> = TParams extends {}
|
|
39
|
-
? keyof TParams extends never
|
|
40
|
-
? TTarget
|
|
41
|
-
: {} & TTarget & TParams
|
|
42
|
-
: TTarget;
|
|
43
|
-
|
|
44
|
-
// Check if provided keys (expressed as a single or union type) are members of TBase
|
|
45
|
-
type AreKeysOf<TBase, TKeys> = Boxed<TKeys> extends Boxed<keyof TBase>
|
|
46
|
-
? true
|
|
47
|
-
: false;
|
|
48
|
-
|
|
49
|
-
// https://stackoverflow.com/a/50375286/476712
|
|
50
|
-
type UnionToIntersection<U> = (U extends any
|
|
51
|
-
? (k: U) => void
|
|
52
|
-
: never) extends ((k: infer I) => void)
|
|
53
|
-
? I
|
|
54
|
-
: never;
|
|
55
|
-
|
|
56
|
-
type ComparisonOperator = '=' | '>' | '>=' | '<' | '<=' | '<>';
|
|
57
|
-
|
|
58
|
-
// If T is an array, get the type of member, else fall back to never
|
|
59
|
-
type ArrayMember<T> = T extends (infer M)[] ? M : never;
|
|
60
|
-
|
|
61
|
-
// If T is an array, get the type of member, else retain original
|
|
62
|
-
type UnwrapArrayMember<T> = T extends (infer M)[] ? M : T;
|
|
63
|
-
|
|
64
|
-
// Wrap a type in a container, making it an object type.
|
|
65
|
-
// This is primarily useful in circumventing special handling of union/intersection in typescript
|
|
66
|
-
interface Boxed<T> {
|
|
67
|
-
_value: T;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// If T can't be assigned to TBase fallback to an alternate type TAlt
|
|
71
|
-
type IncompatibleToAlt<T, TBase, TAlt> = T extends TBase ? T : TAlt;
|
|
72
|
-
|
|
73
|
-
type ArrayIfAlready<T1, T2> = T1 extends any[] ? T2[] : T2;
|
|
74
|
-
|
|
75
|
-
// Boxing is necessary to prevent distribution of conditional types:
|
|
76
|
-
// https://lorefnon.tech/2019/05/02/using-boxing-to-prevent-distribution-of-conditional-types/
|
|
77
|
-
type PartialOrAny<TBase, TKeys> = Boxed<TKeys> extends Boxed<never>
|
|
78
|
-
? {}
|
|
79
|
-
: Boxed<TKeys> extends Boxed<keyof TBase>
|
|
80
|
-
? SafePick<TBase, TKeys & keyof TBase>
|
|
81
|
-
: any;
|
|
82
|
-
|
|
83
|
-
// Retain the association of original keys with aliased keys at type level
|
|
84
|
-
// to facilitates type-safe aliasing for object syntax
|
|
85
|
-
type MappedAliasType<TBase, TAliasMapping> = {} & {
|
|
86
|
-
[K in keyof TAliasMapping]: TAliasMapping[K] extends keyof TBase
|
|
87
|
-
? TBase[TAliasMapping[K]]
|
|
88
|
-
: any
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// Container type for situations when we want a partial/intersection eventually
|
|
92
|
-
// but the keys being selected or additional properties being augmented are not
|
|
93
|
-
// all known at once and we would want to effectively build up a partial/intersection
|
|
94
|
-
// over multiple steps.
|
|
95
|
-
type DeferredKeySelection<
|
|
96
|
-
// The base of selection. In intermediate stages this may be unknown.
|
|
97
|
-
// If it remains unknown at the point of resolution, the selection will fall back to any
|
|
98
|
-
TBase,
|
|
99
|
-
// Union of keys to be selected
|
|
100
|
-
// In intermediate stages this may be never.
|
|
101
|
-
TKeys extends string,
|
|
102
|
-
// Changes how the resolution should behave if TKeys is never.
|
|
103
|
-
// If true, then we assume that some keys were selected, and if TKeys is never, we will fall back to any.
|
|
104
|
-
// If false, and TKeys is never, then we select TBase in its entirety
|
|
105
|
-
THasSelect extends true | false = false,
|
|
106
|
-
// Mapping of aliases <key in result> -> <key in TBase>
|
|
107
|
-
TAliasMapping extends {} = {},
|
|
108
|
-
// If enabled, then instead of extracting a partial, during resolution
|
|
109
|
-
// we will pick just a single property.
|
|
110
|
-
TSingle extends boolean = false,
|
|
111
|
-
// Extra props which will be intersected with the result
|
|
112
|
-
TIntersectProps extends {} = {},
|
|
113
|
-
// Extra props which will be unioned with the result
|
|
114
|
-
TUnionProps = never
|
|
115
|
-
> = {
|
|
116
|
-
// These properties are not actually used, but exist simply because
|
|
117
|
-
// typescript doesn't end up happy when type parameters are unused
|
|
118
|
-
_base: TBase;
|
|
119
|
-
_hasSelection: THasSelect;
|
|
120
|
-
_keys: TKeys;
|
|
121
|
-
_aliases: TAliasMapping;
|
|
122
|
-
_single: TSingle;
|
|
123
|
-
_intersectProps: TIntersectProps;
|
|
124
|
-
_unionProps: TUnionProps;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// An companion namespace for DeferredKeySelection which provides type operators
|
|
128
|
-
// to build up participants of intersection/partial over multiple invocations
|
|
129
|
-
// and for final resolution.
|
|
130
|
-
//
|
|
131
|
-
// While the comments use wordings such as replacement and addition, it is important
|
|
132
|
-
// to keep in mind that types are always immutable and all type operators return new altered types.
|
|
133
|
-
declare namespace DeferredKeySelection {
|
|
134
|
-
type Any = DeferredKeySelection<any, any, any, any, any, any, any>;
|
|
135
|
-
|
|
136
|
-
// Replace the Base if already a deferred selection.
|
|
137
|
-
// If not, create a new deferred selection with specified base.
|
|
138
|
-
type SetBase<TSelection, TBase> = TSelection extends DeferredKeySelection<
|
|
139
|
-
any,
|
|
140
|
-
infer TKeys,
|
|
141
|
-
infer THasSelect,
|
|
142
|
-
infer TAliasMapping,
|
|
143
|
-
infer TSingle,
|
|
144
|
-
infer TIntersectProps,
|
|
145
|
-
infer TUnionProps
|
|
146
|
-
>
|
|
147
|
-
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps, TUnionProps>
|
|
148
|
-
: DeferredKeySelection<TBase, never>;
|
|
149
|
-
|
|
150
|
-
// If TSelection is already a deferred selection, then replace the base with TBase
|
|
151
|
-
// If unknown, create a new deferred selection with TBase as the base
|
|
152
|
-
// Else, retain original
|
|
153
|
-
//
|
|
154
|
-
// For practical reasons applicable to current context, we always return arrays of
|
|
155
|
-
// deferred selections. So, this particular operator may not be useful in generic contexts.
|
|
156
|
-
type ReplaceBase<TSelection, TBase> = UnwrapArrayMember<
|
|
157
|
-
TSelection
|
|
158
|
-
> extends DeferredKeySelection.Any
|
|
159
|
-
? ArrayIfAlready<TSelection, DeferredKeySelection.SetBase<UnwrapArrayMember<TSelection>, TBase>>
|
|
160
|
-
: unknown extends UnwrapArrayMember<TSelection>
|
|
161
|
-
? ArrayIfAlready<TSelection, DeferredKeySelection.SetBase<unknown, TBase>>
|
|
162
|
-
: TSelection;
|
|
163
|
-
|
|
164
|
-
// Type operators to substitute individual type parameters:
|
|
165
|
-
|
|
166
|
-
type SetSingle<
|
|
167
|
-
TSelection,
|
|
168
|
-
TSingle extends boolean
|
|
169
|
-
> = TSelection extends DeferredKeySelection<
|
|
170
|
-
infer TBase,
|
|
171
|
-
infer TKeys,
|
|
172
|
-
infer THasSelect,
|
|
173
|
-
infer TAliasMapping,
|
|
174
|
-
any,
|
|
175
|
-
infer TIntersectProps,
|
|
176
|
-
infer TUnionProps
|
|
177
|
-
>
|
|
178
|
-
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps, TUnionProps>
|
|
179
|
-
: never;
|
|
180
|
-
|
|
181
|
-
type AddKey<
|
|
182
|
-
TSelection,
|
|
183
|
-
TKey extends string
|
|
184
|
-
> = TSelection extends DeferredKeySelection<
|
|
185
|
-
infer TBase,
|
|
186
|
-
infer TKeys,
|
|
187
|
-
any,
|
|
188
|
-
infer TAliasMapping,
|
|
189
|
-
infer TSingle,
|
|
190
|
-
infer TIntersectProps,
|
|
191
|
-
infer TUnionProps
|
|
192
|
-
>
|
|
193
|
-
? DeferredKeySelection<TBase, TKeys | TKey, true, TAliasMapping, TSingle, TIntersectProps, TUnionProps>
|
|
194
|
-
: DeferredKeySelection<unknown, TKey, true>;
|
|
195
|
-
|
|
196
|
-
type AddAliases<TSelection, T> = TSelection extends DeferredKeySelection<
|
|
197
|
-
infer TBase,
|
|
198
|
-
infer TKeys,
|
|
199
|
-
infer THasSelect,
|
|
200
|
-
infer TAliasMapping,
|
|
201
|
-
infer TSingle,
|
|
202
|
-
infer TIntersectProps,
|
|
203
|
-
infer TUnionProps
|
|
204
|
-
>
|
|
205
|
-
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping & T, TSingle, TIntersectProps, TUnionProps>
|
|
206
|
-
: DeferredKeySelection<unknown, never, false, T>;
|
|
207
|
-
|
|
208
|
-
type AddUnionMember<TSelection, T> = TSelection extends DeferredKeySelection<
|
|
209
|
-
infer TBase,
|
|
210
|
-
infer TKeys,
|
|
211
|
-
infer THasSelect,
|
|
212
|
-
infer TAliasMapping,
|
|
213
|
-
infer TSingle,
|
|
214
|
-
infer TIntersectProps,
|
|
215
|
-
infer TUnionProps
|
|
216
|
-
>
|
|
217
|
-
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps, TUnionProps | T>
|
|
218
|
-
: DeferredKeySelection<TSelection, never, false, {}, false, {}, T>;
|
|
219
|
-
|
|
220
|
-
// Convenience utility to set base, keys and aliases in a single type
|
|
221
|
-
// application
|
|
222
|
-
type Augment<T, TBase, TKey extends string, TAliasMapping = {}> = AddAliases<
|
|
223
|
-
AddKey<SetBase<T, TBase>, TKey>,
|
|
224
|
-
TAliasMapping
|
|
225
|
-
>;
|
|
226
|
-
|
|
227
|
-
// Core resolution logic -- Refer to docs for DeferredKeySelection for specifics
|
|
228
|
-
type ResolveOne<TSelection> = TSelection extends DeferredKeySelection<
|
|
229
|
-
infer TBase,
|
|
230
|
-
infer TKeys,
|
|
231
|
-
infer THasSelect,
|
|
232
|
-
infer TAliasMapping,
|
|
233
|
-
infer TSingle,
|
|
234
|
-
infer TIntersectProps,
|
|
235
|
-
infer TUnionProps
|
|
236
|
-
>
|
|
237
|
-
? UnknownToAny<
|
|
238
|
-
// ^ We convert final result to any if it is unknown for backward compatibility.
|
|
239
|
-
// Historically knex typings have been liberal with returning any and changing
|
|
240
|
-
// default return type to unknown would be a major breaking change for users.
|
|
241
|
-
//
|
|
242
|
-
// So we compromise on type safety here and return any.
|
|
243
|
-
AugmentParams<
|
|
244
|
-
AnyToUnknown<TBase> extends {}
|
|
245
|
-
// ^ Conversion of any -> unknown is needed here to prevent distribution
|
|
246
|
-
// of any over the conditional
|
|
247
|
-
? TSingle extends true
|
|
248
|
-
? TKeys extends keyof TBase
|
|
249
|
-
? TBase[TKeys]
|
|
250
|
-
: any
|
|
251
|
-
: AugmentParams<
|
|
252
|
-
true extends THasSelect ? PartialOrAny<TBase, TKeys> : TBase,
|
|
253
|
-
MappedAliasType<TBase, TAliasMapping>
|
|
254
|
-
>
|
|
255
|
-
: unknown,
|
|
256
|
-
TIntersectProps
|
|
257
|
-
> | TUnionProps
|
|
258
|
-
>
|
|
259
|
-
: TSelection;
|
|
260
|
-
|
|
261
|
-
type Resolve<TSelection> = TSelection extends DeferredKeySelection.Any
|
|
262
|
-
? Knex.ResolveTableType<ResolveOne<TSelection>>
|
|
263
|
-
: TSelection extends DeferredKeySelection.Any[]
|
|
264
|
-
? Knex.ResolveTableType<ResolveOne<TSelection[0]>>[]
|
|
265
|
-
: TSelection extends (infer I)[]
|
|
266
|
-
? UnknownToAny<Knex.ResolveTableType<I>>[]
|
|
267
|
-
: UnknownToAny<Knex.ResolveTableType<TSelection>>;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
type AggregationQueryResult<TResult, TIntersectProps2> = ArrayIfAlready<
|
|
271
|
-
TResult,
|
|
272
|
-
UnwrapArrayMember<TResult> extends DeferredKeySelection<
|
|
273
|
-
infer TBase,
|
|
274
|
-
infer TKeys,
|
|
275
|
-
infer THasSelect,
|
|
276
|
-
infer TAliasMapping,
|
|
277
|
-
infer TSingle,
|
|
278
|
-
infer TIntersectProps,
|
|
279
|
-
infer TUnionProps
|
|
280
|
-
>
|
|
281
|
-
? true extends THasSelect
|
|
282
|
-
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps & TIntersectProps2, TUnionProps>
|
|
283
|
-
: DeferredKeySelection<{}, never, true, {}, false, TIntersectProps2>
|
|
284
|
-
: TIntersectProps2
|
|
285
|
-
>;
|
|
286
|
-
|
|
287
|
-
// Convenience alias and associated companion namespace for working
|
|
288
|
-
// with DeferredSelection having TSingle=true.
|
|
289
|
-
//
|
|
290
|
-
// When TSingle=true in DeferredSelection, then we are effectively
|
|
291
|
-
// deferring an index access operation (TBase[TKey]) over a potentially
|
|
292
|
-
// unknown initial type of TBase and potentially never initial type of TKey
|
|
293
|
-
|
|
294
|
-
type DeferredIndex<TBase, TKey extends string> = DeferredKeySelection<TBase, TKey, false, {}, true>;
|
|
295
|
-
|
|
296
|
-
declare namespace DeferredIndex {
|
|
297
|
-
type Augment<
|
|
298
|
-
T,
|
|
299
|
-
TBase,
|
|
300
|
-
TKey extends string,
|
|
301
|
-
TAliasMapping = {}
|
|
302
|
-
> = DeferredKeySelection.SetSingle<
|
|
303
|
-
DeferredKeySelection.AddKey<DeferredKeySelection.SetBase<T, TBase>, TKey>,
|
|
304
|
-
true
|
|
305
|
-
>;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// If we have more categories of deferred selection in future,
|
|
309
|
-
// this will combine all of them
|
|
310
|
-
type ResolveResult<S> = DeferredKeySelection.Resolve<S>;
|
|
311
|
-
|
|
312
|
-
// # Type-aliases for common type combinations
|
|
313
|
-
|
|
314
|
-
type Callback = Function;
|
|
315
|
-
type Client = Function;
|
|
316
|
-
|
|
317
|
-
type Dict<T = any> = { [k: string]: T; };
|
|
318
|
-
|
|
319
|
-
type SafePick<T, K extends keyof T> = T extends {} ? Pick<T, K> : any;
|
|
320
|
-
|
|
321
|
-
type TableOptions = PgTableOptions;
|
|
322
|
-
|
|
323
|
-
interface PgTableOptions {
|
|
324
|
-
only?: boolean;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
interface DMLOptions {
|
|
328
|
-
includeTriggerModifications?: boolean;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
interface Knex<TRecord extends {} = any, TResult = unknown[]>
|
|
332
|
-
extends Knex.QueryInterface<TRecord, TResult>, events.EventEmitter {
|
|
333
|
-
<TTable extends Knex.TableNames>(
|
|
334
|
-
tableName: TTable,
|
|
335
|
-
options?: TableOptions
|
|
336
|
-
): Knex.QueryBuilder<Knex.TableType<TTable>, DeferredKeySelection<Knex.ResolveTableType<Knex.TableType<TTable>>, never>[]>;
|
|
337
|
-
<TRecord2 = TRecord, TResult2 = DeferredKeySelection<TRecord2, never>[]>(
|
|
338
|
-
tableName?: Knex.TableDescriptor | Knex.AliasDict,
|
|
339
|
-
options?: TableOptions
|
|
340
|
-
): Knex.QueryBuilder<TRecord2, TResult2>;
|
|
341
|
-
VERSION: string;
|
|
342
|
-
__knex__: string;
|
|
343
|
-
|
|
344
|
-
raw: Knex.RawBuilder<TRecord>;
|
|
345
|
-
|
|
346
|
-
transactionProvider(
|
|
347
|
-
config?: any
|
|
348
|
-
): () => Promise<Knex.Transaction>;
|
|
349
|
-
transaction(
|
|
350
|
-
transactionScope?: null,
|
|
351
|
-
config?: any
|
|
352
|
-
): Promise<Knex.Transaction>;
|
|
353
|
-
transaction<T>(
|
|
354
|
-
transactionScope: (trx: Knex.Transaction) => Promise<T> | void,
|
|
355
|
-
config?: any
|
|
356
|
-
): Promise<T>;
|
|
357
|
-
initialize(config?: Knex.Config): void;
|
|
358
|
-
destroy(callback: Function): void;
|
|
359
|
-
destroy(): Promise<void>;
|
|
360
|
-
|
|
361
|
-
batchInsert<TRecord2 = TRecord, TResult2 = number[]>(
|
|
362
|
-
tableName: Knex.TableDescriptor,
|
|
363
|
-
data: TRecord2 extends Knex.CompositeTableType<unknown>
|
|
364
|
-
? ReadonlyArray<Knex.ResolveTableType<TRecord2, 'insert'>>
|
|
365
|
-
: ReadonlyArray<Knex.DbRecordArr<TRecord2>>,
|
|
366
|
-
chunkSize?: number,
|
|
367
|
-
): Knex.BatchInsertBuilder<TRecord2, TResult2>;
|
|
368
|
-
|
|
369
|
-
schema: Knex.SchemaBuilder;
|
|
370
|
-
queryBuilder<TRecord2 = TRecord, TResult2 = TResult>(): Knex.QueryBuilder<
|
|
371
|
-
TRecord2,
|
|
372
|
-
TResult2
|
|
373
|
-
>;
|
|
374
|
-
|
|
375
|
-
client: any;
|
|
376
|
-
migrate: Knex.Migrator;
|
|
377
|
-
seed: Knex.Seeder;
|
|
378
|
-
fn: Knex.FunctionHelper;
|
|
379
|
-
ref: Knex.RefBuilder;
|
|
380
|
-
userParams: Record<string, any>;
|
|
381
|
-
withUserParams(params: Record<string, any>): Knex;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
declare function Knex<TRecord extends {} = any, TResult = unknown[]>(
|
|
385
|
-
config: Knex.Config | string
|
|
386
|
-
): Knex<TRecord, TResult>;
|
|
387
|
-
|
|
388
|
-
declare namespace Knex {
|
|
389
|
-
//
|
|
390
|
-
// Utility Types
|
|
391
|
-
//
|
|
392
|
-
|
|
393
|
-
type Value =
|
|
394
|
-
| string
|
|
395
|
-
| number
|
|
396
|
-
| boolean
|
|
397
|
-
| null
|
|
398
|
-
| Date
|
|
399
|
-
| Array<string>
|
|
400
|
-
| Array<number>
|
|
401
|
-
| Array<Date>
|
|
402
|
-
| Array<boolean>
|
|
403
|
-
| Buffer
|
|
404
|
-
| Knex.Raw;
|
|
405
|
-
|
|
406
|
-
interface ValueDict extends Dict<Value | Knex.QueryBuilder> {}
|
|
407
|
-
interface AliasDict extends Dict<string> {}
|
|
408
|
-
|
|
409
|
-
type ColumnDescriptor<TRecord, TResult> =
|
|
410
|
-
| string
|
|
411
|
-
| Knex.Raw
|
|
412
|
-
| Knex.QueryBuilder<TRecord, TResult>
|
|
413
|
-
| Dict<string>;
|
|
414
|
-
|
|
415
|
-
type InferrableColumnDescriptor<TRecord extends {}> =
|
|
416
|
-
| keyof TRecord
|
|
417
|
-
| Knex.Ref<any, any>
|
|
418
|
-
| Dict<keyof TRecord>;
|
|
419
|
-
|
|
420
|
-
type TableDescriptor = string | Knex.Raw | Knex.QueryBuilder;
|
|
421
|
-
|
|
422
|
-
type Lookup<TRegistry extends {}, TKey extends string, TDefault = never> =
|
|
423
|
-
TKey extends keyof TRegistry ?
|
|
424
|
-
TRegistry[TKey] :
|
|
425
|
-
TDefault;
|
|
426
|
-
|
|
427
|
-
type MaybeRawColumn<TColumn> = TColumn | Raw<TColumn>;
|
|
428
|
-
|
|
429
|
-
type MaybeRawRecord<TRecord> = {
|
|
430
|
-
[K in keyof TRecord]: MaybeRawColumn<TRecord[K]>
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
type DbColumn<TColumn> = Readonly<MaybeRawColumn<TColumn>>;
|
|
434
|
-
|
|
435
|
-
type DbRecord<TRecord> = Readonly<SafePartial<MaybeRawRecord<TRecord>>>;
|
|
436
|
-
|
|
437
|
-
type DbRecordArr<TRecord> = Readonly<MaybeArray<DbRecord<TRecord>>>;
|
|
438
|
-
|
|
439
|
-
export type CompositeTableType<TBase, TInsert = TBase, TUpdate = Partial<TInsert>> = {
|
|
440
|
-
base: TBase,
|
|
441
|
-
insert: TInsert,
|
|
442
|
-
update: TUpdate,
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
type TableNames = keyof Tables;
|
|
446
|
-
|
|
447
|
-
type TableInterfaceScope = keyof CompositeTableType<unknown>;
|
|
448
|
-
|
|
449
|
-
type TableType<TTable extends keyof Tables> = Tables[TTable];
|
|
450
|
-
|
|
451
|
-
type ResolveTableType<TCompositeTableType, TScope extends TableInterfaceScope = 'base'> = TCompositeTableType extends CompositeTableType<unknown>
|
|
452
|
-
? TCompositeTableType[TScope]
|
|
453
|
-
: TCompositeTableType;
|
|
454
|
-
|
|
455
|
-
interface OnConflictQueryBuilder<TRecord, TResult> {
|
|
456
|
-
ignore(): QueryBuilder<TRecord, TResult>;
|
|
457
|
-
merge(data?: DbRecord<TRecord>): QueryBuilder<TRecord, TResult>;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
//
|
|
461
|
-
// QueryInterface
|
|
462
|
-
//
|
|
463
|
-
type ClearStatements = "with" | "select" | "columns" | "hintComments" | "where" | "union" | "join" | "group" | "order" | "having" | "limit" | "offset" | "counter" | "counters";
|
|
464
|
-
|
|
465
|
-
interface QueryInterface<TRecord extends {} = any, TResult = any> {
|
|
466
|
-
select: Select<TRecord, TResult>;
|
|
467
|
-
as: As<TRecord, TResult>;
|
|
468
|
-
columns: Select<TRecord, TResult>;
|
|
469
|
-
column: Select<TRecord, TResult>;
|
|
470
|
-
hintComment: HintComment<TRecord, TResult>;
|
|
471
|
-
from: Table<TRecord, TResult>;
|
|
472
|
-
into: Table<TRecord, TResult>;
|
|
473
|
-
table: Table<TRecord, TResult>;
|
|
474
|
-
distinct: Distinct<TRecord, TResult>;
|
|
475
|
-
distinctOn: DistinctOn<TRecord, TResult>;
|
|
476
|
-
|
|
477
|
-
// Joins
|
|
478
|
-
join: Join<TRecord, TResult>;
|
|
479
|
-
joinRaw: JoinRaw<TRecord, TResult>;
|
|
480
|
-
innerJoin: Join<TRecord, TResult>;
|
|
481
|
-
leftJoin: Join<TRecord, TResult>;
|
|
482
|
-
leftOuterJoin: Join<TRecord, TResult>;
|
|
483
|
-
rightJoin: Join<TRecord, TResult>;
|
|
484
|
-
rightOuterJoin: Join<TRecord, TResult>;
|
|
485
|
-
outerJoin: Join<TRecord, TResult>;
|
|
486
|
-
fullOuterJoin: Join<TRecord, TResult>;
|
|
487
|
-
crossJoin: Join<TRecord, TResult>;
|
|
488
|
-
|
|
489
|
-
// Withs
|
|
490
|
-
with: With<TRecord, TResult>;
|
|
491
|
-
withRecursive: With<TRecord, TResult>;
|
|
492
|
-
withRaw: WithRaw<TRecord, TResult>;
|
|
493
|
-
withSchema: WithSchema<TRecord, TResult>;
|
|
494
|
-
withWrapped: WithWrapped<TRecord, TResult>;
|
|
495
|
-
|
|
496
|
-
// Wheres
|
|
497
|
-
where: Where<TRecord, TResult>;
|
|
498
|
-
andWhere: Where<TRecord, TResult>;
|
|
499
|
-
orWhere: Where<TRecord, TResult>;
|
|
500
|
-
whereNot: Where<TRecord, TResult>;
|
|
501
|
-
andWhereNot: Where<TRecord, TResult>;
|
|
502
|
-
orWhereNot: Where<TRecord, TResult>;
|
|
503
|
-
whereRaw: WhereRaw<TRecord, TResult>;
|
|
504
|
-
orWhereRaw: WhereRaw<TRecord, TResult>;
|
|
505
|
-
andWhereRaw: WhereRaw<TRecord, TResult>;
|
|
506
|
-
whereWrapped: WhereWrapped<TRecord, TResult>;
|
|
507
|
-
havingWrapped: WhereWrapped<TRecord, TResult>;
|
|
508
|
-
whereExists: WhereExists<TRecord, TResult>;
|
|
509
|
-
orWhereExists: WhereExists<TRecord, TResult>;
|
|
510
|
-
whereNotExists: WhereExists<TRecord, TResult>;
|
|
511
|
-
orWhereNotExists: WhereExists<TRecord, TResult>;
|
|
512
|
-
whereIn: WhereIn<TRecord, TResult>;
|
|
513
|
-
orWhereIn: WhereIn<TRecord, TResult>;
|
|
514
|
-
whereNotIn: WhereIn<TRecord, TResult>;
|
|
515
|
-
orWhereNotIn: WhereIn<TRecord, TResult>;
|
|
516
|
-
whereNull: WhereNull<TRecord, TResult>;
|
|
517
|
-
orWhereNull: WhereNull<TRecord, TResult>;
|
|
518
|
-
whereNotNull: WhereNull<TRecord, TResult>;
|
|
519
|
-
orWhereNotNull: WhereNull<TRecord, TResult>;
|
|
520
|
-
whereBetween: WhereBetween<TRecord, TResult>;
|
|
521
|
-
orWhereBetween: WhereBetween<TRecord, TResult>;
|
|
522
|
-
andWhereBetween: WhereBetween<TRecord, TResult>;
|
|
523
|
-
whereNotBetween: WhereBetween<TRecord, TResult>;
|
|
524
|
-
orWhereNotBetween: WhereBetween<TRecord, TResult>;
|
|
525
|
-
andWhereNotBetween: WhereBetween<TRecord, TResult>;
|
|
526
|
-
|
|
527
|
-
// Group by
|
|
528
|
-
groupBy: GroupBy<TRecord, TResult>;
|
|
529
|
-
groupByRaw: RawQueryBuilder<TRecord, TResult>;
|
|
530
|
-
|
|
531
|
-
// Order by
|
|
532
|
-
orderBy: OrderBy<TRecord, TResult>;
|
|
533
|
-
orderByRaw: RawQueryBuilder<TRecord, TResult>;
|
|
534
|
-
|
|
535
|
-
// Intersect
|
|
536
|
-
intersect: Intersect<TRecord, TResult>;
|
|
537
|
-
|
|
538
|
-
// Union
|
|
539
|
-
union: Union<TRecord, TResult>;
|
|
540
|
-
unionAll: Union<TRecord, TResult>;
|
|
541
|
-
|
|
542
|
-
// Having
|
|
543
|
-
having: Having<TRecord, TResult>;
|
|
544
|
-
andHaving: Having<TRecord, TResult>;
|
|
545
|
-
havingRaw: RawQueryBuilder<TRecord, TResult>;
|
|
546
|
-
orHaving: Having<TRecord, TResult>;
|
|
547
|
-
orHavingRaw: RawQueryBuilder<TRecord, TResult>;
|
|
548
|
-
havingIn: HavingRange<TRecord, TResult>;
|
|
549
|
-
orHavingNotBetween: HavingRange<TRecord, TResult>;
|
|
550
|
-
havingNotBetween: HavingRange<TRecord, TResult>;
|
|
551
|
-
orHavingBetween: HavingRange<TRecord, TResult>;
|
|
552
|
-
havingBetween: HavingRange<TRecord, TResult>;
|
|
553
|
-
|
|
554
|
-
// Clear
|
|
555
|
-
clearSelect(): QueryBuilder<
|
|
556
|
-
TRecord,
|
|
557
|
-
UnwrapArrayMember<TResult> extends DeferredKeySelection<
|
|
558
|
-
infer TBase,
|
|
559
|
-
infer TKeys,
|
|
560
|
-
true,
|
|
561
|
-
any,
|
|
562
|
-
any,
|
|
563
|
-
any,
|
|
564
|
-
any
|
|
565
|
-
>
|
|
566
|
-
? DeferredKeySelection<TBase, never>[]
|
|
567
|
-
: TResult
|
|
568
|
-
>;
|
|
569
|
-
clearWhere(): QueryBuilder<TRecord, TResult>;
|
|
570
|
-
clearGroup(): QueryBuilder<TRecord, TResult>;
|
|
571
|
-
clearOrder(): QueryBuilder<TRecord, TResult>;
|
|
572
|
-
clearHaving(): QueryBuilder<TRecord, TResult>;
|
|
573
|
-
clearCounters(): QueryBuilder<TRecord, TResult>;
|
|
574
|
-
clear(statement: ClearStatements): QueryBuilder<TRecord, TResult>;
|
|
575
|
-
|
|
576
|
-
// Paging
|
|
577
|
-
offset(offset: number): QueryBuilder<TRecord, TResult>;
|
|
578
|
-
limit(limit: number): QueryBuilder<TRecord, TResult>;
|
|
579
|
-
|
|
580
|
-
// Aggregation
|
|
581
|
-
count: AsymmetricAggregation<TRecord, TResult, Lookup<ResultTypes.Registry, "Count", number | string>>;
|
|
582
|
-
countDistinct: AsymmetricAggregation<TRecord, TResult, Lookup<ResultTypes.Registry, "Count", number | string>>;
|
|
583
|
-
min: TypePreservingAggregation<TRecord, TResult>;
|
|
584
|
-
max: TypePreservingAggregation<TRecord, TResult>;
|
|
585
|
-
sum: TypePreservingAggregation<TRecord, TResult>;
|
|
586
|
-
sumDistinct: TypePreservingAggregation<TRecord, TResult>;
|
|
587
|
-
avg: TypePreservingAggregation<TRecord, TResult>;
|
|
588
|
-
avgDistinct: TypePreservingAggregation<TRecord, TResult>;
|
|
589
|
-
|
|
590
|
-
increment(
|
|
591
|
-
columnName: keyof TRecord,
|
|
592
|
-
amount?: number
|
|
593
|
-
): QueryBuilder<TRecord, number>;
|
|
594
|
-
increment(
|
|
595
|
-
columnName: string,
|
|
596
|
-
amount?: number
|
|
597
|
-
): QueryBuilder<TRecord, number>;
|
|
598
|
-
|
|
599
|
-
decrement(
|
|
600
|
-
columnName: keyof TRecord,
|
|
601
|
-
amount?: number
|
|
602
|
-
): QueryBuilder<TRecord, number>;
|
|
603
|
-
decrement(
|
|
604
|
-
columnName: string,
|
|
605
|
-
amount?: number
|
|
606
|
-
): QueryBuilder<TRecord, number>;
|
|
607
|
-
|
|
608
|
-
// Others
|
|
609
|
-
first: Select<TRecord, DeferredKeySelection.AddUnionMember<UnwrapArrayMember<TResult>, undefined>>;
|
|
610
|
-
|
|
611
|
-
pluck<K extends keyof TRecord>(
|
|
612
|
-
column: K
|
|
613
|
-
): QueryBuilder<TRecord, TRecord[K][]>;
|
|
614
|
-
pluck<TResult2 extends {}>(column: string): QueryBuilder<TRecord, TResult2>;
|
|
615
|
-
|
|
616
|
-
insert(
|
|
617
|
-
data: TRecord extends CompositeTableType<unknown>
|
|
618
|
-
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
619
|
-
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
620
|
-
returning: '*',
|
|
621
|
-
options?: DMLOptions
|
|
622
|
-
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
623
|
-
insert<
|
|
624
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
625
|
-
TResult2 = DeferredIndex.Augment<
|
|
626
|
-
UnwrapArrayMember<TResult>,
|
|
627
|
-
ResolveTableType<TRecord>,
|
|
628
|
-
TKey
|
|
629
|
-
>[]
|
|
630
|
-
>(
|
|
631
|
-
data: TRecord extends CompositeTableType<unknown>
|
|
632
|
-
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
633
|
-
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
634
|
-
returning: TKey,
|
|
635
|
-
options?: DMLOptions
|
|
636
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
637
|
-
insert<
|
|
638
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
639
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
640
|
-
UnwrapArrayMember<TResult>,
|
|
641
|
-
ResolveTableType<TRecord>,
|
|
642
|
-
TKey
|
|
643
|
-
>[]
|
|
644
|
-
>(
|
|
645
|
-
data: TRecord extends CompositeTableType<unknown>
|
|
646
|
-
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
647
|
-
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
648
|
-
returning: readonly TKey[],
|
|
649
|
-
options?: DMLOptions
|
|
650
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
651
|
-
insert<
|
|
652
|
-
TKey extends string,
|
|
653
|
-
TResult2 = DeferredIndex.Augment<
|
|
654
|
-
UnwrapArrayMember<TResult>,
|
|
655
|
-
TRecord,
|
|
656
|
-
TKey
|
|
657
|
-
>[]
|
|
658
|
-
>(
|
|
659
|
-
data: TRecord extends CompositeTableType<unknown>
|
|
660
|
-
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
661
|
-
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
662
|
-
returning: TKey,
|
|
663
|
-
options?: DMLOptions
|
|
664
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
665
|
-
insert<
|
|
666
|
-
TKey extends string,
|
|
667
|
-
TResult2 = DeferredIndex.Augment<
|
|
668
|
-
UnwrapArrayMember<TResult>,
|
|
669
|
-
TRecord,
|
|
670
|
-
TKey
|
|
671
|
-
>[]
|
|
672
|
-
>(
|
|
673
|
-
data: TRecord extends CompositeTableType<unknown>
|
|
674
|
-
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
675
|
-
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
676
|
-
returning: readonly TKey[],
|
|
677
|
-
options?: DMLOptions
|
|
678
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
679
|
-
insert<TResult2 = number[]>(
|
|
680
|
-
data: TRecord extends CompositeTableType<unknown>
|
|
681
|
-
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
682
|
-
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>
|
|
683
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
684
|
-
|
|
685
|
-
modify<TRecord2 extends {} = any, TResult2 extends {} = any>(
|
|
686
|
-
callback: QueryCallbackWithArgs<TRecord, any>,
|
|
687
|
-
...args: any[]
|
|
688
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
689
|
-
update<
|
|
690
|
-
K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
|
|
691
|
-
K2 extends StrKey<ResolveTableType<TRecord>>,
|
|
692
|
-
TResult2 = DeferredIndex.Augment<
|
|
693
|
-
UnwrapArrayMember<TResult>,
|
|
694
|
-
ResolveTableType<TRecord>,
|
|
695
|
-
K2
|
|
696
|
-
>[]
|
|
697
|
-
>(
|
|
698
|
-
columnName: K1,
|
|
699
|
-
value: DbColumn<ResolveTableType<TRecord, 'update'>[K1]>,
|
|
700
|
-
returning: K2,
|
|
701
|
-
options?: DMLOptions
|
|
702
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
703
|
-
update<
|
|
704
|
-
K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
|
|
705
|
-
K2 extends StrKey<ResolveTableType<TRecord>>,
|
|
706
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
707
|
-
UnwrapArrayMember<TResult>,
|
|
708
|
-
ResolveTableType<TRecord>,
|
|
709
|
-
K2
|
|
710
|
-
>[]
|
|
711
|
-
>(
|
|
712
|
-
columnName: K1,
|
|
713
|
-
value: DbColumn<ResolveTableType<TRecord, 'update'>[K1]>,
|
|
714
|
-
returning: readonly K2[],
|
|
715
|
-
options?: DMLOptions
|
|
716
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
717
|
-
update<K extends keyof TRecord>(
|
|
718
|
-
columnName: K,
|
|
719
|
-
value: DbColumn<TRecord[K]>
|
|
720
|
-
): QueryBuilder<TRecord, number>;
|
|
721
|
-
update<TResult2 = SafePartial<TRecord>[]>(
|
|
722
|
-
columnName: string,
|
|
723
|
-
value: Value,
|
|
724
|
-
returning: string | readonly string[],
|
|
725
|
-
options?: DMLOptions
|
|
726
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
727
|
-
update(
|
|
728
|
-
data: DbRecordArr<TRecord>,
|
|
729
|
-
returning: '*',
|
|
730
|
-
options?: DMLOptions
|
|
731
|
-
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
732
|
-
update<
|
|
733
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
734
|
-
TResult2 = DeferredIndex.Augment<
|
|
735
|
-
UnwrapArrayMember<TResult>,
|
|
736
|
-
ResolveTableType<TRecord>,
|
|
737
|
-
TKey
|
|
738
|
-
>[]
|
|
739
|
-
>(
|
|
740
|
-
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
741
|
-
returning: TKey,
|
|
742
|
-
options?: DMLOptions
|
|
743
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
744
|
-
update<
|
|
745
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
746
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
747
|
-
UnwrapArrayMember<TResult>,
|
|
748
|
-
ResolveTableType<TRecord>,
|
|
749
|
-
TKey
|
|
750
|
-
>[]
|
|
751
|
-
>(
|
|
752
|
-
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
753
|
-
returning: readonly TKey[],
|
|
754
|
-
options?: DMLOptions
|
|
755
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
756
|
-
update<
|
|
757
|
-
TKey extends string = string,
|
|
758
|
-
TResult2 extends {}[] = DeferredKeySelection.Augment<
|
|
759
|
-
UnwrapArrayMember<TResult>,
|
|
760
|
-
TRecord,
|
|
761
|
-
TKey
|
|
762
|
-
>[]
|
|
763
|
-
>(
|
|
764
|
-
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
765
|
-
returning: TKey | readonly TKey[],
|
|
766
|
-
options?: DMLOptions
|
|
767
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
768
|
-
update<
|
|
769
|
-
TKey extends string,
|
|
770
|
-
TResult2 extends {}[] = DeferredKeySelection.Augment<
|
|
771
|
-
UnwrapArrayMember<TResult>,
|
|
772
|
-
TRecord,
|
|
773
|
-
TKey
|
|
774
|
-
>[]
|
|
775
|
-
>(
|
|
776
|
-
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
777
|
-
returning: readonly TKey[],
|
|
778
|
-
options?: DMLOptions
|
|
779
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
780
|
-
update<TResult2 = number>(
|
|
781
|
-
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>
|
|
782
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
783
|
-
|
|
784
|
-
update<TResult2 = number>(columnName: string, value: Value): QueryBuilder<TRecord, TResult2>;
|
|
785
|
-
|
|
786
|
-
returning(column: '*', options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
787
|
-
returning<
|
|
788
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
789
|
-
TResult2 = DeferredIndex.Augment<
|
|
790
|
-
UnwrapArrayMember<TResult>,
|
|
791
|
-
ResolveTableType<TRecord>,
|
|
792
|
-
TKey
|
|
793
|
-
>[]
|
|
794
|
-
>(
|
|
795
|
-
column: TKey,
|
|
796
|
-
options?: DMLOptions
|
|
797
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
798
|
-
returning<
|
|
799
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
800
|
-
TResult2 = DeferredKeySelection.SetSingle<
|
|
801
|
-
DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, ResolveTableType<TRecord>, TKey>,
|
|
802
|
-
false
|
|
803
|
-
>[]
|
|
804
|
-
>(
|
|
805
|
-
columns: readonly TKey[],
|
|
806
|
-
options?: DMLOptions
|
|
807
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
808
|
-
returning<TResult2 = SafePartial<TRecord>[]>(
|
|
809
|
-
column: string | readonly string[],
|
|
810
|
-
options?: DMLOptions
|
|
811
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
812
|
-
|
|
813
|
-
onConflict<
|
|
814
|
-
TKey extends StrKey<TRecord>,
|
|
815
|
-
TResult2 = DeferredIndex.Augment<
|
|
816
|
-
UnwrapArrayMember<TResult>,
|
|
817
|
-
TRecord,
|
|
818
|
-
TKey
|
|
819
|
-
>[]
|
|
820
|
-
>(
|
|
821
|
-
column: TKey
|
|
822
|
-
): OnConflictQueryBuilder<TRecord, TResult2>;
|
|
823
|
-
onConflict<
|
|
824
|
-
TKey extends StrKey<TRecord>,
|
|
825
|
-
TResult2 = DeferredKeySelection.SetSingle<
|
|
826
|
-
DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, TRecord, TKey>,
|
|
827
|
-
false
|
|
828
|
-
>[]
|
|
829
|
-
>(
|
|
830
|
-
columns: readonly TKey[]
|
|
831
|
-
): OnConflictQueryBuilder<TRecord, TResult2>;
|
|
832
|
-
|
|
833
|
-
del(
|
|
834
|
-
returning: '*',
|
|
835
|
-
options?: DMLOptions
|
|
836
|
-
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
837
|
-
del<
|
|
838
|
-
TKey extends StrKey<TRecord>,
|
|
839
|
-
TResult2 = DeferredIndex.Augment<
|
|
840
|
-
UnwrapArrayMember<TResult>,
|
|
841
|
-
TRecord,
|
|
842
|
-
TKey
|
|
843
|
-
>[]
|
|
844
|
-
>(
|
|
845
|
-
returning: TKey,
|
|
846
|
-
options?: DMLOptions
|
|
847
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
848
|
-
del<
|
|
849
|
-
TKey extends StrKey<TRecord>,
|
|
850
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
851
|
-
UnwrapArrayMember<TResult>,
|
|
852
|
-
TRecord,
|
|
853
|
-
TKey
|
|
854
|
-
>[]
|
|
855
|
-
>(
|
|
856
|
-
returning: readonly TKey[],
|
|
857
|
-
options?: DMLOptions
|
|
858
|
-
): QueryBuilder<TRecord, TResult2[]>;
|
|
859
|
-
del<TResult2 = SafePartial<TRecord>[]>(
|
|
860
|
-
returning: string | readonly string[],
|
|
861
|
-
options?: DMLOptions
|
|
862
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
863
|
-
del<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
|
|
864
|
-
|
|
865
|
-
delete(
|
|
866
|
-
returning: '*',
|
|
867
|
-
options?: DMLOptions
|
|
868
|
-
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
869
|
-
delete<
|
|
870
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
871
|
-
TResult2 = DeferredIndex.Augment<
|
|
872
|
-
UnwrapArrayMember<TResult>,
|
|
873
|
-
ResolveTableType<TRecord>,
|
|
874
|
-
TKey
|
|
875
|
-
>[]
|
|
876
|
-
>(
|
|
877
|
-
returning: TKey,
|
|
878
|
-
options?: DMLOptions
|
|
879
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
880
|
-
delete<
|
|
881
|
-
TKey extends StrKey<TRecord>,
|
|
882
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
883
|
-
UnwrapArrayMember<TResult>,
|
|
884
|
-
TRecord,
|
|
885
|
-
TKey
|
|
886
|
-
>[]
|
|
887
|
-
>(
|
|
888
|
-
returning: readonly TKey[],
|
|
889
|
-
options?: DMLOptions
|
|
890
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
891
|
-
delete<TResult2 = any>(
|
|
892
|
-
returning: string | readonly string[],
|
|
893
|
-
options?: DMLOptions
|
|
894
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
895
|
-
delete<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
|
|
896
|
-
|
|
897
|
-
truncate(): QueryBuilder<TRecord, void>;
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
interface As<TRecord, TResult> {
|
|
901
|
-
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
|
|
902
|
-
(columnName: string): QueryBuilder<TRecord, TResult>;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
type IntersectAliases<AliasUT> =
|
|
906
|
-
UnionToIntersection<
|
|
907
|
-
IncompatibleToAlt<
|
|
908
|
-
AliasUT extends (infer I)[]
|
|
909
|
-
? I extends Ref<any, infer TMapping>
|
|
910
|
-
? TMapping
|
|
911
|
-
: I
|
|
912
|
-
: never,
|
|
913
|
-
Dict,
|
|
914
|
-
{}
|
|
915
|
-
>
|
|
916
|
-
>;
|
|
917
|
-
|
|
918
|
-
interface AliasQueryBuilder<TRecord extends {} = any, TResult = unknown[]> {
|
|
919
|
-
<
|
|
920
|
-
AliasUT extends InferrableColumnDescriptor<ResolveTableType<TRecord>>[],
|
|
921
|
-
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
922
|
-
UnwrapArrayMember<TResult>,
|
|
923
|
-
ResolveTableType<TRecord>,
|
|
924
|
-
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
925
|
-
IntersectAliases<AliasUT>
|
|
926
|
-
>>
|
|
927
|
-
>(
|
|
928
|
-
...aliases: AliasUT
|
|
929
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
930
|
-
|
|
931
|
-
<
|
|
932
|
-
AliasUT extends InferrableColumnDescriptor<ResolveTableType<TRecord>>[],
|
|
933
|
-
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
934
|
-
UnwrapArrayMember<TResult>,
|
|
935
|
-
ResolveTableType<TRecord>,
|
|
936
|
-
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
937
|
-
IntersectAliases<AliasUT>
|
|
938
|
-
>>
|
|
939
|
-
>(
|
|
940
|
-
aliases: AliasUT
|
|
941
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
942
|
-
|
|
943
|
-
<
|
|
944
|
-
AliasUT extends (Dict | string)[],
|
|
945
|
-
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
946
|
-
UnwrapArrayMember<TResult>,
|
|
947
|
-
ResolveTableType<TRecord>,
|
|
948
|
-
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
949
|
-
IntersectAliases<AliasUT>
|
|
950
|
-
>>
|
|
951
|
-
>(
|
|
952
|
-
...aliases: AliasUT
|
|
953
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
954
|
-
|
|
955
|
-
<
|
|
956
|
-
AliasUT extends (Dict | string)[],
|
|
957
|
-
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
958
|
-
UnwrapArrayMember<TResult>,
|
|
959
|
-
TRecord,
|
|
960
|
-
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
961
|
-
IntersectAliases<AliasUT>
|
|
962
|
-
>>
|
|
963
|
-
>(
|
|
964
|
-
aliases: AliasUT
|
|
965
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
interface Select<TRecord extends {} = any, TResult = unknown[]>
|
|
969
|
-
extends AliasQueryBuilder<TRecord, TResult>,
|
|
970
|
-
ColumnNameQueryBuilder<TRecord, TResult> {
|
|
971
|
-
(): QueryBuilder<TRecord, TResult>;
|
|
972
|
-
|
|
973
|
-
<TResult2 = ArrayIfAlready<TResult, any>, TInnerRecord = any, TInnerResult = any>(
|
|
974
|
-
...subQueryBuilders: readonly QueryBuilder<TInnerRecord, TInnerResult>[]
|
|
975
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
976
|
-
|
|
977
|
-
<TResult2 = ArrayIfAlready<TResult, any>, TInnerRecord = any, TInnerResult = any>(
|
|
978
|
-
subQueryBuilders: readonly QueryBuilder<TInnerRecord, TInnerResult>[]
|
|
979
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
interface HintComment<TRecord extends {} = any, TResult extends {} = any> {
|
|
983
|
-
(hint: string): QueryBuilder<TRecord, TResult>;
|
|
984
|
-
(hints: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
interface Table<TRecord extends {} = any, TResult extends {} = any> {
|
|
988
|
-
<
|
|
989
|
-
TTable extends TableNames,
|
|
990
|
-
TRecord2 = TableType<TTable>,
|
|
991
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, ResolveTableType<TRecord2>>
|
|
992
|
-
>(
|
|
993
|
-
tableName: TTable,
|
|
994
|
-
options?: TableOptions
|
|
995
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
996
|
-
<
|
|
997
|
-
TRecord2 = unknown,
|
|
998
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
999
|
-
>(
|
|
1000
|
-
tableName: TableDescriptor | AliasDict,
|
|
1001
|
-
options?: TableOptions
|
|
1002
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1003
|
-
<
|
|
1004
|
-
TRecord2 = unknown,
|
|
1005
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1006
|
-
>(
|
|
1007
|
-
callback: Function,
|
|
1008
|
-
options?: TableOptions
|
|
1009
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1010
|
-
<
|
|
1011
|
-
TRecord2 = unknown,
|
|
1012
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1013
|
-
>(
|
|
1014
|
-
raw: Raw,
|
|
1015
|
-
options?: TableOptions
|
|
1016
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
interface Distinct<TRecord extends {}, TResult = {}[]>
|
|
1020
|
-
extends ColumnNameQueryBuilder<TRecord, TResult> {}
|
|
1021
|
-
|
|
1022
|
-
interface DistinctOn<TRecord extends {}, TResult = {}[]> {
|
|
1023
|
-
<ColNameUT extends keyof TRecord>(
|
|
1024
|
-
...columnNames: readonly ColNameUT[]
|
|
1025
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1026
|
-
|
|
1027
|
-
<ColNameUT extends keyof TRecord>(
|
|
1028
|
-
columnNames: readonly ColNameUT[]
|
|
1029
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1030
|
-
|
|
1031
|
-
(...columnNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1032
|
-
(columnNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
interface JoinCallback {
|
|
1036
|
-
(this: JoinClause, join: JoinClause): void;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
interface Join<TRecord extends {} = any, TResult = unknown[]> {
|
|
1040
|
-
<
|
|
1041
|
-
TJoinTargetRecord extends {} = any,
|
|
1042
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1043
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1044
|
-
>(
|
|
1045
|
-
raw: Raw
|
|
1046
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1047
|
-
<
|
|
1048
|
-
TTable extends TableNames,
|
|
1049
|
-
TRecord2 = ResolveTableType<TRecord> & ResolveTableType<TableType<TTable>>,
|
|
1050
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1051
|
-
>(
|
|
1052
|
-
tableName: TTable,
|
|
1053
|
-
clause: JoinCallback
|
|
1054
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1055
|
-
<
|
|
1056
|
-
TJoinTargetRecord extends {} = any,
|
|
1057
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1058
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1059
|
-
>(
|
|
1060
|
-
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1061
|
-
clause: JoinCallback
|
|
1062
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1063
|
-
<
|
|
1064
|
-
TJoinTargetRecord extends {} = any,
|
|
1065
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1066
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1067
|
-
>(
|
|
1068
|
-
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1069
|
-
columns: { [key: string]: string | number | boolean | Raw }
|
|
1070
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1071
|
-
<
|
|
1072
|
-
TJoinTargetRecord extends {} = any,
|
|
1073
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1074
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1075
|
-
>(
|
|
1076
|
-
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1077
|
-
raw: Raw
|
|
1078
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1079
|
-
<
|
|
1080
|
-
TTable extends TableNames,
|
|
1081
|
-
TRecord2 = ResolveTableType<TRecord> & ResolveTableType<TableType<TTable>>,
|
|
1082
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1083
|
-
>(
|
|
1084
|
-
tableName: TTable,
|
|
1085
|
-
column1: string,
|
|
1086
|
-
column2: string
|
|
1087
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1088
|
-
<
|
|
1089
|
-
TJoinTargetRecord extends {} = any,
|
|
1090
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1091
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1092
|
-
>(
|
|
1093
|
-
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1094
|
-
column1: string,
|
|
1095
|
-
column2: string
|
|
1096
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1097
|
-
<
|
|
1098
|
-
TJoinTargetRecord extends {} = any,
|
|
1099
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1100
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1101
|
-
>(
|
|
1102
|
-
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1103
|
-
column1: string,
|
|
1104
|
-
raw: Raw
|
|
1105
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1106
|
-
<
|
|
1107
|
-
TTable extends TableNames,
|
|
1108
|
-
TRecord2 = ResolveTableType<TRecord> & ResolveTableType<TableType<TTable>>,
|
|
1109
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1110
|
-
>(
|
|
1111
|
-
tableName: TTable,
|
|
1112
|
-
column1: string,
|
|
1113
|
-
operator: string,
|
|
1114
|
-
column2: string
|
|
1115
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1116
|
-
<
|
|
1117
|
-
TJoinTargetRecord extends {} = any,
|
|
1118
|
-
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1119
|
-
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1120
|
-
>(
|
|
1121
|
-
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1122
|
-
column1: string,
|
|
1123
|
-
operator: string,
|
|
1124
|
-
column2: string
|
|
1125
|
-
): QueryBuilder<TRecord2, TResult2>;
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
interface JoinClause {
|
|
1129
|
-
on(raw: Raw): JoinClause;
|
|
1130
|
-
on(callback: JoinCallback): JoinClause;
|
|
1131
|
-
on(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1132
|
-
on(column1: string, column2: string): JoinClause;
|
|
1133
|
-
on(column1: string, raw: Raw): JoinClause;
|
|
1134
|
-
on(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1135
|
-
andOn(raw: Raw): JoinClause;
|
|
1136
|
-
andOn(callback: JoinCallback): JoinClause;
|
|
1137
|
-
andOn(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1138
|
-
andOn(column1: string, column2: string): JoinClause;
|
|
1139
|
-
andOn(column1: string, raw: Raw): JoinClause;
|
|
1140
|
-
andOn(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1141
|
-
orOn(raw: Raw): JoinClause;
|
|
1142
|
-
orOn(callback: JoinCallback): JoinClause;
|
|
1143
|
-
orOn(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1144
|
-
orOn(column1: string, column2: string): JoinClause;
|
|
1145
|
-
orOn(column1: string, raw: Raw): JoinClause;
|
|
1146
|
-
orOn(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1147
|
-
onIn(column1: string, values: readonly any[]): JoinClause;
|
|
1148
|
-
andOnIn(column1: string, values: readonly any[]): JoinClause;
|
|
1149
|
-
orOnIn(column1: string, values: readonly any[]): JoinClause;
|
|
1150
|
-
onNotIn(column1: string, values: readonly any[]): JoinClause;
|
|
1151
|
-
andOnNotIn(column1: string, values: readonly any[]): JoinClause;
|
|
1152
|
-
orOnNotIn(column1: string, values: readonly any[]): JoinClause;
|
|
1153
|
-
onNull(column1: string): JoinClause;
|
|
1154
|
-
andOnNull(column1: string): JoinClause;
|
|
1155
|
-
orOnNull(column1: string): JoinClause;
|
|
1156
|
-
onNotNull(column1: string): JoinClause;
|
|
1157
|
-
andOnNotNull(column1: string): JoinClause;
|
|
1158
|
-
orOnNotNull(column1: string): JoinClause;
|
|
1159
|
-
onExists(callback: QueryCallback): JoinClause;
|
|
1160
|
-
andOnExists(callback: QueryCallback): JoinClause;
|
|
1161
|
-
orOnExists(callback: QueryCallback): JoinClause;
|
|
1162
|
-
onNotExists(callback: QueryCallback): JoinClause;
|
|
1163
|
-
andOnNotExists(callback: QueryCallback): JoinClause;
|
|
1164
|
-
orOnNotExists(callback: QueryCallback): JoinClause;
|
|
1165
|
-
onBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1166
|
-
andOnBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1167
|
-
orOnBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1168
|
-
onNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1169
|
-
andOnNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1170
|
-
orOnNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1171
|
-
using(
|
|
1172
|
-
column: string | readonly string[] | Raw | { [key: string]: string | Raw }
|
|
1173
|
-
): JoinClause;
|
|
1174
|
-
type(type: string): JoinClause;
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
interface JoinRaw<TRecord = any, TResult = unknown[]> {
|
|
1178
|
-
(tableName: string, binding?: Value | ValueDict): QueryBuilder<
|
|
1179
|
-
TRecord,
|
|
1180
|
-
TResult
|
|
1181
|
-
>;
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
interface With<TRecord = any, TResult = unknown[]>
|
|
1185
|
-
extends WithRaw<TRecord, TResult>,
|
|
1186
|
-
WithWrapped<TRecord, TResult> {}
|
|
1187
|
-
|
|
1188
|
-
interface WithRaw<TRecord = any, TResult = unknown[]> {
|
|
1189
|
-
(alias: string, raw: Raw | QueryBuilder): QueryBuilder<TRecord, TResult>;
|
|
1190
|
-
(alias: string, sql: string, bindings?: readonly Value[] | Object): QueryBuilder<
|
|
1191
|
-
TRecord,
|
|
1192
|
-
TResult
|
|
1193
|
-
>;
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
interface WithSchema<TRecord = any, TResult = unknown[]> {
|
|
1197
|
-
(schema: string): QueryBuilder<TRecord, TResult>;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
interface WithWrapped<TRecord = any, TResult = unknown[]> {
|
|
1201
|
-
(alias: string, queryBuilder: QueryBuilder): QueryBuilder<TRecord, TResult>;
|
|
1202
|
-
(
|
|
1203
|
-
alias: string,
|
|
1204
|
-
callback: (queryBuilder: QueryBuilder) => any
|
|
1205
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
interface Where<TRecord = any, TResult = unknown>
|
|
1209
|
-
extends WhereRaw<TRecord, TResult>,
|
|
1210
|
-
WhereWrapped<TRecord, TResult>,
|
|
1211
|
-
WhereNull<TRecord, TResult> {
|
|
1212
|
-
(raw: Raw): QueryBuilder<TRecord, TResult>;
|
|
1213
|
-
|
|
1214
|
-
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1215
|
-
|
|
1216
|
-
(object: DbRecord<ResolveTableType<TRecord>>): QueryBuilder<TRecord, TResult>;
|
|
1217
|
-
|
|
1218
|
-
(object: Readonly<Object>): QueryBuilder<TRecord, TResult>;
|
|
1219
|
-
|
|
1220
|
-
<T extends keyof ResolveTableType<TRecord>>(
|
|
1221
|
-
columnName: T,
|
|
1222
|
-
value: DbColumn<ResolveTableType<TRecord>[T]> | null
|
|
1223
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1224
|
-
|
|
1225
|
-
(columnName: string, value: Value | null): QueryBuilder<TRecord, TResult>;
|
|
1226
|
-
|
|
1227
|
-
<T extends keyof ResolveTableType<TRecord>>(
|
|
1228
|
-
columnName: T,
|
|
1229
|
-
operator: ComparisonOperator,
|
|
1230
|
-
value: DbColumn<ResolveTableType<TRecord>[T]> | null
|
|
1231
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1232
|
-
|
|
1233
|
-
(columnName: string, operator: string, value: Value | null): QueryBuilder<
|
|
1234
|
-
TRecord,
|
|
1235
|
-
TResult
|
|
1236
|
-
>;
|
|
1237
|
-
|
|
1238
|
-
<T extends keyof ResolveTableType<TRecord>, TRecordInner, TResultInner>(
|
|
1239
|
-
columnName: T,
|
|
1240
|
-
operator: ComparisonOperator,
|
|
1241
|
-
value: QueryBuilder<TRecordInner, TResultInner>
|
|
1242
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1243
|
-
|
|
1244
|
-
<TRecordInner, TResultInner>(
|
|
1245
|
-
columnName: string,
|
|
1246
|
-
operator: string,
|
|
1247
|
-
value: QueryBuilder<TRecordInner, TResultInner>
|
|
1248
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1249
|
-
|
|
1250
|
-
(left: Raw, operator: string, right: Value | null): QueryBuilder<
|
|
1251
|
-
TRecord,
|
|
1252
|
-
TResult
|
|
1253
|
-
>;
|
|
1254
|
-
|
|
1255
|
-
<TRecordInner, TResultInner>(
|
|
1256
|
-
left: Raw,
|
|
1257
|
-
operator: string,
|
|
1258
|
-
right: QueryBuilder<TRecordInner, TResultInner>
|
|
1259
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
interface WhereRaw<TRecord = any, TResult = unknown[]>
|
|
1263
|
-
extends RawQueryBuilder<TRecord, TResult> {
|
|
1264
|
-
(condition: boolean): QueryBuilder<TRecord, TResult>;
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
interface WhereWrapped<TRecord = any, TResult = unknown[]> {
|
|
1268
|
-
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
interface WhereNull<TRecord = any, TResult = unknown[]> {
|
|
1272
|
-
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
|
|
1273
|
-
(columnName: string): QueryBuilder<TRecord, TResult>;
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
interface WhereBetween<TRecord = any, TResult = unknown[]> {
|
|
1277
|
-
<K extends keyof TRecord>(
|
|
1278
|
-
columnName: K,
|
|
1279
|
-
range: readonly [DbColumn<TRecord[K]>, DbColumn<TRecord[K]>]
|
|
1280
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1281
|
-
(columnName: string, range: readonly [Value, Value]): QueryBuilder<TRecord, TResult>;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
interface WhereExists<TRecord = any, TResult = unknown[]> {
|
|
1285
|
-
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1286
|
-
<TRecordInner, TResultInner>(
|
|
1287
|
-
query: QueryBuilder<TRecordInner, TResultInner>
|
|
1288
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
interface WhereIn<TRecord = any, TResult = unknown[]> {
|
|
1292
|
-
<K extends keyof ResolveTableType<TRecord>>(
|
|
1293
|
-
columnName: K,
|
|
1294
|
-
values: readonly DbColumn<ResolveTableType<TRecord>[K]>[] | QueryCallback
|
|
1295
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1296
|
-
(columnName: string, values: readonly Value[] | QueryCallback): QueryBuilder<
|
|
1297
|
-
TRecord,
|
|
1298
|
-
TResult
|
|
1299
|
-
>;
|
|
1300
|
-
<K extends keyof ResolveTableType<TRecord>>(
|
|
1301
|
-
columnNames: readonly K[],
|
|
1302
|
-
values: readonly (readonly DbColumn<ResolveTableType<TRecord>[K]>[])[] | QueryCallback
|
|
1303
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1304
|
-
(columnNames: readonly string[], values: readonly Value[][] | QueryCallback): QueryBuilder<
|
|
1305
|
-
TRecord,
|
|
1306
|
-
TResult
|
|
1307
|
-
>;
|
|
1308
|
-
<K extends keyof TRecord, TRecordInner, TResultInner>(
|
|
1309
|
-
columnName: K,
|
|
1310
|
-
values: QueryBuilder<TRecordInner, TRecord[K]>
|
|
1311
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1312
|
-
<TRecordInner, TResultInner>(
|
|
1313
|
-
columnName: string,
|
|
1314
|
-
values: Value[] | QueryBuilder<TRecordInner, TResultInner>
|
|
1315
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1316
|
-
<K extends keyof TRecord, TRecordInner, TResultInner>(
|
|
1317
|
-
columnNames: readonly K[],
|
|
1318
|
-
values: QueryBuilder<TRecordInner, TRecord[K]>
|
|
1319
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1320
|
-
<TRecordInner, TResultInner>(
|
|
1321
|
-
columnNames: readonly string[],
|
|
1322
|
-
values: QueryBuilder<TRecordInner, TResultInner>
|
|
1323
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
// Note: Attempting to unify AsymmetricAggregation & TypePreservingAggregation
|
|
1327
|
-
// by extracting out a common base interface will not work because order of overloads
|
|
1328
|
-
// is significant.
|
|
1329
|
-
|
|
1330
|
-
interface AsymmetricAggregation<TRecord = any, TResult = unknown[], TValue = any> {
|
|
1331
|
-
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1332
|
-
...columnNames: readonly (keyof ResolveTableType<TRecord>)[]
|
|
1333
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1334
|
-
<
|
|
1335
|
-
TAliases extends {} = Record<string, string | string[] | Knex.Raw>,
|
|
1336
|
-
TResult2 = AggregationQueryResult<TResult, {[k in keyof TAliases]?: TValue}>
|
|
1337
|
-
>(aliases: TAliases): QueryBuilder<TRecord, TResult2>;
|
|
1338
|
-
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1339
|
-
...columnNames: ReadonlyArray<Readonly<Record<string, string | string[] | Knex.Raw>> | Knex.Raw | string>
|
|
1340
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
interface TypePreservingAggregation<TRecord = any, TResult = unknown[], TValue = any> {
|
|
1344
|
-
<
|
|
1345
|
-
TKey extends keyof ResolveTableType<TRecord>,
|
|
1346
|
-
TResult2 = AggregationQueryResult<TResult, Dict<ResolveTableType<TRecord>[TKey]>>
|
|
1347
|
-
>(
|
|
1348
|
-
...columnNames: readonly TKey[]
|
|
1349
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1350
|
-
<
|
|
1351
|
-
TAliases extends {} = Readonly<Record<string, string | string[] | Knex.Raw>>,
|
|
1352
|
-
TResult2 = AggregationQueryResult<TResult, {
|
|
1353
|
-
// We have optional here because in most dialects aggregating by multiple keys simultaneously
|
|
1354
|
-
// causes rest of the keys to be dropped and only first to be considered
|
|
1355
|
-
[K in keyof TAliases]?: K extends keyof TRecord ?
|
|
1356
|
-
TRecord[K] :
|
|
1357
|
-
TValue
|
|
1358
|
-
}>
|
|
1359
|
-
>(aliases: TAliases): QueryBuilder<TRecord, TResult2>;
|
|
1360
|
-
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1361
|
-
...columnNames: ReadonlyArray<Readonly<Record<string, string | readonly string[] | Knex.Raw>> | Knex.Raw | string>
|
|
1362
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
interface GroupBy<TRecord = any, TResult = unknown[]>
|
|
1366
|
-
extends RawQueryBuilder<TRecord, TResult>,
|
|
1367
|
-
ColumnNameQueryBuilder<TRecord, TResult> {}
|
|
1368
|
-
|
|
1369
|
-
interface OrderBy<TRecord = any, TResult = unknown[]> {
|
|
1370
|
-
(columnName: keyof TRecord | QueryBuilder, order?: 'asc' | 'desc'): QueryBuilder<
|
|
1371
|
-
TRecord,
|
|
1372
|
-
TResult
|
|
1373
|
-
>;
|
|
1374
|
-
(columnName: string | QueryBuilder, order?: string): QueryBuilder<TRecord, TResult>;
|
|
1375
|
-
(
|
|
1376
|
-
columnDefs: Array<
|
|
1377
|
-
keyof TRecord | Readonly<{
|
|
1378
|
-
column: keyof TRecord | QueryBuilder;
|
|
1379
|
-
order?: 'asc' | 'desc'
|
|
1380
|
-
}>
|
|
1381
|
-
>
|
|
1382
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1383
|
-
(
|
|
1384
|
-
columnDefs: Array<string | Readonly<{
|
|
1385
|
-
column: string | QueryBuilder;
|
|
1386
|
-
order?: string;
|
|
1387
|
-
}>>
|
|
1388
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
interface Intersect<TRecord = any, TResult = unknown[]> {
|
|
1392
|
-
(
|
|
1393
|
-
callback: MaybeArray<QueryCallback | QueryBuilder<TRecord> | Raw>,
|
|
1394
|
-
wrap?: boolean
|
|
1395
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1396
|
-
(
|
|
1397
|
-
...callbacks: readonly (QueryCallback | Raw | QueryBuilder<TRecord>)[]
|
|
1398
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
interface Union<TRecord = any, TResult = unknown[]>
|
|
1402
|
-
extends Intersect<TRecord, TResult> {}
|
|
1403
|
-
|
|
1404
|
-
interface Having<TRecord = any, TResult = unknown[]>
|
|
1405
|
-
extends WhereWrapped<TRecord, TResult> {
|
|
1406
|
-
<K extends keyof TRecord>(
|
|
1407
|
-
column: K,
|
|
1408
|
-
operator: ComparisonOperator,
|
|
1409
|
-
value: DbColumn<TRecord[K]>
|
|
1410
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1411
|
-
|
|
1412
|
-
(
|
|
1413
|
-
column: string | Raw,
|
|
1414
|
-
operator: string,
|
|
1415
|
-
value: Value | QueryBuilder | null
|
|
1416
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1417
|
-
|
|
1418
|
-
(raw: Raw): QueryBuilder<
|
|
1419
|
-
TRecord,
|
|
1420
|
-
TResult
|
|
1421
|
-
>;
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
interface HavingRange<TRecord = any, TResult = unknown[]> {
|
|
1425
|
-
<K extends keyof TRecord>(
|
|
1426
|
-
columnName: K,
|
|
1427
|
-
values: readonly DbColumn<TRecord[K]>[]
|
|
1428
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1429
|
-
(columnName: string, values: readonly Value[]): QueryBuilder<TRecord, TResult>;
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
// commons
|
|
1433
|
-
|
|
1434
|
-
interface ColumnNameQueryBuilder<TRecord = any, TResult = unknown[]> {
|
|
1435
|
-
// When all columns are known to be keys of original record,
|
|
1436
|
-
// we can extend our selection by these columns
|
|
1437
|
-
(columnName: '*'): QueryBuilder<
|
|
1438
|
-
TRecord,
|
|
1439
|
-
ArrayIfAlready<TResult, DeferredKeySelection<TRecord, string>>
|
|
1440
|
-
>;
|
|
1441
|
-
|
|
1442
|
-
<
|
|
1443
|
-
ColNameUT extends keyof ResolveTableType<TRecord>,
|
|
1444
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
1445
|
-
UnwrapArrayMember<TResult>,
|
|
1446
|
-
ResolveTableType<TRecord>,
|
|
1447
|
-
ColNameUT & string
|
|
1448
|
-
>[]
|
|
1449
|
-
>(
|
|
1450
|
-
...columnNames: readonly ColNameUT[]
|
|
1451
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1452
|
-
|
|
1453
|
-
<
|
|
1454
|
-
ColNameUT extends keyof ResolveTableType<TRecord>,
|
|
1455
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
1456
|
-
UnwrapArrayMember<TResult>,
|
|
1457
|
-
ResolveTableType<TRecord>,
|
|
1458
|
-
ColNameUT & string
|
|
1459
|
-
>[]
|
|
1460
|
-
>(
|
|
1461
|
-
columnNames: readonly ColNameUT[]
|
|
1462
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1463
|
-
|
|
1464
|
-
// For non-inferrable column selection, we will allow consumer to
|
|
1465
|
-
// specify result type and if not widen the result to entire record type with any omissions permitted
|
|
1466
|
-
<
|
|
1467
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
1468
|
-
UnwrapArrayMember<TResult>,
|
|
1469
|
-
SafePartial<TRecord>,
|
|
1470
|
-
keyof TRecord & string
|
|
1471
|
-
>[]
|
|
1472
|
-
>(
|
|
1473
|
-
...columnNames: readonly ColumnDescriptor<TRecord, TResult>[]
|
|
1474
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1475
|
-
|
|
1476
|
-
<
|
|
1477
|
-
TResult2 = DeferredKeySelection.Augment<
|
|
1478
|
-
UnwrapArrayMember<TResult>,
|
|
1479
|
-
SafePartial<TRecord>,
|
|
1480
|
-
keyof TRecord & string
|
|
1481
|
-
>[]
|
|
1482
|
-
>(
|
|
1483
|
-
columnNames: readonly ColumnDescriptor<TRecord, TResult>[]
|
|
1484
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
type RawBinding = Value | QueryBuilder;
|
|
1488
|
-
|
|
1489
|
-
interface RawQueryBuilder<TRecord = any, TResult = unknown[]> {
|
|
1490
|
-
<TResult2 = TResult>(
|
|
1491
|
-
sql: string,
|
|
1492
|
-
bindings?: readonly RawBinding[] | ValueDict | RawBinding
|
|
1493
|
-
): QueryBuilder<TRecord, TResult2>;
|
|
1494
|
-
<TResult2 = TResult>(raw: Raw<TResult2>): QueryBuilder<
|
|
1495
|
-
TRecord,
|
|
1496
|
-
TResult2
|
|
1497
|
-
>;
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
// Raw
|
|
1501
|
-
|
|
1502
|
-
interface Raw<TResult = any>
|
|
1503
|
-
extends events.EventEmitter,
|
|
1504
|
-
ChainableInterface<ResolveResult<TResult>> {
|
|
1505
|
-
timeout(ms: number, options?: {cancel?: boolean}): Raw<TResult>;
|
|
1506
|
-
wrap<TResult2 = TResult>(before: string, after: string): Raw<TResult>;
|
|
1507
|
-
toSQL(): Sql;
|
|
1508
|
-
queryContext(context: any): Raw<TResult>;
|
|
1509
|
-
queryContext(): any;
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
interface RawBuilder<TRecord extends {} = any, TResult = any> {
|
|
1513
|
-
<TResult2 = TResult>(value: Value): Raw<TResult2>;
|
|
1514
|
-
<TResult2 = TResult>(sql: string, ...bindings: readonly RawBinding[]): Raw<TResult2>;
|
|
1515
|
-
<TResult2 = TResult>(sql: string, bindings: readonly RawBinding[] | ValueDict): Raw<TResult2>;
|
|
1516
|
-
}
|
|
1517
|
-
|
|
1518
|
-
const RefMemberTag: unique symbol;
|
|
1519
|
-
|
|
1520
|
-
interface Ref<TSrc extends string, TMapping extends {}> extends Raw<string> {
|
|
1521
|
-
// TypeScript can behave weirdly if type parameters are not
|
|
1522
|
-
// actually used in the members of type.
|
|
1523
|
-
//
|
|
1524
|
-
// See: https://github.com/knex/knex/issues/3932
|
|
1525
|
-
//
|
|
1526
|
-
// We simply need to propagate the type context so that we can extract
|
|
1527
|
-
// them later, but we just add a "phantom" property so that typescript
|
|
1528
|
-
// doesn't think that these parameters are unused
|
|
1529
|
-
//
|
|
1530
|
-
// Because unique symbol is used here, there is no way to actually
|
|
1531
|
-
// access this at runtime
|
|
1532
|
-
[RefMemberTag]: {
|
|
1533
|
-
src: TSrc,
|
|
1534
|
-
mapping: TMapping
|
|
1535
|
-
};
|
|
1536
|
-
withSchema(schema: string): this;
|
|
1537
|
-
as<TAlias extends string>(alias: TAlias): Ref<TSrc, {[K in TAlias]: TSrc}>;
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
|
-
interface RefBuilder {
|
|
1541
|
-
<TSrc extends string>(src: TSrc): Ref<TSrc, {[K in TSrc]: TSrc}>;
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
interface BatchInsertBuilder<TRecord extends {} = any, TResult = number[]> extends Promise<ResolveResult<TResult>> {
|
|
1545
|
-
transacting(trx: Transaction): this;
|
|
1546
|
-
// see returning methods from QueryInterface
|
|
1547
|
-
returning(column: '*'): BatchInsertBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
1548
|
-
returning<
|
|
1549
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1550
|
-
TResult2 = DeferredIndex.Augment<
|
|
1551
|
-
UnwrapArrayMember<TResult>,
|
|
1552
|
-
ResolveTableType<TRecord>,
|
|
1553
|
-
TKey
|
|
1554
|
-
>[]
|
|
1555
|
-
>(
|
|
1556
|
-
column: TKey
|
|
1557
|
-
): BatchInsertBuilder<TRecord, TResult2>;
|
|
1558
|
-
returning<
|
|
1559
|
-
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1560
|
-
TResult2 = DeferredKeySelection.SetSingle<
|
|
1561
|
-
DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, ResolveTableType<TRecord>, TKey>,
|
|
1562
|
-
false
|
|
1563
|
-
>[]
|
|
1564
|
-
>(
|
|
1565
|
-
columns: readonly TKey[]
|
|
1566
|
-
): BatchInsertBuilder<TRecord, TResult2>;
|
|
1567
|
-
// if data with specific type passed, exclude this method
|
|
1568
|
-
returning<TResult2 = SafePartial<TRecord>[]>(
|
|
1569
|
-
column: unknown extends TRecord ? string | readonly string[] : never
|
|
1570
|
-
): BatchInsertBuilder<TRecord, TResult2>;
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
//
|
|
1574
|
-
// QueryBuilder
|
|
1575
|
-
//
|
|
1576
|
-
|
|
1577
|
-
type QueryCallback<TRecord = any, TResult = unknown[]> = (
|
|
1578
|
-
this: QueryBuilder<TRecord, TResult>,
|
|
1579
|
-
builder: QueryBuilder<TRecord, TResult>
|
|
1580
|
-
) => void;
|
|
1581
|
-
|
|
1582
|
-
type QueryCallbackWithArgs<TRecord = any, TResult = unknown[]> = (
|
|
1583
|
-
this: QueryBuilder<TRecord, TResult>,
|
|
1584
|
-
builder: QueryBuilder<TRecord, TResult>,
|
|
1585
|
-
...args: any[]
|
|
1586
|
-
) => void;
|
|
1587
|
-
|
|
1588
|
-
interface QueryBuilder<
|
|
1589
|
-
TRecord extends {} = any,
|
|
1590
|
-
TResult = any
|
|
1591
|
-
>
|
|
1592
|
-
extends QueryInterface<TRecord, TResult>,
|
|
1593
|
-
ChainableInterface<ResolveResult<TResult>> {
|
|
1594
|
-
client: Client;
|
|
1595
|
-
or: QueryBuilder<TRecord, TResult>;
|
|
1596
|
-
not: QueryBuilder<TRecord, TResult>;
|
|
1597
|
-
and: QueryBuilder<TRecord, TResult>;
|
|
1598
|
-
|
|
1599
|
-
// TODO: Promise?
|
|
1600
|
-
columnInfo(column?: keyof TRecord): Promise<ColumnInfo>;
|
|
1601
|
-
|
|
1602
|
-
forUpdate(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
1603
|
-
forUpdate(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1604
|
-
|
|
1605
|
-
forShare(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
1606
|
-
forShare(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1607
|
-
|
|
1608
|
-
skipLocked(): QueryBuilder<TRecord, TResult>;
|
|
1609
|
-
noWait(): QueryBuilder<TRecord, TResult>;
|
|
1610
|
-
|
|
1611
|
-
toSQL(): Sql;
|
|
1612
|
-
|
|
1613
|
-
on(event: string, callback: Function): QueryBuilder<TRecord, TResult>;
|
|
1614
|
-
|
|
1615
|
-
queryContext(context: any): QueryBuilder<TRecord, TResult>;
|
|
1616
|
-
queryContext(): any;
|
|
1617
|
-
|
|
1618
|
-
clone(): QueryBuilder<TRecord, TResult>;
|
|
1619
|
-
timeout(ms: number, options?: {cancel?: boolean}): QueryBuilder<TRecord, TResult>;
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
interface Sql {
|
|
1623
|
-
method: string;
|
|
1624
|
-
options: any;
|
|
1625
|
-
bindings: readonly Value[];
|
|
1626
|
-
sql: string;
|
|
1627
|
-
toNative(): SqlNative;
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
interface SqlNative {
|
|
1631
|
-
bindings: readonly Value[];
|
|
1632
|
-
sql: string;
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
//
|
|
1636
|
-
// Chainable interface
|
|
1637
|
-
//
|
|
1638
|
-
|
|
1639
|
-
type ExposedPromiseKeys =
|
|
1640
|
-
| "then"
|
|
1641
|
-
| "catch"
|
|
1642
|
-
| "finally";
|
|
1643
|
-
|
|
1644
|
-
interface StringTagSupport {
|
|
1645
|
-
readonly [Symbol.toStringTag]: string;
|
|
1646
|
-
}
|
|
1647
|
-
interface ChainableInterface<T = any> extends Pick<Promise<T>, keyof Promise<T> & ExposedPromiseKeys>, StringTagSupport {
|
|
1648
|
-
toQuery(): string;
|
|
1649
|
-
options(options: Readonly<{ [key: string]: any }>): this;
|
|
1650
|
-
connection(connection: any): this;
|
|
1651
|
-
debug(enabled: boolean): this;
|
|
1652
|
-
transacting(trx: Transaction): this;
|
|
1653
|
-
stream(handler: (readable: stream.PassThrough) => any): Promise<any>;
|
|
1654
|
-
stream(
|
|
1655
|
-
options: Readonly<{ [key: string]: any }>,
|
|
1656
|
-
handler: (readable: stream.PassThrough) => any
|
|
1657
|
-
): Promise<any>;
|
|
1658
|
-
stream(options?: Readonly<{ [key: string]: any }>): stream.PassThrough;
|
|
1659
|
-
pipe<T extends NodeJS.WritableStream>(
|
|
1660
|
-
writable: T,
|
|
1661
|
-
options?: Readonly<{ [key: string]: any }>
|
|
1662
|
-
): stream.PassThrough;
|
|
1663
|
-
asCallback(callback: Function): Promise<T>;
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
interface Transaction<TRecord extends {} = any, TResult = any>
|
|
1667
|
-
extends Knex<TRecord, TResult> {
|
|
1668
|
-
executionPromise: Promise<TResult>;
|
|
1669
|
-
isCompleted: () => boolean;
|
|
1670
|
-
|
|
1671
|
-
query<TRecord extends {} = any, TResult = void>(
|
|
1672
|
-
conn: any,
|
|
1673
|
-
sql: any,
|
|
1674
|
-
status: any,
|
|
1675
|
-
value: any
|
|
1676
|
-
): QueryBuilder<TRecord, TResult>;
|
|
1677
|
-
savepoint<T = any>(
|
|
1678
|
-
transactionScope: (trx: Transaction) => any
|
|
1679
|
-
): Promise<T>;
|
|
1680
|
-
commit(value?: any): QueryBuilder<TRecord, TResult>;
|
|
1681
|
-
rollback(error?: any): QueryBuilder<TRecord, TResult>;
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
//
|
|
1685
|
-
// Schema builder
|
|
1686
|
-
//
|
|
1687
|
-
|
|
1688
|
-
interface SchemaBuilder extends ChainableInterface<void> {
|
|
1689
|
-
createTable(
|
|
1690
|
-
tableName: string,
|
|
1691
|
-
callback: (tableBuilder: CreateTableBuilder) => any
|
|
1692
|
-
): SchemaBuilder;
|
|
1693
|
-
createTableIfNotExists(
|
|
1694
|
-
tableName: string,
|
|
1695
|
-
callback: (tableBuilder: CreateTableBuilder) => any
|
|
1696
|
-
): SchemaBuilder;
|
|
1697
|
-
createSchema(schemaName: string): SchemaBuilder;
|
|
1698
|
-
createSchemaIfNotExists(schemaName: string): SchemaBuilder;
|
|
1699
|
-
alterTable(
|
|
1700
|
-
tableName: string,
|
|
1701
|
-
callback: (tableBuilder: CreateTableBuilder) => any
|
|
1702
|
-
): SchemaBuilder;
|
|
1703
|
-
renameTable(oldTableName: string, newTableName: string): Promise<void>;
|
|
1704
|
-
dropTable(tableName: string): SchemaBuilder;
|
|
1705
|
-
hasTable(tableName: string): Promise<boolean>;
|
|
1706
|
-
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
1707
|
-
table(
|
|
1708
|
-
tableName: string,
|
|
1709
|
-
callback: (tableBuilder: AlterTableBuilder) => any
|
|
1710
|
-
): Promise<void>;
|
|
1711
|
-
dropTableIfExists(tableName: string): SchemaBuilder;
|
|
1712
|
-
dropSchema(schemaName: string): SchemaBuilder;
|
|
1713
|
-
dropSchemaIfExists(schemaName: string): SchemaBuilder;
|
|
1714
|
-
raw(statement: string): SchemaBuilder;
|
|
1715
|
-
withSchema(schemaName: string): SchemaBuilder;
|
|
1716
|
-
queryContext(context: any): SchemaBuilder;
|
|
1717
|
-
toString(): string;
|
|
1718
|
-
toSQL(): Sql;
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
interface TableBuilder {
|
|
1722
|
-
increments(columnName?: string): ColumnBuilder;
|
|
1723
|
-
bigIncrements(columnName?: string): ColumnBuilder;
|
|
1724
|
-
dropColumn(columnName: string): TableBuilder;
|
|
1725
|
-
dropColumns(...columnNames: string[]): TableBuilder;
|
|
1726
|
-
renameColumn(from: string, to: string): ColumnBuilder;
|
|
1727
|
-
integer(columnName: string, length?: number): ColumnBuilder;
|
|
1728
|
-
bigInteger(columnName: string): ColumnBuilder;
|
|
1729
|
-
text(columnName: string, textType?: string): ColumnBuilder;
|
|
1730
|
-
string(columnName: string, length?: number): ColumnBuilder;
|
|
1731
|
-
float(
|
|
1732
|
-
columnName: string,
|
|
1733
|
-
precision?: number,
|
|
1734
|
-
scale?: number
|
|
1735
|
-
): ColumnBuilder;
|
|
1736
|
-
double(
|
|
1737
|
-
columnName: string,
|
|
1738
|
-
precision?: number,
|
|
1739
|
-
scale?: number
|
|
1740
|
-
): ColumnBuilder;
|
|
1741
|
-
decimal(
|
|
1742
|
-
columnName: string,
|
|
1743
|
-
precision?: number | null,
|
|
1744
|
-
scale?: number
|
|
1745
|
-
): ColumnBuilder;
|
|
1746
|
-
boolean(columnName: string): ColumnBuilder;
|
|
1747
|
-
date(columnName: string): ColumnBuilder;
|
|
1748
|
-
dateTime(columnName: string, options?: Readonly<{useTz?: boolean, precision?: number}>): ColumnBuilder;
|
|
1749
|
-
time(columnName: string): ColumnBuilder;
|
|
1750
|
-
timestamp(columnName: string, options?: Readonly<{useTz?: boolean, precision?: number}>): ColumnBuilder;
|
|
1751
|
-
/** @deprecated */
|
|
1752
|
-
timestamp(columnName: string, withoutTz?: boolean, precision?: number): ColumnBuilder;
|
|
1753
|
-
timestamps(
|
|
1754
|
-
useTimestampType?: boolean,
|
|
1755
|
-
makeDefaultNow?: boolean
|
|
1756
|
-
): ColumnBuilder;
|
|
1757
|
-
binary(columnName: string, length?: number): ColumnBuilder;
|
|
1758
|
-
enum(
|
|
1759
|
-
columnName: string,
|
|
1760
|
-
values: readonly Value[],
|
|
1761
|
-
options?: EnumOptions
|
|
1762
|
-
): ColumnBuilder;
|
|
1763
|
-
enu(
|
|
1764
|
-
columnName: string,
|
|
1765
|
-
values: readonly Value[],
|
|
1766
|
-
options?: EnumOptions
|
|
1767
|
-
): ColumnBuilder;
|
|
1768
|
-
json(columnName: string): ColumnBuilder;
|
|
1769
|
-
jsonb(columnName: string): ColumnBuilder;
|
|
1770
|
-
uuid(columnName: string): ColumnBuilder;
|
|
1771
|
-
comment(val: string): TableBuilder;
|
|
1772
|
-
specificType(columnName: string, type: string): ColumnBuilder;
|
|
1773
|
-
primary(columnNames: readonly string[], constraintName?: string): TableBuilder;
|
|
1774
|
-
index(
|
|
1775
|
-
columnNames: string | readonly (string | Raw)[],
|
|
1776
|
-
indexName?: string,
|
|
1777
|
-
indexType?: string
|
|
1778
|
-
): TableBuilder;
|
|
1779
|
-
unique(columnNames: readonly (string | Raw)[], indexName?: string): TableBuilder;
|
|
1780
|
-
foreign(column: string, foreignKeyName?: string): ForeignConstraintBuilder;
|
|
1781
|
-
foreign(
|
|
1782
|
-
columns: readonly string[],
|
|
1783
|
-
foreignKeyName?: string
|
|
1784
|
-
): MultikeyForeignConstraintBuilder;
|
|
1785
|
-
dropForeign(columnNames: readonly string[], foreignKeyName?: string): TableBuilder;
|
|
1786
|
-
dropUnique(columnNames: readonly (string | Raw)[], indexName?: string): TableBuilder;
|
|
1787
|
-
dropPrimary(constraintName?: string): TableBuilder;
|
|
1788
|
-
dropIndex(columnNames: string | readonly (string | Raw)[], indexName?: string): TableBuilder;
|
|
1789
|
-
dropTimestamps(): ColumnBuilder;
|
|
1790
|
-
queryContext(context: any): TableBuilder;
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
interface CreateTableBuilder extends TableBuilder {
|
|
1794
|
-
engine(val: string): CreateTableBuilder;
|
|
1795
|
-
charset(val: string): CreateTableBuilder;
|
|
1796
|
-
collate(val: string): CreateTableBuilder;
|
|
1797
|
-
inherits(val: string): CreateTableBuilder;
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
interface AlterTableBuilder extends TableBuilder {}
|
|
1801
|
-
|
|
1802
|
-
interface ColumnBuilder {
|
|
1803
|
-
index(indexName?: string): ColumnBuilder;
|
|
1804
|
-
primary(constraintName?: string): ColumnBuilder;
|
|
1805
|
-
unique(indexName?: string): ColumnBuilder;
|
|
1806
|
-
references(columnName: string): ReferencingColumnBuilder;
|
|
1807
|
-
onDelete(command: string): ColumnBuilder;
|
|
1808
|
-
onUpdate(command: string): ColumnBuilder;
|
|
1809
|
-
defaultTo(value: Value | null): ColumnBuilder;
|
|
1810
|
-
unsigned(): ColumnBuilder;
|
|
1811
|
-
notNullable(): ColumnBuilder;
|
|
1812
|
-
nullable(): ColumnBuilder;
|
|
1813
|
-
comment(value: string): ColumnBuilder;
|
|
1814
|
-
alter(): ColumnBuilder;
|
|
1815
|
-
queryContext(context: any): ColumnBuilder;
|
|
1816
|
-
withKeyName(keyName: string): ColumnBuilder;
|
|
1817
|
-
after(columnName: string): ColumnBuilder;
|
|
1818
|
-
first(): ColumnBuilder;
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
interface ForeignConstraintBuilder {
|
|
1822
|
-
references(columnName: string): ReferencingColumnBuilder;
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
interface MultikeyForeignConstraintBuilder {
|
|
1826
|
-
references(columnNames: readonly string[]): ReferencingColumnBuilder;
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
interface PostgreSqlColumnBuilder extends ColumnBuilder {
|
|
1830
|
-
index(indexName?: string, indexType?: string): ColumnBuilder;
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
interface ReferencingColumnBuilder extends ColumnBuilder {
|
|
1834
|
-
inTable(tableName: string): ColumnBuilder;
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
interface AlterColumnBuilder extends ColumnBuilder {}
|
|
1838
|
-
|
|
1839
|
-
interface MySqlAlterColumnBuilder extends AlterColumnBuilder {
|
|
1840
|
-
first(): AlterColumnBuilder;
|
|
1841
|
-
after(columnName: string): AlterColumnBuilder;
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
//
|
|
1845
|
-
// Configurations
|
|
1846
|
-
//
|
|
1847
|
-
|
|
1848
|
-
interface ColumnInfo {
|
|
1849
|
-
defaultValue: Value;
|
|
1850
|
-
type: string;
|
|
1851
|
-
maxLength: number;
|
|
1852
|
-
nullable: boolean;
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
interface Config<SV extends {} = any> {
|
|
1856
|
-
debug?: boolean;
|
|
1857
|
-
client?: string | typeof Client;
|
|
1858
|
-
dialect?: string;
|
|
1859
|
-
version?: string;
|
|
1860
|
-
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
|
|
1861
|
-
pool?: PoolConfig;
|
|
1862
|
-
migrations?: MigratorConfig;
|
|
1863
|
-
postProcessResponse?: (result: any, queryContext: any) => any;
|
|
1864
|
-
wrapIdentifier?: (
|
|
1865
|
-
value: string,
|
|
1866
|
-
origImpl: (value: string) => string,
|
|
1867
|
-
queryContext: any
|
|
1868
|
-
) => string;
|
|
1869
|
-
seeds?: SeederConfig<SV>;
|
|
1870
|
-
acquireConnectionTimeout?: number;
|
|
1871
|
-
useNullAsDefault?: boolean;
|
|
1872
|
-
searchPath?: string | readonly string[];
|
|
1873
|
-
asyncStackTraces?: boolean;
|
|
1874
|
-
log?: Logger;
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
|
-
type StaticConnectionConfig =
|
|
1878
|
-
| ConnectionConfig
|
|
1879
|
-
| MariaSqlConnectionConfig
|
|
1880
|
-
| MySqlConnectionConfig
|
|
1881
|
-
| MySql2ConnectionConfig
|
|
1882
|
-
| MsSqlConnectionConfig
|
|
1883
|
-
| OracleDbConnectionConfig
|
|
1884
|
-
| PgConnectionConfig
|
|
1885
|
-
| RedshiftConnectionConfig
|
|
1886
|
-
| Sqlite3ConnectionConfig
|
|
1887
|
-
| SocketConnectionConfig;
|
|
1888
|
-
|
|
1889
|
-
type ConnectionConfigProvider = SyncConnectionConfigProvider | AsyncConnectionConfigProvider;
|
|
1890
|
-
type SyncConnectionConfigProvider = () => StaticConnectionConfig;
|
|
1891
|
-
type AsyncConnectionConfigProvider = () => Promise<StaticConnectionConfig>;
|
|
1892
|
-
|
|
1893
|
-
interface ConnectionConfig {
|
|
1894
|
-
host: string;
|
|
1895
|
-
user: string;
|
|
1896
|
-
password: string;
|
|
1897
|
-
database: string;
|
|
1898
|
-
domain?: string;
|
|
1899
|
-
instanceName?: string;
|
|
1900
|
-
debug?: boolean;
|
|
1901
|
-
requestTimeout?: number;
|
|
1902
|
-
}
|
|
1903
|
-
|
|
1904
|
-
// Config object for mssql: see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mssql/index.d.ts
|
|
1905
|
-
interface MsSqlConnectionConfig {
|
|
1906
|
-
driver?: string;
|
|
1907
|
-
user?: string;
|
|
1908
|
-
password?: string;
|
|
1909
|
-
server: string;
|
|
1910
|
-
port?: number;
|
|
1911
|
-
domain?: string;
|
|
1912
|
-
database: string;
|
|
1913
|
-
connectionTimeout?: number;
|
|
1914
|
-
requestTimeout?: number;
|
|
1915
|
-
stream?: boolean;
|
|
1916
|
-
parseJSON?: boolean;
|
|
1917
|
-
expirationChecker?(): boolean;
|
|
1918
|
-
options?: Readonly<{
|
|
1919
|
-
encrypt?: boolean;
|
|
1920
|
-
instanceName?: string;
|
|
1921
|
-
useUTC?: boolean;
|
|
1922
|
-
tdsVersion?: string;
|
|
1923
|
-
appName?: string;
|
|
1924
|
-
abortTransactionOnError?: boolean;
|
|
1925
|
-
trustedConnection?: boolean;
|
|
1926
|
-
enableArithAbort?: boolean;
|
|
1927
|
-
isolationLevel?: 'READ_UNCOMMITTED' | 'READ_COMMITTED' | 'REPEATABLE_READ' | 'SERIALIZABLE' | 'SNAPSHOT';
|
|
1928
|
-
maxRetriesOnTransientErrors?: number;
|
|
1929
|
-
multiSubnetFailover?: boolean;
|
|
1930
|
-
packetSize?: number;
|
|
1931
|
-
trustServerCertificate?: boolean;
|
|
1932
|
-
}>;
|
|
1933
|
-
pool?: Readonly<{
|
|
1934
|
-
min?: number;
|
|
1935
|
-
max?: number;
|
|
1936
|
-
idleTimeoutMillis?: number;
|
|
1937
|
-
maxWaitingClients?: number;
|
|
1938
|
-
testOnBorrow?: boolean;
|
|
1939
|
-
acquireTimeoutMillis?: number;
|
|
1940
|
-
fifo?: boolean;
|
|
1941
|
-
priorityRange?: number;
|
|
1942
|
-
autostart?: boolean;
|
|
1943
|
-
evictionRunIntervalMillis?: number;
|
|
1944
|
-
numTestsPerRun?: number;
|
|
1945
|
-
softIdleTimeoutMillis?: number;
|
|
1946
|
-
Promise?: any;
|
|
1947
|
-
}>;
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
|
-
// Config object for mariasql: https://github.com/mscdex/node-mariasql#client-methods
|
|
1951
|
-
interface MariaSqlConnectionConfig {
|
|
1952
|
-
user?: string;
|
|
1953
|
-
password?: string;
|
|
1954
|
-
host?: string;
|
|
1955
|
-
port?: number;
|
|
1956
|
-
unixSocket?: string;
|
|
1957
|
-
protocol?: string;
|
|
1958
|
-
db?: string;
|
|
1959
|
-
keepQueries?: boolean;
|
|
1960
|
-
multiStatements?: boolean;
|
|
1961
|
-
connTimeout?: number;
|
|
1962
|
-
pingInterval?: number;
|
|
1963
|
-
secureAuth?: boolean;
|
|
1964
|
-
compress?: boolean;
|
|
1965
|
-
ssl?: boolean | MariaSslConfiguration;
|
|
1966
|
-
local_infile?: boolean;
|
|
1967
|
-
read_default_file?: string;
|
|
1968
|
-
read_default_group?: string;
|
|
1969
|
-
charset?: string;
|
|
1970
|
-
streamHWM?: number;
|
|
1971
|
-
expirationChecker?(): boolean;
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
interface MariaSslConfiguration {
|
|
1975
|
-
key?: string;
|
|
1976
|
-
cert?: string;
|
|
1977
|
-
ca?: string;
|
|
1978
|
-
capath?: string;
|
|
1979
|
-
cipher?: string;
|
|
1980
|
-
rejectUnauthorized?: boolean;
|
|
1981
|
-
expirationChecker?(): boolean;
|
|
1982
|
-
}
|
|
1983
|
-
|
|
1984
|
-
// Config object for mysql: https://github.com/mysqljs/mysql#connection-options
|
|
1985
|
-
interface MySqlConnectionConfig {
|
|
1986
|
-
host?: string;
|
|
1987
|
-
port?: number;
|
|
1988
|
-
localAddress?: string;
|
|
1989
|
-
socketPath?: string;
|
|
1990
|
-
user?: string;
|
|
1991
|
-
password?: string;
|
|
1992
|
-
database?: string;
|
|
1993
|
-
charset?: string;
|
|
1994
|
-
timezone?: string;
|
|
1995
|
-
connectTimeout?: number;
|
|
1996
|
-
stringifyObjects?: boolean;
|
|
1997
|
-
insecureAuth?: boolean;
|
|
1998
|
-
typeCast?: any;
|
|
1999
|
-
queryFormat?: (query: string, values: any) => string;
|
|
2000
|
-
supportBigNumbers?: boolean;
|
|
2001
|
-
bigNumberStrings?: boolean;
|
|
2002
|
-
dateStrings?: boolean;
|
|
2003
|
-
debug?: boolean;
|
|
2004
|
-
trace?: boolean;
|
|
2005
|
-
multipleStatements?: boolean;
|
|
2006
|
-
flags?: string;
|
|
2007
|
-
ssl?: string | MariaSslConfiguration;
|
|
2008
|
-
decimalNumbers?: boolean;
|
|
2009
|
-
expirationChecker?(): boolean;
|
|
2010
|
-
}
|
|
2011
|
-
|
|
2012
|
-
// Config object for mysql2: https://github.com/sidorares/node-mysql2/blob/master/lib/connection_config.js
|
|
2013
|
-
// Some options for connection pooling and MySQL server API are excluded.
|
|
2014
|
-
interface MySql2ConnectionConfig extends MySqlConnectionConfig {
|
|
2015
|
-
authPlugins?: {[pluginName: string]: (pluginMetadata: any) => ((pluginData: any) => any)};
|
|
2016
|
-
authSwitchHandler?: (data: any, callback: () => void) => any;
|
|
2017
|
-
charsetNumber?: number;
|
|
2018
|
-
compress?: boolean;
|
|
2019
|
-
connectAttributes?: {[attrNames: string]: any};
|
|
2020
|
-
enableKeepAlive?: boolean;
|
|
2021
|
-
keepAliveInitialDelay?: number;
|
|
2022
|
-
maxPreparedStatements?: number;
|
|
2023
|
-
namedPlaceholders?: boolean;
|
|
2024
|
-
nestTables?: boolean | string;
|
|
2025
|
-
passwordSha1?: string;
|
|
2026
|
-
rowsAsArray?: boolean;
|
|
2027
|
-
stream?: boolean | ((opts: any) => Stream) | Stream;
|
|
2028
|
-
uri?: string;
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
interface OracleDbConnectionConfig {
|
|
2032
|
-
host: string;
|
|
2033
|
-
user: string;
|
|
2034
|
-
password?: string;
|
|
2035
|
-
database?: string;
|
|
2036
|
-
domain?: string;
|
|
2037
|
-
instanceName?: string;
|
|
2038
|
-
debug?: boolean;
|
|
2039
|
-
requestTimeout?: number;
|
|
2040
|
-
connectString?: string;
|
|
2041
|
-
expirationChecker?(): boolean;
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
// Config object for pg: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts
|
|
2045
|
-
interface PgConnectionConfig {
|
|
2046
|
-
user?: string;
|
|
2047
|
-
database?: string;
|
|
2048
|
-
password?: string;
|
|
2049
|
-
port?: number;
|
|
2050
|
-
host?: string;
|
|
2051
|
-
connectionString?: string;
|
|
2052
|
-
keepAlive?: boolean;
|
|
2053
|
-
stream?: stream.Duplex;
|
|
2054
|
-
statement_timeout?: false | number;
|
|
2055
|
-
connectionTimeoutMillis?: number;
|
|
2056
|
-
keepAliveInitialDelayMillis?: number;
|
|
2057
|
-
ssl?: boolean | ConnectionOptions;
|
|
2058
|
-
application_name?: string;
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
type RedshiftConnectionConfig = PgConnectionConfig;
|
|
2062
|
-
|
|
2063
|
-
/** Used with SQLite3 adapter */
|
|
2064
|
-
interface Sqlite3ConnectionConfig {
|
|
2065
|
-
filename: string;
|
|
2066
|
-
debug?: boolean;
|
|
2067
|
-
expirationChecker?(): boolean;
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
interface SocketConnectionConfig {
|
|
2071
|
-
socketPath: string;
|
|
2072
|
-
user: string;
|
|
2073
|
-
password: string;
|
|
2074
|
-
database: string;
|
|
2075
|
-
debug?: boolean;
|
|
2076
|
-
expirationChecker?(): boolean;
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
interface PoolConfig {
|
|
2080
|
-
name?: string;
|
|
2081
|
-
afterCreate?: Function;
|
|
2082
|
-
min?: number;
|
|
2083
|
-
max?: number;
|
|
2084
|
-
refreshIdle?: boolean;
|
|
2085
|
-
idleTimeoutMillis?: number;
|
|
2086
|
-
reapIntervalMillis?: number;
|
|
2087
|
-
returnToHead?: boolean;
|
|
2088
|
-
priorityRange?: number;
|
|
2089
|
-
log?: (message: string, logLevel: string) => void;
|
|
2090
|
-
|
|
2091
|
-
// tarn configs
|
|
2092
|
-
propagateCreateError?: boolean;
|
|
2093
|
-
createRetryIntervalMillis?: number;
|
|
2094
|
-
createTimeoutMillis?: number;
|
|
2095
|
-
destroyTimeoutMillis?: number;
|
|
2096
|
-
acquireTimeoutMillis?: number;
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
type LogFn = (message: any) => void;
|
|
2100
|
-
|
|
2101
|
-
interface Logger {
|
|
2102
|
-
warn?: LogFn;
|
|
2103
|
-
error?: LogFn;
|
|
2104
|
-
debug?: LogFn;
|
|
2105
|
-
inspectionDepth?: number;
|
|
2106
|
-
enableColors?: boolean;
|
|
2107
|
-
deprecate?: (method: string, alternative: string) => void;
|
|
2108
|
-
}
|
|
2109
|
-
|
|
2110
|
-
interface Migration {
|
|
2111
|
-
up: (knex: Knex) => PromiseLike<any>;
|
|
2112
|
-
down?: (kenx: Knex) => PromiseLike<any>;
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
|
-
interface MigrationSource<TMigrationSpec> {
|
|
2116
|
-
getMigrations(loadExtensions: readonly string[]): Promise<TMigrationSpec[]>;
|
|
2117
|
-
getMigrationName(migration: TMigrationSpec): string;
|
|
2118
|
-
getMigration(migration: TMigrationSpec): Migration;
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
interface MigratorConfig {
|
|
2122
|
-
database?: string;
|
|
2123
|
-
directory?: string | readonly string[];
|
|
2124
|
-
extension?: string;
|
|
2125
|
-
stub?: string;
|
|
2126
|
-
tableName?: string;
|
|
2127
|
-
schemaName?: string;
|
|
2128
|
-
disableTransactions?: boolean;
|
|
2129
|
-
disableMigrationsListValidation?: boolean;
|
|
2130
|
-
sortDirsSeparately?: boolean;
|
|
2131
|
-
loadExtensions?: readonly string[];
|
|
2132
|
-
migrationSource?: MigrationSource<unknown>;
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
interface Migrator {
|
|
2136
|
-
make(name: string, config?: MigratorConfig): Promise<string>;
|
|
2137
|
-
latest(config?: MigratorConfig): Promise<any>;
|
|
2138
|
-
rollback(config?: MigratorConfig, all?: boolean): Promise<any>;
|
|
2139
|
-
status(config?: MigratorConfig): Promise<number>;
|
|
2140
|
-
currentVersion(config?: MigratorConfig): Promise<string>;
|
|
2141
|
-
list(config?: MigratorConfig): Promise<any>;
|
|
2142
|
-
up(config?: MigratorConfig): Promise<any>;
|
|
2143
|
-
down(config?: MigratorConfig): Promise<any>;
|
|
2144
|
-
forceFreeMigrationsLock(config?: MigratorConfig): Promise<any>;
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
interface SeederConfig<V extends {} = any> {
|
|
2148
|
-
extension?: string;
|
|
2149
|
-
directory?: string | readonly string[];
|
|
2150
|
-
loadExtensions?: readonly string[];
|
|
2151
|
-
specific?: string;
|
|
2152
|
-
timestampFilenamePrefix?: boolean;
|
|
2153
|
-
recursive?: boolean;
|
|
2154
|
-
sortDirsSeparately?: boolean;
|
|
2155
|
-
stub?: string;
|
|
2156
|
-
variables?: V;
|
|
2157
|
-
}
|
|
2158
|
-
|
|
2159
|
-
class Seeder {
|
|
2160
|
-
constructor(knex: Knex);
|
|
2161
|
-
setConfig(config: SeederConfig): SeederConfig;
|
|
2162
|
-
run(config?: SeederConfig): Promise<[string[]]>;
|
|
2163
|
-
make(name: string, config?: SeederConfig): Promise<string>;
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
interface FunctionHelper {
|
|
2167
|
-
now(precision?: number): Raw;
|
|
2168
|
-
}
|
|
2169
|
-
|
|
2170
|
-
interface EnumOptions {
|
|
2171
|
-
useNative: boolean;
|
|
2172
|
-
existingType?: boolean;
|
|
2173
|
-
schemaName?: string;
|
|
2174
|
-
enumName: string;
|
|
2175
|
-
}
|
|
2176
|
-
|
|
2177
|
-
//
|
|
2178
|
-
// Clients
|
|
2179
|
-
//
|
|
2180
|
-
|
|
2181
|
-
class Client extends events.EventEmitter {
|
|
2182
|
-
constructor(config: Config);
|
|
2183
|
-
config: Config;
|
|
2184
|
-
dialect: string;
|
|
2185
|
-
driverName: string;
|
|
2186
|
-
connectionSettings: object;
|
|
2187
|
-
|
|
2188
|
-
acquireRawConnection(): Promise<any>;
|
|
2189
|
-
destroyRawConnection(connection: any): Promise<void>;
|
|
2190
|
-
validateConnection(connection: any): Promise<boolean>;
|
|
2191
|
-
logger: Logger;
|
|
2192
|
-
version?: string;
|
|
2193
|
-
connectionConfigProvider: any;
|
|
2194
|
-
connectionConfigExpirationChecker: null | (() => boolean);
|
|
2195
|
-
valueForUndefined: any;
|
|
2196
|
-
formatter(builder: any): any;
|
|
2197
|
-
queryBuilder(): QueryBuilder;
|
|
2198
|
-
queryCompiler(builder: any): any;
|
|
2199
|
-
schemaBuilder(): SchemaBuilder;
|
|
2200
|
-
schemaCompiler(builder: SchemaBuilder): any;
|
|
2201
|
-
tableBuilder(type: any, tableName: any, fn: any): TableBuilder;
|
|
2202
|
-
tableCompiler(tableBuilder: any): any;
|
|
2203
|
-
columnBuilder(tableBuilder: any, type: any, args: any): ColumnBuilder;
|
|
2204
|
-
columnCompiler(tableBuilder: any, columnBuilder: any): any;
|
|
2205
|
-
runner(builder: any): any;
|
|
2206
|
-
transaction(container: any, config: any, outerTx: any): Transaction;
|
|
2207
|
-
raw(...args: any[]): any;
|
|
2208
|
-
ref(...args: any[]): Ref<any, any>;
|
|
2209
|
-
query(connection: any, obj: any): any;
|
|
2210
|
-
stream(connection: any, obj: any, stream: any, options: any): any;
|
|
2211
|
-
prepBindings(bindings: any): any;
|
|
2212
|
-
positionBindings(sql: any): any;
|
|
2213
|
-
postProcessResponse(resp: any, queryContext: any): any;
|
|
2214
|
-
wrapIdentifier(value: any, queryContext: any): any;
|
|
2215
|
-
customWrapIdentifier(value: any, origImpl: any, queryContext: any): any;
|
|
2216
|
-
wrapIdentifierImpl(value: any): string;
|
|
2217
|
-
initializeDriver(): void;
|
|
2218
|
-
driver: any;
|
|
2219
|
-
poolDefaults(): {
|
|
2220
|
-
min: number;
|
|
2221
|
-
max: number;
|
|
2222
|
-
propagateCreateError: boolean;
|
|
2223
|
-
};
|
|
2224
|
-
getPoolSettings(poolConfig: any): any;
|
|
2225
|
-
initializePool(config?: {}): void;
|
|
2226
|
-
pool: tarn.Pool<any> | undefined;
|
|
2227
|
-
acquireConnection(): any;
|
|
2228
|
-
releaseConnection(connection: any): any;
|
|
2229
|
-
destroy(callback: any): any;
|
|
2230
|
-
database(): any;
|
|
2231
|
-
canCancelQuery: boolean;
|
|
2232
|
-
assertCanCancelQuery(): void;
|
|
2233
|
-
cancelQuery(): void;
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
class QueryBuilder {
|
|
2237
|
-
static extend(
|
|
2238
|
-
methodName: string,
|
|
2239
|
-
fn: <TRecord extends {} = any, TResult = unknown[]>(
|
|
2240
|
-
this: QueryBuilder<TRecord, TResult>,
|
|
2241
|
-
...args: any[]
|
|
2242
|
-
) => QueryBuilder<TRecord, TResult>
|
|
2243
|
-
): void;
|
|
2244
|
-
}
|
|
2245
|
-
|
|
2246
|
-
export class KnexTimeoutError extends Error {}
|
|
2247
|
-
}
|
|
2248
|
-
|
|
2249
|
-
export = Knex;
|
|
1
|
+
// Originally based on contributions to DefinitelyTyped:
|
|
2
|
+
// Definitions by: Qubo <https://github.com/tkQubo>
|
|
3
|
+
// Pablo Rodríguez <https://github.com/MeLlamoPablo>
|
|
4
|
+
// Matt R. Wilson <https://github.com/mastermatt>
|
|
5
|
+
// Satana Charuwichitratana <https://github.com/micksatana>
|
|
6
|
+
// Shrey Jain <https://github.com/shreyjain1994>
|
|
7
|
+
// TypeScript Version: 3.7
|
|
8
|
+
|
|
9
|
+
import tarn = require('tarn');
|
|
10
|
+
import events = require('events');
|
|
11
|
+
import stream = require('stream');
|
|
12
|
+
import ResultTypes = require('./result');
|
|
13
|
+
|
|
14
|
+
import { Tables } from './tables';
|
|
15
|
+
|
|
16
|
+
import { ConnectionOptions } from "tls";
|
|
17
|
+
import { Stream } from "stream";
|
|
18
|
+
|
|
19
|
+
// # Generic type-level utilities
|
|
20
|
+
|
|
21
|
+
// If T is object then make it a partial otherwise fallback to any
|
|
22
|
+
//
|
|
23
|
+
// This is primarily to prevent type incompatibilities where target can be unknown.
|
|
24
|
+
// While unknown can be assigned to any, Partial<unknown> can't be.
|
|
25
|
+
type SafePartial<T> = Partial<AnyOrUnknownToOther<T, {}>>;
|
|
26
|
+
|
|
27
|
+
type MaybeArray<T> = T | T[];
|
|
28
|
+
|
|
29
|
+
type StrKey<T> = string & keyof T;
|
|
30
|
+
|
|
31
|
+
// If T is unknown then convert to any, else retain original
|
|
32
|
+
type UnknownToAny<T> = unknown extends T ? any : T;
|
|
33
|
+
type AnyToUnknown<T> = unknown extends T ? unknown : T;
|
|
34
|
+
type AnyOrUnknownToOther<T1, T2> = unknown extends T1 ? T2 : T1;
|
|
35
|
+
|
|
36
|
+
// Intersection conditionally applied only when TParams is non-empty
|
|
37
|
+
// This is primarily to keep the signatures more intuitive.
|
|
38
|
+
type AugmentParams<TTarget, TParams> = TParams extends {}
|
|
39
|
+
? keyof TParams extends never
|
|
40
|
+
? TTarget
|
|
41
|
+
: {} & TTarget & TParams
|
|
42
|
+
: TTarget;
|
|
43
|
+
|
|
44
|
+
// Check if provided keys (expressed as a single or union type) are members of TBase
|
|
45
|
+
type AreKeysOf<TBase, TKeys> = Boxed<TKeys> extends Boxed<keyof TBase>
|
|
46
|
+
? true
|
|
47
|
+
: false;
|
|
48
|
+
|
|
49
|
+
// https://stackoverflow.com/a/50375286/476712
|
|
50
|
+
type UnionToIntersection<U> = (U extends any
|
|
51
|
+
? (k: U) => void
|
|
52
|
+
: never) extends ((k: infer I) => void)
|
|
53
|
+
? I
|
|
54
|
+
: never;
|
|
55
|
+
|
|
56
|
+
type ComparisonOperator = '=' | '>' | '>=' | '<' | '<=' | '<>';
|
|
57
|
+
|
|
58
|
+
// If T is an array, get the type of member, else fall back to never
|
|
59
|
+
type ArrayMember<T> = T extends (infer M)[] ? M : never;
|
|
60
|
+
|
|
61
|
+
// If T is an array, get the type of member, else retain original
|
|
62
|
+
type UnwrapArrayMember<T> = T extends (infer M)[] ? M : T;
|
|
63
|
+
|
|
64
|
+
// Wrap a type in a container, making it an object type.
|
|
65
|
+
// This is primarily useful in circumventing special handling of union/intersection in typescript
|
|
66
|
+
interface Boxed<T> {
|
|
67
|
+
_value: T;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// If T can't be assigned to TBase fallback to an alternate type TAlt
|
|
71
|
+
type IncompatibleToAlt<T, TBase, TAlt> = T extends TBase ? T : TAlt;
|
|
72
|
+
|
|
73
|
+
type ArrayIfAlready<T1, T2> = T1 extends any[] ? T2[] : T2;
|
|
74
|
+
|
|
75
|
+
// Boxing is necessary to prevent distribution of conditional types:
|
|
76
|
+
// https://lorefnon.tech/2019/05/02/using-boxing-to-prevent-distribution-of-conditional-types/
|
|
77
|
+
type PartialOrAny<TBase, TKeys> = Boxed<TKeys> extends Boxed<never>
|
|
78
|
+
? {}
|
|
79
|
+
: Boxed<TKeys> extends Boxed<keyof TBase>
|
|
80
|
+
? SafePick<TBase, TKeys & keyof TBase>
|
|
81
|
+
: any;
|
|
82
|
+
|
|
83
|
+
// Retain the association of original keys with aliased keys at type level
|
|
84
|
+
// to facilitates type-safe aliasing for object syntax
|
|
85
|
+
type MappedAliasType<TBase, TAliasMapping> = {} & {
|
|
86
|
+
[K in keyof TAliasMapping]: TAliasMapping[K] extends keyof TBase
|
|
87
|
+
? TBase[TAliasMapping[K]]
|
|
88
|
+
: any
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Container type for situations when we want a partial/intersection eventually
|
|
92
|
+
// but the keys being selected or additional properties being augmented are not
|
|
93
|
+
// all known at once and we would want to effectively build up a partial/intersection
|
|
94
|
+
// over multiple steps.
|
|
95
|
+
type DeferredKeySelection<
|
|
96
|
+
// The base of selection. In intermediate stages this may be unknown.
|
|
97
|
+
// If it remains unknown at the point of resolution, the selection will fall back to any
|
|
98
|
+
TBase,
|
|
99
|
+
// Union of keys to be selected
|
|
100
|
+
// In intermediate stages this may be never.
|
|
101
|
+
TKeys extends string,
|
|
102
|
+
// Changes how the resolution should behave if TKeys is never.
|
|
103
|
+
// If true, then we assume that some keys were selected, and if TKeys is never, we will fall back to any.
|
|
104
|
+
// If false, and TKeys is never, then we select TBase in its entirety
|
|
105
|
+
THasSelect extends true | false = false,
|
|
106
|
+
// Mapping of aliases <key in result> -> <key in TBase>
|
|
107
|
+
TAliasMapping extends {} = {},
|
|
108
|
+
// If enabled, then instead of extracting a partial, during resolution
|
|
109
|
+
// we will pick just a single property.
|
|
110
|
+
TSingle extends boolean = false,
|
|
111
|
+
// Extra props which will be intersected with the result
|
|
112
|
+
TIntersectProps extends {} = {},
|
|
113
|
+
// Extra props which will be unioned with the result
|
|
114
|
+
TUnionProps = never
|
|
115
|
+
> = {
|
|
116
|
+
// These properties are not actually used, but exist simply because
|
|
117
|
+
// typescript doesn't end up happy when type parameters are unused
|
|
118
|
+
_base: TBase;
|
|
119
|
+
_hasSelection: THasSelect;
|
|
120
|
+
_keys: TKeys;
|
|
121
|
+
_aliases: TAliasMapping;
|
|
122
|
+
_single: TSingle;
|
|
123
|
+
_intersectProps: TIntersectProps;
|
|
124
|
+
_unionProps: TUnionProps;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// An companion namespace for DeferredKeySelection which provides type operators
|
|
128
|
+
// to build up participants of intersection/partial over multiple invocations
|
|
129
|
+
// and for final resolution.
|
|
130
|
+
//
|
|
131
|
+
// While the comments use wordings such as replacement and addition, it is important
|
|
132
|
+
// to keep in mind that types are always immutable and all type operators return new altered types.
|
|
133
|
+
declare namespace DeferredKeySelection {
|
|
134
|
+
type Any = DeferredKeySelection<any, any, any, any, any, any, any>;
|
|
135
|
+
|
|
136
|
+
// Replace the Base if already a deferred selection.
|
|
137
|
+
// If not, create a new deferred selection with specified base.
|
|
138
|
+
type SetBase<TSelection, TBase> = TSelection extends DeferredKeySelection<
|
|
139
|
+
any,
|
|
140
|
+
infer TKeys,
|
|
141
|
+
infer THasSelect,
|
|
142
|
+
infer TAliasMapping,
|
|
143
|
+
infer TSingle,
|
|
144
|
+
infer TIntersectProps,
|
|
145
|
+
infer TUnionProps
|
|
146
|
+
>
|
|
147
|
+
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps, TUnionProps>
|
|
148
|
+
: DeferredKeySelection<TBase, never>;
|
|
149
|
+
|
|
150
|
+
// If TSelection is already a deferred selection, then replace the base with TBase
|
|
151
|
+
// If unknown, create a new deferred selection with TBase as the base
|
|
152
|
+
// Else, retain original
|
|
153
|
+
//
|
|
154
|
+
// For practical reasons applicable to current context, we always return arrays of
|
|
155
|
+
// deferred selections. So, this particular operator may not be useful in generic contexts.
|
|
156
|
+
type ReplaceBase<TSelection, TBase> = UnwrapArrayMember<
|
|
157
|
+
TSelection
|
|
158
|
+
> extends DeferredKeySelection.Any
|
|
159
|
+
? ArrayIfAlready<TSelection, DeferredKeySelection.SetBase<UnwrapArrayMember<TSelection>, TBase>>
|
|
160
|
+
: unknown extends UnwrapArrayMember<TSelection>
|
|
161
|
+
? ArrayIfAlready<TSelection, DeferredKeySelection.SetBase<unknown, TBase>>
|
|
162
|
+
: TSelection;
|
|
163
|
+
|
|
164
|
+
// Type operators to substitute individual type parameters:
|
|
165
|
+
|
|
166
|
+
type SetSingle<
|
|
167
|
+
TSelection,
|
|
168
|
+
TSingle extends boolean
|
|
169
|
+
> = TSelection extends DeferredKeySelection<
|
|
170
|
+
infer TBase,
|
|
171
|
+
infer TKeys,
|
|
172
|
+
infer THasSelect,
|
|
173
|
+
infer TAliasMapping,
|
|
174
|
+
any,
|
|
175
|
+
infer TIntersectProps,
|
|
176
|
+
infer TUnionProps
|
|
177
|
+
>
|
|
178
|
+
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps, TUnionProps>
|
|
179
|
+
: never;
|
|
180
|
+
|
|
181
|
+
type AddKey<
|
|
182
|
+
TSelection,
|
|
183
|
+
TKey extends string
|
|
184
|
+
> = TSelection extends DeferredKeySelection<
|
|
185
|
+
infer TBase,
|
|
186
|
+
infer TKeys,
|
|
187
|
+
any,
|
|
188
|
+
infer TAliasMapping,
|
|
189
|
+
infer TSingle,
|
|
190
|
+
infer TIntersectProps,
|
|
191
|
+
infer TUnionProps
|
|
192
|
+
>
|
|
193
|
+
? DeferredKeySelection<TBase, TKeys | TKey, true, TAliasMapping, TSingle, TIntersectProps, TUnionProps>
|
|
194
|
+
: DeferredKeySelection<unknown, TKey, true>;
|
|
195
|
+
|
|
196
|
+
type AddAliases<TSelection, T> = TSelection extends DeferredKeySelection<
|
|
197
|
+
infer TBase,
|
|
198
|
+
infer TKeys,
|
|
199
|
+
infer THasSelect,
|
|
200
|
+
infer TAliasMapping,
|
|
201
|
+
infer TSingle,
|
|
202
|
+
infer TIntersectProps,
|
|
203
|
+
infer TUnionProps
|
|
204
|
+
>
|
|
205
|
+
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping & T, TSingle, TIntersectProps, TUnionProps>
|
|
206
|
+
: DeferredKeySelection<unknown, never, false, T>;
|
|
207
|
+
|
|
208
|
+
type AddUnionMember<TSelection, T> = TSelection extends DeferredKeySelection<
|
|
209
|
+
infer TBase,
|
|
210
|
+
infer TKeys,
|
|
211
|
+
infer THasSelect,
|
|
212
|
+
infer TAliasMapping,
|
|
213
|
+
infer TSingle,
|
|
214
|
+
infer TIntersectProps,
|
|
215
|
+
infer TUnionProps
|
|
216
|
+
>
|
|
217
|
+
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps, TUnionProps | T>
|
|
218
|
+
: DeferredKeySelection<TSelection, never, false, {}, false, {}, T>;
|
|
219
|
+
|
|
220
|
+
// Convenience utility to set base, keys and aliases in a single type
|
|
221
|
+
// application
|
|
222
|
+
type Augment<T, TBase, TKey extends string, TAliasMapping = {}> = AddAliases<
|
|
223
|
+
AddKey<SetBase<T, TBase>, TKey>,
|
|
224
|
+
TAliasMapping
|
|
225
|
+
>;
|
|
226
|
+
|
|
227
|
+
// Core resolution logic -- Refer to docs for DeferredKeySelection for specifics
|
|
228
|
+
type ResolveOne<TSelection> = TSelection extends DeferredKeySelection<
|
|
229
|
+
infer TBase,
|
|
230
|
+
infer TKeys,
|
|
231
|
+
infer THasSelect,
|
|
232
|
+
infer TAliasMapping,
|
|
233
|
+
infer TSingle,
|
|
234
|
+
infer TIntersectProps,
|
|
235
|
+
infer TUnionProps
|
|
236
|
+
>
|
|
237
|
+
? UnknownToAny<
|
|
238
|
+
// ^ We convert final result to any if it is unknown for backward compatibility.
|
|
239
|
+
// Historically knex typings have been liberal with returning any and changing
|
|
240
|
+
// default return type to unknown would be a major breaking change for users.
|
|
241
|
+
//
|
|
242
|
+
// So we compromise on type safety here and return any.
|
|
243
|
+
AugmentParams<
|
|
244
|
+
AnyToUnknown<TBase> extends {}
|
|
245
|
+
// ^ Conversion of any -> unknown is needed here to prevent distribution
|
|
246
|
+
// of any over the conditional
|
|
247
|
+
? TSingle extends true
|
|
248
|
+
? TKeys extends keyof TBase
|
|
249
|
+
? TBase[TKeys]
|
|
250
|
+
: any
|
|
251
|
+
: AugmentParams<
|
|
252
|
+
true extends THasSelect ? PartialOrAny<TBase, TKeys> : TBase,
|
|
253
|
+
MappedAliasType<TBase, TAliasMapping>
|
|
254
|
+
>
|
|
255
|
+
: unknown,
|
|
256
|
+
TIntersectProps
|
|
257
|
+
> | TUnionProps
|
|
258
|
+
>
|
|
259
|
+
: TSelection;
|
|
260
|
+
|
|
261
|
+
type Resolve<TSelection> = TSelection extends DeferredKeySelection.Any
|
|
262
|
+
? Knex.ResolveTableType<ResolveOne<TSelection>>
|
|
263
|
+
: TSelection extends DeferredKeySelection.Any[]
|
|
264
|
+
? Knex.ResolveTableType<ResolveOne<TSelection[0]>>[]
|
|
265
|
+
: TSelection extends (infer I)[]
|
|
266
|
+
? UnknownToAny<Knex.ResolveTableType<I>>[]
|
|
267
|
+
: UnknownToAny<Knex.ResolveTableType<TSelection>>;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
type AggregationQueryResult<TResult, TIntersectProps2> = ArrayIfAlready<
|
|
271
|
+
TResult,
|
|
272
|
+
UnwrapArrayMember<TResult> extends DeferredKeySelection<
|
|
273
|
+
infer TBase,
|
|
274
|
+
infer TKeys,
|
|
275
|
+
infer THasSelect,
|
|
276
|
+
infer TAliasMapping,
|
|
277
|
+
infer TSingle,
|
|
278
|
+
infer TIntersectProps,
|
|
279
|
+
infer TUnionProps
|
|
280
|
+
>
|
|
281
|
+
? true extends THasSelect
|
|
282
|
+
? DeferredKeySelection<TBase, TKeys, THasSelect, TAliasMapping, TSingle, TIntersectProps & TIntersectProps2, TUnionProps>
|
|
283
|
+
: DeferredKeySelection<{}, never, true, {}, false, TIntersectProps2>
|
|
284
|
+
: TIntersectProps2
|
|
285
|
+
>;
|
|
286
|
+
|
|
287
|
+
// Convenience alias and associated companion namespace for working
|
|
288
|
+
// with DeferredSelection having TSingle=true.
|
|
289
|
+
//
|
|
290
|
+
// When TSingle=true in DeferredSelection, then we are effectively
|
|
291
|
+
// deferring an index access operation (TBase[TKey]) over a potentially
|
|
292
|
+
// unknown initial type of TBase and potentially never initial type of TKey
|
|
293
|
+
|
|
294
|
+
type DeferredIndex<TBase, TKey extends string> = DeferredKeySelection<TBase, TKey, false, {}, true>;
|
|
295
|
+
|
|
296
|
+
declare namespace DeferredIndex {
|
|
297
|
+
type Augment<
|
|
298
|
+
T,
|
|
299
|
+
TBase,
|
|
300
|
+
TKey extends string,
|
|
301
|
+
TAliasMapping = {}
|
|
302
|
+
> = DeferredKeySelection.SetSingle<
|
|
303
|
+
DeferredKeySelection.AddKey<DeferredKeySelection.SetBase<T, TBase>, TKey>,
|
|
304
|
+
true
|
|
305
|
+
>;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// If we have more categories of deferred selection in future,
|
|
309
|
+
// this will combine all of them
|
|
310
|
+
type ResolveResult<S> = DeferredKeySelection.Resolve<S>;
|
|
311
|
+
|
|
312
|
+
// # Type-aliases for common type combinations
|
|
313
|
+
|
|
314
|
+
type Callback = Function;
|
|
315
|
+
type Client = Function;
|
|
316
|
+
|
|
317
|
+
type Dict<T = any> = { [k: string]: T; };
|
|
318
|
+
|
|
319
|
+
type SafePick<T, K extends keyof T> = T extends {} ? Pick<T, K> : any;
|
|
320
|
+
|
|
321
|
+
type TableOptions = PgTableOptions;
|
|
322
|
+
|
|
323
|
+
interface PgTableOptions {
|
|
324
|
+
only?: boolean;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
interface DMLOptions {
|
|
328
|
+
includeTriggerModifications?: boolean;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
interface Knex<TRecord extends {} = any, TResult = unknown[]>
|
|
332
|
+
extends Knex.QueryInterface<TRecord, TResult>, events.EventEmitter {
|
|
333
|
+
<TTable extends Knex.TableNames>(
|
|
334
|
+
tableName: TTable,
|
|
335
|
+
options?: TableOptions
|
|
336
|
+
): Knex.QueryBuilder<Knex.TableType<TTable>, DeferredKeySelection<Knex.ResolveTableType<Knex.TableType<TTable>>, never>[]>;
|
|
337
|
+
<TRecord2 = TRecord, TResult2 = DeferredKeySelection<TRecord2, never>[]>(
|
|
338
|
+
tableName?: Knex.TableDescriptor | Knex.AliasDict,
|
|
339
|
+
options?: TableOptions
|
|
340
|
+
): Knex.QueryBuilder<TRecord2, TResult2>;
|
|
341
|
+
VERSION: string;
|
|
342
|
+
__knex__: string;
|
|
343
|
+
|
|
344
|
+
raw: Knex.RawBuilder<TRecord>;
|
|
345
|
+
|
|
346
|
+
transactionProvider(
|
|
347
|
+
config?: any
|
|
348
|
+
): () => Promise<Knex.Transaction>;
|
|
349
|
+
transaction(
|
|
350
|
+
transactionScope?: null,
|
|
351
|
+
config?: any
|
|
352
|
+
): Promise<Knex.Transaction>;
|
|
353
|
+
transaction<T>(
|
|
354
|
+
transactionScope: (trx: Knex.Transaction) => Promise<T> | void,
|
|
355
|
+
config?: any
|
|
356
|
+
): Promise<T>;
|
|
357
|
+
initialize(config?: Knex.Config): void;
|
|
358
|
+
destroy(callback: Function): void;
|
|
359
|
+
destroy(): Promise<void>;
|
|
360
|
+
|
|
361
|
+
batchInsert<TRecord2 = TRecord, TResult2 = number[]>(
|
|
362
|
+
tableName: Knex.TableDescriptor,
|
|
363
|
+
data: TRecord2 extends Knex.CompositeTableType<unknown>
|
|
364
|
+
? ReadonlyArray<Knex.ResolveTableType<TRecord2, 'insert'>>
|
|
365
|
+
: ReadonlyArray<Knex.DbRecordArr<TRecord2>>,
|
|
366
|
+
chunkSize?: number,
|
|
367
|
+
): Knex.BatchInsertBuilder<TRecord2, TResult2>;
|
|
368
|
+
|
|
369
|
+
schema: Knex.SchemaBuilder;
|
|
370
|
+
queryBuilder<TRecord2 = TRecord, TResult2 = TResult>(): Knex.QueryBuilder<
|
|
371
|
+
TRecord2,
|
|
372
|
+
TResult2
|
|
373
|
+
>;
|
|
374
|
+
|
|
375
|
+
client: any;
|
|
376
|
+
migrate: Knex.Migrator;
|
|
377
|
+
seed: Knex.Seeder;
|
|
378
|
+
fn: Knex.FunctionHelper;
|
|
379
|
+
ref: Knex.RefBuilder;
|
|
380
|
+
userParams: Record<string, any>;
|
|
381
|
+
withUserParams(params: Record<string, any>): Knex;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
declare function Knex<TRecord extends {} = any, TResult = unknown[]>(
|
|
385
|
+
config: Knex.Config | string
|
|
386
|
+
): Knex<TRecord, TResult>;
|
|
387
|
+
|
|
388
|
+
declare namespace Knex {
|
|
389
|
+
//
|
|
390
|
+
// Utility Types
|
|
391
|
+
//
|
|
392
|
+
|
|
393
|
+
type Value =
|
|
394
|
+
| string
|
|
395
|
+
| number
|
|
396
|
+
| boolean
|
|
397
|
+
| null
|
|
398
|
+
| Date
|
|
399
|
+
| Array<string>
|
|
400
|
+
| Array<number>
|
|
401
|
+
| Array<Date>
|
|
402
|
+
| Array<boolean>
|
|
403
|
+
| Buffer
|
|
404
|
+
| Knex.Raw;
|
|
405
|
+
|
|
406
|
+
interface ValueDict extends Dict<Value | Knex.QueryBuilder> {}
|
|
407
|
+
interface AliasDict extends Dict<string> {}
|
|
408
|
+
|
|
409
|
+
type ColumnDescriptor<TRecord, TResult> =
|
|
410
|
+
| string
|
|
411
|
+
| Knex.Raw
|
|
412
|
+
| Knex.QueryBuilder<TRecord, TResult>
|
|
413
|
+
| Dict<string>;
|
|
414
|
+
|
|
415
|
+
type InferrableColumnDescriptor<TRecord extends {}> =
|
|
416
|
+
| keyof TRecord
|
|
417
|
+
| Knex.Ref<any, any>
|
|
418
|
+
| Dict<keyof TRecord>;
|
|
419
|
+
|
|
420
|
+
type TableDescriptor = string | Knex.Raw | Knex.QueryBuilder;
|
|
421
|
+
|
|
422
|
+
type Lookup<TRegistry extends {}, TKey extends string, TDefault = never> =
|
|
423
|
+
TKey extends keyof TRegistry ?
|
|
424
|
+
TRegistry[TKey] :
|
|
425
|
+
TDefault;
|
|
426
|
+
|
|
427
|
+
type MaybeRawColumn<TColumn> = TColumn | Raw<TColumn>;
|
|
428
|
+
|
|
429
|
+
type MaybeRawRecord<TRecord> = {
|
|
430
|
+
[K in keyof TRecord]: MaybeRawColumn<TRecord[K]>
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
type DbColumn<TColumn> = Readonly<MaybeRawColumn<TColumn>>;
|
|
434
|
+
|
|
435
|
+
type DbRecord<TRecord> = Readonly<SafePartial<MaybeRawRecord<TRecord>>>;
|
|
436
|
+
|
|
437
|
+
type DbRecordArr<TRecord> = Readonly<MaybeArray<DbRecord<TRecord>>>;
|
|
438
|
+
|
|
439
|
+
export type CompositeTableType<TBase, TInsert = TBase, TUpdate = Partial<TInsert>> = {
|
|
440
|
+
base: TBase,
|
|
441
|
+
insert: TInsert,
|
|
442
|
+
update: TUpdate,
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
type TableNames = keyof Tables;
|
|
446
|
+
|
|
447
|
+
type TableInterfaceScope = keyof CompositeTableType<unknown>;
|
|
448
|
+
|
|
449
|
+
type TableType<TTable extends keyof Tables> = Tables[TTable];
|
|
450
|
+
|
|
451
|
+
type ResolveTableType<TCompositeTableType, TScope extends TableInterfaceScope = 'base'> = TCompositeTableType extends CompositeTableType<unknown>
|
|
452
|
+
? TCompositeTableType[TScope]
|
|
453
|
+
: TCompositeTableType;
|
|
454
|
+
|
|
455
|
+
interface OnConflictQueryBuilder<TRecord, TResult> {
|
|
456
|
+
ignore(): QueryBuilder<TRecord, TResult>;
|
|
457
|
+
merge(data?: DbRecord<TRecord>): QueryBuilder<TRecord, TResult>;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
//
|
|
461
|
+
// QueryInterface
|
|
462
|
+
//
|
|
463
|
+
type ClearStatements = "with" | "select" | "columns" | "hintComments" | "where" | "union" | "join" | "group" | "order" | "having" | "limit" | "offset" | "counter" | "counters";
|
|
464
|
+
|
|
465
|
+
interface QueryInterface<TRecord extends {} = any, TResult = any> {
|
|
466
|
+
select: Select<TRecord, TResult>;
|
|
467
|
+
as: As<TRecord, TResult>;
|
|
468
|
+
columns: Select<TRecord, TResult>;
|
|
469
|
+
column: Select<TRecord, TResult>;
|
|
470
|
+
hintComment: HintComment<TRecord, TResult>;
|
|
471
|
+
from: Table<TRecord, TResult>;
|
|
472
|
+
into: Table<TRecord, TResult>;
|
|
473
|
+
table: Table<TRecord, TResult>;
|
|
474
|
+
distinct: Distinct<TRecord, TResult>;
|
|
475
|
+
distinctOn: DistinctOn<TRecord, TResult>;
|
|
476
|
+
|
|
477
|
+
// Joins
|
|
478
|
+
join: Join<TRecord, TResult>;
|
|
479
|
+
joinRaw: JoinRaw<TRecord, TResult>;
|
|
480
|
+
innerJoin: Join<TRecord, TResult>;
|
|
481
|
+
leftJoin: Join<TRecord, TResult>;
|
|
482
|
+
leftOuterJoin: Join<TRecord, TResult>;
|
|
483
|
+
rightJoin: Join<TRecord, TResult>;
|
|
484
|
+
rightOuterJoin: Join<TRecord, TResult>;
|
|
485
|
+
outerJoin: Join<TRecord, TResult>;
|
|
486
|
+
fullOuterJoin: Join<TRecord, TResult>;
|
|
487
|
+
crossJoin: Join<TRecord, TResult>;
|
|
488
|
+
|
|
489
|
+
// Withs
|
|
490
|
+
with: With<TRecord, TResult>;
|
|
491
|
+
withRecursive: With<TRecord, TResult>;
|
|
492
|
+
withRaw: WithRaw<TRecord, TResult>;
|
|
493
|
+
withSchema: WithSchema<TRecord, TResult>;
|
|
494
|
+
withWrapped: WithWrapped<TRecord, TResult>;
|
|
495
|
+
|
|
496
|
+
// Wheres
|
|
497
|
+
where: Where<TRecord, TResult>;
|
|
498
|
+
andWhere: Where<TRecord, TResult>;
|
|
499
|
+
orWhere: Where<TRecord, TResult>;
|
|
500
|
+
whereNot: Where<TRecord, TResult>;
|
|
501
|
+
andWhereNot: Where<TRecord, TResult>;
|
|
502
|
+
orWhereNot: Where<TRecord, TResult>;
|
|
503
|
+
whereRaw: WhereRaw<TRecord, TResult>;
|
|
504
|
+
orWhereRaw: WhereRaw<TRecord, TResult>;
|
|
505
|
+
andWhereRaw: WhereRaw<TRecord, TResult>;
|
|
506
|
+
whereWrapped: WhereWrapped<TRecord, TResult>;
|
|
507
|
+
havingWrapped: WhereWrapped<TRecord, TResult>;
|
|
508
|
+
whereExists: WhereExists<TRecord, TResult>;
|
|
509
|
+
orWhereExists: WhereExists<TRecord, TResult>;
|
|
510
|
+
whereNotExists: WhereExists<TRecord, TResult>;
|
|
511
|
+
orWhereNotExists: WhereExists<TRecord, TResult>;
|
|
512
|
+
whereIn: WhereIn<TRecord, TResult>;
|
|
513
|
+
orWhereIn: WhereIn<TRecord, TResult>;
|
|
514
|
+
whereNotIn: WhereIn<TRecord, TResult>;
|
|
515
|
+
orWhereNotIn: WhereIn<TRecord, TResult>;
|
|
516
|
+
whereNull: WhereNull<TRecord, TResult>;
|
|
517
|
+
orWhereNull: WhereNull<TRecord, TResult>;
|
|
518
|
+
whereNotNull: WhereNull<TRecord, TResult>;
|
|
519
|
+
orWhereNotNull: WhereNull<TRecord, TResult>;
|
|
520
|
+
whereBetween: WhereBetween<TRecord, TResult>;
|
|
521
|
+
orWhereBetween: WhereBetween<TRecord, TResult>;
|
|
522
|
+
andWhereBetween: WhereBetween<TRecord, TResult>;
|
|
523
|
+
whereNotBetween: WhereBetween<TRecord, TResult>;
|
|
524
|
+
orWhereNotBetween: WhereBetween<TRecord, TResult>;
|
|
525
|
+
andWhereNotBetween: WhereBetween<TRecord, TResult>;
|
|
526
|
+
|
|
527
|
+
// Group by
|
|
528
|
+
groupBy: GroupBy<TRecord, TResult>;
|
|
529
|
+
groupByRaw: RawQueryBuilder<TRecord, TResult>;
|
|
530
|
+
|
|
531
|
+
// Order by
|
|
532
|
+
orderBy: OrderBy<TRecord, TResult>;
|
|
533
|
+
orderByRaw: RawQueryBuilder<TRecord, TResult>;
|
|
534
|
+
|
|
535
|
+
// Intersect
|
|
536
|
+
intersect: Intersect<TRecord, TResult>;
|
|
537
|
+
|
|
538
|
+
// Union
|
|
539
|
+
union: Union<TRecord, TResult>;
|
|
540
|
+
unionAll: Union<TRecord, TResult>;
|
|
541
|
+
|
|
542
|
+
// Having
|
|
543
|
+
having: Having<TRecord, TResult>;
|
|
544
|
+
andHaving: Having<TRecord, TResult>;
|
|
545
|
+
havingRaw: RawQueryBuilder<TRecord, TResult>;
|
|
546
|
+
orHaving: Having<TRecord, TResult>;
|
|
547
|
+
orHavingRaw: RawQueryBuilder<TRecord, TResult>;
|
|
548
|
+
havingIn: HavingRange<TRecord, TResult>;
|
|
549
|
+
orHavingNotBetween: HavingRange<TRecord, TResult>;
|
|
550
|
+
havingNotBetween: HavingRange<TRecord, TResult>;
|
|
551
|
+
orHavingBetween: HavingRange<TRecord, TResult>;
|
|
552
|
+
havingBetween: HavingRange<TRecord, TResult>;
|
|
553
|
+
|
|
554
|
+
// Clear
|
|
555
|
+
clearSelect(): QueryBuilder<
|
|
556
|
+
TRecord,
|
|
557
|
+
UnwrapArrayMember<TResult> extends DeferredKeySelection<
|
|
558
|
+
infer TBase,
|
|
559
|
+
infer TKeys,
|
|
560
|
+
true,
|
|
561
|
+
any,
|
|
562
|
+
any,
|
|
563
|
+
any,
|
|
564
|
+
any
|
|
565
|
+
>
|
|
566
|
+
? DeferredKeySelection<TBase, never>[]
|
|
567
|
+
: TResult
|
|
568
|
+
>;
|
|
569
|
+
clearWhere(): QueryBuilder<TRecord, TResult>;
|
|
570
|
+
clearGroup(): QueryBuilder<TRecord, TResult>;
|
|
571
|
+
clearOrder(): QueryBuilder<TRecord, TResult>;
|
|
572
|
+
clearHaving(): QueryBuilder<TRecord, TResult>;
|
|
573
|
+
clearCounters(): QueryBuilder<TRecord, TResult>;
|
|
574
|
+
clear(statement: ClearStatements): QueryBuilder<TRecord, TResult>;
|
|
575
|
+
|
|
576
|
+
// Paging
|
|
577
|
+
offset(offset: number): QueryBuilder<TRecord, TResult>;
|
|
578
|
+
limit(limit: number): QueryBuilder<TRecord, TResult>;
|
|
579
|
+
|
|
580
|
+
// Aggregation
|
|
581
|
+
count: AsymmetricAggregation<TRecord, TResult, Lookup<ResultTypes.Registry, "Count", number | string>>;
|
|
582
|
+
countDistinct: AsymmetricAggregation<TRecord, TResult, Lookup<ResultTypes.Registry, "Count", number | string>>;
|
|
583
|
+
min: TypePreservingAggregation<TRecord, TResult>;
|
|
584
|
+
max: TypePreservingAggregation<TRecord, TResult>;
|
|
585
|
+
sum: TypePreservingAggregation<TRecord, TResult>;
|
|
586
|
+
sumDistinct: TypePreservingAggregation<TRecord, TResult>;
|
|
587
|
+
avg: TypePreservingAggregation<TRecord, TResult>;
|
|
588
|
+
avgDistinct: TypePreservingAggregation<TRecord, TResult>;
|
|
589
|
+
|
|
590
|
+
increment(
|
|
591
|
+
columnName: keyof TRecord,
|
|
592
|
+
amount?: number
|
|
593
|
+
): QueryBuilder<TRecord, number>;
|
|
594
|
+
increment(
|
|
595
|
+
columnName: string,
|
|
596
|
+
amount?: number
|
|
597
|
+
): QueryBuilder<TRecord, number>;
|
|
598
|
+
|
|
599
|
+
decrement(
|
|
600
|
+
columnName: keyof TRecord,
|
|
601
|
+
amount?: number
|
|
602
|
+
): QueryBuilder<TRecord, number>;
|
|
603
|
+
decrement(
|
|
604
|
+
columnName: string,
|
|
605
|
+
amount?: number
|
|
606
|
+
): QueryBuilder<TRecord, number>;
|
|
607
|
+
|
|
608
|
+
// Others
|
|
609
|
+
first: Select<TRecord, DeferredKeySelection.AddUnionMember<UnwrapArrayMember<TResult>, undefined>>;
|
|
610
|
+
|
|
611
|
+
pluck<K extends keyof TRecord>(
|
|
612
|
+
column: K
|
|
613
|
+
): QueryBuilder<TRecord, TRecord[K][]>;
|
|
614
|
+
pluck<TResult2 extends {}>(column: string): QueryBuilder<TRecord, TResult2>;
|
|
615
|
+
|
|
616
|
+
insert(
|
|
617
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
618
|
+
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
619
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
620
|
+
returning: '*',
|
|
621
|
+
options?: DMLOptions
|
|
622
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
623
|
+
insert<
|
|
624
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
625
|
+
TResult2 = DeferredIndex.Augment<
|
|
626
|
+
UnwrapArrayMember<TResult>,
|
|
627
|
+
ResolveTableType<TRecord>,
|
|
628
|
+
TKey
|
|
629
|
+
>[]
|
|
630
|
+
>(
|
|
631
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
632
|
+
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
633
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
634
|
+
returning: TKey,
|
|
635
|
+
options?: DMLOptions
|
|
636
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
637
|
+
insert<
|
|
638
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
639
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
640
|
+
UnwrapArrayMember<TResult>,
|
|
641
|
+
ResolveTableType<TRecord>,
|
|
642
|
+
TKey
|
|
643
|
+
>[]
|
|
644
|
+
>(
|
|
645
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
646
|
+
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
647
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
648
|
+
returning: readonly TKey[],
|
|
649
|
+
options?: DMLOptions
|
|
650
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
651
|
+
insert<
|
|
652
|
+
TKey extends string,
|
|
653
|
+
TResult2 = DeferredIndex.Augment<
|
|
654
|
+
UnwrapArrayMember<TResult>,
|
|
655
|
+
TRecord,
|
|
656
|
+
TKey
|
|
657
|
+
>[]
|
|
658
|
+
>(
|
|
659
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
660
|
+
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
661
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
662
|
+
returning: TKey,
|
|
663
|
+
options?: DMLOptions
|
|
664
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
665
|
+
insert<
|
|
666
|
+
TKey extends string,
|
|
667
|
+
TResult2 = DeferredIndex.Augment<
|
|
668
|
+
UnwrapArrayMember<TResult>,
|
|
669
|
+
TRecord,
|
|
670
|
+
TKey
|
|
671
|
+
>[]
|
|
672
|
+
>(
|
|
673
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
674
|
+
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
675
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>,
|
|
676
|
+
returning: readonly TKey[],
|
|
677
|
+
options?: DMLOptions
|
|
678
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
679
|
+
insert<TResult2 = number[]>(
|
|
680
|
+
data: TRecord extends CompositeTableType<unknown>
|
|
681
|
+
? ResolveTableType<TRecord, 'insert'> | ReadonlyArray<ResolveTableType<TRecord, 'insert'>>
|
|
682
|
+
: DbRecordArr<TRecord> | ReadonlyArray<DbRecordArr<TRecord>>
|
|
683
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
684
|
+
|
|
685
|
+
modify<TRecord2 extends {} = any, TResult2 extends {} = any>(
|
|
686
|
+
callback: QueryCallbackWithArgs<TRecord, any>,
|
|
687
|
+
...args: any[]
|
|
688
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
689
|
+
update<
|
|
690
|
+
K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
|
|
691
|
+
K2 extends StrKey<ResolveTableType<TRecord>>,
|
|
692
|
+
TResult2 = DeferredIndex.Augment<
|
|
693
|
+
UnwrapArrayMember<TResult>,
|
|
694
|
+
ResolveTableType<TRecord>,
|
|
695
|
+
K2
|
|
696
|
+
>[]
|
|
697
|
+
>(
|
|
698
|
+
columnName: K1,
|
|
699
|
+
value: DbColumn<ResolveTableType<TRecord, 'update'>[K1]>,
|
|
700
|
+
returning: K2,
|
|
701
|
+
options?: DMLOptions
|
|
702
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
703
|
+
update<
|
|
704
|
+
K1 extends StrKey<ResolveTableType<TRecord, 'update'>>,
|
|
705
|
+
K2 extends StrKey<ResolveTableType<TRecord>>,
|
|
706
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
707
|
+
UnwrapArrayMember<TResult>,
|
|
708
|
+
ResolveTableType<TRecord>,
|
|
709
|
+
K2
|
|
710
|
+
>[]
|
|
711
|
+
>(
|
|
712
|
+
columnName: K1,
|
|
713
|
+
value: DbColumn<ResolveTableType<TRecord, 'update'>[K1]>,
|
|
714
|
+
returning: readonly K2[],
|
|
715
|
+
options?: DMLOptions
|
|
716
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
717
|
+
update<K extends keyof TRecord>(
|
|
718
|
+
columnName: K,
|
|
719
|
+
value: DbColumn<TRecord[K]>
|
|
720
|
+
): QueryBuilder<TRecord, number>;
|
|
721
|
+
update<TResult2 = SafePartial<TRecord>[]>(
|
|
722
|
+
columnName: string,
|
|
723
|
+
value: Value,
|
|
724
|
+
returning: string | readonly string[],
|
|
725
|
+
options?: DMLOptions
|
|
726
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
727
|
+
update(
|
|
728
|
+
data: DbRecordArr<TRecord>,
|
|
729
|
+
returning: '*',
|
|
730
|
+
options?: DMLOptions
|
|
731
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
732
|
+
update<
|
|
733
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
734
|
+
TResult2 = DeferredIndex.Augment<
|
|
735
|
+
UnwrapArrayMember<TResult>,
|
|
736
|
+
ResolveTableType<TRecord>,
|
|
737
|
+
TKey
|
|
738
|
+
>[]
|
|
739
|
+
>(
|
|
740
|
+
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
741
|
+
returning: TKey,
|
|
742
|
+
options?: DMLOptions
|
|
743
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
744
|
+
update<
|
|
745
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
746
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
747
|
+
UnwrapArrayMember<TResult>,
|
|
748
|
+
ResolveTableType<TRecord>,
|
|
749
|
+
TKey
|
|
750
|
+
>[]
|
|
751
|
+
>(
|
|
752
|
+
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
753
|
+
returning: readonly TKey[],
|
|
754
|
+
options?: DMLOptions
|
|
755
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
756
|
+
update<
|
|
757
|
+
TKey extends string = string,
|
|
758
|
+
TResult2 extends {}[] = DeferredKeySelection.Augment<
|
|
759
|
+
UnwrapArrayMember<TResult>,
|
|
760
|
+
TRecord,
|
|
761
|
+
TKey
|
|
762
|
+
>[]
|
|
763
|
+
>(
|
|
764
|
+
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
765
|
+
returning: TKey | readonly TKey[],
|
|
766
|
+
options?: DMLOptions
|
|
767
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
768
|
+
update<
|
|
769
|
+
TKey extends string,
|
|
770
|
+
TResult2 extends {}[] = DeferredKeySelection.Augment<
|
|
771
|
+
UnwrapArrayMember<TResult>,
|
|
772
|
+
TRecord,
|
|
773
|
+
TKey
|
|
774
|
+
>[]
|
|
775
|
+
>(
|
|
776
|
+
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>,
|
|
777
|
+
returning: readonly TKey[],
|
|
778
|
+
options?: DMLOptions
|
|
779
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
780
|
+
update<TResult2 = number>(
|
|
781
|
+
data: TRecord extends CompositeTableType<unknown> ? ResolveTableType<TRecord, 'update'> : DbRecordArr<TRecord>
|
|
782
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
783
|
+
|
|
784
|
+
update<TResult2 = number>(columnName: string, value: Value): QueryBuilder<TRecord, TResult2>;
|
|
785
|
+
|
|
786
|
+
returning(column: '*', options?: DMLOptions): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
787
|
+
returning<
|
|
788
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
789
|
+
TResult2 = DeferredIndex.Augment<
|
|
790
|
+
UnwrapArrayMember<TResult>,
|
|
791
|
+
ResolveTableType<TRecord>,
|
|
792
|
+
TKey
|
|
793
|
+
>[]
|
|
794
|
+
>(
|
|
795
|
+
column: TKey,
|
|
796
|
+
options?: DMLOptions
|
|
797
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
798
|
+
returning<
|
|
799
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
800
|
+
TResult2 = DeferredKeySelection.SetSingle<
|
|
801
|
+
DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, ResolveTableType<TRecord>, TKey>,
|
|
802
|
+
false
|
|
803
|
+
>[]
|
|
804
|
+
>(
|
|
805
|
+
columns: readonly TKey[],
|
|
806
|
+
options?: DMLOptions
|
|
807
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
808
|
+
returning<TResult2 = SafePartial<TRecord>[]>(
|
|
809
|
+
column: string | readonly string[],
|
|
810
|
+
options?: DMLOptions
|
|
811
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
812
|
+
|
|
813
|
+
onConflict<
|
|
814
|
+
TKey extends StrKey<TRecord>,
|
|
815
|
+
TResult2 = DeferredIndex.Augment<
|
|
816
|
+
UnwrapArrayMember<TResult>,
|
|
817
|
+
TRecord,
|
|
818
|
+
TKey
|
|
819
|
+
>[]
|
|
820
|
+
>(
|
|
821
|
+
column: TKey
|
|
822
|
+
): OnConflictQueryBuilder<TRecord, TResult2>;
|
|
823
|
+
onConflict<
|
|
824
|
+
TKey extends StrKey<TRecord>,
|
|
825
|
+
TResult2 = DeferredKeySelection.SetSingle<
|
|
826
|
+
DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, TRecord, TKey>,
|
|
827
|
+
false
|
|
828
|
+
>[]
|
|
829
|
+
>(
|
|
830
|
+
columns: readonly TKey[]
|
|
831
|
+
): OnConflictQueryBuilder<TRecord, TResult2>;
|
|
832
|
+
|
|
833
|
+
del(
|
|
834
|
+
returning: '*',
|
|
835
|
+
options?: DMLOptions
|
|
836
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
837
|
+
del<
|
|
838
|
+
TKey extends StrKey<TRecord>,
|
|
839
|
+
TResult2 = DeferredIndex.Augment<
|
|
840
|
+
UnwrapArrayMember<TResult>,
|
|
841
|
+
TRecord,
|
|
842
|
+
TKey
|
|
843
|
+
>[]
|
|
844
|
+
>(
|
|
845
|
+
returning: TKey,
|
|
846
|
+
options?: DMLOptions
|
|
847
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
848
|
+
del<
|
|
849
|
+
TKey extends StrKey<TRecord>,
|
|
850
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
851
|
+
UnwrapArrayMember<TResult>,
|
|
852
|
+
TRecord,
|
|
853
|
+
TKey
|
|
854
|
+
>[]
|
|
855
|
+
>(
|
|
856
|
+
returning: readonly TKey[],
|
|
857
|
+
options?: DMLOptions
|
|
858
|
+
): QueryBuilder<TRecord, TResult2[]>;
|
|
859
|
+
del<TResult2 = SafePartial<TRecord>[]>(
|
|
860
|
+
returning: string | readonly string[],
|
|
861
|
+
options?: DMLOptions
|
|
862
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
863
|
+
del<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
|
|
864
|
+
|
|
865
|
+
delete(
|
|
866
|
+
returning: '*',
|
|
867
|
+
options?: DMLOptions
|
|
868
|
+
): QueryBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
869
|
+
delete<
|
|
870
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
871
|
+
TResult2 = DeferredIndex.Augment<
|
|
872
|
+
UnwrapArrayMember<TResult>,
|
|
873
|
+
ResolveTableType<TRecord>,
|
|
874
|
+
TKey
|
|
875
|
+
>[]
|
|
876
|
+
>(
|
|
877
|
+
returning: TKey,
|
|
878
|
+
options?: DMLOptions
|
|
879
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
880
|
+
delete<
|
|
881
|
+
TKey extends StrKey<TRecord>,
|
|
882
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
883
|
+
UnwrapArrayMember<TResult>,
|
|
884
|
+
TRecord,
|
|
885
|
+
TKey
|
|
886
|
+
>[]
|
|
887
|
+
>(
|
|
888
|
+
returning: readonly TKey[],
|
|
889
|
+
options?: DMLOptions
|
|
890
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
891
|
+
delete<TResult2 = any>(
|
|
892
|
+
returning: string | readonly string[],
|
|
893
|
+
options?: DMLOptions
|
|
894
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
895
|
+
delete<TResult2 = number>(): QueryBuilder<TRecord, TResult2>;
|
|
896
|
+
|
|
897
|
+
truncate(): QueryBuilder<TRecord, void>;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
interface As<TRecord, TResult> {
|
|
901
|
+
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
|
|
902
|
+
(columnName: string): QueryBuilder<TRecord, TResult>;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
type IntersectAliases<AliasUT> =
|
|
906
|
+
UnionToIntersection<
|
|
907
|
+
IncompatibleToAlt<
|
|
908
|
+
AliasUT extends (infer I)[]
|
|
909
|
+
? I extends Ref<any, infer TMapping>
|
|
910
|
+
? TMapping
|
|
911
|
+
: I
|
|
912
|
+
: never,
|
|
913
|
+
Dict,
|
|
914
|
+
{}
|
|
915
|
+
>
|
|
916
|
+
>;
|
|
917
|
+
|
|
918
|
+
interface AliasQueryBuilder<TRecord extends {} = any, TResult = unknown[]> {
|
|
919
|
+
<
|
|
920
|
+
AliasUT extends InferrableColumnDescriptor<ResolveTableType<TRecord>>[],
|
|
921
|
+
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
922
|
+
UnwrapArrayMember<TResult>,
|
|
923
|
+
ResolveTableType<TRecord>,
|
|
924
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
925
|
+
IntersectAliases<AliasUT>
|
|
926
|
+
>>
|
|
927
|
+
>(
|
|
928
|
+
...aliases: AliasUT
|
|
929
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
930
|
+
|
|
931
|
+
<
|
|
932
|
+
AliasUT extends InferrableColumnDescriptor<ResolveTableType<TRecord>>[],
|
|
933
|
+
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
934
|
+
UnwrapArrayMember<TResult>,
|
|
935
|
+
ResolveTableType<TRecord>,
|
|
936
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
937
|
+
IntersectAliases<AliasUT>
|
|
938
|
+
>>
|
|
939
|
+
>(
|
|
940
|
+
aliases: AliasUT
|
|
941
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
942
|
+
|
|
943
|
+
<
|
|
944
|
+
AliasUT extends (Dict | string)[],
|
|
945
|
+
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
946
|
+
UnwrapArrayMember<TResult>,
|
|
947
|
+
ResolveTableType<TRecord>,
|
|
948
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
949
|
+
IntersectAliases<AliasUT>
|
|
950
|
+
>>
|
|
951
|
+
>(
|
|
952
|
+
...aliases: AliasUT
|
|
953
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
954
|
+
|
|
955
|
+
<
|
|
956
|
+
AliasUT extends (Dict | string)[],
|
|
957
|
+
TResult2 = ArrayIfAlready<TResult, DeferredKeySelection.Augment<
|
|
958
|
+
UnwrapArrayMember<TResult>,
|
|
959
|
+
TRecord,
|
|
960
|
+
IncompatibleToAlt<ArrayMember<AliasUT>, string, never>,
|
|
961
|
+
IntersectAliases<AliasUT>
|
|
962
|
+
>>
|
|
963
|
+
>(
|
|
964
|
+
aliases: AliasUT
|
|
965
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
interface Select<TRecord extends {} = any, TResult = unknown[]>
|
|
969
|
+
extends AliasQueryBuilder<TRecord, TResult>,
|
|
970
|
+
ColumnNameQueryBuilder<TRecord, TResult> {
|
|
971
|
+
(): QueryBuilder<TRecord, TResult>;
|
|
972
|
+
|
|
973
|
+
<TResult2 = ArrayIfAlready<TResult, any>, TInnerRecord = any, TInnerResult = any>(
|
|
974
|
+
...subQueryBuilders: readonly QueryBuilder<TInnerRecord, TInnerResult>[]
|
|
975
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
976
|
+
|
|
977
|
+
<TResult2 = ArrayIfAlready<TResult, any>, TInnerRecord = any, TInnerResult = any>(
|
|
978
|
+
subQueryBuilders: readonly QueryBuilder<TInnerRecord, TInnerResult>[]
|
|
979
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
interface HintComment<TRecord extends {} = any, TResult extends {} = any> {
|
|
983
|
+
(hint: string): QueryBuilder<TRecord, TResult>;
|
|
984
|
+
(hints: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
interface Table<TRecord extends {} = any, TResult extends {} = any> {
|
|
988
|
+
<
|
|
989
|
+
TTable extends TableNames,
|
|
990
|
+
TRecord2 = TableType<TTable>,
|
|
991
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, ResolveTableType<TRecord2>>
|
|
992
|
+
>(
|
|
993
|
+
tableName: TTable,
|
|
994
|
+
options?: TableOptions
|
|
995
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
996
|
+
<
|
|
997
|
+
TRecord2 = unknown,
|
|
998
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
999
|
+
>(
|
|
1000
|
+
tableName: TableDescriptor | AliasDict,
|
|
1001
|
+
options?: TableOptions
|
|
1002
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1003
|
+
<
|
|
1004
|
+
TRecord2 = unknown,
|
|
1005
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1006
|
+
>(
|
|
1007
|
+
callback: Function,
|
|
1008
|
+
options?: TableOptions
|
|
1009
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1010
|
+
<
|
|
1011
|
+
TRecord2 = unknown,
|
|
1012
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1013
|
+
>(
|
|
1014
|
+
raw: Raw,
|
|
1015
|
+
options?: TableOptions
|
|
1016
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
interface Distinct<TRecord extends {}, TResult = {}[]>
|
|
1020
|
+
extends ColumnNameQueryBuilder<TRecord, TResult> {}
|
|
1021
|
+
|
|
1022
|
+
interface DistinctOn<TRecord extends {}, TResult = {}[]> {
|
|
1023
|
+
<ColNameUT extends keyof TRecord>(
|
|
1024
|
+
...columnNames: readonly ColNameUT[]
|
|
1025
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1026
|
+
|
|
1027
|
+
<ColNameUT extends keyof TRecord>(
|
|
1028
|
+
columnNames: readonly ColNameUT[]
|
|
1029
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1030
|
+
|
|
1031
|
+
(...columnNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1032
|
+
(columnNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
interface JoinCallback {
|
|
1036
|
+
(this: JoinClause, join: JoinClause): void;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
interface Join<TRecord extends {} = any, TResult = unknown[]> {
|
|
1040
|
+
<
|
|
1041
|
+
TJoinTargetRecord extends {} = any,
|
|
1042
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1043
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1044
|
+
>(
|
|
1045
|
+
raw: Raw
|
|
1046
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1047
|
+
<
|
|
1048
|
+
TTable extends TableNames,
|
|
1049
|
+
TRecord2 = ResolveTableType<TRecord> & ResolveTableType<TableType<TTable>>,
|
|
1050
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1051
|
+
>(
|
|
1052
|
+
tableName: TTable,
|
|
1053
|
+
clause: JoinCallback
|
|
1054
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1055
|
+
<
|
|
1056
|
+
TJoinTargetRecord extends {} = any,
|
|
1057
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1058
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1059
|
+
>(
|
|
1060
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1061
|
+
clause: JoinCallback
|
|
1062
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1063
|
+
<
|
|
1064
|
+
TJoinTargetRecord extends {} = any,
|
|
1065
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1066
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1067
|
+
>(
|
|
1068
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1069
|
+
columns: { [key: string]: string | number | boolean | Raw }
|
|
1070
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1071
|
+
<
|
|
1072
|
+
TJoinTargetRecord extends {} = any,
|
|
1073
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1074
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1075
|
+
>(
|
|
1076
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1077
|
+
raw: Raw
|
|
1078
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1079
|
+
<
|
|
1080
|
+
TTable extends TableNames,
|
|
1081
|
+
TRecord2 = ResolveTableType<TRecord> & ResolveTableType<TableType<TTable>>,
|
|
1082
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1083
|
+
>(
|
|
1084
|
+
tableName: TTable,
|
|
1085
|
+
column1: string,
|
|
1086
|
+
column2: string
|
|
1087
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1088
|
+
<
|
|
1089
|
+
TJoinTargetRecord extends {} = any,
|
|
1090
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1091
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1092
|
+
>(
|
|
1093
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1094
|
+
column1: string,
|
|
1095
|
+
column2: string
|
|
1096
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1097
|
+
<
|
|
1098
|
+
TJoinTargetRecord extends {} = any,
|
|
1099
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1100
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1101
|
+
>(
|
|
1102
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1103
|
+
column1: string,
|
|
1104
|
+
raw: Raw
|
|
1105
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1106
|
+
<
|
|
1107
|
+
TTable extends TableNames,
|
|
1108
|
+
TRecord2 = ResolveTableType<TRecord> & ResolveTableType<TableType<TTable>>,
|
|
1109
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1110
|
+
>(
|
|
1111
|
+
tableName: TTable,
|
|
1112
|
+
column1: string,
|
|
1113
|
+
operator: string,
|
|
1114
|
+
column2: string
|
|
1115
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1116
|
+
<
|
|
1117
|
+
TJoinTargetRecord extends {} = any,
|
|
1118
|
+
TRecord2 extends {} = TRecord & TJoinTargetRecord,
|
|
1119
|
+
TResult2 = DeferredKeySelection.ReplaceBase<TResult, TRecord2>
|
|
1120
|
+
>(
|
|
1121
|
+
tableName: TableDescriptor | AliasDict | QueryCallback,
|
|
1122
|
+
column1: string,
|
|
1123
|
+
operator: string,
|
|
1124
|
+
column2: string
|
|
1125
|
+
): QueryBuilder<TRecord2, TResult2>;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
interface JoinClause {
|
|
1129
|
+
on(raw: Raw): JoinClause;
|
|
1130
|
+
on(callback: JoinCallback): JoinClause;
|
|
1131
|
+
on(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1132
|
+
on(column1: string, column2: string): JoinClause;
|
|
1133
|
+
on(column1: string, raw: Raw): JoinClause;
|
|
1134
|
+
on(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1135
|
+
andOn(raw: Raw): JoinClause;
|
|
1136
|
+
andOn(callback: JoinCallback): JoinClause;
|
|
1137
|
+
andOn(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1138
|
+
andOn(column1: string, column2: string): JoinClause;
|
|
1139
|
+
andOn(column1: string, raw: Raw): JoinClause;
|
|
1140
|
+
andOn(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1141
|
+
orOn(raw: Raw): JoinClause;
|
|
1142
|
+
orOn(callback: JoinCallback): JoinClause;
|
|
1143
|
+
orOn(columns: { [key: string]: string | Raw }): JoinClause;
|
|
1144
|
+
orOn(column1: string, column2: string): JoinClause;
|
|
1145
|
+
orOn(column1: string, raw: Raw): JoinClause;
|
|
1146
|
+
orOn(column1: string, operator: string, column2: string | Raw): JoinClause;
|
|
1147
|
+
onIn(column1: string, values: readonly any[]): JoinClause;
|
|
1148
|
+
andOnIn(column1: string, values: readonly any[]): JoinClause;
|
|
1149
|
+
orOnIn(column1: string, values: readonly any[]): JoinClause;
|
|
1150
|
+
onNotIn(column1: string, values: readonly any[]): JoinClause;
|
|
1151
|
+
andOnNotIn(column1: string, values: readonly any[]): JoinClause;
|
|
1152
|
+
orOnNotIn(column1: string, values: readonly any[]): JoinClause;
|
|
1153
|
+
onNull(column1: string): JoinClause;
|
|
1154
|
+
andOnNull(column1: string): JoinClause;
|
|
1155
|
+
orOnNull(column1: string): JoinClause;
|
|
1156
|
+
onNotNull(column1: string): JoinClause;
|
|
1157
|
+
andOnNotNull(column1: string): JoinClause;
|
|
1158
|
+
orOnNotNull(column1: string): JoinClause;
|
|
1159
|
+
onExists(callback: QueryCallback): JoinClause;
|
|
1160
|
+
andOnExists(callback: QueryCallback): JoinClause;
|
|
1161
|
+
orOnExists(callback: QueryCallback): JoinClause;
|
|
1162
|
+
onNotExists(callback: QueryCallback): JoinClause;
|
|
1163
|
+
andOnNotExists(callback: QueryCallback): JoinClause;
|
|
1164
|
+
orOnNotExists(callback: QueryCallback): JoinClause;
|
|
1165
|
+
onBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1166
|
+
andOnBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1167
|
+
orOnBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1168
|
+
onNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1169
|
+
andOnNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1170
|
+
orOnNotBetween(column1: string, range: readonly [any, any]): JoinClause;
|
|
1171
|
+
using(
|
|
1172
|
+
column: string | readonly string[] | Raw | { [key: string]: string | Raw }
|
|
1173
|
+
): JoinClause;
|
|
1174
|
+
type(type: string): JoinClause;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
interface JoinRaw<TRecord = any, TResult = unknown[]> {
|
|
1178
|
+
(tableName: string, binding?: Value | ValueDict): QueryBuilder<
|
|
1179
|
+
TRecord,
|
|
1180
|
+
TResult
|
|
1181
|
+
>;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
interface With<TRecord = any, TResult = unknown[]>
|
|
1185
|
+
extends WithRaw<TRecord, TResult>,
|
|
1186
|
+
WithWrapped<TRecord, TResult> {}
|
|
1187
|
+
|
|
1188
|
+
interface WithRaw<TRecord = any, TResult = unknown[]> {
|
|
1189
|
+
(alias: string, raw: Raw | QueryBuilder): QueryBuilder<TRecord, TResult>;
|
|
1190
|
+
(alias: string, sql: string, bindings?: readonly Value[] | Object): QueryBuilder<
|
|
1191
|
+
TRecord,
|
|
1192
|
+
TResult
|
|
1193
|
+
>;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
interface WithSchema<TRecord = any, TResult = unknown[]> {
|
|
1197
|
+
(schema: string): QueryBuilder<TRecord, TResult>;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
interface WithWrapped<TRecord = any, TResult = unknown[]> {
|
|
1201
|
+
(alias: string, queryBuilder: QueryBuilder): QueryBuilder<TRecord, TResult>;
|
|
1202
|
+
(
|
|
1203
|
+
alias: string,
|
|
1204
|
+
callback: (queryBuilder: QueryBuilder) => any
|
|
1205
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
interface Where<TRecord = any, TResult = unknown>
|
|
1209
|
+
extends WhereRaw<TRecord, TResult>,
|
|
1210
|
+
WhereWrapped<TRecord, TResult>,
|
|
1211
|
+
WhereNull<TRecord, TResult> {
|
|
1212
|
+
(raw: Raw): QueryBuilder<TRecord, TResult>;
|
|
1213
|
+
|
|
1214
|
+
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1215
|
+
|
|
1216
|
+
(object: DbRecord<ResolveTableType<TRecord>>): QueryBuilder<TRecord, TResult>;
|
|
1217
|
+
|
|
1218
|
+
(object: Readonly<Object>): QueryBuilder<TRecord, TResult>;
|
|
1219
|
+
|
|
1220
|
+
<T extends keyof ResolveTableType<TRecord>>(
|
|
1221
|
+
columnName: T,
|
|
1222
|
+
value: DbColumn<ResolveTableType<TRecord>[T]> | null
|
|
1223
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1224
|
+
|
|
1225
|
+
(columnName: string, value: Value | null): QueryBuilder<TRecord, TResult>;
|
|
1226
|
+
|
|
1227
|
+
<T extends keyof ResolveTableType<TRecord>>(
|
|
1228
|
+
columnName: T,
|
|
1229
|
+
operator: ComparisonOperator,
|
|
1230
|
+
value: DbColumn<ResolveTableType<TRecord>[T]> | null
|
|
1231
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1232
|
+
|
|
1233
|
+
(columnName: string, operator: string, value: Value | null): QueryBuilder<
|
|
1234
|
+
TRecord,
|
|
1235
|
+
TResult
|
|
1236
|
+
>;
|
|
1237
|
+
|
|
1238
|
+
<T extends keyof ResolveTableType<TRecord>, TRecordInner, TResultInner>(
|
|
1239
|
+
columnName: T,
|
|
1240
|
+
operator: ComparisonOperator,
|
|
1241
|
+
value: QueryBuilder<TRecordInner, TResultInner>
|
|
1242
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1243
|
+
|
|
1244
|
+
<TRecordInner, TResultInner>(
|
|
1245
|
+
columnName: string,
|
|
1246
|
+
operator: string,
|
|
1247
|
+
value: QueryBuilder<TRecordInner, TResultInner>
|
|
1248
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1249
|
+
|
|
1250
|
+
(left: Raw, operator: string, right: Value | null): QueryBuilder<
|
|
1251
|
+
TRecord,
|
|
1252
|
+
TResult
|
|
1253
|
+
>;
|
|
1254
|
+
|
|
1255
|
+
<TRecordInner, TResultInner>(
|
|
1256
|
+
left: Raw,
|
|
1257
|
+
operator: string,
|
|
1258
|
+
right: QueryBuilder<TRecordInner, TResultInner>
|
|
1259
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
interface WhereRaw<TRecord = any, TResult = unknown[]>
|
|
1263
|
+
extends RawQueryBuilder<TRecord, TResult> {
|
|
1264
|
+
(condition: boolean): QueryBuilder<TRecord, TResult>;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
interface WhereWrapped<TRecord = any, TResult = unknown[]> {
|
|
1268
|
+
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
interface WhereNull<TRecord = any, TResult = unknown[]> {
|
|
1272
|
+
(columnName: keyof TRecord): QueryBuilder<TRecord, TResult>;
|
|
1273
|
+
(columnName: string): QueryBuilder<TRecord, TResult>;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
interface WhereBetween<TRecord = any, TResult = unknown[]> {
|
|
1277
|
+
<K extends keyof TRecord>(
|
|
1278
|
+
columnName: K,
|
|
1279
|
+
range: readonly [DbColumn<TRecord[K]>, DbColumn<TRecord[K]>]
|
|
1280
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1281
|
+
(columnName: string, range: readonly [Value, Value]): QueryBuilder<TRecord, TResult>;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
interface WhereExists<TRecord = any, TResult = unknown[]> {
|
|
1285
|
+
(callback: QueryCallback<TRecord, TResult>): QueryBuilder<TRecord, TResult>;
|
|
1286
|
+
<TRecordInner, TResultInner>(
|
|
1287
|
+
query: QueryBuilder<TRecordInner, TResultInner>
|
|
1288
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
interface WhereIn<TRecord = any, TResult = unknown[]> {
|
|
1292
|
+
<K extends keyof ResolveTableType<TRecord>>(
|
|
1293
|
+
columnName: K,
|
|
1294
|
+
values: readonly DbColumn<ResolveTableType<TRecord>[K]>[] | QueryCallback
|
|
1295
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1296
|
+
(columnName: string, values: readonly Value[] | QueryCallback): QueryBuilder<
|
|
1297
|
+
TRecord,
|
|
1298
|
+
TResult
|
|
1299
|
+
>;
|
|
1300
|
+
<K extends keyof ResolveTableType<TRecord>>(
|
|
1301
|
+
columnNames: readonly K[],
|
|
1302
|
+
values: readonly (readonly DbColumn<ResolveTableType<TRecord>[K]>[])[] | QueryCallback
|
|
1303
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1304
|
+
(columnNames: readonly string[], values: readonly Value[][] | QueryCallback): QueryBuilder<
|
|
1305
|
+
TRecord,
|
|
1306
|
+
TResult
|
|
1307
|
+
>;
|
|
1308
|
+
<K extends keyof TRecord, TRecordInner, TResultInner>(
|
|
1309
|
+
columnName: K,
|
|
1310
|
+
values: QueryBuilder<TRecordInner, TRecord[K]>
|
|
1311
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1312
|
+
<TRecordInner, TResultInner>(
|
|
1313
|
+
columnName: string,
|
|
1314
|
+
values: Value[] | QueryBuilder<TRecordInner, TResultInner>
|
|
1315
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1316
|
+
<K extends keyof TRecord, TRecordInner, TResultInner>(
|
|
1317
|
+
columnNames: readonly K[],
|
|
1318
|
+
values: QueryBuilder<TRecordInner, TRecord[K]>
|
|
1319
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1320
|
+
<TRecordInner, TResultInner>(
|
|
1321
|
+
columnNames: readonly string[],
|
|
1322
|
+
values: QueryBuilder<TRecordInner, TResultInner>
|
|
1323
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
// Note: Attempting to unify AsymmetricAggregation & TypePreservingAggregation
|
|
1327
|
+
// by extracting out a common base interface will not work because order of overloads
|
|
1328
|
+
// is significant.
|
|
1329
|
+
|
|
1330
|
+
interface AsymmetricAggregation<TRecord = any, TResult = unknown[], TValue = any> {
|
|
1331
|
+
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1332
|
+
...columnNames: readonly (keyof ResolveTableType<TRecord>)[]
|
|
1333
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1334
|
+
<
|
|
1335
|
+
TAliases extends {} = Record<string, string | string[] | Knex.Raw>,
|
|
1336
|
+
TResult2 = AggregationQueryResult<TResult, {[k in keyof TAliases]?: TValue}>
|
|
1337
|
+
>(aliases: TAliases): QueryBuilder<TRecord, TResult2>;
|
|
1338
|
+
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1339
|
+
...columnNames: ReadonlyArray<Readonly<Record<string, string | string[] | Knex.Raw>> | Knex.Raw | string>
|
|
1340
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
interface TypePreservingAggregation<TRecord = any, TResult = unknown[], TValue = any> {
|
|
1344
|
+
<
|
|
1345
|
+
TKey extends keyof ResolveTableType<TRecord>,
|
|
1346
|
+
TResult2 = AggregationQueryResult<TResult, Dict<ResolveTableType<TRecord>[TKey]>>
|
|
1347
|
+
>(
|
|
1348
|
+
...columnNames: readonly TKey[]
|
|
1349
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1350
|
+
<
|
|
1351
|
+
TAliases extends {} = Readonly<Record<string, string | string[] | Knex.Raw>>,
|
|
1352
|
+
TResult2 = AggregationQueryResult<TResult, {
|
|
1353
|
+
// We have optional here because in most dialects aggregating by multiple keys simultaneously
|
|
1354
|
+
// causes rest of the keys to be dropped and only first to be considered
|
|
1355
|
+
[K in keyof TAliases]?: K extends keyof TRecord ?
|
|
1356
|
+
TRecord[K] :
|
|
1357
|
+
TValue
|
|
1358
|
+
}>
|
|
1359
|
+
>(aliases: TAliases): QueryBuilder<TRecord, TResult2>;
|
|
1360
|
+
<TResult2 = AggregationQueryResult<TResult, Dict<TValue>>>(
|
|
1361
|
+
...columnNames: ReadonlyArray<Readonly<Record<string, string | readonly string[] | Knex.Raw>> | Knex.Raw | string>
|
|
1362
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
interface GroupBy<TRecord = any, TResult = unknown[]>
|
|
1366
|
+
extends RawQueryBuilder<TRecord, TResult>,
|
|
1367
|
+
ColumnNameQueryBuilder<TRecord, TResult> {}
|
|
1368
|
+
|
|
1369
|
+
interface OrderBy<TRecord = any, TResult = unknown[]> {
|
|
1370
|
+
(columnName: keyof TRecord | QueryBuilder, order?: 'asc' | 'desc'): QueryBuilder<
|
|
1371
|
+
TRecord,
|
|
1372
|
+
TResult
|
|
1373
|
+
>;
|
|
1374
|
+
(columnName: string | QueryBuilder, order?: string): QueryBuilder<TRecord, TResult>;
|
|
1375
|
+
(
|
|
1376
|
+
columnDefs: Array<
|
|
1377
|
+
keyof TRecord | Readonly<{
|
|
1378
|
+
column: keyof TRecord | QueryBuilder;
|
|
1379
|
+
order?: 'asc' | 'desc'
|
|
1380
|
+
}>
|
|
1381
|
+
>
|
|
1382
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1383
|
+
(
|
|
1384
|
+
columnDefs: Array<string | Readonly<{
|
|
1385
|
+
column: string | QueryBuilder;
|
|
1386
|
+
order?: string;
|
|
1387
|
+
}>>
|
|
1388
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
interface Intersect<TRecord = any, TResult = unknown[]> {
|
|
1392
|
+
(
|
|
1393
|
+
callback: MaybeArray<QueryCallback | QueryBuilder<TRecord> | Raw>,
|
|
1394
|
+
wrap?: boolean
|
|
1395
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1396
|
+
(
|
|
1397
|
+
...callbacks: readonly (QueryCallback | Raw | QueryBuilder<TRecord>)[]
|
|
1398
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
interface Union<TRecord = any, TResult = unknown[]>
|
|
1402
|
+
extends Intersect<TRecord, TResult> {}
|
|
1403
|
+
|
|
1404
|
+
interface Having<TRecord = any, TResult = unknown[]>
|
|
1405
|
+
extends WhereWrapped<TRecord, TResult> {
|
|
1406
|
+
<K extends keyof TRecord>(
|
|
1407
|
+
column: K,
|
|
1408
|
+
operator: ComparisonOperator,
|
|
1409
|
+
value: DbColumn<TRecord[K]>
|
|
1410
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1411
|
+
|
|
1412
|
+
(
|
|
1413
|
+
column: string | Raw,
|
|
1414
|
+
operator: string,
|
|
1415
|
+
value: Value | QueryBuilder | null
|
|
1416
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1417
|
+
|
|
1418
|
+
(raw: Raw): QueryBuilder<
|
|
1419
|
+
TRecord,
|
|
1420
|
+
TResult
|
|
1421
|
+
>;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
interface HavingRange<TRecord = any, TResult = unknown[]> {
|
|
1425
|
+
<K extends keyof TRecord>(
|
|
1426
|
+
columnName: K,
|
|
1427
|
+
values: readonly DbColumn<TRecord[K]>[]
|
|
1428
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1429
|
+
(columnName: string, values: readonly Value[]): QueryBuilder<TRecord, TResult>;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// commons
|
|
1433
|
+
|
|
1434
|
+
interface ColumnNameQueryBuilder<TRecord = any, TResult = unknown[]> {
|
|
1435
|
+
// When all columns are known to be keys of original record,
|
|
1436
|
+
// we can extend our selection by these columns
|
|
1437
|
+
(columnName: '*'): QueryBuilder<
|
|
1438
|
+
TRecord,
|
|
1439
|
+
ArrayIfAlready<TResult, DeferredKeySelection<TRecord, string>>
|
|
1440
|
+
>;
|
|
1441
|
+
|
|
1442
|
+
<
|
|
1443
|
+
ColNameUT extends keyof ResolveTableType<TRecord>,
|
|
1444
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1445
|
+
UnwrapArrayMember<TResult>,
|
|
1446
|
+
ResolveTableType<TRecord>,
|
|
1447
|
+
ColNameUT & string
|
|
1448
|
+
>[]
|
|
1449
|
+
>(
|
|
1450
|
+
...columnNames: readonly ColNameUT[]
|
|
1451
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1452
|
+
|
|
1453
|
+
<
|
|
1454
|
+
ColNameUT extends keyof ResolveTableType<TRecord>,
|
|
1455
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1456
|
+
UnwrapArrayMember<TResult>,
|
|
1457
|
+
ResolveTableType<TRecord>,
|
|
1458
|
+
ColNameUT & string
|
|
1459
|
+
>[]
|
|
1460
|
+
>(
|
|
1461
|
+
columnNames: readonly ColNameUT[]
|
|
1462
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1463
|
+
|
|
1464
|
+
// For non-inferrable column selection, we will allow consumer to
|
|
1465
|
+
// specify result type and if not widen the result to entire record type with any omissions permitted
|
|
1466
|
+
<
|
|
1467
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1468
|
+
UnwrapArrayMember<TResult>,
|
|
1469
|
+
SafePartial<TRecord>,
|
|
1470
|
+
keyof TRecord & string
|
|
1471
|
+
>[]
|
|
1472
|
+
>(
|
|
1473
|
+
...columnNames: readonly ColumnDescriptor<TRecord, TResult>[]
|
|
1474
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1475
|
+
|
|
1476
|
+
<
|
|
1477
|
+
TResult2 = DeferredKeySelection.Augment<
|
|
1478
|
+
UnwrapArrayMember<TResult>,
|
|
1479
|
+
SafePartial<TRecord>,
|
|
1480
|
+
keyof TRecord & string
|
|
1481
|
+
>[]
|
|
1482
|
+
>(
|
|
1483
|
+
columnNames: readonly ColumnDescriptor<TRecord, TResult>[]
|
|
1484
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
type RawBinding = Value | QueryBuilder;
|
|
1488
|
+
|
|
1489
|
+
interface RawQueryBuilder<TRecord = any, TResult = unknown[]> {
|
|
1490
|
+
<TResult2 = TResult>(
|
|
1491
|
+
sql: string,
|
|
1492
|
+
bindings?: readonly RawBinding[] | ValueDict | RawBinding
|
|
1493
|
+
): QueryBuilder<TRecord, TResult2>;
|
|
1494
|
+
<TResult2 = TResult>(raw: Raw<TResult2>): QueryBuilder<
|
|
1495
|
+
TRecord,
|
|
1496
|
+
TResult2
|
|
1497
|
+
>;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
// Raw
|
|
1501
|
+
|
|
1502
|
+
interface Raw<TResult = any>
|
|
1503
|
+
extends events.EventEmitter,
|
|
1504
|
+
ChainableInterface<ResolveResult<TResult>> {
|
|
1505
|
+
timeout(ms: number, options?: {cancel?: boolean}): Raw<TResult>;
|
|
1506
|
+
wrap<TResult2 = TResult>(before: string, after: string): Raw<TResult>;
|
|
1507
|
+
toSQL(): Sql;
|
|
1508
|
+
queryContext(context: any): Raw<TResult>;
|
|
1509
|
+
queryContext(): any;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
interface RawBuilder<TRecord extends {} = any, TResult = any> {
|
|
1513
|
+
<TResult2 = TResult>(value: Value): Raw<TResult2>;
|
|
1514
|
+
<TResult2 = TResult>(sql: string, ...bindings: readonly RawBinding[]): Raw<TResult2>;
|
|
1515
|
+
<TResult2 = TResult>(sql: string, bindings: readonly RawBinding[] | ValueDict): Raw<TResult2>;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
const RefMemberTag: unique symbol;
|
|
1519
|
+
|
|
1520
|
+
interface Ref<TSrc extends string, TMapping extends {}> extends Raw<string> {
|
|
1521
|
+
// TypeScript can behave weirdly if type parameters are not
|
|
1522
|
+
// actually used in the members of type.
|
|
1523
|
+
//
|
|
1524
|
+
// See: https://github.com/knex/knex/issues/3932
|
|
1525
|
+
//
|
|
1526
|
+
// We simply need to propagate the type context so that we can extract
|
|
1527
|
+
// them later, but we just add a "phantom" property so that typescript
|
|
1528
|
+
// doesn't think that these parameters are unused
|
|
1529
|
+
//
|
|
1530
|
+
// Because unique symbol is used here, there is no way to actually
|
|
1531
|
+
// access this at runtime
|
|
1532
|
+
[RefMemberTag]: {
|
|
1533
|
+
src: TSrc,
|
|
1534
|
+
mapping: TMapping
|
|
1535
|
+
};
|
|
1536
|
+
withSchema(schema: string): this;
|
|
1537
|
+
as<TAlias extends string>(alias: TAlias): Ref<TSrc, {[K in TAlias]: TSrc}>;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
interface RefBuilder {
|
|
1541
|
+
<TSrc extends string>(src: TSrc): Ref<TSrc, {[K in TSrc]: TSrc}>;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
interface BatchInsertBuilder<TRecord extends {} = any, TResult = number[]> extends Promise<ResolveResult<TResult>> {
|
|
1545
|
+
transacting(trx: Transaction): this;
|
|
1546
|
+
// see returning methods from QueryInterface
|
|
1547
|
+
returning(column: '*'): BatchInsertBuilder<TRecord, DeferredKeySelection<TRecord, never>[]>;
|
|
1548
|
+
returning<
|
|
1549
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1550
|
+
TResult2 = DeferredIndex.Augment<
|
|
1551
|
+
UnwrapArrayMember<TResult>,
|
|
1552
|
+
ResolveTableType<TRecord>,
|
|
1553
|
+
TKey
|
|
1554
|
+
>[]
|
|
1555
|
+
>(
|
|
1556
|
+
column: TKey
|
|
1557
|
+
): BatchInsertBuilder<TRecord, TResult2>;
|
|
1558
|
+
returning<
|
|
1559
|
+
TKey extends StrKey<ResolveTableType<TRecord>>,
|
|
1560
|
+
TResult2 = DeferredKeySelection.SetSingle<
|
|
1561
|
+
DeferredKeySelection.Augment<UnwrapArrayMember<TResult>, ResolveTableType<TRecord>, TKey>,
|
|
1562
|
+
false
|
|
1563
|
+
>[]
|
|
1564
|
+
>(
|
|
1565
|
+
columns: readonly TKey[]
|
|
1566
|
+
): BatchInsertBuilder<TRecord, TResult2>;
|
|
1567
|
+
// if data with specific type passed, exclude this method
|
|
1568
|
+
returning<TResult2 = SafePartial<TRecord>[]>(
|
|
1569
|
+
column: unknown extends TRecord ? string | readonly string[] : never
|
|
1570
|
+
): BatchInsertBuilder<TRecord, TResult2>;
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
//
|
|
1574
|
+
// QueryBuilder
|
|
1575
|
+
//
|
|
1576
|
+
|
|
1577
|
+
type QueryCallback<TRecord = any, TResult = unknown[]> = (
|
|
1578
|
+
this: QueryBuilder<TRecord, TResult>,
|
|
1579
|
+
builder: QueryBuilder<TRecord, TResult>
|
|
1580
|
+
) => void;
|
|
1581
|
+
|
|
1582
|
+
type QueryCallbackWithArgs<TRecord = any, TResult = unknown[]> = (
|
|
1583
|
+
this: QueryBuilder<TRecord, TResult>,
|
|
1584
|
+
builder: QueryBuilder<TRecord, TResult>,
|
|
1585
|
+
...args: any[]
|
|
1586
|
+
) => void;
|
|
1587
|
+
|
|
1588
|
+
interface QueryBuilder<
|
|
1589
|
+
TRecord extends {} = any,
|
|
1590
|
+
TResult = any
|
|
1591
|
+
>
|
|
1592
|
+
extends QueryInterface<TRecord, TResult>,
|
|
1593
|
+
ChainableInterface<ResolveResult<TResult>> {
|
|
1594
|
+
client: Client;
|
|
1595
|
+
or: QueryBuilder<TRecord, TResult>;
|
|
1596
|
+
not: QueryBuilder<TRecord, TResult>;
|
|
1597
|
+
and: QueryBuilder<TRecord, TResult>;
|
|
1598
|
+
|
|
1599
|
+
// TODO: Promise?
|
|
1600
|
+
columnInfo(column?: keyof TRecord): Promise<ColumnInfo>;
|
|
1601
|
+
|
|
1602
|
+
forUpdate(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
1603
|
+
forUpdate(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1604
|
+
|
|
1605
|
+
forShare(...tableNames: string[]): QueryBuilder<TRecord, TResult>;
|
|
1606
|
+
forShare(tableNames: readonly string[]): QueryBuilder<TRecord, TResult>;
|
|
1607
|
+
|
|
1608
|
+
skipLocked(): QueryBuilder<TRecord, TResult>;
|
|
1609
|
+
noWait(): QueryBuilder<TRecord, TResult>;
|
|
1610
|
+
|
|
1611
|
+
toSQL(): Sql;
|
|
1612
|
+
|
|
1613
|
+
on(event: string, callback: Function): QueryBuilder<TRecord, TResult>;
|
|
1614
|
+
|
|
1615
|
+
queryContext(context: any): QueryBuilder<TRecord, TResult>;
|
|
1616
|
+
queryContext(): any;
|
|
1617
|
+
|
|
1618
|
+
clone(): QueryBuilder<TRecord, TResult>;
|
|
1619
|
+
timeout(ms: number, options?: {cancel?: boolean}): QueryBuilder<TRecord, TResult>;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
interface Sql {
|
|
1623
|
+
method: string;
|
|
1624
|
+
options: any;
|
|
1625
|
+
bindings: readonly Value[];
|
|
1626
|
+
sql: string;
|
|
1627
|
+
toNative(): SqlNative;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
interface SqlNative {
|
|
1631
|
+
bindings: readonly Value[];
|
|
1632
|
+
sql: string;
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
//
|
|
1636
|
+
// Chainable interface
|
|
1637
|
+
//
|
|
1638
|
+
|
|
1639
|
+
type ExposedPromiseKeys =
|
|
1640
|
+
| "then"
|
|
1641
|
+
| "catch"
|
|
1642
|
+
| "finally";
|
|
1643
|
+
|
|
1644
|
+
interface StringTagSupport {
|
|
1645
|
+
readonly [Symbol.toStringTag]: string;
|
|
1646
|
+
}
|
|
1647
|
+
interface ChainableInterface<T = any> extends Pick<Promise<T>, keyof Promise<T> & ExposedPromiseKeys>, StringTagSupport {
|
|
1648
|
+
toQuery(): string;
|
|
1649
|
+
options(options: Readonly<{ [key: string]: any }>): this;
|
|
1650
|
+
connection(connection: any): this;
|
|
1651
|
+
debug(enabled: boolean): this;
|
|
1652
|
+
transacting(trx: Transaction): this;
|
|
1653
|
+
stream(handler: (readable: stream.PassThrough) => any): Promise<any>;
|
|
1654
|
+
stream(
|
|
1655
|
+
options: Readonly<{ [key: string]: any }>,
|
|
1656
|
+
handler: (readable: stream.PassThrough) => any
|
|
1657
|
+
): Promise<any>;
|
|
1658
|
+
stream(options?: Readonly<{ [key: string]: any }>): stream.PassThrough;
|
|
1659
|
+
pipe<T extends NodeJS.WritableStream>(
|
|
1660
|
+
writable: T,
|
|
1661
|
+
options?: Readonly<{ [key: string]: any }>
|
|
1662
|
+
): stream.PassThrough;
|
|
1663
|
+
asCallback(callback: Function): Promise<T>;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
interface Transaction<TRecord extends {} = any, TResult = any>
|
|
1667
|
+
extends Knex<TRecord, TResult> {
|
|
1668
|
+
executionPromise: Promise<TResult>;
|
|
1669
|
+
isCompleted: () => boolean;
|
|
1670
|
+
|
|
1671
|
+
query<TRecord extends {} = any, TResult = void>(
|
|
1672
|
+
conn: any,
|
|
1673
|
+
sql: any,
|
|
1674
|
+
status: any,
|
|
1675
|
+
value: any
|
|
1676
|
+
): QueryBuilder<TRecord, TResult>;
|
|
1677
|
+
savepoint<T = any>(
|
|
1678
|
+
transactionScope: (trx: Transaction) => any
|
|
1679
|
+
): Promise<T>;
|
|
1680
|
+
commit(value?: any): QueryBuilder<TRecord, TResult>;
|
|
1681
|
+
rollback(error?: any): QueryBuilder<TRecord, TResult>;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
//
|
|
1685
|
+
// Schema builder
|
|
1686
|
+
//
|
|
1687
|
+
|
|
1688
|
+
interface SchemaBuilder extends ChainableInterface<void> {
|
|
1689
|
+
createTable(
|
|
1690
|
+
tableName: string,
|
|
1691
|
+
callback: (tableBuilder: CreateTableBuilder) => any
|
|
1692
|
+
): SchemaBuilder;
|
|
1693
|
+
createTableIfNotExists(
|
|
1694
|
+
tableName: string,
|
|
1695
|
+
callback: (tableBuilder: CreateTableBuilder) => any
|
|
1696
|
+
): SchemaBuilder;
|
|
1697
|
+
createSchema(schemaName: string): SchemaBuilder;
|
|
1698
|
+
createSchemaIfNotExists(schemaName: string): SchemaBuilder;
|
|
1699
|
+
alterTable(
|
|
1700
|
+
tableName: string,
|
|
1701
|
+
callback: (tableBuilder: CreateTableBuilder) => any
|
|
1702
|
+
): SchemaBuilder;
|
|
1703
|
+
renameTable(oldTableName: string, newTableName: string): Promise<void>;
|
|
1704
|
+
dropTable(tableName: string): SchemaBuilder;
|
|
1705
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
1706
|
+
hasColumn(tableName: string, columnName: string): Promise<boolean>;
|
|
1707
|
+
table(
|
|
1708
|
+
tableName: string,
|
|
1709
|
+
callback: (tableBuilder: AlterTableBuilder) => any
|
|
1710
|
+
): Promise<void>;
|
|
1711
|
+
dropTableIfExists(tableName: string): SchemaBuilder;
|
|
1712
|
+
dropSchema(schemaName: string): SchemaBuilder;
|
|
1713
|
+
dropSchemaIfExists(schemaName: string): SchemaBuilder;
|
|
1714
|
+
raw(statement: string): SchemaBuilder;
|
|
1715
|
+
withSchema(schemaName: string): SchemaBuilder;
|
|
1716
|
+
queryContext(context: any): SchemaBuilder;
|
|
1717
|
+
toString(): string;
|
|
1718
|
+
toSQL(): Sql;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
interface TableBuilder {
|
|
1722
|
+
increments(columnName?: string): ColumnBuilder;
|
|
1723
|
+
bigIncrements(columnName?: string): ColumnBuilder;
|
|
1724
|
+
dropColumn(columnName: string): TableBuilder;
|
|
1725
|
+
dropColumns(...columnNames: string[]): TableBuilder;
|
|
1726
|
+
renameColumn(from: string, to: string): ColumnBuilder;
|
|
1727
|
+
integer(columnName: string, length?: number): ColumnBuilder;
|
|
1728
|
+
bigInteger(columnName: string): ColumnBuilder;
|
|
1729
|
+
text(columnName: string, textType?: string): ColumnBuilder;
|
|
1730
|
+
string(columnName: string, length?: number): ColumnBuilder;
|
|
1731
|
+
float(
|
|
1732
|
+
columnName: string,
|
|
1733
|
+
precision?: number,
|
|
1734
|
+
scale?: number
|
|
1735
|
+
): ColumnBuilder;
|
|
1736
|
+
double(
|
|
1737
|
+
columnName: string,
|
|
1738
|
+
precision?: number,
|
|
1739
|
+
scale?: number
|
|
1740
|
+
): ColumnBuilder;
|
|
1741
|
+
decimal(
|
|
1742
|
+
columnName: string,
|
|
1743
|
+
precision?: number | null,
|
|
1744
|
+
scale?: number
|
|
1745
|
+
): ColumnBuilder;
|
|
1746
|
+
boolean(columnName: string): ColumnBuilder;
|
|
1747
|
+
date(columnName: string): ColumnBuilder;
|
|
1748
|
+
dateTime(columnName: string, options?: Readonly<{useTz?: boolean, precision?: number}>): ColumnBuilder;
|
|
1749
|
+
time(columnName: string): ColumnBuilder;
|
|
1750
|
+
timestamp(columnName: string, options?: Readonly<{useTz?: boolean, precision?: number}>): ColumnBuilder;
|
|
1751
|
+
/** @deprecated */
|
|
1752
|
+
timestamp(columnName: string, withoutTz?: boolean, precision?: number): ColumnBuilder;
|
|
1753
|
+
timestamps(
|
|
1754
|
+
useTimestampType?: boolean,
|
|
1755
|
+
makeDefaultNow?: boolean
|
|
1756
|
+
): ColumnBuilder;
|
|
1757
|
+
binary(columnName: string, length?: number): ColumnBuilder;
|
|
1758
|
+
enum(
|
|
1759
|
+
columnName: string,
|
|
1760
|
+
values: readonly Value[],
|
|
1761
|
+
options?: EnumOptions
|
|
1762
|
+
): ColumnBuilder;
|
|
1763
|
+
enu(
|
|
1764
|
+
columnName: string,
|
|
1765
|
+
values: readonly Value[],
|
|
1766
|
+
options?: EnumOptions
|
|
1767
|
+
): ColumnBuilder;
|
|
1768
|
+
json(columnName: string): ColumnBuilder;
|
|
1769
|
+
jsonb(columnName: string): ColumnBuilder;
|
|
1770
|
+
uuid(columnName: string): ColumnBuilder;
|
|
1771
|
+
comment(val: string): TableBuilder;
|
|
1772
|
+
specificType(columnName: string, type: string): ColumnBuilder;
|
|
1773
|
+
primary(columnNames: readonly string[], constraintName?: string): TableBuilder;
|
|
1774
|
+
index(
|
|
1775
|
+
columnNames: string | readonly (string | Raw)[],
|
|
1776
|
+
indexName?: string,
|
|
1777
|
+
indexType?: string
|
|
1778
|
+
): TableBuilder;
|
|
1779
|
+
unique(columnNames: readonly (string | Raw)[], indexName?: string): TableBuilder;
|
|
1780
|
+
foreign(column: string, foreignKeyName?: string): ForeignConstraintBuilder;
|
|
1781
|
+
foreign(
|
|
1782
|
+
columns: readonly string[],
|
|
1783
|
+
foreignKeyName?: string
|
|
1784
|
+
): MultikeyForeignConstraintBuilder;
|
|
1785
|
+
dropForeign(columnNames: readonly string[], foreignKeyName?: string): TableBuilder;
|
|
1786
|
+
dropUnique(columnNames: readonly (string | Raw)[], indexName?: string): TableBuilder;
|
|
1787
|
+
dropPrimary(constraintName?: string): TableBuilder;
|
|
1788
|
+
dropIndex(columnNames: string | readonly (string | Raw)[], indexName?: string): TableBuilder;
|
|
1789
|
+
dropTimestamps(): ColumnBuilder;
|
|
1790
|
+
queryContext(context: any): TableBuilder;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
interface CreateTableBuilder extends TableBuilder {
|
|
1794
|
+
engine(val: string): CreateTableBuilder;
|
|
1795
|
+
charset(val: string): CreateTableBuilder;
|
|
1796
|
+
collate(val: string): CreateTableBuilder;
|
|
1797
|
+
inherits(val: string): CreateTableBuilder;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
interface AlterTableBuilder extends TableBuilder {}
|
|
1801
|
+
|
|
1802
|
+
interface ColumnBuilder {
|
|
1803
|
+
index(indexName?: string): ColumnBuilder;
|
|
1804
|
+
primary(constraintName?: string): ColumnBuilder;
|
|
1805
|
+
unique(indexName?: string): ColumnBuilder;
|
|
1806
|
+
references(columnName: string): ReferencingColumnBuilder;
|
|
1807
|
+
onDelete(command: string): ColumnBuilder;
|
|
1808
|
+
onUpdate(command: string): ColumnBuilder;
|
|
1809
|
+
defaultTo(value: Value | null): ColumnBuilder;
|
|
1810
|
+
unsigned(): ColumnBuilder;
|
|
1811
|
+
notNullable(): ColumnBuilder;
|
|
1812
|
+
nullable(): ColumnBuilder;
|
|
1813
|
+
comment(value: string): ColumnBuilder;
|
|
1814
|
+
alter(): ColumnBuilder;
|
|
1815
|
+
queryContext(context: any): ColumnBuilder;
|
|
1816
|
+
withKeyName(keyName: string): ColumnBuilder;
|
|
1817
|
+
after(columnName: string): ColumnBuilder;
|
|
1818
|
+
first(): ColumnBuilder;
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
interface ForeignConstraintBuilder {
|
|
1822
|
+
references(columnName: string): ReferencingColumnBuilder;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
interface MultikeyForeignConstraintBuilder {
|
|
1826
|
+
references(columnNames: readonly string[]): ReferencingColumnBuilder;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
interface PostgreSqlColumnBuilder extends ColumnBuilder {
|
|
1830
|
+
index(indexName?: string, indexType?: string): ColumnBuilder;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
interface ReferencingColumnBuilder extends ColumnBuilder {
|
|
1834
|
+
inTable(tableName: string): ColumnBuilder;
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
interface AlterColumnBuilder extends ColumnBuilder {}
|
|
1838
|
+
|
|
1839
|
+
interface MySqlAlterColumnBuilder extends AlterColumnBuilder {
|
|
1840
|
+
first(): AlterColumnBuilder;
|
|
1841
|
+
after(columnName: string): AlterColumnBuilder;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
//
|
|
1845
|
+
// Configurations
|
|
1846
|
+
//
|
|
1847
|
+
|
|
1848
|
+
interface ColumnInfo {
|
|
1849
|
+
defaultValue: Value;
|
|
1850
|
+
type: string;
|
|
1851
|
+
maxLength: number;
|
|
1852
|
+
nullable: boolean;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
interface Config<SV extends {} = any> {
|
|
1856
|
+
debug?: boolean;
|
|
1857
|
+
client?: string | typeof Client;
|
|
1858
|
+
dialect?: string;
|
|
1859
|
+
version?: string;
|
|
1860
|
+
connection?: string | StaticConnectionConfig | ConnectionConfigProvider;
|
|
1861
|
+
pool?: PoolConfig;
|
|
1862
|
+
migrations?: MigratorConfig;
|
|
1863
|
+
postProcessResponse?: (result: any, queryContext: any) => any;
|
|
1864
|
+
wrapIdentifier?: (
|
|
1865
|
+
value: string,
|
|
1866
|
+
origImpl: (value: string) => string,
|
|
1867
|
+
queryContext: any
|
|
1868
|
+
) => string;
|
|
1869
|
+
seeds?: SeederConfig<SV>;
|
|
1870
|
+
acquireConnectionTimeout?: number;
|
|
1871
|
+
useNullAsDefault?: boolean;
|
|
1872
|
+
searchPath?: string | readonly string[];
|
|
1873
|
+
asyncStackTraces?: boolean;
|
|
1874
|
+
log?: Logger;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
type StaticConnectionConfig =
|
|
1878
|
+
| ConnectionConfig
|
|
1879
|
+
| MariaSqlConnectionConfig
|
|
1880
|
+
| MySqlConnectionConfig
|
|
1881
|
+
| MySql2ConnectionConfig
|
|
1882
|
+
| MsSqlConnectionConfig
|
|
1883
|
+
| OracleDbConnectionConfig
|
|
1884
|
+
| PgConnectionConfig
|
|
1885
|
+
| RedshiftConnectionConfig
|
|
1886
|
+
| Sqlite3ConnectionConfig
|
|
1887
|
+
| SocketConnectionConfig;
|
|
1888
|
+
|
|
1889
|
+
type ConnectionConfigProvider = SyncConnectionConfigProvider | AsyncConnectionConfigProvider;
|
|
1890
|
+
type SyncConnectionConfigProvider = () => StaticConnectionConfig;
|
|
1891
|
+
type AsyncConnectionConfigProvider = () => Promise<StaticConnectionConfig>;
|
|
1892
|
+
|
|
1893
|
+
interface ConnectionConfig {
|
|
1894
|
+
host: string;
|
|
1895
|
+
user: string;
|
|
1896
|
+
password: string;
|
|
1897
|
+
database: string;
|
|
1898
|
+
domain?: string;
|
|
1899
|
+
instanceName?: string;
|
|
1900
|
+
debug?: boolean;
|
|
1901
|
+
requestTimeout?: number;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
// Config object for mssql: see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mssql/index.d.ts
|
|
1905
|
+
interface MsSqlConnectionConfig {
|
|
1906
|
+
driver?: string;
|
|
1907
|
+
user?: string;
|
|
1908
|
+
password?: string;
|
|
1909
|
+
server: string;
|
|
1910
|
+
port?: number;
|
|
1911
|
+
domain?: string;
|
|
1912
|
+
database: string;
|
|
1913
|
+
connectionTimeout?: number;
|
|
1914
|
+
requestTimeout?: number;
|
|
1915
|
+
stream?: boolean;
|
|
1916
|
+
parseJSON?: boolean;
|
|
1917
|
+
expirationChecker?(): boolean;
|
|
1918
|
+
options?: Readonly<{
|
|
1919
|
+
encrypt?: boolean;
|
|
1920
|
+
instanceName?: string;
|
|
1921
|
+
useUTC?: boolean;
|
|
1922
|
+
tdsVersion?: string;
|
|
1923
|
+
appName?: string;
|
|
1924
|
+
abortTransactionOnError?: boolean;
|
|
1925
|
+
trustedConnection?: boolean;
|
|
1926
|
+
enableArithAbort?: boolean;
|
|
1927
|
+
isolationLevel?: 'READ_UNCOMMITTED' | 'READ_COMMITTED' | 'REPEATABLE_READ' | 'SERIALIZABLE' | 'SNAPSHOT';
|
|
1928
|
+
maxRetriesOnTransientErrors?: number;
|
|
1929
|
+
multiSubnetFailover?: boolean;
|
|
1930
|
+
packetSize?: number;
|
|
1931
|
+
trustServerCertificate?: boolean;
|
|
1932
|
+
}>;
|
|
1933
|
+
pool?: Readonly<{
|
|
1934
|
+
min?: number;
|
|
1935
|
+
max?: number;
|
|
1936
|
+
idleTimeoutMillis?: number;
|
|
1937
|
+
maxWaitingClients?: number;
|
|
1938
|
+
testOnBorrow?: boolean;
|
|
1939
|
+
acquireTimeoutMillis?: number;
|
|
1940
|
+
fifo?: boolean;
|
|
1941
|
+
priorityRange?: number;
|
|
1942
|
+
autostart?: boolean;
|
|
1943
|
+
evictionRunIntervalMillis?: number;
|
|
1944
|
+
numTestsPerRun?: number;
|
|
1945
|
+
softIdleTimeoutMillis?: number;
|
|
1946
|
+
Promise?: any;
|
|
1947
|
+
}>;
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// Config object for mariasql: https://github.com/mscdex/node-mariasql#client-methods
|
|
1951
|
+
interface MariaSqlConnectionConfig {
|
|
1952
|
+
user?: string;
|
|
1953
|
+
password?: string;
|
|
1954
|
+
host?: string;
|
|
1955
|
+
port?: number;
|
|
1956
|
+
unixSocket?: string;
|
|
1957
|
+
protocol?: string;
|
|
1958
|
+
db?: string;
|
|
1959
|
+
keepQueries?: boolean;
|
|
1960
|
+
multiStatements?: boolean;
|
|
1961
|
+
connTimeout?: number;
|
|
1962
|
+
pingInterval?: number;
|
|
1963
|
+
secureAuth?: boolean;
|
|
1964
|
+
compress?: boolean;
|
|
1965
|
+
ssl?: boolean | MariaSslConfiguration;
|
|
1966
|
+
local_infile?: boolean;
|
|
1967
|
+
read_default_file?: string;
|
|
1968
|
+
read_default_group?: string;
|
|
1969
|
+
charset?: string;
|
|
1970
|
+
streamHWM?: number;
|
|
1971
|
+
expirationChecker?(): boolean;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
interface MariaSslConfiguration {
|
|
1975
|
+
key?: string;
|
|
1976
|
+
cert?: string;
|
|
1977
|
+
ca?: string;
|
|
1978
|
+
capath?: string;
|
|
1979
|
+
cipher?: string;
|
|
1980
|
+
rejectUnauthorized?: boolean;
|
|
1981
|
+
expirationChecker?(): boolean;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
// Config object for mysql: https://github.com/mysqljs/mysql#connection-options
|
|
1985
|
+
interface MySqlConnectionConfig {
|
|
1986
|
+
host?: string;
|
|
1987
|
+
port?: number;
|
|
1988
|
+
localAddress?: string;
|
|
1989
|
+
socketPath?: string;
|
|
1990
|
+
user?: string;
|
|
1991
|
+
password?: string;
|
|
1992
|
+
database?: string;
|
|
1993
|
+
charset?: string;
|
|
1994
|
+
timezone?: string;
|
|
1995
|
+
connectTimeout?: number;
|
|
1996
|
+
stringifyObjects?: boolean;
|
|
1997
|
+
insecureAuth?: boolean;
|
|
1998
|
+
typeCast?: any;
|
|
1999
|
+
queryFormat?: (query: string, values: any) => string;
|
|
2000
|
+
supportBigNumbers?: boolean;
|
|
2001
|
+
bigNumberStrings?: boolean;
|
|
2002
|
+
dateStrings?: boolean;
|
|
2003
|
+
debug?: boolean;
|
|
2004
|
+
trace?: boolean;
|
|
2005
|
+
multipleStatements?: boolean;
|
|
2006
|
+
flags?: string;
|
|
2007
|
+
ssl?: string | MariaSslConfiguration;
|
|
2008
|
+
decimalNumbers?: boolean;
|
|
2009
|
+
expirationChecker?(): boolean;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// Config object for mysql2: https://github.com/sidorares/node-mysql2/blob/master/lib/connection_config.js
|
|
2013
|
+
// Some options for connection pooling and MySQL server API are excluded.
|
|
2014
|
+
interface MySql2ConnectionConfig extends MySqlConnectionConfig {
|
|
2015
|
+
authPlugins?: {[pluginName: string]: (pluginMetadata: any) => ((pluginData: any) => any)};
|
|
2016
|
+
authSwitchHandler?: (data: any, callback: () => void) => any;
|
|
2017
|
+
charsetNumber?: number;
|
|
2018
|
+
compress?: boolean;
|
|
2019
|
+
connectAttributes?: {[attrNames: string]: any};
|
|
2020
|
+
enableKeepAlive?: boolean;
|
|
2021
|
+
keepAliveInitialDelay?: number;
|
|
2022
|
+
maxPreparedStatements?: number;
|
|
2023
|
+
namedPlaceholders?: boolean;
|
|
2024
|
+
nestTables?: boolean | string;
|
|
2025
|
+
passwordSha1?: string;
|
|
2026
|
+
rowsAsArray?: boolean;
|
|
2027
|
+
stream?: boolean | ((opts: any) => Stream) | Stream;
|
|
2028
|
+
uri?: string;
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
interface OracleDbConnectionConfig {
|
|
2032
|
+
host: string;
|
|
2033
|
+
user: string;
|
|
2034
|
+
password?: string;
|
|
2035
|
+
database?: string;
|
|
2036
|
+
domain?: string;
|
|
2037
|
+
instanceName?: string;
|
|
2038
|
+
debug?: boolean;
|
|
2039
|
+
requestTimeout?: number;
|
|
2040
|
+
connectString?: string;
|
|
2041
|
+
expirationChecker?(): boolean;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
// Config object for pg: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/pg/index.d.ts
|
|
2045
|
+
interface PgConnectionConfig {
|
|
2046
|
+
user?: string;
|
|
2047
|
+
database?: string;
|
|
2048
|
+
password?: string;
|
|
2049
|
+
port?: number;
|
|
2050
|
+
host?: string;
|
|
2051
|
+
connectionString?: string;
|
|
2052
|
+
keepAlive?: boolean;
|
|
2053
|
+
stream?: stream.Duplex;
|
|
2054
|
+
statement_timeout?: false | number;
|
|
2055
|
+
connectionTimeoutMillis?: number;
|
|
2056
|
+
keepAliveInitialDelayMillis?: number;
|
|
2057
|
+
ssl?: boolean | ConnectionOptions;
|
|
2058
|
+
application_name?: string;
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
type RedshiftConnectionConfig = PgConnectionConfig;
|
|
2062
|
+
|
|
2063
|
+
/** Used with SQLite3 adapter */
|
|
2064
|
+
interface Sqlite3ConnectionConfig {
|
|
2065
|
+
filename: string;
|
|
2066
|
+
debug?: boolean;
|
|
2067
|
+
expirationChecker?(): boolean;
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
interface SocketConnectionConfig {
|
|
2071
|
+
socketPath: string;
|
|
2072
|
+
user: string;
|
|
2073
|
+
password: string;
|
|
2074
|
+
database: string;
|
|
2075
|
+
debug?: boolean;
|
|
2076
|
+
expirationChecker?(): boolean;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
interface PoolConfig {
|
|
2080
|
+
name?: string;
|
|
2081
|
+
afterCreate?: Function;
|
|
2082
|
+
min?: number;
|
|
2083
|
+
max?: number;
|
|
2084
|
+
refreshIdle?: boolean;
|
|
2085
|
+
idleTimeoutMillis?: number;
|
|
2086
|
+
reapIntervalMillis?: number;
|
|
2087
|
+
returnToHead?: boolean;
|
|
2088
|
+
priorityRange?: number;
|
|
2089
|
+
log?: (message: string, logLevel: string) => void;
|
|
2090
|
+
|
|
2091
|
+
// tarn configs
|
|
2092
|
+
propagateCreateError?: boolean;
|
|
2093
|
+
createRetryIntervalMillis?: number;
|
|
2094
|
+
createTimeoutMillis?: number;
|
|
2095
|
+
destroyTimeoutMillis?: number;
|
|
2096
|
+
acquireTimeoutMillis?: number;
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
type LogFn = (message: any) => void;
|
|
2100
|
+
|
|
2101
|
+
interface Logger {
|
|
2102
|
+
warn?: LogFn;
|
|
2103
|
+
error?: LogFn;
|
|
2104
|
+
debug?: LogFn;
|
|
2105
|
+
inspectionDepth?: number;
|
|
2106
|
+
enableColors?: boolean;
|
|
2107
|
+
deprecate?: (method: string, alternative: string) => void;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
interface Migration {
|
|
2111
|
+
up: (knex: Knex) => PromiseLike<any>;
|
|
2112
|
+
down?: (kenx: Knex) => PromiseLike<any>;
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
interface MigrationSource<TMigrationSpec> {
|
|
2116
|
+
getMigrations(loadExtensions: readonly string[]): Promise<TMigrationSpec[]>;
|
|
2117
|
+
getMigrationName(migration: TMigrationSpec): string;
|
|
2118
|
+
getMigration(migration: TMigrationSpec): Migration;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
interface MigratorConfig {
|
|
2122
|
+
database?: string;
|
|
2123
|
+
directory?: string | readonly string[];
|
|
2124
|
+
extension?: string;
|
|
2125
|
+
stub?: string;
|
|
2126
|
+
tableName?: string;
|
|
2127
|
+
schemaName?: string;
|
|
2128
|
+
disableTransactions?: boolean;
|
|
2129
|
+
disableMigrationsListValidation?: boolean;
|
|
2130
|
+
sortDirsSeparately?: boolean;
|
|
2131
|
+
loadExtensions?: readonly string[];
|
|
2132
|
+
migrationSource?: MigrationSource<unknown>;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
interface Migrator {
|
|
2136
|
+
make(name: string, config?: MigratorConfig): Promise<string>;
|
|
2137
|
+
latest(config?: MigratorConfig): Promise<any>;
|
|
2138
|
+
rollback(config?: MigratorConfig, all?: boolean): Promise<any>;
|
|
2139
|
+
status(config?: MigratorConfig): Promise<number>;
|
|
2140
|
+
currentVersion(config?: MigratorConfig): Promise<string>;
|
|
2141
|
+
list(config?: MigratorConfig): Promise<any>;
|
|
2142
|
+
up(config?: MigratorConfig): Promise<any>;
|
|
2143
|
+
down(config?: MigratorConfig): Promise<any>;
|
|
2144
|
+
forceFreeMigrationsLock(config?: MigratorConfig): Promise<any>;
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
interface SeederConfig<V extends {} = any> {
|
|
2148
|
+
extension?: string;
|
|
2149
|
+
directory?: string | readonly string[];
|
|
2150
|
+
loadExtensions?: readonly string[];
|
|
2151
|
+
specific?: string;
|
|
2152
|
+
timestampFilenamePrefix?: boolean;
|
|
2153
|
+
recursive?: boolean;
|
|
2154
|
+
sortDirsSeparately?: boolean;
|
|
2155
|
+
stub?: string;
|
|
2156
|
+
variables?: V;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
class Seeder {
|
|
2160
|
+
constructor(knex: Knex);
|
|
2161
|
+
setConfig(config: SeederConfig): SeederConfig;
|
|
2162
|
+
run(config?: SeederConfig): Promise<[string[]]>;
|
|
2163
|
+
make(name: string, config?: SeederConfig): Promise<string>;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
interface FunctionHelper {
|
|
2167
|
+
now(precision?: number): Raw;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
interface EnumOptions {
|
|
2171
|
+
useNative: boolean;
|
|
2172
|
+
existingType?: boolean;
|
|
2173
|
+
schemaName?: string;
|
|
2174
|
+
enumName: string;
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
//
|
|
2178
|
+
// Clients
|
|
2179
|
+
//
|
|
2180
|
+
|
|
2181
|
+
class Client extends events.EventEmitter {
|
|
2182
|
+
constructor(config: Config);
|
|
2183
|
+
config: Config;
|
|
2184
|
+
dialect: string;
|
|
2185
|
+
driverName: string;
|
|
2186
|
+
connectionSettings: object;
|
|
2187
|
+
|
|
2188
|
+
acquireRawConnection(): Promise<any>;
|
|
2189
|
+
destroyRawConnection(connection: any): Promise<void>;
|
|
2190
|
+
validateConnection(connection: any): Promise<boolean>;
|
|
2191
|
+
logger: Logger;
|
|
2192
|
+
version?: string;
|
|
2193
|
+
connectionConfigProvider: any;
|
|
2194
|
+
connectionConfigExpirationChecker: null | (() => boolean);
|
|
2195
|
+
valueForUndefined: any;
|
|
2196
|
+
formatter(builder: any): any;
|
|
2197
|
+
queryBuilder(): QueryBuilder;
|
|
2198
|
+
queryCompiler(builder: any): any;
|
|
2199
|
+
schemaBuilder(): SchemaBuilder;
|
|
2200
|
+
schemaCompiler(builder: SchemaBuilder): any;
|
|
2201
|
+
tableBuilder(type: any, tableName: any, fn: any): TableBuilder;
|
|
2202
|
+
tableCompiler(tableBuilder: any): any;
|
|
2203
|
+
columnBuilder(tableBuilder: any, type: any, args: any): ColumnBuilder;
|
|
2204
|
+
columnCompiler(tableBuilder: any, columnBuilder: any): any;
|
|
2205
|
+
runner(builder: any): any;
|
|
2206
|
+
transaction(container: any, config: any, outerTx: any): Transaction;
|
|
2207
|
+
raw(...args: any[]): any;
|
|
2208
|
+
ref(...args: any[]): Ref<any, any>;
|
|
2209
|
+
query(connection: any, obj: any): any;
|
|
2210
|
+
stream(connection: any, obj: any, stream: any, options: any): any;
|
|
2211
|
+
prepBindings(bindings: any): any;
|
|
2212
|
+
positionBindings(sql: any): any;
|
|
2213
|
+
postProcessResponse(resp: any, queryContext: any): any;
|
|
2214
|
+
wrapIdentifier(value: any, queryContext: any): any;
|
|
2215
|
+
customWrapIdentifier(value: any, origImpl: any, queryContext: any): any;
|
|
2216
|
+
wrapIdentifierImpl(value: any): string;
|
|
2217
|
+
initializeDriver(): void;
|
|
2218
|
+
driver: any;
|
|
2219
|
+
poolDefaults(): {
|
|
2220
|
+
min: number;
|
|
2221
|
+
max: number;
|
|
2222
|
+
propagateCreateError: boolean;
|
|
2223
|
+
};
|
|
2224
|
+
getPoolSettings(poolConfig: any): any;
|
|
2225
|
+
initializePool(config?: {}): void;
|
|
2226
|
+
pool: tarn.Pool<any> | undefined;
|
|
2227
|
+
acquireConnection(): any;
|
|
2228
|
+
releaseConnection(connection: any): any;
|
|
2229
|
+
destroy(callback: any): any;
|
|
2230
|
+
database(): any;
|
|
2231
|
+
canCancelQuery: boolean;
|
|
2232
|
+
assertCanCancelQuery(): void;
|
|
2233
|
+
cancelQuery(): void;
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
class QueryBuilder {
|
|
2237
|
+
static extend(
|
|
2238
|
+
methodName: string,
|
|
2239
|
+
fn: <TRecord extends {} = any, TResult = unknown[]>(
|
|
2240
|
+
this: QueryBuilder<TRecord, TResult>,
|
|
2241
|
+
...args: any[]
|
|
2242
|
+
) => QueryBuilder<TRecord, TResult>
|
|
2243
|
+
): void;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
export class KnexTimeoutError extends Error {}
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
export = Knex;
|