let bar x = PROJECT [Foo_a, Foo_b] x let selection z x = PROJECT [Foo_whatever] (SELECT [Foo_name = z] x) let foo b c = b + c let selection2 a b c x = SELECT [Foo_name = a AND (Foo_whatever < Foo_something OR Foo_something >= foo b c)] x module Opaque : sig type whatever_id val encode_whatever_id : whatever_id -> string val decode_whatever_id : string -> whatever_id end = struct type 'a opaque_int = int type whatever_id = [`Whatever_id] opaque_int let encode_whatever_id = string_of_int let decode_whatever_id = int_of_string end include Opaque TABLE user users COLUMN id SERIAL AUTO PRIMARY KEY COLUMN name VARCHAR(64) COLUMN age INT NULLABLE COLUMN whatever_id INT(whatever_id) FOREIGN(whatever, id) COLUMN nickname VARCHAR(64) DEFAULT "baka" END let table : ([`Foo_name of string | `Foo_whatever of int | `Foo_something of int | `Foo_a of bool | `Foo_b of float], [`Foo_name | `Foo_whatever | `Foo_something | `Foo_a | `Foo_b ]) Relational.relation = Relational.table "foo" { Relational.value_to_sql = (function `Foo_name s -> s | `Foo_whatever i | `Foo_something i -> string_of_int i | `Foo_a b -> string_of_bool b | `Foo_b f -> string_of_float f); value_of_sql = (fun t isnull s -> match t with `Foo_whatever -> `Foo_whatever (int_of_string s) | `Foo_something -> `Foo_something (int_of_string s) | `Foo_name -> `Foo_name s | `Foo_a -> `Foo_a (s = "true") | `Foo_b -> `Foo_b (float_of_string s)) } ["name"; "whatever"; "something"; "a"; "b"] let foo2 = SELECT [Foo_foo = "bar"] (RENAME [Foo_name AS Foo_foo] table) let foo3 = ORDER [Foo_foo] foo2 let foo4 = ORDER [Foo_name DESC] table let foo5 y = PRODUCT [Foo_foo] [Foo_bar] foo3 y let () = let disp x = print_endline (Relational.to_sql x) in disp (bar table); disp (selection "Koshimizu Haruna" table); disp (selection2 "Jung" 12 12 table); disp foo3