-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a wrapper around ExecuteScalar #22
Comments
Hi @FoggyFinder, Thanks for reaching out. Appreciate the interest. I had the same line of thinking in the past. In fact, original iterations of this project had a invocation pathway for So I decided that the optimal route was to leverage I had thought about creating a Anyway, I'm open to hearing if there's a use case that I'm missing. But ultimately, I don't imagine I'll be adding an explicit wrapper around ExecuteScalar(). Make sense? |
Well, right, I really don't care how it would work internally.
It's just a bit annoying to check result first and then check whether the query is actually returned something. I wrote a simple function though module Db =
let execSingle cmd =
match Db.querySingle (fun r -> r.GetValue(0) |> unbox) cmd with
| DbResult.Ok r when r.IsSome ->
Result.Ok r.Value
| DbResult.Ok _ ->
Result.Error "A query didn't return any value"
| DbResult.Error err ->
Result.Error err.Statement which I haven't tested yet but I believe it would work. |
Here's what I've come up with, which shares a signature with the functions I removed (i.e., Hopefully they will help your use cases. Apologies if there's been any frustration, my goal wasn't to make a library that made someone's job harder. An example usage: dbCommand conn { cmdText "SELECT 1" }
|> Db.scalar Convert.ToInt32 // or, Db.Async.scalar Convert.ToInt32
|> printfn "%i" // outputs: 1 Once I get the thumbs up from you, I'll release a new minor version of the package to include this in the API. |
perfect, thank you |
You can test this out in 6.1.0-beta1. |
Wonderful 🎉 During testing got a |
It seems like currently one has to use
querySingle
etc that isn't convenientThe text was updated successfully, but these errors were encountered: