FruityFoundation/FruityFoundation.DataAccess.Abstractions.FSharp/ReadWriteDb.fs

42 lines
2.1 KiB
Forth
Raw Normal View History

[<RequireQualifiedAccess>]
module FruityFoundation.DataAccess.Abstractions.FSharp.ReadWriteDb
open System.Collections.Generic
open System.Threading
open FSharp.Control
open FruityFoundation.DataAccess.Abstractions
2024-09-05 23:03:43 -04:00
open FruityFoundation.FsBase
let private toKeyValuePair (parms : (string * obj) seq) =
parms
|> Seq.map (fun (name, value) -> KeyValuePair(name, value))
let query<'a> (connection : IDatabaseConnection<ReadWrite>) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = task {
return! connection.Query<'a>(sql, parms |> toKeyValuePair, cancellationToken)
}
let queryUnbuffered<'a> (connection : IDatabaseConnection<ReadWrite>) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = taskSeq {
yield! connection.QueryUnbuffered<'a>(sql, parms |> toKeyValuePair, cancellationToken)
}
let querySingle<'a> (connection : IDatabaseConnection<ReadWrite>) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = task {
return! connection.QuerySingle<'a>(sql, parms |> toKeyValuePair, cancellationToken)
}
2024-09-05 23:03:43 -04:00
let tryQueryFirst<'a> (connection : ReadOnly IDatabaseConnection) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = task {
2024-09-05 23:22:02 -04:00
let! result = connection.TryQueryFirst<'a>(sql, parms |> toKeyValuePair, cancellationToken)
2024-09-05 23:03:43 -04:00
return result |> Option.fromMaybe
}
let execute (connection : IDatabaseConnection<ReadWrite>) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = task {
return! connection.Execute(sql, parms |> toKeyValuePair, cancellationToken)
}
let executeScalar<'a> (connection : IDatabaseConnection<ReadWrite>) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = task {
return! connection.ExecuteScalar<'a>(sql, parms |> toKeyValuePair, cancellationToken)
}
let executeReader (connection : IDatabaseConnection<ReadWrite>) (cancellationToken : CancellationToken) (sql : string) (parms : (string * obj) seq) = task {
return! connection.ExecuteReader(sql, parms |> toKeyValuePair, cancellationToken)
}