This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
/
squel.d.ts
1750 lines (1487 loc) · 52.4 KB
/
squel.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* tslint:disable:max-file-line-count */
declare namespace squel {
type Flavour = "mssql" | "mysql" | "postgres";
type ValueHandler<T> = (value: T, asParam: boolean) => string | ParamString;
interface BuilderConstructor<B> {
new(options?: QueryBuilderOptions): B;
}
/*
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
* Base classes
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
*/
interface ToParamOptions {
/**
* The index to start numbered parameter placeholders at. Default is `1`.
*/
numberedParametersStartAt: number;
}
/**
* Base class for cloneable builders
*/
interface Cloneable {
/**
* Clone this object instance.
*/
clone(): this;
}
interface CompleteQueryBuilderOptions {
/**
* If `true` then table names will be rendered inside quotes. The quote character used is configurable via the
* `nameQuoteCharacter` option. `Default: (false)`.
*/
autoQuoteTableNames: boolean;
/**
* If `true` then field names will be rendered inside quotes. The quote character used is configurable via the
* `nameQuoteCharacter` option. `Default: (false)`.
*/
autoQuoteFieldNames: boolean;
/**
* If `true` then alias names will be rendered inside quotes. The quote character used is configurable via the
* `tableAliasQuoteCharacter` and `fieldAliasQuoteCharacter` options. `Default: (false)`.
*/
autoQuoteAliasNames: boolean;
/**
* Use `AS` clause when outputting table aliases. `Default: (false)`.
*/
useAsForTableAliasNames: boolean;
/**
* The quote character used when quoting table and field names. <code>Default: (`)</code>.
*/
nameQuoteCharacter: string;
/**
* The quote character used when quoting table alias names. <code>Default: (`)</code>.
*/
tableAliasQuoteCharacter: string;
/**
* The quote character used when quoting field alias names. `Default: (")`.
*/
fieldAliasQuoteCharacter: string;
/**
* Custom value type handlers for this builder. These override the handlers set for the given value types via
* [[Cls.registerValueHandler]] `Default: ([])`.
*/
valueHandlers: ValueHandler<any>[];
/**
* String used to represent a parameter value. `Default: (?)`.
*/
parameterCharacter: string;
/**
* Whether to use numbered parameters placeholders when building parameterized query strings.
* `Default: (false, postgres: true)`.
*/
numberedParameters: boolean;
/**
* Numbered parameters prefix character(s). `Default: ($)`.
*/
numberedParametersPrefix: string;
/**
* The index to start numbered parameter placeholders at. `Default: (1)`.
*/
numberedParametersStartAt: number;
/**
* Whether to replace single quotes within strings. The replacement is specified in
* `singleQuoteReplacement`. `Default: (false)`.
*/
replaceSingleQuotes: boolean;
/**
* What to replace single quotes with if replaceSingleQuotes is enabled. `Default: ('')`.
*/
singleQuoteReplacement: string;
/**
* String used to join individual blocks in a query when it is stringified. `Default: ( )`.
*/
separator: string;
/**
* Function to process string values, prior to insertion into a query string. `Default: (null)`.
*/
stringFormatter: any | null;
/**
* Whether to prevent the addition of brackets () when nesting this query builder's output. `Default: (false)`.
*/
rawNesting: boolean;
}
type QueryBuilderOptions = Partial<CompleteQueryBuilderOptions>;
interface ParamString {
text: string;
values: any[];
}
export interface FormattingOptions {
// TODO
}
export interface BuildManyStringOptions {
/**
* Whether to build paramterized string. Default is false.
*/
buildParameterized?: boolean;
/**
* Whether this expression is nested within another.
*/
nested?: boolean;
}
export interface BuildStringOptions extends BuildManyStringOptions {
/**
* Formatting options for values in query string.
*/
formattingOptions?: FormattingOptions;
}
export interface FormatValueResult<T = any> {
formatted: boolean;
value: T;
rawNesting?: boolean;
}
/**
* Base class for all builders
*/
interface BaseBuilder extends Cloneable {
options: CompleteQueryBuilderOptions;
/**
* Register a custom value type handler. We may wish to use custom value types (e.g. `Date`) and have Squel
* automatically take care of formatting them when building the output query string.
*
* @param type The class object or `typeof` string representing the value type to handle
* @param handler The handler method to call when we wish to format this value for output in a query string
*/
registerValueHandler(type: {new(...args: any[]): any} | string, handler: ValueHandler<any>): this;
/**
* Build and return the final query string.
*/
toString(): string;
/**
* Build and return the final parameterized query string along with the list of formatted parameter values.
*
* @param options Additional options.
*/
toParam(options?: ToParamOptions): ParamString;
/**
* Sanitize given expression.
*
* Note: This ensures that the type is a string or BaseBuilder, else it throws an error
*/
_sanitizeExpression<T extends string | BaseBuilder>(expr: T): T;
/**
* Sanitize the given name.
*
* The 'type' parameter is used to construct a meaningful error message in case validation fails.
*/
_sanitizeName(value: string, type: string): string;
_sanitizeField<T extends string | BaseBuilder>(item: T): T;
_sanitizeBaseBuilder<T extends BaseBuilder>(item: T): T;
_sanitizeTable<T extends string | BaseBuilder>(item: T): T;
_sanitizeTableAlias(item: string): string;
_sanitizeFieldAlias(item: string): string;
/**
* Sanitize the given limit/offset value.
*/
_sanitizeLimitOffset(value: number): number;
/**
* Santize the given field value
*/
_sanitizeValue<T>(item: T): T;
/**
* Escape a string value, e.g. escape quotes and other characters within it.
*/
_escapeValue(value: string): string;
_formatTableName(item: string): string;
_formatFieldAlias(item: string): string;
_formatTableAlias(item: string): string;
_formatFieldName(item: string, formattingOptions?: {ignorePeriodsForFieldNameQuotes?: boolean}): string;
_formatCustomValue<T = any>(
value: T,
asParam: boolean,
formattingOptions?: FormattingOptions,
): FormatValueResult<T>;
// Note: this type definition does not handle multi-dimensional arrays
// TODO(demurgos): Handle multidimensional arrays
_formatValueForParamArray<T = any>(
value: T[],
formattingOptions?: FormattingOptions,
): FormatValueResult<T>[];
_formatValueForParamArray<T = any>(
value: T,
formattingOptions?: FormattingOptions,
): FormatValueResult<T>;
/**
* Format the given field value for inclusion into the query string
*/
_formatValueForQueryString(initialValue: any, formattingOptions?: FormattingOptions): string;
_applyNestingFormatting(str: string, nesting?: boolean): string;
/**
* Build given string and its corresponding parameter values into
* output.
*
* @param str
* @param values
* @param options Additional options.
*/
_buildString(str: string, values: any[], options?: BuildStringOptions): ParamString;
/**
* Build all given strings and their corresponding parameter values into
* output.
*
* @param strings
* @param strValues array of value arrays corresponding to each string.
* @param options Additional options.
*/
_buildManyStrings(strings: string[], strValues: any[][], options?: BuildManyStringOptions): ParamString;
_toParamString(options?: ToParamOptions): ParamString;
}
/*
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
* Expression
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
*/
export interface ExpressionNode {
type: "AND" | "OR";
expr: string | BaseBuilder;
para: any[];
}
/**
* An SQL expression builder.
*
* SQL expressions are used in WHERE and ON clauses to filter data by various criteria.
*
* Expressions can be nested. Nested expression contains can themselves
* contain nested expressions. When rendered a nested expression will be
* fully contained within brackets.
*
* All the build methods in this object return the object instance for chained method calling purposes.
*/
interface Expression extends BaseBuilder {
_nodes: ExpressionNode[];
/**
* Add to the current expression using `AND`.
*
* @param expr The expression to add
* @param params The expression parameters supplied as additional arguments Default is `[]`.
*/
and(expr: string | Expression, ...params: any[]): this;
/**
* Add to the current expression using `OR`.
*
* @param expr The expression to add
* @param params The expression parameters supplied as additional arguments Default is `[]`.
*/
or(expr: string | Expression, ...params: any[]): this;
}
/*
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
* Case
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
*/
export interface CaseItem {
expression: string;
values: any[];
result?: any;
}
/**
* An SQL CASE expression builder.
*
* SQL cases are used to select proper values based on specific criteria.
*/
interface Case extends BaseBuilder {
_cases: CaseItem[];
_elseValue: any | null;
/**
* A `WHEN` clause
*
* @param expression The expression for the current case.
* @param values Additional arguments for parameter substitution. See guide for examples. Default is `null`.
*/
when(expression: string, ...values: any[]): this;
/**
* A THEN clause
*
* @param result The result for the current case.
*/
then(result: any): this;
/**
* An `ELSE` clause
*
* @param elseValue The else value for the current case.
*/
else(elseValue: any): this;
}
/*
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
* Building blocks
* ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
*/
/**
* A building block represents a single build-step within a query building process.
*
* Query builders consist of one or more building blocks which get run in a particular order. Building blocks can
* optionally specify methods to expose through the query builder interface. They can access all the input data for
* the query builder and manipulate it as necessary, as well as append to the final query string output.
*
* If you wish to customize how queries get built or add proprietary query phrases and content then it is
* recommended that you do so using one or more custom building blocks.
*
* Original idea posted in https://github.com/hiddentao/export/issues/10#issuecomment-15016427
*/
interface Block extends BaseBuilder {
/**
* Get input methods to expose within the query builder.
*
* By default all methods except the following get returned:
* methods prefixed with _
* constructor and toString()
*
* @return Object key -> function pairs
*/
exposedMethods(): {[key: string]: (...args: any[]) => any};
}
/**
* A fixed string which always gets output
*/
interface StringBlock extends Block {
_str: string;
}
interface StringBlockConstructor {
new(options: QueryBuilderOptions | undefined, str: string): StringBlock;
}
/**
* A function string block
*/
interface FunctionBlock extends Block {
_strings: string[];
_values: any[];
/**
* Insert a function value, see [[FunctionBlock]].
*/
function(str: string, ...value: any[]): void;
}
interface FunctionMixin {
/**
* Insert a function value, see [[FunctionBlock]].
*/
function(str: string, ...value: any[]): this;
}
export interface Table {
table: string | BaseBuilder;
alias: string | null;
}
interface TableBlockOptions extends QueryBuilderOptions {
/**
* If true then only allow one table spec.
*/
singleTable?: boolean;
}
interface AbstractTableBlock extends Block {
options: CompleteQueryBuilderOptions & TableBlockOptions;
_tables: Table[];
/**
* Update given table.
*
* An alias may also be specified for the table.
*
* Concrete subclasses should provide a method which calls this
*/
_table(table: string | BaseBuilder, alias?: string): void;
/**
* get whether a table has been set
*/
_hasTable(): boolean;
}
interface TargetTableBlock extends AbstractTableBlock {
target(table: string): void;
}
interface TargetTableMixin {
/**
* The actual target table whose data is to be deleted. Used in conjunction with `from()`.
*
* @param table Name of table.
*/
target(table: string): this;
}
interface UpdateTableBlock extends AbstractTableBlock {
table(name: string, alias?: string): void;
}
interface UpdateTableMixin {
/**
* A table to update.
*
* @param name Name of table.
* @param alias An alias by which to refer to this table. Default is `null`.
*/
table(name: string, alias?: string): this;
}
interface FromTableBlock extends AbstractTableBlock {
from(name: string | BaseBuilder, alias?: string): void;
}
interface FromTableMixin {
/**
* A table to select data from.
*
* @param name Name of table or a builder.
* @param alias An alias by which to refer to this table. Default is null.
*/
from(name: string | BaseBuilder, alias?: string): this;
}
interface IntoTableBlock extends AbstractTableBlock {
into(name: string): void;
}
interface IntoTableMixin {
/**
* The table to insert into.
*
* @param name Name of table.
*/
into(name: string): this;
}
interface FieldOptions {
/**
* When `autoQuoteFieldNames` is turned on this flag instructs it to ignore the period (.) character within field
* names. Default is `false`.
*/
ignorePeriodsForFieldNameQuotes?: boolean;
}
export interface Field {
alias: string | null;
field: string | BaseBuilder;
options: FieldOptions;
}
interface GetFieldBlock extends Block {
_fields: Field[];
/**
* Add the given field to the final result set.
*
* The 'field' parameter does not necessarily have to be a fieldname. It can use database functions too,
* e.g. DATE_FORMAT(a.started, "%H")
*
* An alias may also be specified for this field.
*/
field(name: string | BaseBuilder, alias?: string, options?: FieldOptions): this;
/**
* Add the given fields to the final result set.
*
* The parameter is an Object containing field names (or database functions) as the keys and aliases for the
* fields as the values. If the value for a key is null then no alias is set for that field.
*
* Internally this method simply calls the field() method of this block to add each individual field.
*/
fields(fields: {[field: string]: string} | string[], options?: FieldOptions): this;
}
interface GetFieldMixin {
/**
* Set a field to select data for.
*
* @param name Name of field OR an SQL expression such as `DATE_FORMAT` OR a builder.
* @param alias An alias by which to refer to this field. Default is `null`.
* @param options Additional options. Default is `null`.
*/
field(name: string | BaseBuilder, alias?: string, options?: FieldOptions): this;
/**
* Set fields to select data for.
*
* @param fields List of field:alias pairs OR Array of field names
* @param options Additional options. Default is `null`.
*/
fields(fields: {[field: string]: string} | string[], options?: FieldOptions): this;
}
/**
* Additional options for `update().set()`.
*/
interface SetOptions {
/**
* When `autoQuoteFieldNames` is turned on this flag instructs it to ignore the period (.) character within
* field names. Default is `false`.
*/
ignorePeriodsForFieldNameQuotes?: boolean;
/**
* If set and the value is a String then it will not be quoted in the output Default is `false`.
*/
dontQuote?: boolean;
}
/**
* Additional options for `update().setFields()`.
*/
interface SetFieldsOptions {
/**
* When `autoQuoteFieldNames` is turned on this flag instructs it to ignore the period (.) character within
* field names. Default is `false`.
*/
ignorePeriodsForFieldNameQuotes?: boolean;
}
interface AbstractSetFieldBlock extends Block {
_fields: (string | BaseBuilder)[];
_values: any[][];
_valueOptions: SetOptions[][];
_reset(): void;
/**
* Update the given field with the given value.
* This will override any previously set value for the given field.
*/
_set(field: string | BaseBuilder, value: any, options?: SetOptions): void;
/**
* Insert fields based on the key/value pairs in the given object
*/
_setFields(fields: {[field: string]: any}, options?: SetOptions): void;
}
interface SetFieldBlock extends AbstractSetFieldBlock {
set(name: string, value?: any, options?: SetOptions): this;
setFields(fields: {[field: string]: any}, options?: SetOptions): this;
/**
* Insert multiple rows for the given fields. Accepts an array of objects.
* This will override all previously set values for every field.
*/
setFieldsRows<T extends {[field: string]: any}>(fieldsRows: T[], options?: SetFieldsOptions): void;
}
interface SetFieldMixin {
/**
* Set a field to a value.
*
* @param name Name of field or an operation.
* @param value Value to set to field. Default is `undefined`.
* @param options Additional options. Default is `null`.
*/
set(name: string, value?: any, options?: SetOptions): this;
/**
* Set fields to given values.
*
* @param fields Field-value pairs.
* @param options Additional options. Default is `null`.
*/
setFields(fields: {[field: string]: any}, options?: SetFieldsOptions): this;
}
interface InsertFieldValueBlock extends AbstractSetFieldBlock {
set(name: string, value: any, options?: SetOptions): void;
setFields(name: {[field: string]: any}, options?: SetFieldsOptions): void;
setFieldsRows<T extends {[field: string]: any}>(fields: T[], options?: SetFieldsOptions): void;
}
interface InsertFieldValueMixin {
/**
* Set a field to a value.
*
* @param name Name of field.
* @param value Value to set to field.
* @param options Additional options. Default is `null`.
*/
set(name: string, value: any, options?: SetOptions): this;
/**
* Set fields to given values.
*
* @param name Field-value pairs.
* @param options Additional options. Default is `null`.
*/
setFields(name: {[field: string]: any}, options?: SetFieldsOptions): this;
/**
* Set fields to given values in the given rows (a multi-row insert).
*
* @param fields An array of objects, where each object is map of field-value pairs for that row
* @param options Additional options. Default is `null`.
*/
setFieldsRows<T extends {[field: string]: any}>(fields: T[], options?: SetFieldsOptions): this;
}
interface InsertFieldsFromQueryBlock extends Block {
_query: null | BaseBuilder;
fromQuery(columns: string[], selectQry: Select): void;
}
interface InsertFieldsFromQueryMixin {
/**
* Insert results of given `SELECT` query
*
* @param columns Names of columns to insert.
* @param selectQry The query to run.
*/
fromQuery(columns: string[], selectQry: Select): this;
}
interface DistinctBlock extends Block {
/**
* Add the DISTINCT keyword to the query.
*/
distinct(): void;
}
interface DistinctMixin {
/**
* Insert the DISTINCT keyword.
*/
distinct(): this;
}
interface GroupByBlock extends Block {
_groups: string[];
/**
* Add a GROUP BY transformation for the given field.
*/
group(field: string): this;
}
interface GroupByMixin {
/**
* Add an GROUP BY clause.
*
* @param field Name of field to group by.
*/
group(field: string): this;
}
interface VerbSingleValueBlockOptions extends QueryBuilderOptions {
/**
* The prefix verb string.
*/
verb?: string;
}
interface AbstractVerbSingleValueBlock extends Block {
options: CompleteQueryBuilderOptions & VerbSingleValueBlockOptions;
_value: number;
_setValue(value: number): void;
}
interface OffsetBlock extends AbstractVerbSingleValueBlock {
/**
* Set the OFFSET transformation.
*
* Call this will override the previously set offset for this query. Also note that Passing 0 for 'max' will
* remove the offset.
*/
offset(limit: number): void;
}
interface OffsetMixin {
/**
* Add an OFFSET clause.
*
* @param limit Index of record to start fetching from.
*/
offset(limit: number): this;
}
interface LimitBlock extends AbstractVerbSingleValueBlock {
/**
* Set the LIMIT transformation.
*
* Call this will override the previously set limit for this query. Also note that Passing 0 for 'max' will remove
* the limit.
*/
limit(limit: number): void;
}
interface LimitMixin {
/**
* Add a LIMIT clause.
*
* @param limit Number of records to limit the query to.
*/
limit(limit: number): this;
}
interface ConditionBlockOptions extends QueryBuilderOptions {
/**
* The condition verb.
*/
verb?: string;
}
interface Condition {
expr: string | Expression;
values: any[];
}
interface AbstractConditionBlock extends Block {
options: CompleteQueryBuilderOptions & ConditionBlockOptions;
_conditions: Condition[];
}
interface WhereBlock extends AbstractConditionBlock {
where(condition: string | Expression, ...args: any[]): void;
}
interface WhereMixin {
/**
* Add a WHERE condition.
*
* @param condition The condition expression.
* @param args Additional arguments for parameter substitution. See guide for examples. Default is `null`.
*/
where(condition: string | Expression, ...args: any[]): this;
}
interface HavingBlock extends AbstractConditionBlock {
having(condition: string | Expression, ...args: any[]): void;
}
interface HavingMixin {
/**
* Add a HAVING condition.
*
* @param condition The condition expression.
* @param args Additional arguments for parameter substitution. See guide for examples. Default
* is `null`.
*/
having(condition: string | Expression, ...args: any[]): this;
}
interface OrderByBlock extends Block {
/**
* Add an ORDER BY transformation for the given field in the given order.
*
* To specify descending order pass false for the 'dir' parameter.
*/
order(field: string, direction?: boolean | null, ...values: any[]): void;
}
interface OrderByMixin {
/**
* Add an ORDER BY clause.
*
* @param field Name of field to sort by.
* @param direction Sort direction. `true` = ascending, `false` = descending, `null` = no direction set.
* Default is `true`.
* @param values List of parameter values specified as additional arguments. Default is `[]`.
*/
order(field: string, direction?: boolean | null, ...values: any[]): this;
}
interface Join {
type: string;
table: string | BaseBuilder;
alias: string | null;
condition: string | Expression | null;
}
interface JoinBlock extends Block {
_joins: Join[];
/**
* Add a JOIN with the given table.
*
* 'table' is the name of the table to join with.
*
* 'alias' is an optional alias for the table name.
*
* 'condition' is an optional condition (containing an SQL expression) for the JOIN.
*
* 'type' must be either one of INNER, OUTER, LEFT or RIGHT. Default is 'INNER'.
*/
join(
name: string | BaseBuilder,
alias?: string,
condition?: string | Expression,
type?: "INNER" | "OUTER" | "LEFT" | "RIGHT",
): this;
left_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
right_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
outer_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
cross_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
}
interface JoinMixin {
/**
* Add an INNER JOIN.
*
* @param name The table to join on. Can be a a [[BaseBuilder]] instance.
* @param alias An alias by which to refer to this table. Default is `null`.
* @param condition A joining ON condition. Default is `null`.
*/
join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
/**
* Add a LEFT JOIN.
*
* @param name The table to join on. Can be a a [[cls.BaseBuilder]] instance.
* @param alias An alias by which to refer to this table. Default is `null`.
* @param condition A joining ON condition. Default is `null`.
*/
left_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
/**
* Add a RIGHT JOIN.
*
* @param name The table to join on. Can be a a [[cls.BaseBuilder]] instance.
* @param alias An alias by which to refer to this table. Default is `null`.
* @param condition A joining ON condition. Default is `null`.
*/
right_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
/**
* Add a OUTER JOIN.
*
* @param name The table to join on. Can be a a [[cls.BaseBuilder]] instance.
* @param alias An alias by which to refer to this table. Default is `null`.
* @param condition A joining ON condition. Default is `null`.
*/
outer_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
/**
* Add a CROSS JOIN.
*
* @param name The table to join on. Can be a a [[cls.BaseBuilder]] instance.
* @param alias An alias by which to refer to this table. Default is `null`.
* @param condition A joining ON condition. Default is `null`.
*/
cross_join(name: string | BaseBuilder, alias?: string, condition?: string | Expression): this;
}
interface Union {
type: string;
table: QueryBuilder;
}
interface UnionBlock extends Block {
_unions: Union[];
/**
* Add a UNION with the given table/query.
*
* 'table' is the name of the table or query to union with.
*
* 'type' must be either one of UNION or UNION ALL.... Default is 'UNION'.
*/
union(table: QueryBuilder, type?: "UNION" | "UNION ALL"): void;
/**
* Add a UNION ALL with the given table/query.
*/
union_all(table: QueryBuilder): void;
}
interface UnionMixin {
/**
* Combine with another `SELECT` using `UNION`.
*
* @param query Another `SELECT` query to combine this query with.
*/
union(query: QueryBuilder): this;
/**
* Combine with another `SELECT` using `UNION ALL`.
*
* @param query Another `SELECT` query to combine this query with.
*/
union_all(query: QueryBuilder): this;
}
/* tslint:disable:member-ordering */
interface Cls {
/**
* Get whether obj is a query builder
*
* Note: this is a loose test checking for `_toParamString`
*/
isSquelBuilder(obj: any): obj is BaseBuilder;
/**