diff --git a/Vp.FSharp.Sql.Sqlite/Library.fs b/Vp.FSharp.Sql.Sqlite/Library.fs index 43cac8d..5f33330 100644 --- a/Vp.FSharp.Sql.Sqlite/Library.fs +++ b/Vp.FSharp.Sql.Sqlite/Library.fs @@ -1,6 +1,7 @@ namespace Vp.FSharp.Sql.Sqlite open System.Data.SQLite +open System.Threading.Tasks open Vp.FSharp.Sql @@ -14,7 +15,28 @@ type SqliteDbValue = | Text of string | Blob of byte array -type SqliteCommandDefinition = CommandDefinition +type SqliteCommandDefinition = + CommandDefinition< + SQLiteConnection, + SQLiteTransaction, + SQLiteCommand, + SQLiteParameter, + SQLiteDataReader, + SqliteDbValue> + +type SqliteGlobalConf = + SqlGlobalConf< + SQLiteConnection, + SQLiteCommand> + +type SqliteDeps = + SqlDeps< + SQLiteConnection, + SQLiteTransaction, + SQLiteCommand, + SQLiteParameter, + SQLiteDataReader, + SqliteDbValue> [] module SqliteCommand = @@ -39,6 +61,11 @@ module SqliteCommand = parameter.Value <- value parameter + let private deps: SqliteDeps = + { CreateCommand = fun connection -> connection.CreateCommand() + ExecuteReaderAsync = fun command _ -> Task.FromResult(command.ExecuteReader()) + DbValueToParameter = dbValueToParameter } + /// Initialize a command definition with the given text contained in the given string. let text value : SqliteCommandDefinition = SqlCommand.text value @@ -47,6 +74,14 @@ module SqliteCommand = let textFromList value : SqliteCommandDefinition = SqlCommand.textFromList value + /// Update the command definition so that when executing the command, it doesn't use any logger. + /// Be it the default one (Global, if any.) or a previously overriden one. + let noLogger commandDefinition = { commandDefinition with Logger = LoggerKind.Nothing } + + /// Update the command definition so that when executing the command, it use the given overriding logger. + /// instead of the default one, aka the Global logger, if any. + let overrideLogger value commandDefinition = { commandDefinition with Logger = LoggerKind.Override value } + /// Update the command definition with the given parameters. let parameters value (commandDefinition: SqliteCommandDefinition) : SqliteCommandDefinition = SqlCommand.parameters value commandDefinition @@ -69,43 +104,45 @@ module SqliteCommand = /// Return the sets of rows as an AsyncSeq accordingly to the command definition. let queryAsyncSeq connection read (commandDefinition: SqliteCommandDefinition) = - SqlCommand.queryAsyncSeq connection dbValueToParameter read commandDefinition + SqlCommand.queryAsyncSeq + connection deps (SqliteGlobalConf.Snapshot) read commandDefinition /// Return the sets of rows as a list accordingly to the command definition. let queryList connection read (commandDefinition: SqliteCommandDefinition) = - SqlCommand.queryList connection dbValueToParameter read commandDefinition + SqlCommand.queryList + connection deps (SqliteGlobalConf.Snapshot) read commandDefinition /// Return the first set of rows as a list accordingly to the command definition. let querySetList connection read (commandDefinition: SqliteCommandDefinition) = - SqlCommand.querySetList connection dbValueToParameter read commandDefinition + SqlCommand.querySetList + connection deps (SqliteGlobalConf.Snapshot) read commandDefinition /// Return the 2 first sets of rows as a tuple of 2 lists accordingly to the command definition. let querySetList2 connection read1 read2 (commandDefinition: SqliteCommandDefinition) = - SqlCommand.querySetList2 connection dbValueToParameter read1 read2 commandDefinition + SqlCommand.querySetList2 + connection deps (SqliteGlobalConf.Snapshot) read1 read2 commandDefinition /// Return the 3 first sets of rows as a tuple of 3 lists accordingly to the command definition. let querySetList3 connection read1 read2 read3 (commandDefinition: SqliteCommandDefinition) = - SqlCommand.querySetList3 connection dbValueToParameter read1 read2 read3 commandDefinition + SqlCommand.querySetList3 + connection deps (SqliteGlobalConf.Snapshot) read1 read2 read3 commandDefinition /// Execute the command accordingly to its definition and, /// - return the first cell value, if it is available and of the given type. /// - throw an exception, otherwise. let executeScalar<'Scalar> connection (commandDefinition: SqliteCommandDefinition) = - SqlCommand.executeScalar<'Scalar, _, _, _> - connection - dbValueToParameter - commandDefinition + SqlCommand.executeScalar<'Scalar, _, _, _, _, _, _, _, _, _> + connection deps (SqliteGlobalConf.Snapshot) commandDefinition /// Execute the command accordingly to its definition and, /// - return Some, if the first cell is available and of the given type. /// - return None, if first cell is DbNull. /// - throw an exception, otherwise. let executeScalarOrNone<'Scalar> connection (commandDefinition: SqliteCommandDefinition) = - SqlCommand.executeScalarOrNone<'Scalar, _, _, _> - connection - dbValueToParameter - commandDefinition + SqlCommand.executeScalarOrNone<'Scalar, _, _, _, _, _, _, _, _, _> + connection deps (SqliteGlobalConf.Snapshot) commandDefinition /// Execute the command accordingly to its definition and, return the number of rows affected. let executeNonQuery connection (commandDefinition: SqliteCommandDefinition) = - SqlCommand.executeNonQuery connection dbValueToParameter commandDefinition + SqlCommand.executeNonQuery + connection deps (SqliteGlobalConf.Snapshot) commandDefinition diff --git a/Vp.FSharp.Sql.Sqlite/Vp.FSharp.Sql.Sqlite.fsproj b/Vp.FSharp.Sql.Sqlite/Vp.FSharp.Sql.Sqlite.fsproj index 484f5b6..d7b1cb3 100644 --- a/Vp.FSharp.Sql.Sqlite/Vp.FSharp.Sql.Sqlite.fsproj +++ b/Vp.FSharp.Sql.Sqlite/Vp.FSharp.Sql.Sqlite.fsproj @@ -24,7 +24,7 @@ - +