Skip to content
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

[Help] How to parse results with sequential access? #29

Closed
ebrakke opened this issue Jul 31, 2021 · 2 comments
Closed

[Help] How to parse results with sequential access? #29

ebrakke opened this issue Jul 31, 2021 · 2 comments

Comments

@ebrakke
Copy link

ebrakke commented Jul 31, 2021

Hello!
I'm pretty new to the F# world, and started to write an application using Falco with Donald. I was following the setup of FalcoJournal for my application, however when I came to DB access, I kept getting a sequential access error.

module StateProvider = 
    type GetAll = unit -> DbResult<State list>
    let getAll (log : ILogger) (conn : IDbConnection) : GetAll =
        fun () ->
            let sql = "SELECT state, state_abbreviation FROM states;"

            let fromDataReader (rd : IDataReader) = 
                {StateAbbreviation = rd.ReadString "state_abbreviation"; State = rd.ReadString "state"}

            dbCommand conn { cmdText sql }
            |> Db.query fromDataReader
            |> DbResult.logError log

When I downgraded to version 5, I was able to get the code to work (change Db.query to DbConn.query)

I noticed that 5.0.* did not have sequential access turned on, which is why I assume it's working when I downgrade. What would I need to update in this code for it to work with sequantial access turned on?

Thank you in advance, your work is much appreciated!

@pimbrouwers
Copy link
Owner

Hi Erik!

Thanks for checking out the library, and welcome to the F# community!

I apologize for the error but luckily it's an easy one to get around. The library is premised on sequential access which is what you already discovered. The benefit of this approach is that when interacting with an IDataReader the contents are streamed through. The drawback however is that the fields must be read in order. I'll be sure to go back and correct the FalcoJournal project and post as well.

The updated SQL statement should look like this:

let sql = "SELECT state_abbreviation, state FROM states;"

@pimbrouwers
Copy link
Owner

Hey Erik! Had a chance to try that out yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants