summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/configuration/ast.ml4
-rw-r--r--lib/model/content.ml5
-rw-r--r--lib/model/data.ml6
-rw-r--r--lib/model/data.mli10
-rw-r--r--lib/model/field.ml18
-rw-r--r--lib/model/field.mli10
-rw-r--r--lib/model/identifier.ml1
-rw-r--r--lib/model/model.ml6
-rw-r--r--lib/model/model.mli26
-rw-r--r--lib/model/path.ml6
-rw-r--r--lib/model/types.ml (renamed from lib/model/typ.ml)6
-rw-r--r--lib/model/types.mli (renamed from lib/model/typ.mli)12
-rw-r--r--lib/query/create.ml14
-rw-r--r--lib/query/encoder.ml14
-rw-r--r--lib/query/insert.ml10
-rw-r--r--lib/query/intf.ml19
-rw-r--r--lib/query/select.ml24
-rw-r--r--lib/query/select.mli2
-rw-r--r--lib/query/update.ml14
-rw-r--r--lib/value/value.ml39
-rw-r--r--lib/value/value.mli16
-rw-r--r--test/common.ml42
-rw-r--r--test/identifier.ml4
-rw-r--r--test/insert_list.ml4
-rw-r--r--test/path.ml12
-rw-r--r--test/schema.ml5
-rw-r--r--test/update.ml19
27 files changed, 188 insertions, 160 deletions
diff --git a/lib/configuration/ast.ml b/lib/configuration/ast.ml
index 8ea92b2..6703386 100644
--- a/lib/configuration/ast.ml
+++ b/lib/configuration/ast.ml
@@ -67,7 +67,7 @@ let get_reference_target : Model.field -> Model.content option =
| MonoReference r | MultiReference r -> (
(* References to static lists are leaves of the dependency graph: they
are not followed here. *)
- match r.Model.Typ.t with
+ match r.Model.Types.t with
| Model.Reference.List _ -> None
| Model.Reference.Content ref -> (
try Some (Model.Reference.get ref)
@@ -127,7 +127,7 @@ let check_fields : Model.Identifier.t -> Model.field Seq.t -> unit =
| Some first ->
let (T t1) = Model.Field.type_ first in
let (T t2) = Model.Field.type_ field in
- if Option.is_none (Model.Typ.eq t1 t2) then
+ if Option.is_none (Model.Types.eq t1 t2) then
raise (ConflictingFields (owner, name)))
fields
diff --git a/lib/model/content.ml b/lib/model/content.ml
index 7b9d9a4..a5e5c10 100644
--- a/lib/model/content.ml
+++ b/lib/model/content.ml
@@ -32,7 +32,8 @@ let fields : 'a t -> 'a Field.t Seq.t =
let find_target : 'a t -> string -> 'a option =
fun t name ->
let feature_opt =
- Seq.find (fun f -> String.equal (Identifier.to_string (Field.name f)) name)
+ Seq.find
+ (fun f -> String.equal (Identifier.to_string (Field.name f)) name)
(fields t)
in
@@ -40,5 +41,5 @@ let find_target : 'a t -> string -> 'a option =
let* feature : 'a Field.t = feature_opt in
let (T feature_type) = Field.type_ feature in
match feature_type with
- | MonoReference t | MultiReference t -> Some t.Typ.t
+ | MonoReference t | MultiReference t -> Some t.Types.t
| Integer | Text -> None
diff --git a/lib/model/data.ml b/lib/model/data.ml
index 9c44203..2d00c4e 100644
--- a/lib/model/data.ml
+++ b/lib/model/data.ml
@@ -8,15 +8,15 @@
representation of the field, e.g. [string option] or [int64 option]) and
over ['t], the target of the field for references — a reference is held as
an [int64] (the id of the target row), while ['t] records what it points to.
- The field type {!Typ.t} stays in the model package; only the data itself
+ The field type {!Types.t} stays in the model package; only the data itself
lives here. *)
type ('ocaml, 't) data =
| None
- | V : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data
+ | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data
let none : ('ocaml, 't) data = None
-let v : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data =
+let v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data =
fun (typ, value) -> V (typ, value)
type 't any = Any : ('ocaml, 't) data -> 't any [@@unboxed]
diff --git a/lib/model/data.mli b/lib/model/data.mli
index 6773589..37e7267 100644
--- a/lib/model/data.mli
+++ b/lib/model/data.mli
@@ -8,18 +8,18 @@
data held (e.g. [string option], [int64 option], or [int64 Seq.t] for a
multivalued reference), and over ['t], the target of the field for
references. The DB representation ['db] appears only inside the field type
- carried by the constructors. The field type {!Typ.t} stays in the model
+ carried by the constructors. The field type {!Types.t} stays in the model
package; only the data itself lives here. *)
type ('ocaml, 't) data = private
| None
- | V : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data
+ | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data
val none : ('ocaml, 't) data
(** [none] tells the field is empty in the database (or left as is, on update)
*)
-val v : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data
+val v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data
(** [v (typ, value)] is the value for the field, in its code representation
['ocaml] — e.g. a single [string option], or an [int64 Seq.t] for a
multivalued reference. The field type [typ] is also reported: it ties the
@@ -39,7 +39,7 @@ val any : ('ocaml, 't) data -> 't any
(* Function providing the data of each field to insert in the database *)
let f : string -> Reference.target any = function
- | "siret" -> any (v (Typ.Text, Some "siret"))
- | "name" -> any (v (Typ.Text, Some "name"))
+ | "siret" -> any (v (Types.Text, Some "siret"))
+ | "name" -> any (v (Types.Text, Some "name"))
| _ -> any none
] *)
diff --git a/lib/model/field.ml b/lib/model/field.ml
index feb712d..241a9df 100644
--- a/lib/model/field.ml
+++ b/lib/model/field.ml
@@ -2,11 +2,11 @@ type textI18n = (string * string) list
(** A label is just an association list*)
type validation = { rule : string list Dsl.t; message : textI18n }
-type 't field_ex = T : ('db, 'ocaml, 't) Typ.t -> 't field_ex
+type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex
type 't t =
| F : {
- named : ('db, 'ocaml, 't) Typ.t Typ.named;
+ named : ('db, 'ocaml, 't) Types.t Types.named;
(** Name and type of the field, tied together *)
label : textI18n;
placeholder : textI18n option;
@@ -21,11 +21,11 @@ type 't t =
['a] — this is what lets {!named_of} re-stamp it with a known type.
The type stays abstract in the interface. *)
-let name : 'ref t -> Identifier.t = fun (F f) -> Typ.name f.named
+let name : 'ref t -> Identifier.t = fun (F f) -> Types.name f.named
let label : 'ref t -> textI18n = fun (F f) -> f.label
let placeholder : 'ref t -> textI18n option = fun (F f) -> f.placeholder
let icon : 'ref t -> unit option = fun (F f) -> f.icon
-let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T (Typ.typ f.named)
+let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T (Types.typ f.named)
let required : 'ref t -> bool = fun (F f) -> f.required
let validation : 'ref t -> validation list = fun (F f) -> f.validation
let criteria : 'ref t -> string list Dsl.t option = fun (F f) -> f.criteria
@@ -44,7 +44,7 @@ let create :
?criteria name ->
F
{
- named = Typ.named ~name ~typ;
+ named = Types.named ~name ~typ;
label;
placeholder;
icon;
@@ -54,11 +54,13 @@ let create :
}
let named_of : type db ocaml ref.
- ref t -> (db, ocaml, ref) Typ.t -> ((db, ocaml, ref) Typ.t) Typ.named option =
+ ref t ->
+ (db, ocaml, ref) Types.t ->
+ (db, ocaml, ref) Types.t Types.named option =
fun (F f) typ ->
- match Typ.eq typ f.named.typ with
+ match Types.eq typ f.named.typ with
| None -> None
| Some Type.Equal -> (
- match Typ.eq_ocaml typ f.named.typ with
+ match Types.eq_ocaml typ f.named.typ with
| None -> None
| Some Type.Equal -> Some f.named)
diff --git a/lib/model/field.mli b/lib/model/field.mli
index 0619f33..3a19ab8 100644
--- a/lib/model/field.mli
+++ b/lib/model/field.mli
@@ -2,16 +2,18 @@ type textI18n = (string * string) list
(** A label is just an association list*)
type validation = { rule : string list Dsl.t; message : textI18n }
-type 't field_ex = T : ('db, 'ocaml, 't) Typ.t -> 't field_ex
+type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex
type 'ref t
(** Description of a field *)
val named_of :
- 'ref t -> ('db, 'ocaml, 'ref) Typ.t -> (('db, 'ocaml, 'ref) Typ.t) Typ.named option
-(** [named_of field typ] is [Some named] — the field's {!Typ.named} type,
+ 'ref t ->
+ ('db, 'ocaml, 'ref) Types.t ->
+ ('db, 'ocaml, 'ref) Types.t Types.named option
+(** [named_of field typ] is [Some named] — the field's {!Types.named} type,
stamped with ['db] and ['ocaml] — when [typ] matches the declared type of
- [field] (checked with {!Typ.eq} and {!Typ.eq_ocaml}); [None] on type
+ [field] (checked with {!Types.eq} and {!Types.eq_ocaml}); [None] on type
mismatch *)
val create :
diff --git a/lib/model/identifier.ml b/lib/model/identifier.ml
index f1a981e..d7d1f3c 100644
--- a/lib/model/identifier.ml
+++ b/lib/model/identifier.ml
@@ -25,6 +25,7 @@ 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 ^ "\""
diff --git a/lib/model/model.ml b/lib/model/model.ml
index c3e5b5b..81d8883 100644
--- a/lib/model/model.ml
+++ b/lib/model/model.ml
@@ -4,7 +4,7 @@
module Identifier = Identifier
module Dsl = Dsl
-module Typ = Typ
+module Types = Types
module Data = Data
module Reference = Reference
module DataList = Data_list
@@ -22,5 +22,5 @@ type content = target Content.t
type section = target Section.t
type field = target Field.t
type field_ex = target Field.field_ex
-type reference = target Typ.reference
-type ('db, 'ocaml) typ = ('db, 'ocaml, target) Typ.t
+type reference = target Types.reference
+type ('db, 'ocaml) typ = ('db, 'ocaml, target) Types.t
diff --git a/lib/model/model.mli b/lib/model/model.mli
index 0326eb2..29d6234 100644
--- a/lib/model/model.mli
+++ b/lib/model/model.mli
@@ -39,8 +39,8 @@
- {!Identifier} — the names of contents and fields, validated so that they
are always safe to embed as SQL identifiers.
- {!Content}, {!Section}, {!Field} — the structure of the model.
- - {!Typ} — the field types (the nature of the data; the data itself lives in
- the value package as [Value.value]).
+ - {!Types} — the field types (the nature of the data; the data itself lives
+ in the value package as [Value.value]).
- {!Reference} — a link from a reference field to its target content.
- {!DataList} — a static list declared in the configuration: referenceable,
but not editable by the user.
@@ -85,25 +85,25 @@ type content = target Content.t
(** A content : the element produced by the configuration loader and manipulated
by the query and rendering layers. *)
-module Typ = Typ
+module Types = Types
(** The type of a field, and the values a field can carry.
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 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,
+ - {!Types.Text} — a string, stored as a nullable column;
+ - {!Types.Integer} — an integer, stored as a nullable column;
+ - {!Types.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;
+ - {!Types.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
+ A {!Types.reference} record carries the target of a reference field (a
{!target}) plus optional [constraints] restricting the allowed values. The
data provided for a field when inserting/updating is a [Value.value] (from
the value package): [None] (leave as is), [V] (a single value) or [Seq] (a
sequence of references, for multivalued fields). *)
-type ('db, 'ocaml) typ = ('db, 'ocaml, target) Typ.t
+type ('db, 'ocaml) typ = ('db, 'ocaml, target) Types.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)
*)
@@ -116,7 +116,7 @@ module Reference = Reference
necessarily exists, and resolved once all contents are registered. This is
what allows contents to reference each other, including cyclically. *)
-type reference = target Typ.reference
+type reference = target Types.reference
(** A reference field target: a {!target}, plus optional constraints *)
module Data = Data
@@ -147,7 +147,7 @@ module Field = Field
(** A field of a content.
A field has a {!Identifier.t} name, a [label] as a list of
- [(language, text)] pairs, a {!Typ.field_ex} type, a [required] flag, and
+ [(language, text)] pairs, a {!Types.field_ex} type, a [required] flag, and
optionally a [placeholder], [validation] rules (a {!Dsl} expression plus a
per-language error message) and a [criteria] controlling when the field is
displayed. Build one with {!Field.create}. *)
diff --git a/lib/model/path.ml b/lib/model/path.ml
index dd62864..374b23b 100644
--- a/lib/model/path.ml
+++ b/lib/model/path.ml
@@ -23,9 +23,9 @@ let target_of_field : Reference.target Field.t -> Reference.target option =
fun field ->
let (Field.T ty) = Field.type_ field in
match ty with
- | Typ.MonoReference reference | Typ.MultiReference reference ->
- Some reference.Typ.t
- | Typ.Text | Typ.Integer -> None
+ | Types.MonoReference reference | Types.MultiReference reference ->
+ Some reference.Types.t
+ | Types.Text | Types.Integer -> None
(** Resolve a path from a target.
diff --git a/lib/model/typ.ml b/lib/model/types.ml
index a13653e..ee244d3 100644
--- a/lib/model/typ.ml
+++ b/lib/model/types.ml
@@ -11,9 +11,9 @@ type 'a reference = {
(** A reference from a field to a target (a content or a static list).
The type stays parameterized over ['a] only to break the module dependency
- cycle ([Reference] depends on [Content], which depends on [Field]/[Typ]); in
- practice ['a] is always {!Model.target}. Use the aliases [Model.reference],
- [Model.content], [Model.field], ... at the use sites. *)
+ cycle ([Reference] depends on [Content], which depends on [Field]/[Types]);
+ in practice ['a] is always {!Model.target}. Use the aliases
+ [Model.reference], [Model.content], [Model.field], ... at the use sites. *)
(** Each of the field types available in the application.
diff --git a/lib/model/typ.mli b/lib/model/types.mli
index 42350a3..81c9d5b 100644
--- a/lib/model/typ.mli
+++ b/lib/model/types.mli
@@ -9,8 +9,8 @@
dedicated table (['db = int64]) but manipulated as a sequence in code
(['ocaml = int64 Seq.t]).
- The third parameter ['t] is the target of the field when it is a
- reference (a content or a static list, i.e. {!Model.target}). *)
+ The third parameter ['t] is the target of the field when it is a reference
+ (a content or a static list, i.e. {!Model.target}). *)
type 'a reference = {
t : 'a;
@@ -25,7 +25,7 @@ type 'a reference = {
(** A reference from a field to a target (a content or a static list).
The type stays parameterized over ['a] only to break the module dependency
- cycle ([Reference] depends on [Content], which depends on [Field]/[Typ]);
+ cycle ([Reference] depends on [Content], which depends on [Field]/[Types]);
in practice ['a] is always {!Model.target}. *)
type ('db, 'ocaml, 't) t =
@@ -67,9 +67,9 @@ type 'typ named = {
(** A named field type: a {!t} together with the field's name.
Named types are built on the fly with {!named} (e.g. from a field, see
- {!Field.named_of}) and used locally as typed handles — e.g. to read the
- data of a field from a value. A pre-built instance exists for the reserved
- field ["id"] (see [Value.id_ref]). *)
+ {!Field.named_of}) and used locally as typed handles — e.g. to read the data
+ of a field from a value. A pre-built instance exists for the reserved field
+ ["id"] (see [Value.id_ref]). *)
val named : name:Identifier.t -> typ:'typ -> 'typ named
(** Build a named type from a name and a type — no uniqueness involved, so
diff --git a/lib/query/create.ml b/lib/query/create.ml
index 49047a7..cf364cf 100644
--- a/lib/query/create.ml
+++ b/lib/query/create.ml
@@ -39,8 +39,7 @@ ADD FOREIGN KEY (best_a_id)
REFERENCES answer(a_id);
*)
-let get_foreign_statement :
- Model.Identifier.t -> Model.Identifier.t -> string =
+let get_foreign_statement : Model.Identifier.t -> Model.Identifier.t -> string =
fun property dst_table ->
"FOREIGN KEY("
^ Model.Identifier.quote property
@@ -69,7 +68,7 @@ let create_external_reference_table :
(* The target is the id of a row in the target content table, or in the
dedicated table of the target list *)
let target_table =
- match reference.Model.Typ.t with
+ match reference.Model.Types.t with
| Model.Reference.Content ref ->
Model.Content.id (Model.Reference.get ref)
| Model.Reference.List list -> list.Model.DataList.id
@@ -129,7 +128,7 @@ let create_list_table :
match Model.Field.type_ field with
| T (MonoReference reference) -> (
let column = Model.Field.name field in
- match reference.Model.Typ.t with
+ match reference.Model.Types.t with
| Model.Reference.List target ->
let dst = target.Model.DataList.id in
if List.mem ~set:created dst then
@@ -149,7 +148,7 @@ let create_list_table :
let fields =
"\"id\" INTEGER PRIMARY KEY"
:: List.fold_left list_fields ~init:foreign ~f:(fun acc field ->
- match get_field_query field with None -> acc | Some q -> q :: acc)
+ match get_field_query field with None -> acc | Some q -> q :: acc)
in
let buff = Buffer.create 128 in
let format = Format.formatter_of_buffer buff in
@@ -217,7 +216,7 @@ let rec create_table :
match Model.Field.type_ field with
| T (MonoReference reference) -> (
let column = Model.Field.name field in
- match reference.Model.Typ.t with
+ match reference.Model.Types.t with
| Model.Reference.List list ->
(* The list tables are created before the content tables, so
the constraint can be declared directly *)
@@ -335,7 +334,8 @@ let create : Caqti_lwt.connection -> Configuration.Ast.setting -> unit Lwt.t =
let* foreign, _ =
Lwt_list.fold_left_s
(fun acc list -> create_list_table db acc list)
- ([], []) (Configuration.Ast.lists conf)
+ ([], [])
+ (Configuration.Ast.lists conf)
in
let contents = Configuration.Ast.root_contents conf in
let* foreign, _ =
diff --git a/lib/query/encoder.ml b/lib/query/encoder.ml
index 5e5f402..4c8d528 100644
--- a/lib/query/encoder.ml
+++ b/lib/query/encoder.ml
@@ -304,18 +304,18 @@ module DataToCaqtiValues = Map (struct
| Model.Data.None ->
(* The provider does not have any value for this property, use the
default value*)
- Model.Typ.default_value content_type
+ Model.Types.default_value content_type
| Model.Data.V (field_type', value) -> (
(* For the single-column fields handled here, the DB and code
representations coincide — match the field type to prove it *)
- let check (type x) (ct : (x, x, Model.target) Model.Typ.t) : x =
- match Model.Typ.eq_ocaml ct field_type' with
+ let check (type x) (ct : (x, x, Model.target) Model.Types.t) : x =
+ match Model.Types.eq_ocaml ct field_type' with
| Some Equal -> value
| None -> raise TypeMismatch
in
match content_type with
- | Model.Typ.MultiReference _ -> raise TypeMismatch
- | Model.Typ.Text as ct -> check ct
- | Model.Typ.Integer as ct -> check ct
- | Model.Typ.MonoReference _ as ct -> check ct))
+ | Model.Types.MultiReference _ -> raise TypeMismatch
+ | Model.Types.Text as ct -> check ct
+ | Model.Types.Integer as ct -> check ct
+ | Model.Types.MonoReference _ as ct -> check ct))
end)
diff --git a/lib/query/insert.ml b/lib/query/insert.ml
index 26597d8..98a5c88 100644
--- a/lib/query/insert.ml
+++ b/lib/query/insert.ml
@@ -63,12 +63,12 @@ module MultiReferencesInsert = struct
let parent = Identifier.quote Identifier.parent
and target = Identifier.quote Identifier.target in
match content_type with
- | Model.Typ.MultiReference _target -> (
+ | Model.Types.MultiReference _target -> (
let (Model.Data.Any d) = provider (Model.Identifier.to_string name) in
match d with
| Model.Data.None -> acc
| Model.Data.V (field_type', values) -> (
- match Model.Typ.eq_ocaml content_type field_type' with
+ match Model.Types.eq_ocaml content_type field_type' with
| None -> raise Encoder.TypeMismatch
| Some Equal ->
let q =
@@ -116,7 +116,7 @@ let insert_row :
collect_fields ~init_fields
~filter:(fun field ->
let (T ty) = Model.Field.type_ field in
- match ty with Model.Typ.MultiReference _ -> false | _ -> true)
+ match ty with Model.Types.MultiReference _ -> false | _ -> true)
fields
in
let insert_template =
@@ -150,7 +150,7 @@ let insert_row :
let (T multi_valuated_fields) =
collect_fields fields ~filter:(fun field ->
let (T ty) = Model.Field.type_ field in
- match ty with Model.Typ.MultiReference _ -> true | _ -> false)
+ match ty with Model.Types.MultiReference _ -> true | _ -> false)
in
let acc =
@@ -202,7 +202,7 @@ let insert :
(* Otherwise update the provider to give a value for the parent *)
function
| "parent" ->
- Model.Data.any (Model.Data.v (Model.Typ.Integer, Some parent_id))
+ Model.Data.any (Model.Data.v (Model.Types.Integer, Some parent_id))
| other -> provider other)
in
let module Db = (val db) in
diff --git a/lib/query/intf.ml b/lib/query/intf.ml
index d00c17b..e848d3c 100644
--- a/lib/query/intf.ml
+++ b/lib/query/intf.ml
@@ -15,15 +15,28 @@ type _ tuple =
| T1 : ('a, _) data -> 'a tuple
| T2 : ('a, _) data * ('b, _) data -> ('a * 'b) tuple
| T3 : ('a, _) data * ('b, _) data * ('c, _) data -> ('a * 'b * 'c) tuple
- | T4 : ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data -> ('a * 'b * 'c * 'd) tuple
+ | T4 :
+ ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data
+ -> ('a * 'b * 'c * 'd) tuple
| T5 :
('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data * ('e, _) data
-> ('a * 'b * 'c * 'd * 'e) tuple
| T6 :
- ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data * ('e, _) data * ('f, _) data
+ ('a, _) data
+ * ('b, _) data
+ * ('c, _) data
+ * ('d, _) data
+ * ('e, _) data
+ * ('f, _) data
-> ('a * 'b * 'c * 'd * 'e * 'f) tuple
| T7 :
- ('a, _) data * ('b, _) data * ('c, _) data * ('d, _) data * ('e, _) data * ('f, _) data * ('g, _) data
+ ('a, _) data
+ * ('b, _) data
+ * ('c, _) data
+ * ('d, _) data
+ * ('e, _) data
+ * ('f, _) data
+ * ('g, _) data
-> ('a * 'b * 'c * 'd * 'e * 'f * 'g) tuple
| T8 :
('a, _) data
diff --git a/lib/query/select.ml b/lib/query/select.ml
index ed7fd0b..cdcaeed 100644
--- a/lib/query/select.ml
+++ b/lib/query/select.ml
@@ -6,7 +6,7 @@ let ( let* ) = Lwt.bind
type callback = {
f :
'db 'ocaml.
- ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named * 'ocaml -> unit;
+ ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named * 'ocaml -> unit;
}
(** Call the callback for one single-column field. For those fields the database
@@ -15,16 +15,16 @@ type callback = {
let apply_field : type a b. callback -> (a, b) Intf.data -> a -> unit =
fun k Intf.{ name; content_type } value ->
match content_type with
- | Model.Typ.Text ->
- let named = Model.Typ.named ~name ~typ:content_type in
+ | Model.Types.Text ->
+ let named = Model.Types.named ~name ~typ:content_type in
k.f (named, value)
- | Model.Typ.Integer ->
- let named = Model.Typ.named ~name ~typ:content_type in
+ | Model.Types.Integer ->
+ let named = Model.Types.named ~name ~typ:content_type in
k.f (named, value)
- | Model.Typ.MonoReference _ ->
- let named = Model.Typ.named ~name ~typ:content_type in
+ | Model.Types.MonoReference _ ->
+ let named = Model.Types.named ~name ~typ:content_type in
k.f (named, value)
- | Model.Typ.MultiReference _ -> raise Encoder.TypeMismatch
+ | Model.Types.MultiReference _ -> raise Encoder.TypeMismatch
(** Call the callback for each field of the tuple, zipping the type descriptors
with the row read from the database *)
@@ -134,8 +134,8 @@ let select_multireference :
let name = Model.Field.name field in
let (Model.Field.T content_type) = Model.Field.type_ field in
match content_type with
- | Model.Typ.MultiReference _ ->
- let named = Model.Typ.named ~name ~typ:content_type in
+ | Model.Types.MultiReference _ ->
+ let named = Model.Types.named ~name ~typ:content_type in
let q =
Croquette_common.Format.format_string (fun format ->
Format.fprintf format "SELECT %s FROM %s WHERE %s = ?"
@@ -167,7 +167,7 @@ let select_row :
let init_fields =
if has_parent then
[
- Model.Field.create (Model.Field.T Model.Typ.Integer) [] ~required:true
+ Model.Field.create (Model.Field.T Model.Types.Integer) [] ~required:true
Model.Identifier.parent;
]
else []
@@ -175,7 +175,7 @@ let select_row :
let fields = init_fields @ fields in
let is_multireference field =
match Model.Field.type_ field with
- | Model.Field.T (Model.Typ.MultiReference _) -> true
+ | Model.Field.T (Model.Types.MultiReference _) -> true
| _ -> false
in
let single_fields = List.filter (fun f -> not (is_multireference f)) fields in
diff --git a/lib/query/select.mli b/lib/query/select.mli
index f93455a..68e4d00 100644
--- a/lib/query/select.mli
+++ b/lib/query/select.mli
@@ -3,7 +3,7 @@
type callback = {
f :
'db 'ocaml.
- ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named * 'ocaml -> unit;
+ ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named * 'ocaml -> unit;
}
(** A callback called once per field of the selected row, with the field's named
type and its data in the code representation ['ocaml] — a pair that can be
diff --git a/lib/query/update.ml b/lib/query/update.ml
index 08a7551..9bd1f2b 100644
--- a/lib/query/update.ml
+++ b/lib/query/update.ml
@@ -60,7 +60,7 @@ module ReferenceListEncoder = Encoder.Map (struct
include Encoder.DefaultEncoder
type 'a t = 'a
- type env = Model.target Model.Typ.multireference * Int64.t Seq.t ref
+ type env = Model.target Model.Types.multireference * Int64.t Seq.t ref
let f : type a b. env -> (a, b) Intf.data -> a t =
fun (t, env) d ->
@@ -68,7 +68,7 @@ module ReferenceListEncoder = Encoder.Map (struct
| Seq.Nil -> raise Not_found
| Cons (value, tl) -> (
env := tl;
- match Model.Typ.eq t d.Intf.content_type with
+ match Model.Types.eq t d.Intf.content_type with
| Some Type.Equal -> value
| None -> raise Encoder.TypeMismatch)
end)
@@ -78,7 +78,7 @@ module ReferencesSet = Set.Make (Int64)
let update_mulivaluated_field :
Caqti_lwt.connection ->
Model.content ->
- (Model.Identifier.t * Model.target Model.Typ.multireference * int64 Seq.t)
+ (Model.Identifier.t * Model.target Model.Types.multireference * int64 Seq.t)
list ->
int64 ->
unit Lwt.t =
@@ -169,7 +169,7 @@ let q :
(fun ((fields, references) as acc :
(Intf.t_type * (string * Model.target Model.Data.any)) list
* (Model.Identifier.t
- * Model.target Model.Typ.multireference
+ * Model.target Model.Types.multireference
* int64 Seq.t)
list) field ->
let name = Model.Field.name field in
@@ -177,13 +177,13 @@ let q :
let tt = Intf.TT { name; content_type } in
let (Model.Data.Any d) = provider (Model.Identifier.to_string name) in
match content_type with
- | Model.Typ.MultiReference _ -> (
+ | Model.Types.MultiReference _ -> (
match d with
| Model.Data.None -> acc
| Model.Data.V (t, seq) -> (
match
- ( Model.Typ.eq content_type t,
- Model.Typ.eq_ocaml content_type t )
+ ( Model.Types.eq content_type t,
+ Model.Types.eq_ocaml content_type t )
with
| Some Type.Equal, Some Type.Equal ->
(fields, (name, t, seq) :: references)
diff --git a/lib/value/value.ml b/lib/value/value.ml
index 7a3a4c2..7cd0e52 100644
--- a/lib/value/value.ml
+++ b/lib/value/value.ml
@@ -4,19 +4,19 @@ type value = Model.target Model.Data.any
let none : value = Model.Data.any Model.Data.none
-let single : ('db, 'ocaml, Model.target) Model.Typ.t * 'ocaml -> value =
+let single : ('db, 'ocaml, Model.target) Model.Types.t * 'ocaml -> value =
fun data -> Model.Data.any (Model.Data.v data)
(** The key of the fields dictionary: an existential pack over the named type of
a field, hiding its ['db] and ['ocaml] parameters *)
type key =
- | Named : ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named -> key
+ | Named : ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named -> key
module Key = struct
type t = key
- let equal : t -> t -> bool = fun (Named a) (Named b) -> Model.Typ.same a b
- let hash : t -> int = fun (Named n) -> Hashtbl.hash (Model.Typ.name n)
+ let equal : t -> t -> bool = fun (Named a) (Named b) -> Model.Types.same a b
+ let hash : t -> int = fun (Named n) -> Hashtbl.hash (Model.Types.name n)
end
module Fields = Hashtbl.Make (Key)
@@ -38,25 +38,27 @@ let target : t -> Model.target = fun t -> t.target
let id : t -> int64 = fun t -> t.id
let add_field : type ocaml.
- t -> ('db, ocaml, Model.target) Model.Typ.t Model.Typ.named -> ocaml -> unit
- =
+ t ->
+ ('db, ocaml, Model.target) Model.Types.t Model.Types.named ->
+ ocaml ->
+ unit =
fun t ref data ->
- let typ = Model.Typ.typ ref in
+ let typ = Model.Types.typ ref in
Fields.replace t.fields (Named ref)
(Model.Data.any (Model.Data.v (typ, data)))
-let id_ref : Model.target Model.Typ.monoreference Model.Typ.named =
- Model.Typ.named ~name:Model.Identifier.id ~typ:Model.Typ.Integer
+let id_ref : Model.target Model.Types.monoreference Model.Types.named =
+ Model.Types.named ~name:Model.Identifier.id ~typ:Model.Types.Integer
let get : type ocaml.
- t -> ('db, ocaml, Model.target) Model.Typ.t Model.Typ.named -> ocaml =
+ t -> ('db, ocaml, Model.target) Model.Types.t Model.Types.named -> ocaml =
fun t ref ->
- match Model.Typ.provably_equal id_ref ref with
+ match Model.Types.provably_equal id_ref ref with
| Some Type.Equal -> Some t.id
| None -> (
match Fields.find_opt t.fields (Named ref) with
| Some (Model.Data.Any (Model.Data.V (typ, payload))) -> (
- match Model.Typ.eq_ocaml (Model.Typ.typ ref) typ with
+ match Model.Types.eq_ocaml (Model.Types.typ ref) typ with
| Some Type.Equal -> payload
| None -> raise Not_found)
| _ -> raise Not_found)
@@ -86,7 +88,8 @@ let load : Caqti_lwt.connection -> Model.target -> Int64.t -> t Lwt.t =
(** Pretty-print the data of a field, whatever its type *)
let pp_data : type db ocaml.
- Format.formatter -> (db, ocaml, Model.target) Model.Typ.t -> ocaml -> unit =
+ Format.formatter -> (db, ocaml, Model.target) Model.Types.t -> ocaml -> unit
+ =
fun fmt typ data ->
let pp_option pp fmt data =
match data with
@@ -94,13 +97,13 @@ let pp_data : type db ocaml.
| None -> Format.pp_print_string fmt "NULL"
in
match typ with
- | Model.Typ.Text ->
+ | Model.Types.Text ->
pp_option (fun fmt s -> Format.fprintf fmt "%S" s) fmt data
- | Model.Typ.Integer ->
+ | Model.Types.Integer ->
pp_option (fun fmt i -> Format.fprintf fmt "%Ld" i) fmt data
- | Model.Typ.MonoReference _ ->
+ | Model.Types.MonoReference _ ->
pp_option (fun fmt i -> Format.fprintf fmt "%Ld" i) fmt data
- | Model.Typ.MultiReference _ ->
+ | Model.Types.MultiReference _ ->
Format.fprintf fmt "[%a]"
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.pp_print_string fmt ", ")
@@ -111,7 +114,7 @@ let pp : Format.formatter -> t -> unit =
fun fmt t ->
let fields =
Fields.fold
- (fun (Named named) data acc -> (Model.Typ.name named, data) :: acc)
+ (fun (Named named) data acc -> (Model.Types.name named, data) :: acc)
t.fields []
|> List.sort (fun (n1, _) (n2, _) -> Model.Identifier.compare n1 n2)
in
diff --git a/lib/value/value.mli b/lib/value/value.mli
index 9ebbca6..eb03965 100644
--- a/lib/value/value.mli
+++ b/lib/value/value.mli
@@ -9,7 +9,7 @@ type value = Model.target Model.Data.any
val none : value
(** [none]: the field is empty (or left as is, on update) *)
-val single : ('db, 'ocaml, Model.target) Model.Typ.t * 'ocaml -> value
+val single : ('db, 'ocaml, Model.target) Model.Types.t * 'ocaml -> value
(** [single (typ, data)]: the value for the field, in its code representation
['ocaml] — a single value, or an [int64 Seq.t] for a multivalued reference —
together with the type [typ] of the field *)
@@ -35,20 +35,22 @@ val id : t -> int64
than [get v id_ref] when the raw [int64] is what is needed (e.g. to run a
query on the row) *)
-val id_ref : Model.target Model.Typ.monoreference Model.Typ.named
-(** The pre-built {!Model.Typ.named} handle of the reserved field ["id"]
+val id_ref : Model.target Model.Types.monoreference Model.Types.named
+(** The pre-built {!Model.Types.named} handle of the reserved field ["id"]
({!Model.Identifier.id}) — an integer field present in every row, content or
list. This is the key to read the primary key of any value. *)
-val get : t -> ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named -> 'ocaml
+val get :
+ t -> ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named -> 'ocaml
(** Read a field of the value and return its data directly in its code
representation ['ocaml] — e.g. [get v id_ref : int64 option] is the primary
key of [v], and a multivalued reference field would yield an [int64 Seq.t].
The match between the requested named type and the readable field is proved
- by {!Model.Typ.provably_equal} on name and type. The reserved field [id_ref]
- is always readable; the other fields are read from the value's dictionary
- (populated by {!load} or {!load'}) and raise [Not_found] when absent. *)
+ by {!Model.Types.provably_equal} on name and type. The reserved field
+ [id_ref] is always readable; the other fields are read from the value's
+ dictionary (populated by {!load} or {!load'}) and raise [Not_found] when
+ absent. *)
val load : Caqti_lwt.connection -> Model.target -> Int64.t -> t Lwt.t
(** [load db target id] builds the value for the row [id] of [target] — a
diff --git a/test/common.ml b/test/common.ml
index b1032e9..7b486b4 100644
--- a/test/common.ml
+++ b/test/common.ml
@@ -65,13 +65,13 @@ let field_columns :
let (Model.Field.T ty) = Model.Field.type_ field in
let key = Model.Identifier.to_string name in
match ty with
- | Model.Typ.MultiReference _ -> []
- | Model.Typ.MonoReference reference when annotate_references ->
+ | Model.Types.MultiReference _ -> []
+ | Model.Types.MonoReference reference when annotate_references ->
[
(key, Model.Identifier.quote name);
( key ^ "_table",
Croquette_common.Sql.quote_literal
- (target_table reference.Model.Typ.t) );
+ (target_table reference.Model.Types.t) );
]
| _ -> [ (key, Model.Identifier.quote name) ])
fields
@@ -144,7 +144,7 @@ let collect_references :
Seq.filter
(fun field ->
let (T ty) = Model.Field.type_ field in
- match ty with Model.Typ.MultiReference _ -> true | _ -> false)
+ match ty with Model.Types.MultiReference _ -> true | _ -> false)
(Model.Content.fields content)
|> List.of_seq
in
@@ -186,16 +186,17 @@ let provider_for_fields : Model.field list -> Int64.t -> string -> Value.value =
| Some field -> (
let (Model.Field.T ty) = Model.Field.type_ field in
match ty with
- | Model.Typ.Text ->
+ | Model.Types.Text ->
Value.single
- (Model.Typ.Text, Some (field_name ^ "-" ^ Int64.to_string row))
- | Model.Typ.Integer -> Value.single (Model.Typ.Integer, Some row)
- | Model.Typ.MonoReference reference ->
- Value.single (Model.Typ.MonoReference reference, Some 1L)
- | Model.Typ.MultiReference reference ->
+ (Model.Types.Text, Some (field_name ^ "-" ^ Int64.to_string row))
+ | Model.Types.Integer -> Value.single (Model.Types.Integer, Some row)
+ | Model.Types.MonoReference reference ->
+ Value.single (Model.Types.MonoReference reference, Some 1L)
+ | Model.Types.MultiReference reference ->
(* Several values per row, to highlight the multivalued data *)
let values = if Int64.equal row 1L then [ 1L; 2L ] else [ 2L ] in
- Value.single (Model.Typ.MultiReference reference, List.to_seq values))
+ Value.single (Model.Types.MultiReference reference, List.to_seq values)
+ )
(** Same, for the fields of a content *)
let provider_for : Model.content -> Int64.t -> string -> Value.value =
@@ -207,33 +208,34 @@ let provider_for : Model.content -> Int64.t -> string -> Value.value =
(** Render a [(named, data)] pair as a single line, whatever the field type *)
let show_field :
'db 'ocaml.
- ('db, 'ocaml, Model.target) Model.Typ.t Model.Typ.named -> 'ocaml -> string
- =
+ ('db, 'ocaml, Model.target) Model.Types.t Model.Types.named ->
+ 'ocaml ->
+ string =
fun named data ->
- let name = Model.Identifier.to_string (Model.Typ.name named) in
+ let name = Model.Identifier.to_string (Model.Types.name named) in
let show : type db ocaml.
- (db, ocaml, Model.target) Model.Typ.t -> ocaml -> string =
+ (db, ocaml, Model.target) Model.Types.t -> ocaml -> string =
fun typ data ->
match typ with
- | Model.Typ.Text -> (
+ | Model.Types.Text -> (
match data with
| Some s -> name ^ " = \"" ^ s ^ "\""
| None -> name ^ " = NULL")
- | Model.Typ.Integer -> (
+ | Model.Types.Integer -> (
match data with
| Some i -> name ^ " = " ^ Int64.to_string i
| None -> name ^ " = NULL")
- | Model.Typ.MonoReference _ -> (
+ | Model.Types.MonoReference _ -> (
match data with
| Some i -> name ^ " -> " ^ Int64.to_string i
| None -> name ^ " = NULL")
- | Model.Typ.MultiReference _ ->
+ | Model.Types.MultiReference _ ->
let targets = List.of_seq data |> List.sort compare in
name ^ " -> ["
^ String.concat "," (List.map Int64.to_string targets)
^ "]"
in
- show (Model.Typ.typ named) data
+ show (Model.Types.typ named) data
(** Read a configuration from the standard input and run [f] with a fresh
in-memory database created from it *)
diff --git a/test/identifier.ml b/test/identifier.ml
index 322f459..34855e5 100644
--- a/test/identifier.ml
+++ b/test/identifier.ml
@@ -12,8 +12,8 @@ type t = string list
let pp : Format.formatter -> t -> unit =
Format.pp_print_list ~pp_sep:Format.pp_print_newline Format.pp_print_string
-(** A valid name is printed in its quoted SQL form, an invalid one is
- reported *)
+(** A valid name is printed in its quoted SQL form, an invalid one is reported
+*)
let check : string -> string =
fun s ->
match Model.Identifier.of_string_opt s with
diff --git a/test/insert_list.ml b/test/insert_list.ml
index 88e17db..3435693 100644
--- a/test/insert_list.ml
+++ b/test/insert_list.ml
@@ -54,12 +54,12 @@ let exec : string list -> t =
List.filter_map list.Model.DataList.fields ~f:(fun field ->
let (Model.Field.T ty) = Model.Field.type_ field in
match ty with
- | Model.Typ.MultiReference reference ->
+ | Model.Types.MultiReference reference ->
Some
( Model.Identifier.dot list.Model.DataList.id
(Model.Field.name field),
Model.Identifier.of_string
- (Common.target_table reference.Model.Typ.t) )
+ (Common.target_table reference.Model.Types.t) )
| _ -> None))
in
let* ext_rows =
diff --git a/test/path.ml b/test/path.ml
index 73daf4a..588c398 100644
--- a/test/path.ml
+++ b/test/path.ml
@@ -26,15 +26,15 @@ let describe_field : Model.field -> string =
let name = Model.Identifier.to_string (Model.Field.name field) in
let (Model.Field.T ty) = Model.Field.type_ field in
match ty with
- | Model.Typ.Text -> "field " ^ name ^ " (text)"
- | Model.Typ.Integer -> "field " ^ name ^ " (integer)"
- | Model.Typ.MonoReference reference ->
+ | Model.Types.Text -> "field " ^ name ^ " (text)"
+ | Model.Types.Integer -> "field " ^ name ^ " (integer)"
+ | Model.Types.MonoReference reference ->
"field " ^ name ^ " (reference -> "
- ^ string_of_target reference.Model.Typ.t
+ ^ string_of_target reference.Model.Types.t
^ ")"
- | Model.Typ.MultiReference reference ->
+ | Model.Types.MultiReference reference ->
"field " ^ name ^ " (multireference -> "
- ^ string_of_target reference.Model.Typ.t
+ ^ string_of_target reference.Model.Types.t
^ ")"
let exec : string list -> t =
diff --git a/test/schema.ml b/test/schema.ml
index 5fcd406..4323368 100644
--- a/test/schema.ml
+++ b/test/schema.ml
@@ -14,7 +14,8 @@ let ( let* ) = Lwt.bind
let ( let+ ) opt cont = Result.map cont opt
let schema_query =
- Caqti.Templater.static Caqti.Templater.T.(string -->! string)
+ Caqti.Templater.static
+ Caqti.Templater.T.(string -->! string)
"SELECT sql from sqlite_schema where name=?"
let get_schema : Caqti_lwt.connection -> string -> string Lwt.t =
@@ -28,4 +29,4 @@ let exec : string list -> t =
let stdin = Common.read_stdin () in
let+ configuration = Configuration.Read_conf.read_string_conf stdin in
Common.with_db configuration (fun db ->
- Lwt_list.map_s (get_schema db) (List.rev tables))
+ Lwt_list.map_s (get_schema db) (List.rev tables))
diff --git a/test/update.ml b/test/update.ml
index 502ad05..f9c36a7 100644
--- a/test/update.ml
+++ b/test/update.ml
@@ -78,7 +78,7 @@ let speclist () =
let (Model.Field.T type_) = Model.Field.type_ feature in
let argument =
match type_ with
- | Model.Typ.Text ->
+ | Model.Types.Text ->
Some
( key,
Arg.String
@@ -89,7 +89,7 @@ let speclist () =
value )
:: !actions),
"<v> Set field with the value <v>" )
- | Model.Typ.Integer ->
+ | Model.Types.Integer ->
Some
( key,
Arg.Int
@@ -100,7 +100,7 @@ let speclist () =
value )
:: !actions),
"<n> Set field with the value <n>" )
- | Model.Typ.MonoReference target ->
+ | Model.Types.MonoReference target ->
Some
( key,
Arg.Int
@@ -112,7 +112,7 @@ let speclist () =
value )
:: !actions),
"<id> Set field with the id" )
- | Model.Typ.MultiReference target ->
+ | Model.Types.MultiReference target ->
Some
( key,
Arg.String
@@ -186,7 +186,7 @@ let exec : string list -> t =
in
let (Model.Field.T t) = Model.Field.type_ field in
begin match t with
- | Model.Typ.MultiReference _ as e ->
+ | Model.Types.MultiReference _ as e ->
Some (Value.single (e, Seq.empty))
| Integer as e -> Some (Value.single (e, None))
| Text as e -> Some (Value.single (e, None))
@@ -194,19 +194,20 @@ let exec : string list -> t =
Some (Value.single (e, None))
end
| Text (k, v) when String.equal k key ->
- Some (Value.single (Model.Typ.Text, Some v))
+ Some (Value.single (Model.Types.Text, Some v))
| Integer (k, v) when String.equal k key ->
Some
(Value.single
- (Model.Typ.Integer, Some (Int64.of_int v)))
+ (Model.Types.Integer, Some (Int64.of_int v)))
| Reference (target, k, v) when String.equal k key ->
Some
(Value.single
- ( Model.Typ.MonoReference target,
+ ( Model.Types.MonoReference target,
Some (Int64.of_int v) ))
| References (target, k, v) when String.equal k key ->
Some
- (Value.single (Model.Typ.MultiReference target, v))
+ (Value.single
+ (Model.Types.MultiReference target, v))
| _ -> None)
actions
in