summaryrefslogtreecommitdiff
path: root/lib/model/model.mli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/model/model.mli')
-rw-r--r--lib/model/model.mli66
1 files changed, 39 insertions, 27 deletions
diff --git a/lib/model/model.mli b/lib/model/model.mli
index afc96f3..8c097f3 100644
--- a/lib/model/model.mli
+++ b/lib/model/model.mli
@@ -7,8 +7,9 @@
list of {!section}s, and optionally sub-contents (a content with a parent is
a subcontent). Each section groups a list of {!field}s. A field has a name,
a label translated in several languages, a {!typ} — text, integer, or a
- reference to another content (single or multivalued) — and optional
- validation rules expressed in a small expression language (see {!Dsl}).
+ reference to another content or to a static {!List.t} (single or
+ multivalued) — and optional validation rules expressed in a small expression
+ language (see {!Dsl}).
For example, this configuration:
@@ -40,32 +41,42 @@
- {!Content}, {!Section}, {!Field} — the structure of the model.
- {!Typ} — the field types, and the values carried by fields.
- {!Reference} — a link from a reference field to its target content.
+ - {!List} — a static list declared in the configuration: referenceable, but
+ not editable by the user.
- {!Dsl} — the expression language used in validation rules and display
criteria.
{2:aliases Resolved types}
The aliases at the end of this file are the model types with references
- resolved to {!Reference.t}. They are the types used everywhere outside this
+ resolved to {!target}. They are the types used everywhere outside this
package: {!content} is what the configuration loader produces and what the
query layer and the HTML renderer operate on. *)
module Identifier = Identifier
-(** Names of contents and fields.
+(** Names of contents, fields and lists.
The type is abstract: the only way to build one is {!Identifier.of_string},
which accepts a non-empty sequence of letters, digits, underscores and
hyphens (rejecting in particular the double quote and the dot), so an
identifier is always safe to embed in a quoted SQL identifier
- ({!Identifier.quote}). *)
+ ({!Identifier.quote}). The fixed columns of the generated schema are
+ predefined: {!Identifier.id}, {!Identifier.parent}, {!Identifier.target}.
+ {!Identifier.dot} builds the composite name of the dedicated table of a
+ multivalued field, e.g. ["entity.user_type"]. *)
module Content = Content
-(** A content: the unit of the model. It has an {!Identifier.t} [id], a list of
- {!Section.t}s, a list of sub-contents, and a weak link to its parent. Build
- one with {!Content.v}; navigate with {!Content.parent} / {!Content.root};
- iterate over all its fields with {!Content.fields}. *)
+(** A content: the unit of the model, editable by the user. It has an
+ {!Identifier.t} [id], a list of {!Section.t}s, a list of sub-contents, and a
+ weak link to its parent. Build one with {!Content.v}; navigate with
+ {!Content.parent} / {!Content.root}; iterate over all its fields with
+ {!Content.fields}. *)
-type content = Reference.t Content.t
+type target = Reference.t Typ.target
+(** The target of a reference field, resolved: either a lazy pointer to a
+ content ({!Typ.Content}) or a static {!List.t} ({!Typ.List}). *)
+
+type content = target Content.t
(** A content : the element produced by the configuration loader and manipulated
by the query and rendering layers. *)
@@ -75,18 +86,19 @@ module Typ = Typ
A field type is one of:
- {!Typ.Text} — a string, stored as a nullable column;
- {!Typ.Integer} — an integer, stored as a nullable column;
- - {!Typ.MonoReference} — a reference to a single content, stored as a
- nullable foreign key;
- - {!Typ.MultiReference} — a reference to several contents of the same kind,
+ - {!Typ.MonoReference} — a reference to a single target ({!target}), stored
+ as a nullable foreign key for a content, or as a plain column for a static
+ list;
+ - {!Typ.MultiReference} — a reference to several targets of the same kind,
stored in a dedicated table ["content.field"].
A {!Typ.reference} record carries the target of a reference field (a
- {!Reference.t}) plus optional [constraints] restricting the allowed values.
- A {!Typ.value} is the data provided for a field when inserting/updating:
+ {!target}) plus optional [constraints] restricting the allowed values. A
+ {!Typ.value} is the data provided for a field when inserting/updating:
{!Typ.None} (leave as is), {!Typ.V} (a single value) or {!Typ.Seq} (a
sequence of references, for multivalued fields). *)
-type 'db typ = ('db, Reference.t) Typ.t
+type 'db typ = ('db, target) Typ.t
(** A field type descriptor ; ['db] is the database representation of the field
(e.g. [string option] for a text field, [int64] for a multivalued reference)
*)
@@ -97,24 +109,24 @@ module Reference = Reference
The target is a lazy pointer ({!Reference.v} / {!Reference.get}): it is
created while the configuration is parsed, before the target content
necessarily exists, and resolved once all contents are registered. This is
- what allows contents to reference each other, including cyclically.
+ what allows contents to reference each other, including cyclically. *)
- This module also defines the aliases for the resolved model types
- ({!Reference.content}, {!Reference.field}, ...), re-exported at the top
- level of this package as {!content}, {!field}, ... *)
+type reference = target Typ.reference
+(** A reference field target: a {!target}, plus optional constraints *)
-type reference = Reference.t Typ.reference
-(** A reference field target: a lazy pointer to a {!content}, plus optional
- constraints *)
+module List = List
+(** A static list declared in the configuration: its entries are loaded from a
+ source (e.g. a CSV file) and the list can be referenced from fields, but it
+ is not editable by the user. *)
module Section = Section
(** A group of fields displayed together, with a per-language [label] and an
optional [criteria] controlling when the whole section is displayed. *)
-type section = Reference.t Section.t
+type section = target Section.t
(** A section of {!content} *)
-type value = Reference.t Typ.value
+type value = target Typ.value
(** A value provided for a field when inserting/updating data *)
module Field = Field
@@ -126,10 +138,10 @@ module Field = Field
per-language error message) and a [criteria] controlling when the field is
displayed. Build one with {!Field.create}. *)
-type field = Reference.t Field.t
+type field = target Field.t
(** A field of {!content} *)
-type field_ex = Reference.t Field.field_ex
+type field_ex = target Field.field_ex
(** The type descriptor of {!field} *)
module Dsl = Dsl