diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-18 20:24:52 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-18 21:57:48 +0100 |
| commit | 62123e577ee5d4066d53f8ad7e5ac3d2eb190430 (patch) | |
| tree | f569686630681a9eceb2685f69b55fe5a2bac17c /lib/model/identifier.ml | |
| parent | 7087a0c2c84e796e474784cbd28d4a4e574cf2c0 (diff) | |
Securized the queries in the database with a dedicated type for the Identifiers
Diffstat (limited to 'lib/model/identifier.ml')
| -rw-r--r-- | lib/model/identifier.ml | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/model/identifier.ml b/lib/model/identifier.ml new file mode 100644 index 0000000..f1a981e --- /dev/null +++ b/lib/model/identifier.ml @@ -0,0 +1,35 @@ +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 |
