adamc@56
|
1 type int
|
adamc@56
|
2 type float
|
adamc@56
|
3 type string
|
adamc@91
|
4
|
adamc@119
|
5 type unit = {}
|
adamc@119
|
6
|
adamc@186
|
7 datatype bool = False | True
|
adamc@186
|
8
|
adamc@284
|
9 (*datatype option t = None | Some of t*)
|
adamc@284
|
10
|
adamc@91
|
11
|
adamc@256
|
12 (** Basic type classes *)
|
adamc@256
|
13
|
adamc@256
|
14 class eq
|
adamc@256
|
15 val eq : t ::: Type -> eq t -> t -> t -> bool
|
adamc@257
|
16 val ne : t ::: Type -> eq t -> t -> t -> bool
|
adamc@256
|
17 val eq_int : eq int
|
adamc@256
|
18 val eq_string : eq string
|
adamc@256
|
19 val eq_bool : eq bool
|
adamc@256
|
20
|
adamc@256
|
21
|
adamc@283
|
22 (** String operations *)
|
adamc@283
|
23
|
adamc@283
|
24 val strcat : string -> string -> string
|
adamc@283
|
25
|
adamc@284
|
26 val intToString : int -> string
|
adamc@285
|
27 val floatToString : float -> string
|
adamc@285
|
28 val boolToString : bool -> string
|
adamc@284
|
29
|
adamc@283
|
30
|
adamc@203
|
31 (** SQL *)
|
adamc@203
|
32
|
adamc@203
|
33 con sql_table :: {Type} -> Type
|
adamc@203
|
34
|
adamc@204
|
35 (*** Queries *)
|
adamc@204
|
36
|
adamc@233
|
37 con sql_query :: {{Type}} -> {Type} -> Type
|
adamc@233
|
38 con sql_query1 :: {{Type}} -> {{Type}} -> {Type} -> Type
|
adamc@234
|
39 con sql_exp :: {{Type}} -> {{Type}} -> {Type} -> Type -> Type
|
adamc@204
|
40
|
adamc@223
|
41 con sql_subset :: {{Type}} -> {{Type}} -> Type
|
adamc@223
|
42 val sql_subset : keep_drop :: {({Type} * {Type})}
|
adamc@223
|
43 -> sql_subset
|
adamc@223
|
44 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
|
adamc@223
|
45 [nm] ~ acc => fields.1 ~ fields.2 =>
|
adamc@223
|
46 [nm = fields.1 ++ fields.2] ++ acc) [] keep_drop)
|
adamc@223
|
47 (fold (fn nm => fn fields :: ({Type} * {Type}) => fn acc =>
|
adamc@223
|
48 [nm] ~ acc =>
|
adamc@223
|
49 [nm = fields.1] ++ acc) [] keep_drop)
|
adamc@223
|
50 val sql_subset_all : tables :: {{Type}}
|
adamc@223
|
51 -> sql_subset tables tables
|
adamc@223
|
52
|
adamc@229
|
53 val sql_query1 : tables ::: {{Type}}
|
adamc@224
|
54 -> grouped ::: {{Type}}
|
adamc@233
|
55 -> selectedFields ::: {{Type}}
|
adamc@233
|
56 -> selectedExps ::: {Type}
|
adamc@223
|
57 -> {From : $(fold (fn nm => fn fields :: {Type} => fn acc =>
|
adamc@223
|
58 [nm] ~ acc => [nm = sql_table fields] ++ acc) [] tables),
|
adamc@234
|
59 Where : sql_exp tables [] [] bool,
|
adamc@224
|
60 GroupBy : sql_subset tables grouped,
|
adamc@234
|
61 Having : sql_exp grouped tables [] bool,
|
adamc@233
|
62 SelectFields : sql_subset grouped selectedFields,
|
adamc@233
|
63 SelectExps : $(fold (fn nm => fn t :: Type => fn acc =>
|
adamc@234
|
64 [nm] ~ acc => [nm = sql_exp grouped tables [] t] ++ acc) [] selectedExps) }
|
adamc@233
|
65 -> sql_query1 tables selectedFields selectedExps
|
adamc@229
|
66
|
adamc@229
|
67 type sql_relop
|
adamc@229
|
68 val sql_union : sql_relop
|
adamc@229
|
69 val sql_intersect : sql_relop
|
adamc@229
|
70 val sql_except : sql_relop
|
adamc@260
|
71 val sql_relop : tables1 ::: {{Type}}
|
adamc@229
|
72 -> tables2 ::: {{Type}}
|
adamc@233
|
73 -> selectedFields ::: {{Type}}
|
adamc@233
|
74 -> selectedExps ::: {Type}
|
adamc@260
|
75 -> sql_relop
|
adamc@233
|
76 -> sql_query1 tables1 selectedFields selectedExps
|
adamc@233
|
77 -> sql_query1 tables2 selectedFields selectedExps
|
adamc@233
|
78 -> sql_query1 selectedFields selectedFields selectedExps
|
adamc@229
|
79
|
adamc@230
|
80 type sql_direction
|
adamc@230
|
81 val sql_asc : sql_direction
|
adamc@230
|
82 val sql_desc : sql_direction
|
adamc@230
|
83
|
adamc@234
|
84 con sql_order_by :: {{Type}} -> {Type} -> Type
|
adamc@234
|
85 val sql_order_by_Nil : tables ::: {{Type}} -> exps :: {Type} -> sql_order_by tables exps
|
adamc@234
|
86 val sql_order_by_Cons : tables ::: {{Type}} -> exps ::: {Type} -> t ::: Type
|
adamc@268
|
87 -> sql_exp tables [] exps t -> sql_direction -> sql_order_by tables exps
|
adamc@234
|
88 -> sql_order_by tables exps
|
adamc@230
|
89
|
adamc@231
|
90 type sql_limit
|
adamc@231
|
91 val sql_no_limit : sql_limit
|
adamc@231
|
92 val sql_limit : int -> sql_limit
|
adamc@231
|
93
|
adamc@232
|
94 type sql_offset
|
adamc@232
|
95 val sql_no_offset : sql_offset
|
adamc@232
|
96 val sql_offset : int -> sql_offset
|
adamc@232
|
97
|
adamc@229
|
98 val sql_query : tables ::: {{Type}}
|
adamc@233
|
99 -> selectedFields ::: {{Type}}
|
adamc@233
|
100 -> selectedExps ::: {Type}
|
adamc@233
|
101 -> {Rows : sql_query1 tables selectedFields selectedExps,
|
adamc@234
|
102 OrderBy : sql_order_by tables selectedExps,
|
adamc@232
|
103 Limit : sql_limit,
|
adamc@232
|
104 Offset : sql_offset}
|
adamc@233
|
105 -> sql_query selectedFields selectedExps
|
adamc@204
|
106
|
adamc@225
|
107 val sql_field : otherTabs ::: {{Type}} -> otherFields ::: {Type} -> fieldType ::: Type -> agg ::: {{Type}}
|
adamc@234
|
108 -> exps ::: {Type}
|
adamc@221
|
109 -> tab :: Name -> field :: Name
|
adamc@234
|
110 -> sql_exp ([tab = [field = fieldType] ++ otherFields] ++ otherTabs) agg exps fieldType
|
adamc@234
|
111
|
adamc@234
|
112 val sql_exp : tabs ::: {{Type}} -> agg ::: {{Type}} -> t ::: Type -> rest ::: {Type} -> nm :: Name
|
adamc@234
|
113 -> sql_exp tabs agg ([nm = t] ++ rest) t
|
adamc@209
|
114
|
adamc@221
|
115 class sql_injectable
|
adamc@221
|
116 val sql_bool : sql_injectable bool
|
adamc@221
|
117 val sql_int : sql_injectable int
|
adamc@221
|
118 val sql_float : sql_injectable float
|
adamc@221
|
119 val sql_string : sql_injectable string
|
adamc@234
|
120 val sql_inject : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type
|
adamc@234
|
121 -> sql_injectable t -> t -> sql_exp tables agg exps t
|
adamc@209
|
122
|
adamc@220
|
123 con sql_unary :: Type -> Type -> Type
|
adamc@220
|
124 val sql_not : sql_unary bool bool
|
adamc@234
|
125 val sql_unary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> arg ::: Type -> res ::: Type
|
adamc@234
|
126 -> sql_unary arg res -> sql_exp tables agg exps arg -> sql_exp tables agg exps res
|
adamc@220
|
127
|
adamc@220
|
128 con sql_binary :: Type -> Type -> Type -> Type
|
adamc@220
|
129 val sql_and : sql_binary bool bool bool
|
adamc@220
|
130 val sql_or : sql_binary bool bool bool
|
adamc@234
|
131 val sql_binary : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
|
adamc@234
|
132 -> arg1 ::: Type -> arg2 ::: Type -> res ::: Type
|
adamc@234
|
133 -> sql_binary arg1 arg2 res -> sql_exp tables agg exps arg1 -> sql_exp tables agg exps arg2
|
adamc@234
|
134 -> sql_exp tables agg exps res
|
adamc@220
|
135
|
adamc@219
|
136 type sql_comparison
|
adamc@219
|
137 val sql_eq : sql_comparison
|
adamc@219
|
138 val sql_ne : sql_comparison
|
adamc@219
|
139 val sql_lt : sql_comparison
|
adamc@219
|
140 val sql_le : sql_comparison
|
adamc@219
|
141 val sql_gt : sql_comparison
|
adamc@219
|
142 val sql_ge : sql_comparison
|
adamc@253
|
143 val sql_comparison : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
|
adamc@236
|
144 -> t ::: Type
|
adamc@253
|
145 -> sql_comparison
|
adamc@234
|
146 -> sql_exp tables agg exps t -> sql_exp tables agg exps t
|
adamc@234
|
147 -> sql_exp tables agg exps bool
|
adamc@203
|
148
|
adamc@235
|
149 val sql_count : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type}
|
adamc@235
|
150 -> unit -> sql_exp tables agg exps int
|
adamc@235
|
151
|
adamc@236
|
152 con sql_aggregate :: Type -> Type
|
adamc@236
|
153 val sql_aggregate : tables ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type
|
adamc@236
|
154 -> sql_aggregate t -> sql_exp agg agg exps t -> sql_exp tables agg exps t
|
adamc@236
|
155
|
adamc@236
|
156 class sql_summable
|
adamc@236
|
157 val sql_summable_int : sql_summable int
|
adamc@236
|
158 val sql_summable_float : sql_summable float
|
adamc@236
|
159 val sql_avg : t ::: Type -> sql_summable t -> sql_aggregate t
|
adamc@236
|
160 val sql_sum : t ::: Type -> sql_summable t -> sql_aggregate t
|
adamc@236
|
161
|
adamc@236
|
162 class sql_maxable
|
adamc@236
|
163 val sql_maxable_int : sql_maxable int
|
adamc@236
|
164 val sql_maxable_float : sql_maxable float
|
adamc@236
|
165 val sql_maxable_string : sql_maxable string
|
adamc@236
|
166 val sql_max : t ::: Type -> sql_maxable t -> sql_aggregate t
|
adamc@236
|
167 val sql_min : t ::: Type -> sql_maxable t -> sql_aggregate t
|
adamc@236
|
168
|
adamc@235
|
169
|
adamc@243
|
170 (*** Executing queries *)
|
adamc@243
|
171
|
adamc@243
|
172 con transaction :: Type -> Type
|
adamc@243
|
173 val return : t ::: Type
|
adamc@243
|
174 -> t -> transaction t
|
adamc@243
|
175 val bind : t1 ::: Type -> t2 ::: Type
|
adamc@243
|
176 -> transaction t1 -> (t1 -> transaction t2)
|
adamc@243
|
177 -> transaction t2
|
adamc@243
|
178
|
adamc@251
|
179 val query : tables ::: {{Type}} -> exps ::: {Type} -> tables ~ exps
|
adamc@252
|
180 -> state ::: Type
|
adamc@243
|
181 -> sql_query tables exps
|
adamc@251
|
182 -> ($(exps ++ fold (fn nm (fields :: {Type}) acc => [nm] ~ acc => [nm = $fields] ++ acc) [] tables)
|
adamc@243
|
183 -> state
|
adamc@243
|
184 -> transaction state)
|
adamc@243
|
185 -> state
|
adamc@243
|
186 -> transaction state
|
adamc@243
|
187
|
adamc@243
|
188
|
adamc@203
|
189 (** XML *)
|
adamc@203
|
190
|
adamc@139
|
191 con tag :: {Type} -> {Unit} -> {Unit} -> {Type} -> {Type} -> Type
|
adamc@91
|
192
|
adamc@91
|
193
|
adamc@139
|
194 con xml :: {Unit} -> {Type} -> {Type} -> Type
|
adamc@141
|
195 val cdata : ctx ::: {Unit} -> use ::: {Type} -> string -> xml ctx use []
|
adamc@104
|
196 val tag : attrsGiven ::: {Type} -> attrsAbsent ::: {Type} -> attrsGiven ~ attrsAbsent
|
adamc@139
|
197 -> ctxOuter ::: {Unit} -> ctxInner ::: {Unit}
|
adamc@139
|
198 -> useOuter ::: {Type} -> useInner ::: {Type} -> useOuter ~ useInner
|
adamc@139
|
199 -> bindOuter ::: {Type} -> bindInner ::: {Type} -> bindOuter ~ bindInner
|
adamc@104
|
200 -> $attrsGiven
|
adamc@139
|
201 -> tag (attrsGiven ++ attrsAbsent) ctxOuter ctxInner useOuter bindOuter
|
adamc@139
|
202 -> xml ctxInner useInner bindInner
|
adamc@139
|
203 -> xml ctxOuter (useOuter ++ useInner) (bindOuter ++ bindInner)
|
adamc@140
|
204 val join : ctx ::: {Unit}
|
adamc@139
|
205 -> use1 ::: {Type} -> bind1 ::: {Type} -> bind2 ::: {Type}
|
adamc@139
|
206 -> use1 ~ bind1 -> bind1 ~ bind2
|
adamc@140
|
207 -> xml ctx use1 bind1
|
adamc@140
|
208 -> xml ctx (use1 ++ bind1) bind2
|
adamc@140
|
209 -> xml ctx use1 (bind1 ++ bind2)
|
adamc@148
|
210 val useMore : ctx ::: {Unit} -> use1 ::: {Type} -> use2 ::: {Type} -> bind ::: {Type}
|
adamc@148
|
211 -> use1 ~ use2
|
adamc@148
|
212 -> xml ctx use1 bind
|
adamc@148
|
213 -> xml ctx (use1 ++ use2) bind
|
adamc@91
|
214
|
adamc@110
|
215 con xhtml = xml [Html]
|
adamc@139
|
216 con page = xhtml [] []
|
adamc@110
|
217
|
adamc@204
|
218 (*** HTML details *)
|
adamc@204
|
219
|
adamc@140
|
220 con html = [Html]
|
adamc@140
|
221 con head = [Head]
|
adamc@140
|
222 con body = [Body]
|
adamc@141
|
223 con lform = [Body, LForm]
|
adamc@93
|
224
|
adamc@140
|
225 val head : unit -> tag [] html head [] []
|
adamc@140
|
226 val title : unit -> tag [] head [] [] []
|
adamc@110
|
227
|
adamc@140
|
228 val body : unit -> tag [] html body [] []
|
adamc@140
|
229 con bodyTag = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
|
adamc@140
|
230 -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
|
adamc@141
|
231 con bodyTagStandalone = fn attrs :: {Type} => ctx ::: {Unit} -> [Body] ~ ctx -> unit
|
adamc@141
|
232 -> tag attrs ([Body] ++ ctx) [] [] []
|
adamc@141
|
233
|
adamc@141
|
234 val br : bodyTagStandalone []
|
adamc@119
|
235
|
adamc@140
|
236 val p : bodyTag []
|
adamc@140
|
237 val b : bodyTag []
|
adamc@140
|
238 val i : bodyTag []
|
adamc@140
|
239 val font : bodyTag [Size = int, Face = string]
|
adamc@140
|
240
|
adamc@140
|
241 val h1 : bodyTag []
|
adamc@140
|
242 val li : bodyTag []
|
adamc@140
|
243
|
adamc@280
|
244 val a : bodyTag [Link = transaction page]
|
adamc@140
|
245
|
adamc@141
|
246 val lform : ctx ::: {Unit} -> [Body] ~ ctx -> bind ::: {Type}
|
adamc@141
|
247 -> xml lform [] bind
|
adamc@141
|
248 -> xml ([Body] ++ ctx) [] []
|
adamc@153
|
249 con lformTag = fn ty :: Type => fn inner :: {Unit} => fn attrs :: {Type} =>
|
adamc@141
|
250 ctx ::: {Unit} -> [LForm] ~ ctx
|
adamc@141
|
251 -> nm :: Name -> unit
|
adamc@153
|
252 -> tag attrs ([LForm] ++ ctx) inner [] [nm = ty]
|
adamc@153
|
253 val textbox : lformTag string [] []
|
adamc@155
|
254 val password : lformTag string [] []
|
adamc@153
|
255 val ltextarea : lformTag string [] []
|
adamc@153
|
256
|
adamc@190
|
257 val checkbox : lformTag bool [] []
|
adamc@190
|
258
|
adamc@153
|
259 con radio = [Body, Radio]
|
adamc@153
|
260 val radio : lformTag string radio []
|
adamc@153
|
261 val radioOption : unit -> tag [Value = string] radio [] [] []
|
adamc@142
|
262
|
adamc@154
|
263 con select = [Select]
|
adamc@154
|
264 val lselect : lformTag string select []
|
adamc@154
|
265 val loption : unit -> tag [Value = string] select [] [] []
|
adamc@154
|
266
|
adamc@142
|
267 val submit : ctx ::: {Unit} -> [LForm] ~ ctx
|
adamc@142
|
268 -> use ::: {Type} -> unit
|
adamc@280
|
269 -> tag [Action = $use -> transaction page] ([LForm] ++ ctx) ([LForm] ++ ctx) use []
|
adamc@283
|
270
|
adamc@283
|
271
|
adamc@283
|
272 (** Aborting *)
|
adamc@283
|
273
|
adamc@283
|
274 val error : t ::: Type -> xml [Body] [] [] -> t
|