From 62123e577ee5d4066d53f8ad7e5ac3d2eb190430 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 18 Nov 2026 20:24:52 +0100 Subject: Securized the queries in the database with a dedicated type for the Identifiers --- lib/model/identifier.ml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/model/identifier.ml (limited to 'lib/model/identifier.ml') 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 -- cgit v1.2.3