diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-20 18:47:26 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-20 18:47:26 +0100 |
| commit | fa4970bf1b74f3fa0b2f63cbd461d98c251dc0f0 (patch) | |
| tree | 577a41415e67510f08f43fc48c794c36a10f6e80 /lib/query/update.ml | |
| parent | b05e2d2be7be28ee6c577671002797cf9abaf177 (diff) | |
Updated the model for representing ocaml types in the application type
Diffstat (limited to 'lib/query/update.ml')
| -rw-r--r-- | lib/query/update.ml | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/lib/query/update.ml b/lib/query/update.ml index 90db29d..ec1510b 100644 --- a/lib/query/update.ml +++ b/lib/query/update.ml @@ -6,7 +6,7 @@ module UpdateTemplate = Encoder.Map (struct type 'a t = string type env = unit - let f : type a. unit -> a Intf.data -> a t = + let f : type a b. unit -> (a, b) Intf.data -> a t = fun () -> function | { name = column; content_type = Text; _ } -> Model.Identifier.quote column ^ "=?" @@ -60,9 +60,9 @@ module ReferenceListEncoder = Encoder.Map (struct include Encoder.DefaultEncoder type 'a t = 'a - type env = (int64, Model.target) Model.Typ.t * Int64.t Seq.t ref + type env = Model.target Model.Typ.multireference * Int64.t Seq.t ref - let f : type a. env -> a Intf.data -> a t = + let f : type a b. env -> (a, b) Intf.data -> a t = fun (t, env) d -> match !env () with | Seq.Nil -> raise Not_found @@ -78,8 +78,7 @@ module ReferencesSet = Set.Make (Int64) let update_mulivaluated_field : Caqti_lwt.connection -> Model.content -> - (Model.Identifier.t * (int64, Model.target) Model.Typ.t * int64 Seq.t) - list -> + (Model.Identifier.t * Model.target Model.Typ.multireference * int64 Seq.t) list -> int64 -> unit Lwt.t = fun db content fields id -> @@ -141,7 +140,7 @@ 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.multi (t, ReferencesSet.to_seq remaining) in + let v = Value.single (t, ReferencesSet.to_seq remaining) in Insert.insert_references db content id field_name v data_type) Lwt.return_unit fields @@ -157,29 +156,42 @@ let q : (* There is a difference between - - Typ.None - - Typ.V None - - The former will be ignored in the update, and the value will remains as is - The later will set the content to NULL in the database. *) + - Value.Data.none + - Value.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) field -> + (fun ((fields, references) as acc : + (Intf.t_type * (string * Value.value)) list + * (Model.Identifier.t * Model.target Model.Typ.multireference * int64 Seq.t) list) + field -> 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 = provider (Model.Identifier.to_string name) in match value with | Value.Data.Any d -> ( - match d with - | Value.Data.None -> acc - | Value.Data.V _ as dv -> - ( ( tt, - (Model.Identifier.to_string name, Value.Data.any dv) ) - :: fields, - references ) - | Value.Data.Seq (t, seq) -> - (fields, (name, t, seq) :: references))) + match content_type with + | Model.Typ.MultiReference _ -> ( + match d with + | Value.Data.None -> acc + | Value.Data.V (t, seq) -> ( + match + ( Model.Typ.eq content_type t, + Model.Typ.eq_ocaml content_type t ) + with + | Some Type.Equal, Some Type.Equal -> + (fields, (name, t, seq) :: references) + | _ -> 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)) + :: fields, + references )))) ([], []) (Model.Content.fields content) in |
