FruityFoundation/FruityFoundation.DataAccess.Abstractions.FSharp/ReadOnlyDb.fs
Kyle d745706082
feat: add FSharp database abstraction layer
I don't love having separate modules for ReadOnly vs. ReadWrite connections, but F# doesn't support covariance, so this is the best I could come up with for now.
2024-07-05 22:35:45 -04:00

36 lines
1.8 KiB
Forth

[<RequireQualifiedAccess>]
module FruityFoundation.DataAccess.Abstractions.FSharp.ReadOnlyDb
open System.Collections.Generic
open System.Threading
open FSharp.Control
open FruityFoundation.DataAccess.Abstractions
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 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)
}