diff options
Diffstat (limited to 'bin/importer.ml')
-rw-r--r-- | bin/importer.ml | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/bin/importer.ml b/bin/importer.ml index 8549643..0da2ab7 100644 --- a/bin/importer.ml +++ b/bin/importer.ml @@ -24,18 +24,18 @@ let creation_date file = module Args = struct type arguments = { - configuration : ImportConf.Syntax.t; + configuration : ImporterSyntax.t; conf_name : string; bom : bool; print_conf : bool; mapping_date : float option; } - let load_conf : string -> ImportConf.Syntax.t = + let load_conf : string -> ImporterSyntax.t = fun file -> match Filename.extension file with | _ -> ( - let (conf : (Db.Syntax.t, string) result) = + let (conf : (ImporterSyntax.t, string) result) = let* configuration_file = try Ok (Otoml.Parser.from_file (exists file)) with | Otoml.Parse_error (position, message) -> @@ -60,7 +60,7 @@ module Args = struct | Ok e -> e) let load () = - let conf = ref ("", ImportConf.dummy_conf) + let conf = ref ("", ImporterSyntax.dummy_conf) and bom = ref true and usage = "importer [--conf configuration.toml]" and print_conf = ref false in @@ -101,11 +101,11 @@ end function is expected to convert the result into string in order to include the content in the output CSV. *) let printer : - string -> Path.t ImportExpression.T.t * ImportCSV.DataType.t -> string = + string -> Path.t ImportExpression.T.t * ImportDataTypes.Value.t -> string = fun locale (column, value) -> ignore column; (* Set the output locale accoording the configuration file *) - ImportCSV.DataType.to_string locale value + ImportDataTypes.Value.to_string locale value let bom = "\xEF\xBB\xBF" @@ -137,7 +137,7 @@ let process_table : table. *) match ImportSQL.Db.query_headers db source with | Ok v -> - let f = ImportCSV.DataType.to_string locale in + let f = ImportDataTypes.Value.to_string locale in let text_headers = Array.map v ~f in Headers.SheeetMap.add source text_headers map | Error _ -> map) @@ -163,24 +163,23 @@ let process_table : match headers_opt with | None -> map | Some v -> - let f = ImportCSV.DataType.to_string locale in + let f = ImportDataTypes.Value.to_string locale in let text_headers = Array.map v ~f in Headers.SheeetMap.add source text_headers map in headers let check_deps : - 'a Db.t -> Csv.out_channel Lazy.t -> ImportConf.Syntax.t -> Table.t -> unit - = + 'a Db.t -> Csv.out_channel Lazy.t -> ImporterSyntax.t -> Table.t -> unit = fun db log_error conf source -> (* For each external check if the values are loaded *) - let dependancies = ImportConf.get_dependancies_for_table conf source in + let dependancies = ImporterSyntax.get_dependancies_for_table conf source in List.iter dependancies ~f:(fun ext -> - match ext.ImportConf.Syntax.Extern.allow_missing with + match ext.ImporterSyntax.Extern.allow_missing with | true -> () | false -> ( Printf.printf "Checking dependancies for %s\n%!" - ext.ImportConf.Syntax.Extern.target.ImportDataTypes.Table.name; + ext.ImporterSyntax.Extern.target.ImportDataTypes.Table.name; try ignore @@ Db.check_foreign db conf ext ~f:(fun values -> @@ -188,7 +187,7 @@ let check_deps : let row = match snd (Array.get values 0) with - | ImportCSV.DataType.Integer i -> i + | ImportDataTypes.Value.Integer i -> i | _ -> -1 and value = snd (Array.get values 1) in let error = @@ -198,11 +197,11 @@ let check_deps : sheet = source.Table.tab; row; value; - target = Some ext.ImportConf.Syntax.Extern.target; + target = Some ext.ImporterSyntax.Extern.target; exn = Failure (Printf.sprintf "Key '%s' not found" - (CSV.DataType.to_string "C" value)); + (ImportDataTypes.Value.to_string "C" value)); } in @@ -232,7 +231,7 @@ let () = (* With the printconf option, we do not need to open any file *) if conf.print_conf then ( - let toml = ImportConf.Syntax.repr conf.configuration in + let toml = ImporterSyntax.repr conf.configuration in Otoml.Printer.to_channel ~collapse_tables:true stdout toml; exit 0); |