1 (* SQL syntax and RA *)
6 type expr
= | Value
of Sql.Type.t
7 | Param
of Stmt.Raw.param
9 | Column
of string * string option (** name, table *)
15 | Expr
of expr
* string option (** name *)
18 type columns
= column list deriving
(Show
)
20 let collect f l
= List.flatten
(List.map f l
)
22 let get_scheme columns tables
=
23 let all = tables
>> List.map snd
>> List.flatten
in
24 let scheme name
= name
>> Tables.get_from tables
>> snd
in
25 let resolve1 = function
31 | Column
(name
,Some t
) -> RA.Scheme.find
(scheme t
) name
32 | Column
(name
,None
) -> RA.Scheme.find
all name
33 | _
-> RA.attr
"" Sql.Type.Text
35 let col = Option.map_default
(fun n
-> {col with RA.name
= n
}) col name
in
38 collect resolve1 columns
44 | Sub l
-> List.fold_left
loop acc l
50 let e = Sub [Value Sql.Type.Text; Param (Next,None); Sub []; Param (Named "ds", Some Sql.Type.Int);] in
51 e >> get_params >> to_string >> print_endline
54 let params_of_column = function
56 | Expr
(e,_) -> get_params e
58 let params_of_columns = collect params_of_column
60 let get_params_opt = function
61 | Some x
-> get_params x
64 let get_params_l = collect get_params