-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathast.ts
More file actions
1167 lines (986 loc) · 26.2 KB
/
ast.ts
File metadata and controls
1167 lines (986 loc) · 26.2 KB
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
// import { IType } from '../../interfaces';
import { nil } from '../utils';
export function locationOf(node: PGNode): NodeLocation {
const n = node._location;
if (!n) {
throw new Error('This statement has not been parsed using location tracking (which has a small performance hit). ')
}
return n;
}
export type Statement = SelectStatement
| CreateTableStatement
| CreateSequenceStatement
| CreateIndexStatement
| CreateExtensionStatement
| CommitStatement
| InsertStatement
| UpdateStatement
| ShowStatement
| PrepareStatement
| DeallocateStatement
| DeleteStatement
| WithStatement
| RollbackStatement
| TablespaceStatement
| CreateViewStatement
| CreateMaterializedViewStatement
| RefreshMaterializedViewStatement
| AlterTableStatement
| AlterIndexStatement
| AlterSequenceStatement
| SetGlobalStatement
| SetTimezone
| SetNames
| CreateEnumType
| CreateCompositeType
| AlterEnumType
| TruncateTableStatement
| DropStatement
| CommentStatement
| CreateSchemaStatement
| WithRecursiveStatement
| RaiseStatement
| ValuesStatement
| CreateFunctionStatement
| DropFunctionStatement
| DoStatement
| BeginStatement
| StartTransactionStatement;
export interface PGNode {
_location?: NodeLocation;
}
export interface PGComment extends PGNode {
comment: string;
}
export interface BeginStatement extends PGNode {
type: 'begin';
isolationLevel?: 'serializable' | 'repeatable read' | 'read committed' | 'read uncommitted';
writeable?: 'read write' | 'read only';
deferrable?: boolean;
}
export interface DoStatement extends PGNode {
type: 'do';
language?: Name;
code: string;
}
export interface CreateFunctionStatement extends PGNode {
type: 'create function';
name: QName;
code?: string;
orReplace?: boolean;
language?: Name;
arguments: FunctionArgument[];
returns?: DataTypeDef | ReturnsTable;
purity?: 'immutable' | 'stable' | 'volatile';
leakproof?: boolean;
onNullInput?: 'call' | 'null' | 'strict';
}
export interface DropFunctionStatement extends PGNode {
type: 'drop function';
ifExists?: boolean;
name: QName;
arguments?: { name?: Name; type: DataTypeDef }[];
}
export interface ReturnsTable extends PGNode {
kind: 'table';
columns: { name: Name; type: DataTypeDef }[];
}
export type FunctionArgumentMode = 'in' | 'out' | 'inout' | 'variadic';
export interface FunctionArgument extends PGNode {
name?: Name;
type: DataTypeDef;
default?: Expr;
mode?: FunctionArgumentMode;
}
export interface CommentStatement extends PGNode {
type: 'comment';
comment: string;
/** This is not exhaustive compared to https://www.postgresql.org/docs/13/sql-comment.html
* But this is what's supported. File an issue if you want more.
*/
on: {
type: 'table' | 'database' | 'index' | 'materialized view' | 'trigger' | 'type' | 'view';
name: QName;
} | {
type: 'column';
column: QColumn;
};
}
export interface RaiseStatement extends PGNode {
type: 'raise';
level?: 'debug' | 'log' | 'info' | 'notice' | 'warning' | 'exception';
format: string;
formatExprs?: Expr[] | nil;
using?: {
type: 'message'
| 'detail'
| 'hint'
| 'errcode'
| 'column'
| 'constraint'
| 'datatype'
| 'table'
| 'schema';
value: Expr;
}[] | nil;
}
export interface CreateSchemaStatement extends PGNode {
type: 'create schema';
name: Name;
ifNotExists?: boolean;
}
export interface PrepareStatement extends PGNode {
type: 'prepare';
name: Name;
args?: DataTypeDef[] | nil;
statement: Statement;
}
export interface DeallocateStatement extends PGNode {
type: 'deallocate';
target: Name | DeallocateStatementOpt;
}
export interface DeallocateStatementOpt extends PGNode {
option: 'all';
}
export interface CreateEnumType extends PGNode {
type: 'create enum',
name: QName;
values: Literal[];
}
export interface CreateCompositeType extends PGNode {
type: 'create composite type';
name: QName;
attributes: CompositeTypeAttribute[];
}
export interface AlterEnumType extends PGNode {
type: 'alter enum',
name: QName,
change: EnumAlteration
}
export type EnumAlteration
= EnumAlterationRename
| EnumAlterationAddValue
export interface EnumAlterationRename {
type: 'rename';
to: QName;
}
export interface EnumAlterationAddValue {
type: 'add value';
add: Literal;
}
export interface CompositeTypeAttribute extends PGNode {
name: Name;
dataType: DataTypeDef;
collate?: Name;
}
export interface Literal extends PGNode {
value: string
}
export interface ShowStatement extends PGNode {
type: 'show';
variable: Name;
}
export interface TruncateTableStatement extends PGNode {
type: 'truncate table';
tables: QName[];
identity?: 'restart' | 'continue';
cascade?: 'cascade' | 'restrict';
}
export interface DropStatement extends PGNode {
type: 'drop table' | 'drop sequence' | 'drop index' | 'drop type' | 'drop trigger';
names: QName[];
ifExists?: boolean;
cascade?: 'cascade' | 'restrict';
concurrently?: boolean;
}
export interface NodeLocation {
/** Location of the last ";" prior to this statement */
start: number;
/** Location of the first ";" after this statement (if any) */
end: number;
}
export interface StartTransactionStatement extends PGNode {
type: 'start transaction';
}
export interface CommitStatement extends PGNode {
type: 'commit';
}
export interface RollbackStatement extends PGNode {
type: 'rollback';
}
export interface TablespaceStatement extends PGNode {
type: 'tablespace';
tablespace: Name;
}
export interface DeleteStatement extends PGNode {
type: 'delete';
from: QNameAliased;
returning?: SelectedColumn[] | nil;
where?: Expr | nil;
}
export interface InsertStatement extends PGNode {
type: 'insert';
into: QNameAliased;
returning?: SelectedColumn[] | nil;
columns?: Name[] | nil;
overriding?: 'system' | 'user';
insert: SelectStatement;
onConflict?: OnConflictAction | nil;
}
export interface OnConflictAction extends PGNode {
on?: OnConflictOnExpr | OnConflictOnConstraint;
do: 'do nothing' | {
sets: SetStatement[];
};
where?: Expr;
}
export interface OnConflictOnExpr extends PGNode {
type: 'on expr';
exprs: Expr[];
}
export interface OnConflictOnConstraint extends PGNode {
type: 'on constraint';
constraint: QName;
}
export interface AlterIndexStatement extends PGNode {
type: 'alter index';
index: QNameAliased;
ifExists?: boolean;
change: IndexAlteration;
}
export type IndexAlteration
= IndexAlterationRename
| IndexAlterationSetTablespace
export interface IndexAlterationRename {
type: 'rename';
to: QName;
}
export interface IndexAlterationSetTablespace {
type: 'set tablespace';
tablespace: QName;
}
export interface AlterTableStatement extends PGNode {
type: 'alter table';
table: QNameAliased;
only?: boolean;
ifExists?: boolean;
changes: TableAlteration[];
}
export interface TableAlterationRename extends PGNode {
type: 'rename';
to: Name;
}
export interface TableAlterationRenameColumn extends PGNode {
type: 'rename column';
column: Name;
to: Name;
}
export interface TableAlterationRenameConstraint extends PGNode {
type: 'rename constraint';
constraint: Name;
to: Name;
}
export interface TableAlterationAddColumn extends PGNode {
type: 'add column';
ifNotExists?: boolean;
column: CreateColumnDef;
}
export interface TableAlterationDropColumn extends PGNode {
type: 'drop column';
ifExists?: boolean;
column: Name;
behaviour?: 'cascade' | 'restrict';
}
export interface TableAlterationDropConstraint extends PGNode {
type: 'drop constraint';
ifExists?: boolean;
constraint: Name;
behaviour?: 'cascade' | 'restrict';
}
export interface TableAlterationAlterColumn extends PGNode {
type: 'alter column',
column: Name;
alter: AlterColumn
}
export interface TableAlterationAddConstraint extends PGNode {
type: 'add constraint',
constraint: TableConstraint;
}
export type TableAlteration = TableAlterationRename
| TableAlterationRenameColumn
| TableAlterationRenameConstraint
| TableAlterationAddColumn
| TableAlterationDropColumn
| TableAlterationAlterColumn
| TableAlterationAddConstraint
| TableAlterationOwner
| TableAlterationDropConstraint
export interface TableAlterationOwner extends PGNode {
type: 'owner';
to: Name;
}
export interface AlterColumnSetType extends PGNode {
type: 'set type';
dataType: DataTypeDef;
}
export interface AlterColumnSetDefault extends PGNode {
type: 'set default';
default: Expr;
updateExisting?: boolean;
}
export interface AlterColumnAddGenerated extends PGNode {
type: 'add generated',
always?: 'always' | 'by default';
constraintName?: Name;
sequence?: {
name?: QName;
} & CreateSequenceOptions;
}
export interface AlterColumnSimple extends PGNode {
type: 'drop default' | 'set not null' | 'drop not null';
};
export type AlterColumn = AlterColumnSetType
| AlterColumnSetDefault
| AlterColumnAddGenerated
| AlterColumnSimple;
/**
* FROM https://www.postgresql.org/docs/12/ddl-constraints.html
*
* Restricting and cascading deletes are the two most common options.
* RESTRICT prevents deletion of a referenced row.
* NO ACTION means that if any referencing rows still exist when the constraint is checked,
* an error is raised; this is the default behavior if you do not specify anything.
* (The essential difference between these two choices is that NO ACTION allows the check to be deferred until later in the transaction, whereas RESTRICT does not.)
* CASCADE specifies that when a referenced row is deleted,
* row(s) referencing it should be automatically deleted as well.
* There are two other options: SET NULL and SET DEFAULT.
* These cause the referencing column(s) in the referencing row(s) to be set to nulls or their default values, respectively, when the referenced row is deleted.
* Note that these do not excuse you from observing any constraints.
* For example, if an action specifies SET DEFAULT but the default value would not satisfy the foreign key constraint, the operation will fail.
*/
export type ConstraintAction = 'cascade'
| 'no action'
| 'restrict'
| 'set null'
| 'set default';
export interface CreateIndexStatement extends PGNode {
type: 'create index';
table: QName;
using?: Name;
expressions: IndexExpression[];
where?: Expr;
unique?: true;
ifNotExists?: true;
concurrently?: true;
indexName?: Name;
tablespace?: string;
with?: CreateIndexWith[];
}
export interface CreateIndexWith extends PGNode {
parameter: string;
value: string;
}
export interface CreateExtensionStatement extends PGNode {
type: 'create extension';
extension: Name;
ifNotExists?: true;
schema?: Name;
version?: Literal;
from?: Literal;
}
export interface IndexExpression extends PGNode {
expression: Expr;
opclass?: QName;
collate?: QName;
order?: 'asc' | 'desc';
nulls?: 'first' | 'last';
}
export interface CreateViewStatementBase extends PGNode {
columnNames?: Name[];
name: QName;
query: SelectStatement;
parameters?: { [name: string]: string };
}
export interface CreateViewStatement extends CreateViewStatementBase {
type: 'create view';
orReplace?: boolean;
recursive?: boolean;
temp?: boolean;
checkOption?: 'local' | 'cascaded';
}
export interface CreateMaterializedViewStatement extends CreateViewStatementBase {
type: 'create materialized view';
tablespace?: Name;
withData?: boolean;
ifNotExists?: boolean;
}
export interface RefreshMaterializedViewStatement extends PGNode {
type: 'refresh materialized view';
name: QName;
concurrently?: boolean;
withData?: boolean;
}
export interface CreateTableStatement extends PGNode {
type: 'create table';
name: QName;
temporary?: boolean;
unlogged?: boolean;
locality?: 'global' | 'local';
ifNotExists?: true;
columns: (CreateColumnDef | CreateColumnsLikeTable)[];
/** Constraints not defined inline */
constraints?: TableConstraint[];
inherits?: QName[];
}
export interface CreateColumnsLikeTable extends PGNode {
kind: 'like table';
like: QName;
options: CreateColumnsLikeTableOpt[];
}
export interface CreateColumnsLikeTableOpt extends PGNode {
verb: 'including' | 'excluding';
option: 'defaults' | 'constraints' | 'indexes' | 'storage' | 'comments' | 'all';
}
export interface CreateColumnDef extends PGNode {
kind: 'column';
name: Name;
dataType: DataTypeDef;
constraints?: ColumnConstraint[];
collate?: QName;
}
export interface Name extends PGNode {
name: string;
}
export interface TableAliasName extends Name, PGNode {
columns?: Name[];
}
export interface QName extends Name, PGNode {
schema?: string;
}
export interface QColumn extends PGNode {
table: string;
column: string;
schema?: string;
}
export type DataTypeDef = ArrayDataTypeDef | BasicDataTypeDef;
export interface ArrayDataTypeDef extends PGNode {
kind: 'array';
arrayOf: DataTypeDef;
}
export interface BasicDataTypeDef extends QName, PGNode {
kind?: undefined;
/** Allows to differenciate types like 'double precision' from their double-quoted counterparts */
doubleQuoted?: true;
/** varchar(length), numeric(precision, scale), ... */
config?: number[];
}
export type ColumnConstraint
= ColumnConstraintSimple
| ColumnConstraintDefault
| AlterColumnAddGenerated
| ColumnConstraintReference
| ColumnConstraintCheck;
export interface ColumnConstraintSimple extends PGNode {
type: 'unique'
| 'primary key'
| 'not null'
| 'null';
constraintName?: Name;
}
export interface ColumnConstraintReference extends TableReference, PGNode {
type: 'reference';
constraintName?: Name;
}
export interface ColumnConstraintDefault extends PGNode {
type: 'default';
default: Expr;
constraintName?: Name;
}
export interface ColumnConstraintForeignKey extends TableReference, PGNode {
type: 'foreign key';
constraintName?: Name;
}
export interface TableReference {
foreignTable: QName;
foreignColumns: Name[];
onDelete?: ConstraintAction;
onUpdate?: ConstraintAction;
match?: 'full' | 'partial' | 'simple';
}
// todo: add EXECLUDE
export type TableConstraint
= TableConstraintUnique
| TableConstraintForeignKey
| TableConstraintCheck;
export type TableConstraintCheck = ColumnConstraintCheck;
export interface TableConstraintUnique extends PGNode {
type: 'primary key' | 'unique';
constraintName?: Name;
columns: Name[];
}
export interface TableConstraintForeignKey extends ColumnConstraintForeignKey {
localColumns: Name[];
}
export interface ColumnConstraintCheck extends PGNode {
type: 'check';
constraintName?: Name;
expr: Expr;
}
export type WithStatementBinding = SelectStatement
| WithStatement
| WithRecursiveStatement
| InsertStatement
| UpdateStatement
| DeleteStatement;
export interface WithStatement extends PGNode {
type: 'with';
bind: {
alias: Name;
statement: WithStatementBinding;
}[];
in: WithStatementBinding;
}
export interface WithRecursiveStatement extends PGNode {
type: 'with recursive';
alias: Name;
columnNames: Name[];
bind: SelectFromUnion;
in: WithStatementBinding;
}
export type SelectStatement = SelectFromStatement
| SelectFromUnion
| ValuesStatement
| WithStatement
| WithRecursiveStatement;
export interface SelectFromStatement extends PGNode {
type: 'select',
columns?: SelectedColumn[] | nil;
from?: From[] | nil;
where?: Expr | nil;
groupBy?: Expr[] | nil;
having?: Expr | nil;
limit?: LimitStatement | nil;
orderBy?: OrderByStatement[] | nil;
distinct?: 'all' | 'distinct' | Expr[] | nil;
for?: ForStatement;
skip?: SkipClause;
}
export interface SelectFromUnion extends PGNode {
type: 'union' | 'union all',
left: SelectStatement;
right: SelectStatement;
}
export interface OrderByStatement extends PGNode {
by: Expr;
order?: 'ASC' | 'DESC' | nil;
nulls?: 'FIRST' | 'LAST' | nil;
}
export interface ForStatement extends PGNode {
type: 'update' | 'no key update' | 'share' | 'key share';
}
export interface SkipClause extends PGNode {
type: 'nowait' | 'skip locked'
}
export interface LimitStatement extends PGNode {
limit?: Expr | nil;
offset?: Expr | nil;
}
export interface UpdateStatement extends PGNode {
type: 'update';
table: QNameAliased;
sets: SetStatement[];
where?: Expr | nil;
from?: From | nil;
returning?: SelectedColumn[] | nil;
}
export interface SetStatement extends PGNode {
column: Name;
value: Expr;
}
export interface SelectedColumn extends PGNode {
expr: Expr;
alias?: Name;
}
export type From = FromTable
| FromStatement
| FromCall
export interface FromCall extends ExprCall, PGNode {
alias?: TableAliasName;
join?: JoinClause | nil;
lateral?: true;
withOrdinality?: boolean;
};
export interface ValuesStatement extends PGNode {
type: 'values';
values: Expr[][];
}
export interface QNameAliased extends QName, PGNode {
alias?: string;
}
export interface QNameMapped extends QNameAliased {
columnNames?: Name[] | nil;
}
export interface FromTable extends PGNode {
type: 'table',
name: QNameMapped;
lateral?: true;
join?: JoinClause | nil;
}
export interface FromStatement extends PGNode {
type: 'statement';
statement: SelectStatement;
alias: string;
lateral?: true;
columnNames?: Name[] | nil;
db?: null | nil;
join?: JoinClause | nil;
}
export interface JoinClause extends PGNode {
type: JoinType;
on?: Expr | nil;
using?: Name[] | nil;
}
export type JoinType = 'INNER JOIN'
| 'LEFT JOIN'
| 'RIGHT JOIN'
| 'FULL JOIN'
| 'CROSS JOIN';
export type Expr = ExprRef
| ExprParameter
| ExprList
| ExprArrayFromSelect
| ExprNull
| ExprExtract
| ExprInteger
| ExprDefault
| ExprMember
| ExprValueKeyword
| ExprArrayIndex
| ExprNumeric
| ExprString
| ExprCase
| ExprBinary
| ExprUnary
| ExprCast
| ExprBool
| ExprCall
| SelectStatement
| WithStatement
| ExprConstant
| ExprTernary
| ExprOverlay
| ExprSubstring;
/**
* Handle special syntax: overlay('12345678' placing 'ab' from 2 for 4)
*/
export interface ExprOverlay extends PGNode {
type: 'overlay';
value: Expr;
placing: Expr;
from: Expr;
for?: Expr | nil;
}
/** Handle special syntax: substring('val' from 2 for 3) */
export interface ExprSubstring extends PGNode {
type: 'substring';
value: Expr;
from?: Expr | nil;
for?: Expr | nil;
}
// === https://www.postgresql.org/docs/12/functions.html
export type LogicOperator = 'OR' | 'AND';
export type EqualityOperator = 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE' | '=' | '!=';
// see https://www.postgresql.org/docs/12/functions-math.html
export type MathOpsBinary = '|' | '&' | '>>' | '^' | '#' | '<<' | '>>';
export type ComparisonOperator = '>' | '>=' | '<' | '<=' | '@>' | '<@' | '?' | '?|' | '?&' | '#>>' | '~' | '~*' | '!~' | '!~*' | '@@';
export type AdditiveOperator = '||' | '-' | '#-' | '&&' | '+';
export type MultiplicativeOperator = '*' | '%' | '/';
export type ConstructOperator = 'AT TIME ZONE';
export type BinaryOperator = LogicOperator
| EqualityOperator
| ComparisonOperator
| AdditiveOperator
| MultiplicativeOperator
| MathOpsBinary
| ConstructOperator;
export interface ExprBinary extends PGNode {
type: 'binary';
left: Expr;
right: Expr;
op: BinaryOperator;
opSchema?: string;
}
export interface ExprConstant extends PGNode {
type: 'constant';
dataType: DataTypeDef, // | IType;
value: any;
}
export type ExprLiteral = ExprConstant | ExprInteger | ExprNumeric | ExprString | ExprBool | ExprNull;
export interface ExprTernary extends PGNode {
type: 'ternary';
value: Expr;
lo: Expr;
hi: Expr;
op: 'BETWEEN' | 'NOT BETWEEN';
}
export interface ExprCast extends PGNode {
type: 'cast';
to: DataTypeDef;
operand: Expr;
}
export type UnaryOperator = '+'
| '-'
| 'NOT'
| 'IS NULL'
| 'IS NOT NULL'
| 'IS TRUE'
| 'IS FALSE'
| 'IS NOT TRUE'
| 'IS NOT FALSE'
| '|/'
| '||/'
| '@'
| '~'
| '@-@'
| '@@'
| '#'
| '?-'
| '?|'
| '!!'
export interface ExprUnary extends PGNode {
type: 'unary';
operand: Expr;
op: UnaryOperator;
opSchema?: string;
}
export interface ExprRef extends PGNode {
type: 'ref';
table?: QName;
name: string | '*';
}
export interface ExprParameter extends PGNode {
type: 'parameter';
name: string;
}
export interface ExprMember extends PGNode {
type: 'member';
operand: Expr;
op: '->' | '->>';
member: string | number;
}
export interface ExprValueKeyword extends PGNode {
type: 'keyword',
keyword: ValueKeyword;
}
export type ValueKeyword = 'current_catalog'
| 'current_date'
| 'current_role'
| 'current_schema'
| 'current_timestamp'
| 'current_time'
| 'localtimestamp'
| 'localtime'
| 'session_user'
| 'user'
| 'current_user'
| 'distinct';
/**
* Function calls.
*
* For aggregation functions, see https://www.postgresql.org/docs/13/sql-expressions.html#SYNTAX-AGGREGATES
*/
export interface ExprCall extends PGNode {
type: 'call';
/** Function name */
function: QName;
/** Arguments list */
args: Expr[];
/** [AGGREGATION FUNCTIONS] Distinct clause specified ? */
distinct?: 'all' | 'distinct';
/** [AGGREGATION FUNCTIONS] Inner order by clause */
orderBy?: OrderByStatement[] | nil;
/** [AGGREGATION FUNCTIONS] Filter clause */
filter?: Expr | nil;
/** [AGGREGATION FUNCTIONS] WITHIN GROUP clause */
withinGroup?: OrderByStatement | nil;
/** [AGGREGATION FUNCTIONS] OVER clause */
over?: CallOver | nil;
}
export interface CallOver extends PGNode {
orderBy?: OrderByStatement[] | nil;
partitionBy?: Expr[] | nil;
}
export interface ExprExtract extends PGNode {
type: 'extract';
field: Name;
from: Expr;
}
export interface ExprList extends PGNode {
type: 'list' | 'array';
expressions: Expr[];
}
export interface ExprArrayFromSelect extends PGNode {
type: 'array select';
select: SelectStatement;
}
export interface ExprArrayIndex extends PGNode {
type: 'arrayIndex',
array: Expr;
index: Expr;
}
export interface ExprNull extends PGNode {
type: 'null';
}
export interface ExprInteger extends PGNode {
type: 'integer';
value: number;
}
export interface ExprDefault extends PGNode {
type: 'default';
}
export interface ExprNumeric extends PGNode {
type: 'numeric';
value: number;
}
export interface ExprString extends PGNode {
type: 'string';