summaryrefslogtreecommitdiff
path: root/lib/query/update.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2026-11-21 11:23:41 +0100
committerSébastien Dailly <sebastien@dailly.me>2026-11-21 11:23:41 +0100
commitce13c93cf14cb71894481b0303a7058a72a6f4ce (patch)
treebd93186a65f6645cb4401f188d266d743cc2fde7 /lib/query/update.ml
parent172a02b80d8dbdcfe09129d7fa76015bb5ec4d79 (diff)
Load values from the database
Diffstat (limited to 'lib/query/update.ml')
-rw-r--r--lib/query/update.ml28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/query/update.ml b/lib/query/update.ml
index 5b53cb7..08a7551 100644
--- a/lib/query/update.ml
+++ b/lib/query/update.ml
@@ -1,6 +1,6 @@
(** Generate the update queries for a content *)
-type provider = string -> Value.value
+type provider = string -> Model.target Model.Data.any
module UpdateTemplate = Encoder.Map (struct
type 'a t = string
@@ -22,7 +22,7 @@ end)
let update_fields :
Caqti_lwt.connection ->
Model.content ->
- (Intf.t_type * (string * Value.value)) list ->
+ (Intf.t_type * (string * Model.target Model.Data.any)) list ->
int64 ->
unit Lwt.t =
fun db content fields id ->
@@ -141,7 +141,9 @@ let update_mulivaluated_field :
At this step, we can just use the code from the insert module. *)
let remaining = ReferencesSet.(diff values (of_list remaining')) in
- let v = Value.single (t, ReferencesSet.to_seq remaining) in
+ let v =
+ Model.Data.any (Model.Data.v (t, ReferencesSet.to_seq remaining))
+ in
Insert.insert_references db content id field_name v data_type)
Lwt.return_unit fields
@@ -149,7 +151,7 @@ let q :
Caqti_lwt.connection ->
Int64.t ->
Model.content ->
- (string -> Value.value) ->
+ (string -> Model.target Model.Data.any) ->
unit Lwt.t =
fun db id content provider ->
let module Db = (val db) in
@@ -157,15 +159,15 @@ let q :
(* There is a difference between
- - Value.Data.none
- - Value.Data.v (typ, None)
+ - Model.Data.none
+ - Model.Data.v (typ, None)
The former will be ignored in the update, and the value will remain as is.
The latter will set the column to NULL in the database. *)
let fields, references =
Seq.fold_left
(fun ((fields, references) as acc :
- (Intf.t_type * (string * Value.value)) list
+ (Intf.t_type * (string * Model.target Model.Data.any)) list
* (Model.Identifier.t
* Model.target Model.Typ.multireference
* int64 Seq.t)
@@ -173,12 +175,12 @@ let q :
let name = Model.Field.name field in
let (Model.Field.T content_type) = Model.Field.type_ field in
let tt = Intf.TT { name; content_type } in
- let (Value.Data.Any d) = provider (Model.Identifier.to_string name) in
+ let (Model.Data.Any d) = provider (Model.Identifier.to_string name) in
match content_type with
| Model.Typ.MultiReference _ -> (
match d with
- | Value.Data.None -> acc
- | Value.Data.V (t, seq) -> (
+ | Model.Data.None -> acc
+ | Model.Data.V (t, seq) -> (
match
( Model.Typ.eq content_type t,
Model.Typ.eq_ocaml content_type t )
@@ -188,9 +190,9 @@ let q :
| _ -> raise Encoder.TypeMismatch))
| _ -> (
match d with
- | Value.Data.None -> acc
- | Value.Data.V _ as dv ->
- ( (tt, (Model.Identifier.to_string name, Value.Data.any dv))
+ | Model.Data.None -> acc
+ | Model.Data.V _ as dv ->
+ ( (tt, (Model.Identifier.to_string name, Model.Data.any dv))
:: fields,
references )))
([], [])