Skip to content

Commit

Permalink
feat(conf): update core nuget
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry Perret authored and natalie-o-perret committed Jan 7, 2021
1 parent 7fc50e1 commit 8b8c4d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Vp.FSharp.Sql.PostgreSql.Tests/Tests.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Tests

open System
open Xunit


[<Fact>]
let ``My test`` () =
Assert.True(true)
Assert.True(true)
69 changes: 44 additions & 25 deletions Vp.FSharp.Sql.PostgreSql/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open System.Net
open System.Collections.Generic
open System.Net.NetworkInformation

open System.Threading.Tasks
open Npgsql
open NpgsqlTypes

Expand Down Expand Up @@ -76,9 +75,28 @@ type PostgreSqlDbValue =
/// See: https://www.npgsql.org/doc/types/enums_and_composites.html
| Enum of Enum

type PostgreSqlCommandDefinition = CommandDefinition<NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand, NpgsqlParameter, NpgsqlDataReader, PostgreSqlDbValue>

type PostgreSqlDeps = SqlDeps<NpgsqlConnection, NpgsqlTransaction, NpgsqlCommand, NpgsqlParameter, NpgsqlDataReader, PostgreSqlDbValue>
type PostgreSqlCommandDefinition =
CommandDefinition<
NpgsqlConnection,
NpgsqlTransaction,
NpgsqlCommand,
NpgsqlParameter,
NpgsqlDataReader,
PostgreSqlDbValue>

type PostgreSqlGlobalConf =
SqlGlobalConf<
NpgsqlConnection,
NpgsqlCommand>

type PostgreSqlDeps =
SqlDeps<
NpgsqlConnection,
NpgsqlTransaction,
NpgsqlCommand,
NpgsqlParameter,
NpgsqlDataReader,
PostgreSqlDbValue>

[<RequireQualifiedAccess>]
module PostgreSqlCommand =
Expand Down Expand Up @@ -231,17 +249,10 @@ module PostgreSqlCommand =
parameter.Value <- value
parameter

let private formatTimeSpan (ts: TimeSpan) : string =
sprintf "%id %02i:%02i:%02i.%03i" ts.Days ts.Hours ts.Minutes ts.Seconds ts.Milliseconds

let mutable globalLogger =
None

let private deps : PostgreSqlDeps =
{ CreateCommand = (fun c -> new NpgsqlCommand("", c))
ExecuteReaderAsync = (fun cmd -> cmd.ExecuteReader() |> Task.FromResult )
DbValueToParameter = dbValueToParameter
GlobalLogger = globalLogger }
let private deps: PostgreSqlDeps =
{ CreateCommand = fun connection -> connection.CreateCommand()
ExecuteReaderAsync = fun command -> command.ExecuteReaderAsync
DbValueToParameter = dbValueToParameter }

/// Initialize a command definition with the given text contained in the given string.
let text value : PostgreSqlCommandDefinition =
Expand Down Expand Up @@ -277,37 +288,45 @@ module PostgreSqlCommand =

/// Return the sets of rows as an AsyncSeq accordingly to the command definition.
let queryAsyncSeq connection read (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.queryAsyncSeq connection deps read commandDefinition
SqlCommand.queryAsyncSeq
connection deps (PostgreSqlGlobalConf.Snapshot) read commandDefinition

/// Return the sets of rows as a list accordingly to the command definition.
let queryList connection read (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.queryList connection deps read commandDefinition
SqlCommand.queryList
connection deps (PostgreSqlGlobalConf.Snapshot) read commandDefinition

/// Return the first set of rows as a list accordingly to the command definition.
let querySetList connection read (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.querySetList connection deps read commandDefinition
SqlCommand.querySetList
connection deps (PostgreSqlGlobalConf.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: PostgreSqlCommandDefinition) =
SqlCommand.querySetList2 connection deps read1 read2 commandDefinition
SqlCommand.querySetList2
connection deps (PostgreSqlGlobalConf.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: PostgreSqlCommandDefinition) =
SqlCommand.querySetList3 connection deps read1 read2 read3 commandDefinition
SqlCommand.querySetList3
connection deps (PostgreSqlGlobalConf.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 connection (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.executeScalar connection deps commandDefinition
let executeScalar<'Scalar> connection (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.executeScalar<'Scalar, _, _, _, _, _, _, _, _, _>
connection deps (PostgreSqlGlobalConf.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 connection (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.executeScalarOrNone connection deps commandDefinition
let executeScalarOrNone<'Scalar> connection (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.executeScalarOrNone<'Scalar, _, _, _, _, _, _, _, _, _>
connection deps (PostgreSqlGlobalConf.Snapshot) commandDefinition

/// Execute the command accordingly to its definition and, return the number of rows affected.
let executeNonQuery connection (commandDefinition: PostgreSqlCommandDefinition) =
SqlCommand.executeNonQuery connection deps commandDefinition
SqlCommand.executeNonQuery
connection deps (PostgreSqlGlobalConf.Snapshot) commandDefinition
4 changes: 2 additions & 2 deletions Vp.FSharp.Sql.PostgreSql/Vp.FSharp.Sql.PostgreSql.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="4.1.4" />
<PackageReference Include="Vp.FSharp.Sql" Version="1.0.27" />
<PackageReference Include="Npgsql" Version="5.0.1.1" />
<PackageReference Include="Vp.FSharp.Sql" Version="1.0.31" />
</ItemGroup>

</Project>

0 comments on commit 8b8c4d4

Please sign in to comment.