let name = __FILE__ let description = "Insert two rows of the given content with a generated provider, and display \ the inserted rows. The configuration is read on the standard input" let speclist () = [] type t = ((string * Int64.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 (fun formatter (content_id, id, content) -> Format.fprintf formatter "@[%s:%Ld@;%s@]" content_id id content)) (** Insert one row of [content], and return its json representation together with one line per value of each multivalued reference field *) let insert_one : Caqti_lwt.connection -> Model.content -> Int64.t -> (string * Int64.t * string) list Lwt.t = fun db content row -> let ( let* ) = Lwt.bind in let* id = Query.insert db content (Common.provider_for content row) in let content_id = Model.Identifier.to_string (Model.Content.id content) in let module Db = (val db) in let* json_result = Db.find (Common.content_as_json content) id in let* json = Caqti_lwt.or_fail json_result in let* ext = Common.collect_references db content id in Lwt.return ((content_id, id, json) :: List.rev ext) 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* lines1 = insert_one db content 1L in let* lines2 = insert_one db content 2L in Lwt.return (lines1 @ lines2)) | _ -> failwith "Invalid arguments"