Skip to content

Commit

Permalink
feat(custom): add custom parameter support
Browse files Browse the repository at this point in the history
  • Loading branch information
Natalie Perret committed Oct 17, 2021
1 parent 16f2afa commit 873ea0f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ Just a little FYI:
type SqliteDbValue =
| Null
| Integer of int64
| Real of double
| Text of string
| Blob of byte array
| Real of double
| Text of string
| Blob of byte array
| Custom of DbType * obj
```

## 🧱`SqliteCommand`
Expand Down Expand Up @@ -175,6 +176,10 @@ Output:

</details>

Note: in case you want to pass some types that aren't yet supported by the library,
you can use the `Custom` DU case which allows you to pass whatever underlying `DbType` with the relevant `obj` value.


<details>
<summary><code>cancellationToken</code></summary>

Expand Down
3 changes: 3 additions & 0 deletions Vp.FSharp.Sql.Sqlite.Tests/Tests.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module Tests

open System

open Xunit


[<Fact>]
let ``My test`` () =
let a: int32 array = [||]
Assert.True(true)
32 changes: 16 additions & 16 deletions Vp.FSharp.Sql.Sqlite/SqliteCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,77 +45,77 @@ let transaction value (commandDefinition: SqliteCommandDefinition) : SqliteComma
/// This function runs asynchronously.
let queryAsyncSeq connection read (commandDefinition: SqliteCommandDefinition) =
SqlCommand.queryAsyncSeq
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read commandDefinition

/// Execute the command and return the sets of rows as an AsyncSeq accordingly to the command definition.
/// This function runs synchronously.
let querySeqSync connection read (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySeqSync
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read commandDefinition

/// Execute the command and return the sets of rows as a list accordingly to the command definition.
/// This function runs asynchronously.
let queryList connection read (commandDefinition: SqliteCommandDefinition) =
SqlCommand.queryList
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read commandDefinition

/// Execute the command and return the sets of rows as a list accordingly to the command definition.
/// This function runs synchronously.
let queryListSync connection read (commandDefinition: SqliteCommandDefinition) =
SqlCommand.queryListSync
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read commandDefinition

/// Execute the command and return the first set of rows as a list accordingly to the command definition.
/// This function runs asynchronously.
let querySetList connection read (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySetList
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read commandDefinition

/// Execute the command and return the first set of rows as a list accordingly to the command definition.
/// This function runs synchronously.
let querySetListSync connection read (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySetListSync
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read commandDefinition

/// Execute the command and return the 2 first sets of rows as a tuple of 2 lists accordingly to the command definition.
/// This function runs asynchronously.
let querySetList2 connection read1 read2 (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySetList2
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read1 read2 commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read1 read2 commandDefinition

/// Execute the command and return the 2 first sets of rows as a tuple of 2 lists accordingly to the command definition.
/// This function runs synchronously.
let querySetList2Sync connection read1 read2 (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySetList2Sync
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read1 read2 commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read1 read2 commandDefinition

/// Execute the command and return the 3 first sets of rows as a tuple of 3 lists accordingly to the command definition.
/// This function runs asynchronously.
let querySetList3 connection read1 read2 read3 (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySetList3
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read1 read2 read3 commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot read1 read2 read3 commandDefinition

/// Execute the command and return the 3 first sets of rows as a tuple of 3 lists accordingly to the command definition.
/// This function runs synchronously.
let querySetList3Sync connection read1 read2 read3 (commandDefinition: SqliteCommandDefinition) =
SqlCommand.querySetList3Sync
connection (Constants.Deps) (SqliteConfiguration.Snapshot) read1 read2 read3 commandDefinition
connection Constants.Deps SqliteConfiguration.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.
/// This function runs asynchronously.
let executeScalar<'Scalar> connection (commandDefinition: SqliteCommandDefinition) =
SqlCommand.executeScalar<'Scalar, _, _, _, _, _, _, _, _>
connection (Constants.Deps) (SqliteConfiguration.Snapshot) commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot 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.
/// This function runs synchronously.
let executeScalarSync<'Scalar> connection (commandDefinition: SqliteCommandDefinition) =
SqlCommand.executeScalarSync<'Scalar, _, _, _, _, _, _, _, _>
connection (Constants.Deps) (SqliteConfiguration.Snapshot) commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot commandDefinition

/// Execute the command accordingly to its definition and,
/// - return Some, if the first cell is available and of the given type.
Expand All @@ -124,7 +124,7 @@ let executeScalarSync<'Scalar> connection (commandDefinition: SqliteCommandDefin
/// This function runs asynchronously.
let executeScalarOrNone<'Scalar> connection (commandDefinition: SqliteCommandDefinition) =
SqlCommand.executeScalarOrNone<'Scalar, _, _, _, _, _, _, _, _>
connection (Constants.Deps) (SqliteConfiguration.Snapshot) commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot commandDefinition

/// Execute the command accordingly to its definition and,
/// - return Some, if the first cell is available and of the given type.
Expand All @@ -133,16 +133,16 @@ let executeScalarOrNone<'Scalar> connection (commandDefinition: SqliteCommandDef
/// This function runs synchronously.
let executeScalarOrNoneSync<'Scalar> connection (commandDefinition: SqliteCommandDefinition) =
SqlCommand.executeScalarOrNoneSync<'Scalar, _, _, _, _, _, _, _, _>
connection (Constants.Deps) (SqliteConfiguration.Snapshot) commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot commandDefinition

/// Execute the command accordingly to its definition and, return the number of rows affected.
/// This function runs asynchronously.
let executeNonQuery connection (commandDefinition: SqliteCommandDefinition) =
SqlCommand.executeNonQuery
connection (Constants.Deps) (SqliteConfiguration.Snapshot) commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot commandDefinition

/// Execute the command accordingly to its definition and, return the number of rows affected.
/// This function runs synchronously.
let executeNonQuerySync connection (commandDefinition: SqliteCommandDefinition) =
SqlCommand.executeNonQuerySync
connection (Constants.Deps) (SqliteConfiguration.Snapshot) commandDefinition
connection Constants.Deps SqliteConfiguration.Snapshot commandDefinition
20 changes: 13 additions & 7 deletions Vp.FSharp.Sql.Sqlite/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ open Vp.FSharp.Sql
type SqliteDbValue =
| Null
| Integer of int64
| Real of double
| Text of string
| Blob of byte array
| Real of double
| Text of string
| Blob of byte array
| Custom of DbType * obj

/// SQLite Command Definition
type SqliteCommandDefinition =
Expand Down Expand Up @@ -53,16 +54,21 @@ type internal Constants private () =
parameter.TypeName <- "NULL"
| Integer value ->
parameter.TypeName <- "INTEGER"
parameter.Value <- value
parameter.Value <- value
| Real value ->
parameter.TypeName <- "REAL"
parameter.Value <- value
parameter.Value <- value
| Text value ->
parameter.TypeName <- "TEXT"
parameter.Value <- value
parameter.Value <- value
| Blob value ->
parameter.TypeName <- "BLOB"
parameter.Value <- value
parameter.Value <- value

| Custom (dbType, value) ->
parameter.DbType <- dbType
parameter.Value <- value

parameter

static member Deps : SqliteDependencies =
Expand Down
1 change: 0 additions & 1 deletion Vp.FSharp.Sql.Sqlite/Vp.FSharp.Sql.Sqlite.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Title>Vp.FSharp.Sql.Sqlite</Title>
<Product>Vp.FSharp</Product>
Expand Down

0 comments on commit 873ea0f

Please sign in to comment.