1 (* SQL syntax and RA *)
6 type expr
= | Value
of Sql.Type.t
9 | Column
of string * string option (** name, table *)
12 let expr_to_string = Show.show
<expr
>
17 | Expr
of expr
* string option (** name *)
20 type columns
= column list deriving
(Show
)
22 let collect f l
= List.flatten
(List.map f l
)
24 let get_scheme columns tables
=
25 let all = tables
>> List.map snd
>> List.flatten
in
26 let scheme name
= name
>> Tables.get_from tables
>> snd
in
27 let resolve1 = function
33 | Column
(name
,Some t
) -> RA.Scheme.find
(scheme t
) name
34 | Column
(name
,None
) -> RA.Scheme.find
all name
35 | _
-> RA.attr
"" Sql.Type.Text
37 let col = Option.map_default
(fun n
-> {col with RA.name
= n
}) col name
in
40 collect resolve1 columns
46 | Sub l
-> List.fold_left
loop acc l
48 in loop [] e
>> List.rev
52 let e = Sub [Value Sql.Type.Text; Param (Next,None); Sub []; Param (Named "ds", Some Sql.Type.Int);] in
53 e >> get_params >> to_string >> print_endline
56 let params_of_column = function
58 | Expr
(e,_) -> get_params e
60 let params_of_columns = collect params_of_column
62 let get_params_opt = function
63 | Some x
-> get_params x
66 let get_params_l = collect get_params
68 let scheme_as_params = List.map
(fun attr
-> Named attr
.RA.name
, Some attr
.RA.domain
)