forked from fsprojects/Rezoom.SQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAST.fs
More file actions
779 lines (690 loc) · 23.1 KB
/
AST.fs
File metadata and controls
779 lines (690 loc) · 23.1 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
namespace Rezoom.SQL.Compiler
open System
open System.Collections.Generic
type NumericLiteral =
| IntegerLiteral of uint64
| FloatLiteral of float
type SignedNumericLiteral =
{ Sign : int // -1, 0, 1
Value : NumericLiteral
}
type Literal =
| NullLiteral
| BooleanLiteral of bool
| StringLiteral of string
| BlobLiteral of byte array
| NumericLiteral of NumericLiteral
| DateTimeLiteral of DateTime
| DateTimeOffsetLiteral of DateTimeOffset
type SavepointName = Name
type Alias = Name option
type IntegerSize =
| Integer16
| Integer32
| Integer64
type FloatSize =
| Float32
| Float64
type TypeName =
| GuidTypeName
| StringTypeName of maxLength : int option
| BinaryTypeName of maxLength : int option
| IntegerTypeName of IntegerSize
| FloatTypeName of FloatSize
| DecimalTypeName
| BooleanTypeName
| DateTimeTypeName
| DateTimeOffsetTypeName
member this.SupportsCollation =
match this with
| StringTypeName _ -> true
| _ -> false
override this.ToString() =
match this with
| GuidTypeName -> "GUID"
| StringTypeName(Some len) -> "STRING(" + string len + ")"
| StringTypeName(None) -> "STRING"
| BinaryTypeName(Some len) -> "BINARY(" + string len + ")"
| BinaryTypeName(None) -> "BINARY"
| IntegerTypeName Integer16 -> "INT16"
| IntegerTypeName Integer32 -> "INT"
| IntegerTypeName Integer64 -> "INT64"
| FloatTypeName Float32 -> "FLOAT32"
| FloatTypeName Float64 -> "FLOAT64"
| DecimalTypeName -> "DECIMAL"
| BooleanTypeName -> "BOOL"
| DateTimeTypeName -> "DATETIME"
| DateTimeOffsetTypeName -> "DATETIMEOFFSET"
[<NoComparison>]
[<CustomEquality>]
type ObjectName<'t> =
{ Source : SourceInfo
SchemaName : Name option
ObjectName : Name
Info : 't
}
override this.ToString() =
string <|
match this.SchemaName with
| None -> this.ObjectName
| Some schema -> schema + "." + this.ObjectName
member this.Equals(other) =
this.SchemaName = other.SchemaName
&& this.ObjectName = other.ObjectName
override this.Equals(other) =
match other with
| :? ObjectName<'t> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() = this.SchemaName +@+ this.ObjectName
interface IEquatable<ObjectName<'t>> with
member this.Equals(other) = this.Equals(other)
[<NoComparison>]
type ColumnName<'t> =
{ Table : ObjectName<'t> option
ColumnName : Name
}
override this.ToString() =
string <|
match this.Table with
| None -> this.ColumnName
| Some tbl -> string tbl + "." + this.ColumnName
type BindParameter =
| NamedParameter of Name // prefix character : or $ or @ is ignored
override this.ToString() =
let (NamedParameter name) = this
"@" + name.Value
type BinaryOperator =
| Concatenate
| Multiply
| Divide
| Modulo
| Add
| Subtract
| BitShiftLeft
| BitShiftRight
| BitAnd
| BitOr
| LessThan
| LessThanOrEqual
| GreaterThan
| GreaterThanOrEqual
| Equal
| NotEqual
| Is
| IsNot
| And
| Or
/// True if this operator expects boolean inputs and has a boolean output.
member this.IsLogicalOperator =
match this with
| And
| Or -> true
| _ -> false
type UnaryOperator =
| Negative
| Not
| BitNot
/// True if this operator expects boolean inputs and has a boolean output.
member this.IsLogicalOperator =
match this with
| Not -> true
| _ -> false
type SimilarityOperator =
| Like
| Match // MATCH on SQLite, SIMILAR TO on PG
| Regexp // REGEXP on SQLite, ~ on PG
[<NoComparison>]
type ExprType<'t, 'e> =
| LiteralExpr of Literal
| BindParameterExpr of BindParameter
| ColumnNameExpr of ColumnName<'t>
| CastExpr of CastExpr<'t, 'e>
| CollateExpr of CollationExpr<'t, 'e>
| FunctionInvocationExpr of FunctionInvocationExpr<'t, 'e>
| SimilarityExpr of SimilarityExpr<'t, 'e>
| BinaryExpr of BinaryExpr<'t, 'e>
| UnaryExpr of UnaryExpr<'t, 'e>
| BetweenExpr of BetweenExpr<'t, 'e>
| InExpr of InExpr<'t, 'e>
| ExistsExpr of SelectStmt<'t, 'e>
| CaseExpr of CaseExpr<'t, 'e>
| ScalarSubqueryExpr of SelectStmt<'t, 'e>
and
[<NoComparison>]
[<CustomEquality>]
Expr<'t, 'e> =
{ Value : ExprType<'t, 'e>
Info : 'e
Source : SourceInfo
}
member this.Equals(other) = this.Value = other.Value
override this.Equals(other) =
match other with
| :? Expr<'t, 'e> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() = this.Value.GetHashCode()
interface IEquatable<Expr<'t, 'e>> with
member this.Equals(other) = this.Equals(other)
and [<NoComparison>] InExpr<'t, 'e> =
{ Invert : bool
Input : Expr<'t, 'e>
Set : InSet<'t, 'e> WithSource
}
and [<NoComparison>] CollationExpr<'t, 'e> =
{ Input : Expr<'t, 'e>
Collation : Name
}
and [<NoComparison>] BinaryExpr<'t, 'e> =
{ Left : Expr<'t, 'e>
Operator : BinaryOperator
Right : Expr<'t, 'e>
}
and [<NoComparison>] UnaryExpr<'t, 'e> =
{ Operator : UnaryOperator
Operand : Expr<'t, 'e>
}
and [<NoComparison>] SimilarityExpr<'t, 'e> =
{ Invert : bool
Operator : SimilarityOperator
Input : Expr<'t, 'e>
Pattern : Expr<'t, 'e>
Escape : Expr<'t, 'e> option
}
and [<NoComparison>] BetweenExpr<'t, 'e> =
{ Invert : bool
Input : Expr<'t, 'e>
Low : Expr<'t, 'e>
High : Expr<'t, 'e>
}
and [<NoComparison>] CastExpr<'t, 'e> =
{ Expression : Expr<'t, 'e>
AsType : TypeName
}
and [<NoComparison>] TableInvocation<'t, 'e> =
{ Table : ObjectName<'t>
Arguments : Expr<'t, 'e> array option // we use an option to distinguish between schema.table and schema.table()
}
and [<NoComparison>] FunctionInvocationExpr<'t, 'e> =
{ FunctionName : Name
Arguments : FunctionArguments<'t, 'e>
}
and [<NoComparison>] CaseExpr<'t, 'e> =
{ Input : Expr<'t, 'e> option
Cases : (Expr<'t, 'e> * Expr<'t, 'e>) array
Else : Expr<'t, 'e> option WithSource
}
and Distinct = | Distinct
and [<NoComparison>] FunctionArguments<'t, 'e> =
| ArgumentWildcard
| ArgumentList of (Distinct option * Expr<'t, 'e> array)
and [<NoComparison>] InSet<'t, 'e> =
| InExpressions of Expr<'t, 'e> array
| InSelect of SelectStmt<'t, 'e>
| InTable of TableInvocation<'t, 'e>
| InParameter of BindParameter
and
[<NoComparison>]
[<CustomEquality>]
SelectStmtCore<'t, 'e> =
{ With : WithClause<'t, 'e> option
Compound : CompoundExpr<'t, 'e>
OrderBy : OrderingTerm<'t, 'e> array option
Limit : Limit<'t, 'e> option
Info : 't
}
member this.Equals(other) =
this.With = other.With
&& this.Compound = other.Compound
&& this.OrderBy = other.OrderBy
&& this.Limit = other.Limit
override this.Equals(other) =
match other with
| :? SelectStmtCore<'t, 'e> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() =
this.With
+@+ this.Compound
+@+ this.OrderBy
+@+ this.Limit
interface IEquatable<SelectStmtCore<'t, 'e>> with
member this.Equals(other) = this.Equals(other)
and SelectStmt<'t, 'e> = SelectStmtCore<'t, 'e> WithSource
and [<NoComparison>] WithClause<'t, 'e> =
{ Recursive : bool
Tables : CommonTableExpression<'t, 'e> array
}
and
[<NoComparison>]
[<CustomEquality>]
CommonTableExpression<'t, 'e> =
{ Name : Name
ColumnNames : Name WithSource array WithSource option
AsSelect : SelectStmt<'t, 'e>
Info : 't
}
member this.Equals(other) =
this.Name = other.Name
&& this.ColumnNames = other.ColumnNames
&& this.AsSelect = other.AsSelect
override this.Equals(other) =
match other with
| :? CommonTableExpression<'t, 'e> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() =
this.Name
+@+ this.ColumnNames
+@+ this.AsSelect
interface IEquatable<CommonTableExpression<'t, 'e>> with
member this.Equals(other) = this.Equals(other)
and OrderDirection =
| Ascending
| Descending
and [<NoComparison>] OrderingTerm<'t, 'e> =
{ By : Expr<'t, 'e>
Direction : OrderDirection
}
and [<NoComparison>] Limit<'t, 'e> =
{ Limit : Expr<'t, 'e>
Offset : Expr<'t, 'e> option
}
and [<NoComparison>] CompoundExprCore<'t, 'e> =
| CompoundTerm of CompoundTerm<'t, 'e>
| Union of CompoundExpr<'t, 'e> * CompoundTerm<'t, 'e>
| UnionAll of CompoundExpr<'t, 'e> * CompoundTerm<'t, 'e>
| Intersect of CompoundExpr<'t, 'e> * CompoundTerm<'t, 'e>
| Except of CompoundExpr<'t, 'e> * CompoundTerm<'t, 'e>
member this.LeftmostInfo =
match this with
| CompoundTerm term -> term.Info
| Union (ex, _)
| UnionAll (ex, _)
| Intersect (ex, _)
| Except (ex, _) -> ex.Value.LeftmostInfo
member this.MergeInfo(add, unknown) =
match this with
| CompoundTerm term -> term.Info
| UnionAll (ex, t) -> add (ex.Value.MergeInfo(add, unknown)) t.Info
| Union (ex, t)
| Intersect (ex, t)
| Except (ex, t) -> unknown (ex.Value.MergeInfo(add, unknown)) t.Info
and CompoundExpr<'t, 'e> = CompoundExprCore<'t, 'e> WithSource
and [<NoComparison>] CompoundTermCore<'t, 'e> =
| Values of Expr<'t, 'e> array WithSource array
| Select of SelectCore<'t, 'e>
and
[<NoComparison>]
[<CustomEquality>]
CompoundTerm<'t, 'e> =
{ Value : CompoundTermCore<'t, 'e>
Source : SourceInfo
Info : 't
}
member this.Equals(other) = other.Value = this.Value
override this.Equals(other) =
match other with
| :? CompoundTerm<'t, 'e> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() = this.Value.GetHashCode()
interface IEquatable<CompoundTerm<'t, 'e>> with
member this.Equals(other) = this.Equals(other)
and
[<NoComparison>]
[<CustomEquality>]
SelectCore<'t, 'e> =
{ Columns : ResultColumns<'t, 'e>
From : TableExpr<'t, 'e> option
Where : Expr<'t, 'e> option
GroupBy : GroupBy<'t, 'e> option
Info : 't
}
member this.Equals(other) =
this.Columns = other.Columns
&& this.From = other.From
&& this.Where = other.Where
&& this.GroupBy = other.GroupBy
override this.Equals(other) =
match other with
| :? SelectCore<'t, 'e> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() =
this.Columns
+@+ this.From
+@+ this.Where
+@+ this.GroupBy
interface IEquatable<SelectCore<'t, 'e>> with
member this.Equals(other) = this.Equals(other)
and [<NoComparison>] GroupBy<'t, 'e> =
{ By : Expr<'t, 'e> array
Having : Expr<'t, 'e> option
}
and [<NoComparison>] ResultColumns<'t, 'e> =
{ Distinct : Distinct option
Columns : ResultColumn<'t, 'e> array
}
and ResultColumnNavCardinality =
| NavOne
| NavOptional
| NavMany
member this.Separator =
match this with
| NavOne -> "$"
| NavOptional -> "?$"
| NavMany -> "*$"
and [<NoComparison>] ResultColumnNav<'t, 'e> =
{ Cardinality : ResultColumnNavCardinality
Name : Name
Columns : ResultColumn<'t, 'e> array
}
and [<NoComparison>] ResultColumnCase<'t, 'e> =
| ColumnsWildcard
| TableColumnsWildcard of Name
| Column of Expr<'t, 'e> * Alias
| ColumnNav of ResultColumnNav<'t, 'e>
member this.AssumeColumn() =
match this with
| Column (expr, alias) -> expr, alias
| _ -> bug "BUG: wildcard was assumed to be a single column (should've been expanded by now)"
and [<NoComparison>] ResultColumn<'t, 'e> =
{ Case : ResultColumnCase<'t, 'e>
Source : SourceInfo
}
and [<NoComparison>] TableOrSubqueryType<'t, 'e> =
| Table of TableInvocation<'t, 'e>
| Subquery of SelectStmt<'t, 'e>
and
[<NoComparison>]
[<CustomEquality>]
TableOrSubquery<'t, 'e> =
{ Table : TableOrSubqueryType<'t, 'e>
Alias : Name option
Info : 't
}
member this.Equals(other) =
this.Table = other.Table
&& this.Alias = other.Alias
override this.Equals(other) =
match other with
| :? TableOrSubquery<'t, 'e> as other -> this.Equals(other)
| _ -> false
override this.GetHashCode() = this.Table +@+ this.Alias
interface IEquatable<TableOrSubquery<'t, 'e>> with
member this.Equals(other) = this.Equals(other)
and JoinType =
| Inner
| LeftOuter
| Cross
| Natural of JoinType
member this.IsOuter = this = LeftOuter
and [<NoComparison>] JoinConstraint<'t, 'e> =
| JoinOn of Expr<'t, 'e>
| JoinUnconstrained
and [<NoComparison>] Join<'t, 'e> =
{ JoinType : JoinType
LeftTable : TableExpr<'t, 'e>
RightTable : TableExpr<'t, 'e>
Constraint : JoinConstraint<'t, 'e>
}
and [<NoComparison>] TableExprCore<'t, 'e> =
| TableOrSubquery of TableOrSubquery<'t, 'e>
| Join of Join<'t, 'e>
and TableExpr<'t, 'e> = TableExprCore<'t, 'e> WithSource
type OnDeleteAction =
| SetNull
| SetDefault
| Cascade
| Restrict
| NoAction
type [<NoComparison>] ForeignKeyClause<'t> =
{ ReferencesTable : ObjectName<'t>
ReferencesColumns : Name WithSource array
OnDelete : OnDeleteAction option
}
type PrimaryKeyClause =
{ Order : OrderDirection
AutoIncrement : bool
}
type [<NoComparison>] ColumnConstraintType<'t, 'e> =
| PrimaryKeyConstraint of PrimaryKeyClause
| UniqueConstraint
| ForeignKeyConstraint of ForeignKeyClause<'t>
member this.DefaultName(tableName : Name, columnName : Name) =
tableName + "_" +
match this with
| PrimaryKeyConstraint _ -> columnName + "_PK"
| UniqueConstraint -> columnName + "_UNIQUE"
| ForeignKeyConstraint fk ->
columnName
+ "_FK_"
+ fk.ReferencesTable.ObjectName.Value
+ "_"
+ String.concat "_" [ for c in fk.ReferencesColumns -> c.Value.Value ]
type [<NoComparison>] ColumnConstraint<'t, 'e> =
{ Name : Name
ColumnConstraintType : ColumnConstraintType<'t, 'e>
}
type [<NoComparison>] ColumnDef<'t, 'e> =
{ Name : Name
Type : TypeName
Nullable : bool
Collation : Name option
DefaultValue : Expr<'t, 'e> option
Constraints : ColumnConstraint<'t, 'e> array
}
member this.IsAutoIncrementPrimaryKey =
this.Constraints
|> Array.exists (fun c ->
match c.ColumnConstraintType with
| PrimaryKeyConstraint c when c.AutoIncrement -> true
| _ -> false)
type TableIndexConstraintType =
| PrimaryKey
| Unique
type [<NoComparison>] TableIndexConstraintClause<'t, 'e> =
{ Type : TableIndexConstraintType
IndexedColumns : (Name * OrderDirection) WithSource array
}
type [<NoComparison>] TableConstraintType<'t, 'e> =
| TableIndexConstraint of TableIndexConstraintClause<'t, 'e>
| TableForeignKeyConstraint of Name WithSource array * ForeignKeyClause<'t>
| TableCheckConstraint of Expr<'t, 'e>
member this.DefaultName(tableName : Name) =
tableName + "_" +
match this with
| TableIndexConstraint con ->
String.concat "_" [ for { Value = name, _ } in con.IndexedColumns -> name.Value ]
+ "_"
+ (match con.Type with
| PrimaryKey -> "PK"
| Unique -> "UNIQUE")
| TableForeignKeyConstraint (names, fk) ->
String.concat "_" [ for name in names -> name.Value.Value ]
+ "_FK_"
+ fk.ReferencesTable.ObjectName.Value
+ "_"
+ String.concat "_" [ for c in fk.ReferencesColumns -> c.Value.Value ]
| TableCheckConstraint _ -> "CHECK"
type [<NoComparison>] TableConstraint<'t, 'e> =
{ Name : Name
TableConstraintType : TableConstraintType<'t, 'e>
}
type [<NoComparison>] CreateTableDefinition<'t, 'e> =
{ Columns : ColumnDef<'t, 'e> WithSource array
Constraints : TableConstraint<'t, 'e> WithSource array
}
type [<NoComparison>] CreateTableAs<'t, 'e> =
| CreateAsDefinition of CreateTableDefinition<'t, 'e>
| CreateAsSelect of SelectStmt<'t, 'e>
type [<NoComparison>] CreateTableStmt<'t, 'e> =
{ Temporary : bool
Name : ObjectName<'t>
As : CreateTableAs<'t, 'e>
}
type [<NoComparison>] CreateIndexStmt<'t, 'e> =
{ Unique : bool
IndexName : ObjectName<'t>
TableName : ObjectName<'t>
IndexedColumns : (Name * OrderDirection) WithSource array
Where : Expr<'t, 'e> option
}
type AlterTableChangeType<'e> =
{ ExistingInfo : 'e
Column : Name
NewType : TypeName
}
type AlterTableChangeNullability<'e> =
{ ExistingInfo : 'e
Column : Name
NewNullable : bool
}
type AlterTableChangeCollation<'e> =
{ ExistingInfo : 'e
Column : Name
// currently we don't support *removing* collations. if you want the default, you must name it.
NewCollation : Name
}
type [<NoComparison>] AlterTableAlteration<'t, 'e> =
| RenameTo of Name
| AddColumn of ColumnDef<'t, 'e> WithSource
| AddConstraint of TableConstraint<'t, 'e> WithSource
| AddDefault of column : Name * defaultValue : Expr<'t, 'e>
| DropColumn of column : Name
| DropConstraint of constr : Name
| DropDefault of column : Name
| ChangeType of AlterTableChangeType<'e>
| ChangeNullability of AlterTableChangeNullability<'e>
| ChangeCollation of AlterTableChangeCollation<'e>
type [<NoComparison>] AlterTableStmt<'t, 'e> =
{ Table : ObjectName<'t>
Alteration : AlterTableAlteration<'t, 'e>
}
type [<NoComparison>] DeleteStmt<'t, 'e> =
{ With : WithClause<'t, 'e> option
DeleteFrom : ObjectName<'t>
Where : Expr<'t, 'e> option
OrderBy : OrderingTerm<'t, 'e> array option
Limit : Limit<'t, 'e> option
}
type UpdateOr =
| UpdateOrRollback
| UpdateOrAbort
| UpdateOrReplace
| UpdateOrFail
| UpdateOrIgnore
type [<NoComparison>] UpdateStmt<'t, 'e> =
{ With : WithClause<'t, 'e> option
UpdateTable : ObjectName<'t>
Or : UpdateOr option
Set : (Name WithSource * Expr<'t, 'e>) array
Where : Expr<'t, 'e> option
OrderBy : OrderingTerm<'t, 'e> array option
Limit : Limit<'t, 'e> option
}
type InsertOr =
| InsertOrRollback
| InsertOrAbort
| InsertOrReplace
| InsertOrFail
| InsertOrIgnore
type [<NoComparison>] InsertStmt<'t, 'e> =
{ With : WithClause<'t, 'e> option
Or : InsertOr option
InsertInto : ObjectName<'t>
Columns : Name WithSource array
Data : SelectStmt<'t, 'e>
}
type [<NoComparison>] CreateViewStmt<'t, 'e> =
{ Temporary : bool
ViewName : ObjectName<'t>
ColumnNames : Name WithSource array option
AsSelect : SelectStmt<'t, 'e>
}
type DropObjectType =
| DropIndex
| DropTable
| DropView
type [<NoComparison>] DropObjectStmt<'t> =
{ Drop : DropObjectType
ObjectName : ObjectName<'t>
}
type [<NoComparison>] VendorStmtFragment<'t, 'e> =
| VendorEmbeddedExpr of Expr<'t, 'e>
| VendorRaw of string
type [<NoComparison>] VendorStmt<'t, 'e> =
{ VendorName : Name WithSource
Fragments : VendorStmtFragment<'t, 'e> array
ImaginaryStmts : Stmt<'t, 'e> array option
}
and [<NoComparison>] Stmt<'t, 'e> =
| AlterTableStmt of AlterTableStmt<'t, 'e>
| CreateIndexStmt of CreateIndexStmt<'t, 'e>
| CreateTableStmt of CreateTableStmt<'t, 'e>
| CreateViewStmt of CreateViewStmt<'t, 'e>
| DeleteStmt of DeleteStmt<'t, 'e>
| DropObjectStmt of DropObjectStmt<'t>
| InsertStmt of InsertStmt<'t, 'e>
| SelectStmt of SelectStmt<'t, 'e>
| UpdateStmt of UpdateStmt<'t, 'e>
type [<NoComparison>] TotalStmt<'t, 'e> =
| CoreStmt of Stmt<'t, 'e>
| VendorStmt of VendorStmt<'t, 'e>
member this.CoreStmts() =
match this with
| CoreStmt stmt -> Seq.singleton stmt
| VendorStmt { ImaginaryStmts = None } -> Seq.empty
| VendorStmt { ImaginaryStmts = Some stmts } -> stmts :> _ seq
member this.SelectStmts() =
this.CoreStmts()
|> Seq.choose (function | SelectStmt s -> Some s | _ -> None)
type ExprType = ExprType<unit, unit>
type Expr = Expr<unit, unit>
type InExpr = InExpr<unit, unit>
type CollationExpr = CollationExpr<unit, unit>
type BetweenExpr = BetweenExpr<unit, unit>
type SimilarityExpr = SimilarityExpr<unit, unit>
type BinaryExpr = BinaryExpr<unit, unit>
type UnaryExpr = UnaryExpr<unit, unit>
type ObjectName = ObjectName<unit>
type ColumnName = ColumnName<unit>
type InSet = InSet<unit, unit>
type CaseExpr = CaseExpr<unit, unit>
type CastExpr = CastExpr<unit, unit>
type FunctionArguments = FunctionArguments<unit, unit>
type FunctionInvocationExpr = FunctionInvocationExpr<unit, unit>
type WithClause = WithClause<unit, unit>
type CommonTableExpression = CommonTableExpression<unit, unit>
type CompoundExprCore = CompoundExprCore<unit, unit>
type CompoundExpr = CompoundExpr<unit, unit>
type CompoundTermCore = CompoundTermCore<unit, unit>
type CompoundTerm = CompoundTerm<unit, unit>
type CreateTableDefinition = CreateTableDefinition<unit, unit>
type CreateTableStmt = CreateTableStmt<unit, unit>
type SelectCore = SelectCore<unit, unit>
type Join = Join<unit, unit>
type JoinConstraint = JoinConstraint<unit, unit>
type GroupBy = GroupBy<unit, unit>
type Limit = Limit<unit, unit>
type OrderingTerm = OrderingTerm<unit, unit>
type ResultColumnCase = ResultColumnCase<unit, unit>
type ResultColumn = ResultColumn<unit, unit>
type ResultColumns = ResultColumns<unit, unit>
type TableOrSubquery = TableOrSubquery<unit, unit>
type TableExprCore = TableExprCore<unit, unit>
type TableExpr = TableExpr<unit, unit>
type TableInvocation = TableInvocation<unit, unit>
type SelectStmt = SelectStmt<unit, unit>
type ColumnConstraint = ColumnConstraint<unit, unit>
type ColumnDef = ColumnDef<unit, unit>
type AlterTableStmt = AlterTableStmt<unit, unit>
type AlterTableAlteration = AlterTableAlteration<unit, unit>
type CreateIndexStmt = CreateIndexStmt<unit, unit>
type TableIndexConstraintClause = TableIndexConstraintClause<unit, unit>
type TableConstraint = TableConstraint<unit, unit>
type CreateViewStmt = CreateViewStmt<unit, unit>
type DeleteStmt = DeleteStmt<unit, unit>
type DropObjectStmt = DropObjectStmt<unit>
type UpdateStmt = UpdateStmt<unit, unit>
type InsertStmt = InsertStmt<unit, unit>
type VendorStmt = VendorStmt<unit, unit>
type Stmt = Stmt<unit, unit>
type TotalStmt = TotalStmt<unit, unit>
type TotalStmts = TotalStmt IReadOnlyList