FruityFoundation/FruityFoundation.DataAccess.Abstractions.FSharp/ReadOnlyDb.fs
Kyle Ratti 6df46d3c2b
Some checks failed
ci / build (6.0.x) (push) Has been cancelled
ci / build (8.0.x) (push) Has been cancelled
fix: specify generic
2024-09-05 23:22:02 -04:00

42 lines
2.1 KiB
Forth

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