summaryrefslogtreecommitdiff
path: root/lib/model/identifier.mli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/model/identifier.mli')
-rw-r--r--lib/model/identifier.mli49
1 files changed, 49 insertions, 0 deletions
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