10 type attr
= {name
: string; domain
: Type.t
;}
13 let attr n d
= {name
=n
;domain
=d
}
20 exception Error
of t
* string
23 match List.find_all
(fun attr -> attr.name
= name
) t
with
25 | [] -> raise
(Error
(t
,"missing attribute " ^ name
))
26 | _
-> raise
(Error
(t
,"duplicate attribute " ^ name
))
28 let project names t
= List.map
(find t
) names
30 let rename t before after
=
33 | x
when x
= before
-> { attr with name
=after
}
36 let cross t1 t2
= t1
@ t2
40 raise
(Error
(t1
, (Show.show
<t
>(t1
)) ^
" not equal to " ^
(Show.show
<t
>(t2
))))
44 let to_string x
= Show.show
<t
>(x
)
45 let print x
= print_endline
(to_string x
)
49 List.map (fun col -> {Attr.name = None; orig = Some (col,t); domain = col.Col.sqltype}) t.Table.cols
53 type table
= string * Scheme.t deriving
(Show
)
55 let print_table t
= print_endline
(Show.show
<table
>(t
))
60 let test = [{name="a";domain=Type.Int}; {name="b";domain=Type.Int}; {name="c";domain=Type.Text};];;
63 let () = print (project ["b";"c";"b"] test)
64 let () = print (project ["b";"d"] test)
65 let () = print (rename test "a" "new_a")