Traits::statement and connection
[sqlgg.git] / sql.ml
blob04421f7d5cb6fb05c6ea1df991adca24c040a8e2
1 (* $Id$ *)
3 open Printf
5 module Type =
6 struct
7 type t = | Int | Text | Blob
8 deriving (Show)
10 let to_string = Show.show<t>
11 (* let to_string = function | Int -> "Int" | Text -> "Text" | Blob -> "Blob" *)
12 let to_cpp_string x = "typename Traits::" ^ (to_string x)
13 end
15 module Constraint =
16 struct
17 type conflict_algo = | Ignore | Replace | Abort | Fail | Rollback
18 deriving (Show)
20 type t = | PrimaryKey | NotNull | Unique | Autoincrement | OnConflict of conflict_algo
21 deriving (Show)
22 end
24 module Col =
25 struct
26 type t = {name:string; cpp_name:string; sqltype:Type.t; constraints:Constraint.t list}
27 deriving (Show)
28 let make name sqltype constraints =
29 {name=name; cpp_name=name; sqltype=sqltype; constraints=constraints}
30 let type_to_string c = Type.to_string c.sqltype
31 let type_to_cpp_string c = Type.to_cpp_string c.sqltype
32 let is_primary_key c = List.mem Constraint.PrimaryKey c.constraints
33 end
35 module Table =
36 struct
37 type t = {name:string; cpp_name:string; cols:Col.t list}
38 deriving (Show)
40 let make name cols = {name=name;cpp_name=name;cols=cols}
41 end