diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-03-27 08:48:05 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-03-27 08:48:05 +0100 |
| commit | 830e7c5d27d161b91402414e6ecd49f1ed818bfb (patch) | |
| tree | 448864635d29b1ea66424cbb9e0816fbcf1e1907 /test/schema.ml | |
Initial commit
Diffstat (limited to 'test/schema.ml')
| -rw-r--r-- | test/schema.ml | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/schema.ml b/test/schema.ml new file mode 100644 index 0000000..0dc386d --- /dev/null +++ b/test/schema.ml @@ -0,0 +1,32 @@ +let name = __FILE__ +let description = "Print the schema for the given tables" +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_newline + Format.pp_print_string) + +let ( let* ) = Lwt.bind +let ( let+ ) opt cont = Result.map cont opt + +let schema_query = + Caqti_request.Infix.(Caqti_type.(string) ->! Caqti_type.string) + "SELECT sql from sqlite_schema where name=?" + +let get_schema : Caqti_lwt.connection -> string -> string Lwt.t = + fun db table_name -> + let module Db = (val db) in + let* result = Db.find schema_query table_name in + Caqti_lwt.or_fail result + +let exec : string list -> t = + fun tables -> + let stdin = In_channel.input_all stdin in + let+ configuration = Configuration.Read_conf.read_string_conf stdin in + Lwt_main.run + (let* db = Common.connect configuration in + Lwt_list.map_s (get_schema db) (List.rev tables)) |
