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/load.ml | |
| parent | 172a02b80d8dbdcfe09129d7fa76015bb5ec4d79 (diff) | |
Load values from the database
Diffstat (limited to 'test/load.ml')
| -rw-r--r-- | test/load.ml | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/load.ml b/test/load.ml new file mode 100644 index 0000000..8f4d2fe --- /dev/null +++ b/test/load.ml @@ -0,0 +1,37 @@ +let name = __FILE__ + +let description = + "Insert two rows of the given content, load them as values with [Value.load] \ + and print them with [Value.pp]. The configuration is read on the standard \ + input" + +let speclist () = [] + +type t = (string list, Configuration.Read_conf.error) result + +let pp : Format.formatter -> t -> unit = + Format.pp_print_result ~error:Configuration.Read_conf.pp_error + ~ok: + (Format.pp_print_list ~pp_sep:Format.pp_print_cut Format.pp_print_string) + +let exec : string list -> t = function + | [ content_id ] -> + Common.exec_with_conf (fun configuration db -> + let content = + Option.get + (Configuration.Ast.get_content configuration + (Model.Identifier.of_string content_id)) + in + let ( let* ) = Lwt.bind in + let* id1 = Query.insert db content (Common.provider_for content 1L) in + let* id2 = Query.insert db content (Common.provider_for content 2L) in + let load_one id = + let v = Value.v content id in + let* () = Value.load db v in + Lwt.return + [ Format.sprintf "row %Ld:" id; Format.asprintf "%a" Value.pp v ] + in + let* lines1 = load_one id1 in + let* lines2 = load_one id2 in + Lwt.return (lines1 @ lines2)) + | _ -> failwith "Invalid arguments" |
