From ce13c93cf14cb71894481b0303a7058a72a6f4ce Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sat, 21 Nov 2026 11:23:41 +0100 Subject: Load values from the database --- test/select.ml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/select.ml (limited to 'test/select.ml') diff --git a/test/select.ml b/test/select.ml new file mode 100644 index 0000000..d185772 --- /dev/null +++ b/test/select.ml @@ -0,0 +1,46 @@ +open StdLabels + +let name = __FILE__ + +let description = + "Insert two rows of the given content, then read them back with \ + [Query.select]. 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 select_one id = + let acc = ref [] in + let* () = + Query.select db id content + { + f = + (fun (named, data) -> + acc := Common.show_field named data :: !acc); + } + in + Lwt.return (List.rev !acc) + in + let* lines1 = select_one id1 in + let* lines2 = select_one id2 in + Lwt.return + (Format.sprintf "row %Ld:" id1 + :: (lines1 @ (Format.sprintf "row %Ld:" id2 :: lines2)))) + | _ -> failwith "Invalid arguments" -- cgit v1.2.3