/
query.d.ts
340 lines (297 loc) · 7.56 KB
/
query.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import { Connection } from './connection-manager';
import { QueryTypes } from '../../query-types';
import { Model, ModelStatic, IncludeOptions } from '../../model';
import { Sequelize } from '../../sequelize';
type BindOrReplacements = { [key: string]: unknown } | unknown[];
type FieldMap = { [key: string]: string };
export interface AbstractQueryGroupJoinDataOptions {
checkExisting: boolean;
}
export interface AbstractQueryOptions {
instance?: Model;
model?: ModelStatic<any>;
type?: QueryTypes;
fieldMap?: boolean;
plain: boolean;
raw: boolean;
nest: boolean;
hasJoin: boolean;
/**
* A function that gets executed while running the query to log the sql.
*/
logging?: boolean | ((sql: string, timing?: number) => void);
include: boolean;
includeNames: unknown[];
includeMap: any;
originalAttributes: unknown[];
attributes: unknown[];
}
export interface AbstractQueryFormatBindOptions {
/**
* skip unescaping $$
*/
skipUnescape: boolean;
/**
* do not replace (but do unescape $$)
*/
skipValueReplace: boolean;
}
type replacementFuncType = ((match: string, key: string, values: unknown[], timeZone?: string, dialect?: string, options?: AbstractQueryFormatBindOptions) => undefined | string);
/**
* An abstract class that Sequelize uses to add query support for a dialect.
*
* This interface is only exposed when running before/afterQuery lifecycle events.
*/
export class AbstractQuery {
/**
* Returns a unique identifier assigned to a query internally by Sequelize.
*/
public uuid: unknown;
/**
* A Sequelize connection instance.
*
* @type {Connection}
* @memberof AbstractQuery
*/
public connection: Connection;
/**
* If provided, returns the model instance.
*
* @type {Model}
* @memberof AbstractQuery
*/
public instance: Model;
/**
* Model type definition.
*
* @type {ModelStatic}
* @memberof AbstractQuery
*/
public model: ModelStatic<any>;
/**
* Returns the current sequelize instance.
*/
public sequelize: Sequelize;
/**
*
* @type {AbstractQueryOptions}
* @memberof AbstractQuery
*/
public options: AbstractQueryOptions;
constructor(connection: Connection, sequelize: Sequelize, options?: AbstractQueryOptions);
/**
* rewrite query with parameters
*
* Examples:
*
* query.formatBindParameters('select $1 as foo', ['fooval']);
*
* query.formatBindParameters('select $foo as foo', { foo: 'fooval' });
*
* Options
* skipUnescape: bool, skip unescaping $$
* skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available
*
* @param {string} sql
* @param {object|Array} values
* @param {string} dialect
* @param {Function} [replacementFunc]
* @param {object} [options]
* @private
*/
static formatBindParameters(sql: string, values: object | Array<object>, dialect: string, replacementFunc: replacementFuncType, options: AbstractQueryFormatBindOptions): undefined | [string, unknown[]];
/**
* Execute the passed sql query.
*
* Examples:
*
* query.run('SELECT 1')
*
* @private
*/
private run(): Error
/**
* Check the logging option of the instance and print deprecation warnings.
*
* @private
*/
private checkLoggingOption(): void;
/**
* Get the attributes of an insert query, which contains the just inserted id.
*
* @returns {string} The field name.
* @private
*/
private getInsertIdField(): string;
/**
* Returns the unique constraint error message for the associated field.
*
* @param field {string} the field name associated with the unique constraint.
*
* @returns {string} The unique constraint error message.
* @private
*/
private getUniqueConstraintErrorMessage(field: string): string;
/**
* Checks if the query type is RAW
*
* @returns {boolean}
*/
public isRawQuery(): boolean;
/**
* Checks if the query type is VERSION
*
* @returns {boolean}
*/
public isVersionQuery(): boolean;
/**
* Checks if the query type is UPSERT
*
* @returns {boolean}
*/
public isUpsertQuery(): boolean;
/**
* Checks if the query type is INSERT
*
* @returns {boolean}
*/
public isInsertQuery(results?: unknown[], metaData?: unknown): boolean;
/**
* Sets auto increment field values (if applicable).
*
* @param results {Array}
* @param metaData {object}
* @returns {boolean}
*/
public handleInsertQuery(results?: unknown[], metaData?: unknown): void;
/**
* Checks if the query type is SHOWTABLES
*
* @returns {boolean}
*/
public isShowTablesQuery(): boolean;
/**
* Flattens and plucks values from results.
*
* @params {Array}
* @returns {Array}
*/
public handleShowTablesQuery(results: unknown[]): unknown[];
/**
* Checks if the query type is SHOWINDEXES
*
* @returns {boolean}
*/
public isShowIndexesQuery(): boolean;
/**
* Checks if the query type is SHOWCONSTRAINTS
*
* @returns {boolean}
*/
public isShowConstraintsQuery(): boolean;
/**
* Checks if the query type is DESCRIBE
*
* @returns {boolean}
*/
public isDescribeQuery(): boolean;
/**
* Checks if the query type is SELECT
*
* @returns {boolean}
*/
public isSelectQuery(): boolean;
/**
* Checks if the query type is BULKUPDATE
*
* @returns {boolean}
*/
public isBulkUpdateQuery(): boolean;
/**
* Checks if the query type is BULKDELETE
*
* @returns {boolean}
*/
public isBulkDeleteQuery(): boolean;
/**
* Checks if the query type is FOREIGNKEYS
*
* @returns {boolean}
*/
public isForeignKeysQuery(): boolean;
/**
* Checks if the query type is UPDATE
*
* @returns {boolean}
*/
public isUpdateQuery(): boolean;
/**
* Maps raw fields to attribute names (if applicable).
*
* @params {Model[]} results from a select query.
* @returns {Model} the first model instance within the select.
*/
public handleSelectQuery(results: Model[]): Model;
/**
* Checks if the query starts with 'show' or 'describe'
*
* @returns {boolean}
*/
public isShowOrDescribeQuery(): boolean;
/**
* Checks if the query starts with 'call'
*
* @returns {boolean}
*/
public isCallQuery(): boolean;
/**
* @param {string} sql
* @param {Function} debugContext
* @param {Array|object} parameters
* @protected
* @returns {Function} A function to call after the query was completed.
*/
protected _logQuery(sql: string, debugContext: ((msg: string) => any), parameters: unknown[]): () => void;
/**
* The function takes the result of the query execution and groups
* the associated data by the callee.
*
* Example:
* groupJoinData([
* {
* some: 'data',
* id: 1,
* association: { foo: 'bar', id: 1 }
* }, {
* some: 'data',
* id: 1,
* association: { foo: 'bar', id: 2 }
* }, {
* some: 'data',
* id: 1,
* association: { foo: 'bar', id: 3 }
* }
* ])
*
* Result:
* Something like this:
*
* [
* {
* some: 'data',
* id: 1,
* association: [
* { foo: 'bar', id: 1 },
* { foo: 'bar', id: 2 },
* { foo: 'bar', id: 3 }
* ]
* }
* ]
*
* @param {Array} rows
* @param {object} includeOptions
* @param {object} options
* @private
*/
static _groupJoinData(rows: unknown[], includeOptions: IncludeOptions, options: AbstractQueryGroupJoinDataOptions): unknown[];
}