summaryrefslogtreecommitdiff
path: root/lib/query
diff options
context:
space:
mode:
Diffstat (limited to 'lib/query')
-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
7 files changed, 55 insertions, 42 deletions
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)