Giter Site home page Giter Site logo

Comments (5)

pimbrouwers avatar pimbrouwers commented on June 24, 2024 1

Fantastic!

This is done and deployed to nuget as part of 6.2.2.

Thanks for your help on this!

from donald.

pimbrouwers avatar pimbrouwers commented on June 24, 2024

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.

JordanMarr avatar JordanMarr commented on June 24, 2024

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.

pimbrouwers avatar pimbrouwers commented on June 24, 2024

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.

JordanMarr avatar JordanMarr commented on June 24, 2024

Oh yeah, that would provide the ideal extension point for this workflow!

from donald.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.