blob: d7d1f3c0ea61eaa82c11beb93aa7eb95bc734c26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
type t = string
exception Invalid of string
let is_valid : string -> bool =
fun id ->
id <> ""
&& String.for_all
(fun c ->
(c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9')
|| c = '_' || c = '-')
id
let of_string_opt : string -> t option =
fun id -> if is_valid id then Some id else None
let of_string : string -> t =
fun id ->
match of_string_opt id with Some id -> id | None -> raise (Invalid id)
let to_string : t -> string = fun id -> id
(** The fixed columns of the generated schema, predefined so that the SQL
generation can refer to them directly. *)
let id : t = of_string "id"
let parent : t = of_string "parent"
let target : t = of_string "target"
let quote : t -> string = fun id -> "\"" ^ id ^ "\""
let dot : t -> t -> t = fun a b -> a ^ "." ^ b
let equal : t -> t -> bool = String.equal
let compare : t -> t -> int = String.compare
let hash : t -> int = Hashtbl.hash
let pp : Format.formatter -> t -> unit = Format.pp_print_string
|