-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(refactor): add specific tc support
- Loading branch information
Kerry Perret
committed
Jan 23, 2021
1 parent
1534808
commit ed334e7
Showing
5 changed files
with
111 additions
and
66 deletions.
There are no files selected for viewing
64 changes: 0 additions & 64 deletions
64
Vp.FSharp.Sql.Sqlite/Library.fs → Vp.FSharp.Sql.Sqlite/SqliteCommand.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[<RequireQualifiedAccess>] | ||
module Vp.FSharp.Sql.Sqlite.SqliteNullDbValue | ||
|
||
open Vp.FSharp.Sql | ||
|
||
|
||
let ifNone toDbValue = NullDbValue.ifNone toDbValue SqliteDbValue.Null | ||
let ifError toDbValue = NullDbValue.ifError toDbValue (fun _ -> SqliteDbValue.Null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[<RequireQualifiedAccess>] | ||
module Vp.FSharp.Sql.SqlServer.SqliteTransaction | ||
|
||
open Vp.FSharp.Sql | ||
open Vp.FSharp.Sql.Sqlite | ||
|
||
|
||
let beginTransactionAsync = Constants.Deps.BeginTransactionAsync | ||
|
||
let commit cancellationToken isolationLevel connection body = | ||
Transaction.commit cancellationToken isolationLevel connection beginTransactionAsync body | ||
let notCommit cancellationToken isolationLevel connection body = | ||
Transaction.notCommit cancellationToken isolationLevel connection beginTransactionAsync body | ||
let commitOnOk cancellationToken isolationLevel connection body = | ||
Transaction.commitOnOk cancellationToken isolationLevel connection beginTransactionAsync body | ||
let commitOnSome cancellationToken isolationLevel connection body = | ||
Transaction.commitOnSome cancellationToken isolationLevel connection beginTransactionAsync body | ||
|
||
let defaultCommit connection body = Transaction.defaultCommit connection beginTransactionAsync body | ||
let defaultNotCommit connection body = Transaction.defaultNotCommit connection beginTransactionAsync body | ||
let defaultCommitOnOk connection body = Transaction.defaultCommitOnOk connection beginTransactionAsync body | ||
let defaultCommitOnSome connection body = Transaction.defaultCommitOnSome connection beginTransactionAsync body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
namespace Vp.FSharp.Sql.Sqlite | ||
|
||
open System.Data | ||
open System.Data.SQLite | ||
open System.Threading.Tasks | ||
|
||
open Vp.FSharp.Sql | ||
|
||
|
||
/// Native SQLite DB types. | ||
/// See https://www.sqlite.org/datatype3.html | ||
type SqliteDbValue = | ||
| Null | ||
| Integer of int64 | ||
| Real of double | ||
| Text of string | ||
| Blob of byte array | ||
|
||
type SqliteCommandDefinition = | ||
CommandDefinition< | ||
SQLiteConnection, | ||
SQLiteCommand, | ||
SQLiteParameter, | ||
SQLiteDataReader, | ||
SQLiteTransaction, | ||
SqliteDbValue> | ||
|
||
type SqliteConfiguration = | ||
SqlConfigurationCache< | ||
SQLiteConnection, | ||
SQLiteCommand> | ||
|
||
type SqliteDependencies = | ||
SqlDependencies< | ||
SQLiteConnection, | ||
SQLiteCommand, | ||
SQLiteParameter, | ||
SQLiteDataReader, | ||
SQLiteTransaction, | ||
SqliteDbValue> | ||
|
||
[<AbstractClass; Sealed>] | ||
type internal Constants private () = | ||
|
||
static member DbValueToParameter name value = | ||
let parameter = SQLiteParameter() | ||
parameter.ParameterName <- name | ||
match value with | ||
| Null -> | ||
parameter.TypeName <- (nameof Null).ToUpperInvariant() | ||
| Integer value -> | ||
parameter.TypeName <- (nameof Integer).ToUpperInvariant() | ||
parameter.Value <- value | ||
| Real value -> | ||
parameter.TypeName <- (nameof Real).ToUpperInvariant() | ||
parameter.Value <- value | ||
| Text value -> | ||
parameter.TypeName <- (nameof Text).ToUpperInvariant() | ||
parameter.Value <- value | ||
| Blob value -> | ||
parameter.TypeName <- (nameof Blob).ToUpperInvariant() | ||
parameter.Value <- value | ||
parameter | ||
|
||
static member Deps : SqliteDependencies = | ||
let beginTransactionAsync (connection: SQLiteConnection) (isolationLevel: IsolationLevel) _ = | ||
ValueTask.FromResult(connection.BeginTransaction(isolationLevel)) | ||
|
||
let executeReaderAsync (command: SQLiteCommand) _ = | ||
Task.FromResult(command.ExecuteReader()) | ||
|
||
{ CreateCommand = fun connection -> connection.CreateCommand() | ||
SetCommandTransaction = fun command transaction -> command.Transaction <- transaction | ||
BeginTransactionAsync = beginTransactionAsync | ||
ExecuteReaderAsync = executeReaderAsync | ||
DbValueToParameter = Constants.DbValueToParameter } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters