summaryrefslogtreecommitdiff
path: root/src/sql.sig
blob: 317c157f625a40e196fbbe3356e2a46b5ece240e (plain)
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
signature SQL = sig

val debug : bool ref

val sqlcacheMode : bool ref

datatype chunk =
         String of string
       | Exp of Mono.exp

val chunkify : Mono.exp -> chunk list

type lvar = int

datatype func =
         DtCon0 of string
       | DtCon1 of string
       | UnCon of string
       | Other of string

datatype exp =
         Const of Prim.t
       | Var of int
       | Lvar of lvar
       | Func of func * exp list
       | Recd of (string * exp) list
       | Proj of exp * string

datatype cmp =
         Eq
       | Ne
       | Lt
       | Le
       | Gt
       | Ge

datatype reln =
         Known
       | Sql of string
       | PCon0 of string
       | PCon1 of string
       | Cmp of cmp

datatype lop =
         And
       | Or

datatype prop =
         True
       | False
       | Unknown
       | Lop of lop * prop * prop
       | Reln of reln * exp list
       | Cond of exp * prop

type 'a parser

val parse : 'a parser -> Mono.exp -> 'a option

datatype Rel =
         RCmp of cmp
       | RLop of lop

datatype sqexp =
         SqConst of Prim.t
       | SqTrue
       | SqFalse
       | SqNot of sqexp
       | Field of string * string
       | Computed of string
       | Binop of Rel * sqexp * sqexp
       | SqKnown of sqexp
       | Inj of Mono.exp
       | SqFunc of string * sqexp
       | Unmodeled
       | Null

datatype ('a,'b) sum = inl of 'a | inr of 'b

datatype sitem =
         SqField of string * string
       | SqExp of sqexp * string

datatype jtype = Inner | Left | Right | Full

datatype fitem =
         Table of string * string (* table AS name *)
       | Join of jtype * fitem * fitem * sqexp
       | Nested of query * string (* query AS name *)

     and query =
         Query1 of {Select : sitem list, From : fitem list, Where : sqexp option}
       | Union of query * query

val query : query parser

datatype dml =
         Insert of string * (string * sqexp) list
       | Delete of string * sqexp
       | Update of string * (string * sqexp) list * sqexp

val dml : dml parser

end