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.mli | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/model/identifier.mli (limited to 'lib/model/identifier.mli') diff --git a/lib/model/identifier.mli b/lib/model/identifier.mli new file mode 100644 index 0000000..eed5d83 --- /dev/null +++ b/lib/model/identifier.mli @@ -0,0 +1,49 @@ +type t +(** An SQL identifier (table or column name). + + The type is abstract and implemented as a string: the only way to create a + value is {!of_string}, which validates the string. A [t] is therefore always + safe to embed in a quoted SQL identifier, and the query layer never + manipulates raw strings for table or column names. *) + +exception Invalid of string +(** Raised by {!of_string} when the string is not a valid identifier. *) + +val is_valid : string -> bool +(** [is_valid s] is [true] iff [s] is a non-empty sequence of letters, digits, + underscores or hyphens. In particular the double quote (which could break + out of a quoted identifier) and the dot (used internally to build the names + of the dedicated tables for multivalued fields) are rejected. *) + +val of_string : string -> t +(** The only way to build an identifier. @raise Invalid if the string is not + valid. *) + +val of_string_opt : string -> t option +(** [of_string_opt s] is [Some id] if [s] is valid, [None] otherwise. *) + +val to_string : t -> string +(** The underlying string. *) + +val id : t +(** The [id] column: primary key of every content table. *) + +val parent : t +(** The [parent] column: foreign key to the parent content, present in + subcontent tables and in the dedicated tables of multivalued fields. *) + +val target : t +(** The [target] column of the dedicated tables for multivalued fields. *) + +val quote : t -> string +(** [quote id] is the SQL quoted form ["..."] of the identifier. *) + +val dot : t -> t -> t +(** [dot a b] is the identifier ["a.b"], used for the dedicated tables of + multivalued fields. Both parts are already validated and contain no dot, so + the result is safe to quote as a single identifier. *) + +val equal : t -> t -> bool +val compare : t -> t -> int +val hash : t -> int +val pp : Format.formatter -> t -> unit -- cgit v1.2.3