2024-07-05 22:35:45 -04:00
|
|
|
[<RequireQualifiedAccess>]
|
|
|
|
module FruityFoundation.DataAccess.Abstractions.FSharp.ReadOnlyDb
|
|
|
|
|
|
|
|
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
|
2024-07-05 22:35:45 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-07-05 22:35:45 -04:00
|
|
|
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)
|
|
|
|
}
|