diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2025-03-17 09:11:25 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2025-03-17 18:59:32 +0100 |
commit | 8b8b730d3ba98d6c9e4e6274844641043b5fefbb (patch) | |
tree | 4cb60dafa05b479d0ca287d501a51db88cecaaa4 /lib/sql | |
parent | 7bfbb67d83011f3e1845dcb9e44c3b6a5e93a9da (diff) |
Moved the syntax module in its own library
Diffstat (limited to 'lib/sql')
-rw-r--r-- | lib/sql/db.ml | 20 | ||||
-rw-r--r-- | lib/sql/db.mli | 25 | ||||
-rw-r--r-- | lib/sql/dune | 7 | ||||
-rw-r--r-- | lib/sql/hashs.ml | 8 | ||||
-rw-r--r-- | lib/sql/header.ml | 5 | ||||
-rw-r--r-- | lib/sql/t.ml | 22 |
6 files changed, 41 insertions, 46 deletions
diff --git a/lib/sql/db.ml b/lib/sql/db.ml index f1aee8c..f2a2653 100644 --- a/lib/sql/db.ml +++ b/lib/sql/db.ml @@ -1,6 +1,4 @@ open StdLabels -module CSV = ImportCSV -module Syntax = ImportConf.Syntax module Table = ImportDataTypes.Table module Path = ImportDataTypes.Path @@ -153,7 +151,7 @@ let eval_key : 'a t -> Sqlite3.stmt option -> ImportAnalyser.Dependency.key list -> - (int * CSV.DataType.t) list -> + (int * ImportDataTypes.Value.t) list -> (Sqlite3.stmt option * Sqlite3.Data.t list) T.result = fun db stmt keys values -> match keys with @@ -204,7 +202,7 @@ let insert : Sqlite3.db -> Sqlite3.stmt -> id:int -> - (int * CSV.DataType.t) list -> + (int * ImportDataTypes.Value.t) list -> unit T.result = fun db statement ~id values -> let** _ = T.savepoint db "PREVIOUS" in @@ -255,9 +253,9 @@ let execute_query : Ok statement let query : - f:((Path.t ImportExpression.T.t * CSV.DataType.t) array -> unit) -> + f:((Path.t ImportExpression.T.t * ImportDataTypes.Value.t) array -> unit) -> Sqlite3.db -> - Syntax.t -> + ImporterSyntax.t -> unit T.result = fun ~f db output -> (* Extract the query from the configuration. *) @@ -280,7 +278,7 @@ let query : in Ok () -let create_view : Sqlite3.db -> Syntax.t -> unit T.result = +let create_view : Sqlite3.db -> ImporterSyntax.t -> unit T.result = fun db output -> ignore output; let* drop = Sqlite3.exec db "DROP VIEW IF EXISTS 'result'" in @@ -300,10 +298,10 @@ let create_view : Sqlite3.db -> Syntax.t -> unit T.result = *) let check_foreign : - f:((string * CSV.DataType.t) array -> unit) -> + f:((string * ImportDataTypes.Value.t) array -> unit) -> Sqlite3.db -> - Syntax.t -> - Syntax.Extern.t -> + ImporterSyntax.t -> + ImporterSyntax.Extern.t -> unit T.result = fun ~f db conf external_ -> let query = ImportAnalyser.Query.check_external conf external_ in @@ -318,7 +316,7 @@ let check_foreign : |> T.to_result let clear_duplicates : - f:((string * ImportCSV.DataType.t) array -> unit) -> + f:((string * ImportDataTypes.Value.t) array -> unit) -> 'a t -> ImportDataTypes.Table.t -> ImportAnalyser.Dependency.key list -> diff --git a/lib/sql/db.mli b/lib/sql/db.mli index 91933c4..213fb27 100644 --- a/lib/sql/db.mli +++ b/lib/sql/db.mli @@ -1,5 +1,3 @@ -module Syntax = ImportConf.Syntax - type 'a t type 'a result = ('a, exn) Result.t @@ -32,7 +30,7 @@ val eval_key : 'a t -> Sqlite3.stmt option -> ImportAnalyser.Dependency.key list -> - (int * ImportCSV.DataType.t) list -> + (int * ImportDataTypes.Value.t) list -> (Sqlite3.stmt option * Sqlite3.Data.t list) result (** Evaluate the keys in sqlite and get the results. @@ -43,7 +41,7 @@ val insert : 'a t -> Sqlite3.stmt -> id:int -> - (int * ImportCSV.DataType.t) list -> + (int * ImportDataTypes.Value.t) list -> unit result (** Insert a new row in the database. @@ -63,10 +61,11 @@ val rollback : 'a t -> unit result val query : f: - ((ImportDataTypes.Path.t ImportExpression.T.t * ImportCSV.DataType.t) array -> + ((ImportDataTypes.Path.t ImportExpression.T.t * ImportDataTypes.Value.t) + array -> unit) -> 'a t -> - Syntax.t -> + ImporterSyntax.t -> unit result (** This one the most important function from the application. The function will transform the configuration into an sql query and will fetch the result from @@ -74,18 +73,18 @@ val query : The function [f] given in argument will be called for each line *) -val create_view : 'a t -> Syntax.t -> unit result +val create_view : 'a t -> ImporterSyntax.t -> unit result (** Create a view which represent the result *) val check_foreign : - f:((string * ImportCSV.DataType.t) array -> unit) -> + f:((string * ImportDataTypes.Value.t) array -> unit) -> 'a t -> - Syntax.t -> - Syntax.Extern.t -> + ImporterSyntax.t -> + ImporterSyntax.Extern.t -> unit result val clear_duplicates : - f:((string * ImportCSV.DataType.t) array -> unit) -> + f:((string * ImportDataTypes.Value.t) array -> unit) -> 'a t -> ImportDataTypes.Table.t -> ImportAnalyser.Dependency.key list -> @@ -95,9 +94,9 @@ val clear_duplicates : val insert_header : 'a t -> ImportDataTypes.Table.t -> - (int * ImportCSV.DataType.t) array -> + (int * ImportDataTypes.Value.t) array -> unit T.result val query_headers : - 'a t -> ImportDataTypes.Table.t -> ImportCSV.DataType.t array T.result + 'a t -> ImportDataTypes.Table.t -> ImportDataTypes.Value.t array T.result (** Get all the headers from the database (used or not) *) diff --git a/lib/sql/dune b/lib/sql/dune index 9f9f205..bd77858 100644 --- a/lib/sql/dune +++ b/lib/sql/dune @@ -4,12 +4,11 @@ re sqlite3 calendar - importAnalyser - importCSV - importConf - importContainers importDataTypes + importContainers importErrors importExpression + importerSyntax + importAnalyser ) ) diff --git a/lib/sql/hashs.ml b/lib/sql/hashs.ml index af1f092..eced2b4 100644 --- a/lib/sql/hashs.ml +++ b/lib/sql/hashs.ml @@ -1,10 +1,8 @@ -(** - This module store the hash of the indexes ([extern_key]) for each table in +(** This module store the hash of the indexes ([extern_key]) for each table in order to update the file if the configuration changed. The hashes are stored in a table named [hashes] and are evaluated just - before inserting the values. -*) + before inserting the values. *) open StdLabels module Table = ImportDataTypes.Table @@ -75,5 +73,5 @@ let query : 'a T.t -> ImportDataTypes.Table.t -> int option T.result = let* _ = T.to_result state in match res with - | Some (ImportCSV.DataType.Integer i) -> Ok (Some i) + | Some (ImportDataTypes.Value.Integer i) -> Ok (Some i) | _ -> Ok None diff --git a/lib/sql/header.ml b/lib/sql/header.ml index 3cac5fb..1f4c9d6 100644 --- a/lib/sql/header.ml +++ b/lib/sql/header.ml @@ -13,7 +13,7 @@ let create_table : 'a T.t -> unit T.result = let insert_header : 'a T.t -> ImportDataTypes.Table.t -> - (int * ImportCSV.DataType.t) array -> + (int * ImportDataTypes.Value.t) array -> unit T.result = fun db table values -> let table_name = Table.name table in @@ -48,7 +48,8 @@ let insert_header : T.commit db let query_headers : - 'a T.t -> ImportDataTypes.Table.t -> ImportCSV.DataType.t array T.result = + 'a T.t -> ImportDataTypes.Table.t -> ImportDataTypes.Value.t array T.result + = fun db table -> let table_name = Table.name table in let query = diff --git a/lib/sql/t.ml b/lib/sql/t.ml index 202c535..2297125 100644 --- a/lib/sql/t.ml +++ b/lib/sql/t.ml @@ -39,14 +39,14 @@ let reset : Sqlite3.stmt -> unit result = fun statement -> to_result (Sqlite3.reset statement) let of_datatype = function - | ImportCSV.DataType.Float f -> Sqlite3.Data.FLOAT f - | ImportCSV.DataType.Integer i -> Sqlite3.Data.INT (Int64.of_int i) - | ImportCSV.DataType.Null -> Sqlite3.Data.NULL - | ImportCSV.DataType.Error _ -> Sqlite3.Data.NULL - | ImportCSV.DataType.Content s -> Sqlite3.Data.TEXT s - -let to_datatype : Sqlite3.Data.t -> ImportCSV.DataType.t = function - | Sqlite3.Data.NONE | Sqlite3.Data.NULL -> ImportCSV.DataType.Null - | Sqlite3.Data.INT i -> ImportCSV.DataType.Integer (Int64.to_int i) - | Sqlite3.Data.FLOAT f -> ImportCSV.DataType.Float f - | Sqlite3.Data.TEXT t | Sqlite3.Data.BLOB t -> ImportCSV.DataType.Content t + | ImportDataTypes.Value.Float f -> Sqlite3.Data.FLOAT f + | ImportDataTypes.Value.Integer i -> Sqlite3.Data.INT (Int64.of_int i) + | ImportDataTypes.Value.Null -> Sqlite3.Data.NULL + | ImportDataTypes.Value.Error _ -> Sqlite3.Data.NULL + | ImportDataTypes.Value.Content s -> Sqlite3.Data.TEXT s + +let to_datatype : Sqlite3.Data.t -> ImportDataTypes.Value.t = function + | Sqlite3.Data.NONE | Sqlite3.Data.NULL -> ImportDataTypes.Value.Null + | Sqlite3.Data.INT i -> ImportDataTypes.Value.Integer (Int64.to_int i) + | Sqlite3.Data.FLOAT f -> ImportDataTypes.Value.Float f + | Sqlite3.Data.TEXT t | Sqlite3.Data.BLOB t -> ImportDataTypes.Value.Content t |