diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-21 11:23:41 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-21 11:23:41 +0100 |
| commit | ce13c93cf14cb71894481b0303a7058a72a6f4ce (patch) | |
| tree | bd93186a65f6645cb4401f188d266d743cc2fde7 /test/update.ml | |
| parent | 172a02b80d8dbdcfe09129d7fa76015bb5ec4d79 (diff) | |
Load values from the database
Diffstat (limited to 'test/update.ml')
| -rw-r--r-- | test/update.ml | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/test/update.ml b/test/update.ml index 18c3821..502ad05 100644 --- a/test/update.ml +++ b/test/update.ml @@ -67,7 +67,10 @@ let configuration = let speclist () = let (lazy configuration) = configuration in - let content = Configuration.Ast.get_content configuration (Model.Identifier.of_string "entity") in + let content = + Configuration.Ast.get_content configuration + (Model.Identifier.of_string "entity") + in let fields = Model.Content.fields (Option.get content) in Seq.fold_left (fun acc feature -> @@ -81,7 +84,10 @@ let speclist () = Arg.String (fun value -> actions := - Text (Model.Identifier.to_string (Model.Field.name feature), value) :: !actions), + Text + ( Model.Identifier.to_string (Model.Field.name feature), + value ) + :: !actions), "<v> Set field with the value <v>" ) | Model.Typ.Integer -> Some @@ -89,7 +95,10 @@ let speclist () = Arg.Int (fun value -> actions := - Integer (Model.Identifier.to_string (Model.Field.name feature), value) :: !actions), + Integer + ( Model.Identifier.to_string (Model.Field.name feature), + value ) + :: !actions), "<n> Set field with the value <n>" ) | Model.Typ.MonoReference target -> Some @@ -97,7 +106,10 @@ let speclist () = Arg.Int (fun value -> actions := - Reference (target, Model.Identifier.to_string (Model.Field.name feature), value) + Reference + ( target, + Model.Identifier.to_string (Model.Field.name feature), + value ) :: !actions), "<id> Set field with the id" ) | Model.Typ.MultiReference target -> @@ -112,7 +124,10 @@ let speclist () = in actions := - References (target, Model.Identifier.to_string (Model.Field.name feature), ids) + References + ( target, + Model.Identifier.to_string (Model.Field.name feature), + ids ) :: !actions), "<id,..> Set this list of values" ) in @@ -133,7 +148,9 @@ let exec : string list -> t = fun _ -> let (lazy configuration) = configuration in let content = - Configuration.Ast.get_content configuration (Model.Identifier.of_string "entity") |> Option.get + Configuration.Ast.get_content configuration + (Model.Identifier.of_string "entity") + |> Option.get in Lwt_main.run @@ -141,12 +158,7 @@ let exec : string list -> t = let* db = Common.connect configuration in let module Db = (val db) in (* Insert a content without any value *) - let* inserted = Query.insert db content (fun _ -> Value.none) in - let id = - match Value.get inserted Value.id_ref with - | Some id -> id - | None -> assert false - in + let* id = Query.insert db content (fun _ -> Value.none) in let group_commit : actions Seq.t Seq.t = List.rev !actions |> List.to_seq @@ -167,7 +179,9 @@ let exec : string list -> t = let field = Model.Content.fields content |> Seq.find (fun f -> - String.equal key (Model.Identifier.to_string (Model.Field.name f))) + String.equal key + (Model.Identifier.to_string + (Model.Field.name f))) |> Option.get in let (Model.Field.T t) = Model.Field.type_ field in @@ -182,13 +196,17 @@ let exec : string list -> t = | Text (k, v) when String.equal k key -> Some (Value.single (Model.Typ.Text, Some v)) | Integer (k, v) when String.equal k key -> - Some (Value.single (Model.Typ.Integer, Some (Int64.of_int v))) + Some + (Value.single + (Model.Typ.Integer, Some (Int64.of_int v))) | Reference (target, k, v) when String.equal k key -> Some (Value.single - (Model.Typ.MonoReference target, Some (Int64.of_int v))) + ( Model.Typ.MonoReference target, + Some (Int64.of_int v) )) | References (target, k, v) when String.equal k key -> - Some (Value.single (Model.Typ.MultiReference target, v)) + Some + (Value.single (Model.Typ.MultiReference target, v)) | _ -> None) actions in |
