Comments (5)
Fantastic!
This is done and deployed to nuget as part of 6.2.2.
Thanks for your help on this!
from donald.
Hey Jordan! Thanks for doing this.
I like the notion of sequential access being the default, since the performance gains are just to great. But I just realized that even though the underyling extension method allows for this to be configured at runtime. I never expose this in the outer API.
So here's my thought, we add two sister funcs for query
and querySingle
. The question is, do we fully expose the underlying Enum? Or do we assume most people want the "CommandBehaviour.Default"?
let queryConfigured (cmdBehaviour : CommandBehaviour) (map : IDataReader -> 'a) (cmd : IDbCommand) : DbResult<'a list> =
tryDo (fun cmd ->
use rd = cmd.ExecReader(cmdBehaviour)
let results = [ while rd.Read() do yield map rd ]
rd.Close() |> ignore
results)
cmd
// vs
let queryDefault (map : IDataReader -> 'a) (cmd : IDbCommand) : DbResult<'a list> =
tryDo (fun cmd ->
use rd = cmd.ExecReader(CommandBehaviour.Default)
let results = [ while rd.Read() do yield map rd ]
rd.Close() |> ignore
results)
cmd
from donald.
That's a tough one (but aren't they all?)! 🤔
Another option could be to leave all that as-is and have a executeReader()
that returns a 'TReader`:
use reader =
conn
|> Db.newCommand "SELECT ..."
|> Db.executeReader
let p = SalesLT.ProductReader(reader)
let c = SalesLT.ProductCategoryReader(reader)
return [
while reader.Read() do
p.Read(),
c.Read()
]
or Async:
```F#
use! reader =
conn
|> Db.newCommand "SELECT ..."
|> Db.Async.executeReader
let p = SalesLT.ProductReader(reader)
let c = SalesLT.ProductCategoryReader(reader)
return [
while reader.Read() do
p.Read(),
c.Read()
]
You may not like that one as much since it makes the user responsible for iterating and disposing the reader as opposed to it being handled within Donald, which is a con. One pro is that the generated readers can be initialized before the looping, as opposed to the c'tor being called each time -- which actually may not be that big of a deal either way.. IDK.
Decisions, decisions! I'll be fine for whatever you think is best for Donald. 😁
from donald.
Indeed! It's funny you suggest that, there was originally a read
func which I had thought would be useful in multi-result set cases. Perhaps I add it again? Something like:
/// Execute paramterized query and return IDataReader
let read (cmd : IDbCommand) : IDataReader =
cmd.ExecReader(CommandBehavior.Default)
/// Execute paramterized query and return IDataReader
let read (cmd : IDbCommand) : Task<IDataReader> =
let dbCmd = cmd :?> DbCommand
dbCmd.ExecReaderAsync(CommandBehavior.Default)
|> continueWith (fun rd -> rd.Result :> IDataReader)
from donald.
Oh yeah, that would provide the ideal extension point for this workflow!
from donald.
Related Issues (20)
- GetDateTimeOffset Signature is string -> DateTime HOT 1
- Unable to execute query without a transaction HOT 6
- Add a wrapper around ExecuteScalar HOT 6
- TransactionBuilder HOT 9
- Cast exception when reading DateTimeOffset with System.Data.SqlClient HOT 4
- [Help] How to parse results with sequential access? HOT 2
- Db.Async.execMany throws "A command is already in progress" with NPGSQL HOT 5
- v.7.0.0 HOT 9
- FsDto lib review HOT 2
- Who is @dysme on the landing page? HOT 3
- CancellationToken support
- Support of transaction in newCommand in Fluent syntax HOT 3
- Getting error while using Db.Async.query method HOT 6
- Require help on query HOT 7
- Support or Transition to Microsoft.Data.SqlClient HOT 3
- SQLite: What SQL Type should I choose for a JSON column? HOT 2
- Possible issue with Db.Async.exec throwing instead of returning a Result HOT 1
- How to deal with DB enums in Donald? HOT 1
- Doc comment error for newSproc HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from donald.