diff options
Diffstat (limited to 'lib/file_handler/csv2sql.ml')
-rw-r--r-- | lib/file_handler/csv2sql.ml | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/file_handler/csv2sql.ml b/lib/file_handler/csv2sql.ml index 42d84eb..a009f74 100644 --- a/lib/file_handler/csv2sql.ml +++ b/lib/file_handler/csv2sql.ml @@ -1,34 +1,33 @@ open StdLabels module A = ImportAnalyser.Dependency -module CSV = ImportCSV module C = ImportContainers -module Syntax = ImportConf.Syntax module Db = ImportSQL.Db -type state = CSV.DataType.t array State.t +type state = ImportDataTypes.Value.t array State.t let default_mapper : - (ImportCSV.DataType.t, ImportCSV.DataType.t array) State.mapper = - { get_row = Fun.id; get_value = Fun.id; default = ImportCSV.DataType.Null } + (ImportDataTypes.Value.t, ImportDataTypes.Value.t array) State.mapper = + { get_row = Fun.id; get_value = Fun.id; default = ImportDataTypes.Value.Null } -let extract_values : string -> CSV.DataType.t = +let extract_values : string -> ImportDataTypes.Value.t = fun value -> (* Test first if the content is empty *) - if String.equal String.empty value then CSV.DataType.Null + if String.equal String.empty value then ImportDataTypes.Value.Null else (* else, try differents conversion in order to see which one works *) match int_of_string_opt value with - | Some i -> CSV.DataType.Integer i + | Some i -> ImportDataTypes.Value.Integer i | None -> ( match float_of_string_opt value with - | Some f -> CSV.DataType.Float f + | Some f -> ImportDataTypes.Value.Float f | None -> (* And finaly convert into date *) - CSV.DataType.Content value) + ImportDataTypes.Value.Content value) (** Initialize the state for the first row, count the column number and create the table in the database *) -let first_row : A.t -> _ Db.t -> state -> CSV.DataType.t list -> state = +let first_row : A.t -> _ Db.t -> state -> ImportDataTypes.Value.t list -> state + = fun mapping db acc row -> (if acc.transaction then match Db.commit db with @@ -69,11 +68,11 @@ let read_csv_line : let importInDatable : log_error:ImportErrors.t -> - conf:Syntax.t -> + conf:ImporterSyntax.t -> dirname:string -> A.t -> 'a Db.t -> - CSV.DataType.t array option Lwt.t = + ImportDataTypes.Value.t array option Lwt.t = fun ~log_error ~conf ~dirname mapping db -> let file = Filename.concat dirname (A.table mapping).file in @@ -86,7 +85,9 @@ let importInDatable : This line could generate an error if the headers are not correctly defined. *) let header = - List.map ~f:(fun v -> CSV.DataType.Content v) (Csv.next csv_channel) + List.map + ~f:(fun v -> ImportDataTypes.Value.Content v) + (Csv.next csv_channel) in let state = @@ -110,7 +111,7 @@ let importInDatable : with | Csv.Failure (line, row, cause) as e -> Printf.eprintf "Error %s on line %d — field : %s\n" cause line - (ImportCSV.Csv.column_to_string row); + (ImportDataTypes.Path.column_to_string row); raise e in ignore @@ State.clear ~log_error db mapping conf; |