GithubHelp home page GithubHelp logo

Comments (4)

pimbrouwers avatar pimbrouwers commented on July 25, 2024 1

Awesome! This has been merged in and deployed through 6.2.3

from donald.

pimbrouwers avatar pimbrouwers commented on July 25, 2024

Hey Daniel! Thanks for bringing this to my attention, admittedly it's not a field type I use or encounter very often. So it's no suprise that I didn't catch this myself (since I use this package everyday at work with SQL Server) and if you look carefully at the "type reader test" the mapper is missing the datetimeoffset 🤦.

So let's solve the two problems in front of us. First and most importantly, getting your code working. Here's a solution for right now.

open System.Data.SqlClient

// quick & dirty
let mapRow (rd : IDataReader) : DateTimeOffset =
    let sqlRd = rd :?> SqlDataReader
    sqlRd.GetDateTimeOffset(sqlRd.GetOrdinal("dto"))

conn
|> Db.newCommand "SELECT SYSDATETIMEOFFSET() AS dto"
|> Db.query mapRow

Now as far as the package goes, I think I have a couple ideas. Regardless of how we proceed on that, first thing should be to mark the current ReadDateTimeOffset as obsolete, release as a patch and remove it in the next major version release.

In my view the cleanest solution is to apply generics. If we change the signature of the map param to the following, you can pass in any function which receives any implementation of the interface.

let query (map : 'reader -> 'a when 'reader :> IDataReader) (cmd : IDbCommand) : DbResult<'a list> =  // ...

// now this works
let mapRow (rd : SqlDataReader) : DateTimeOffset =
    rd.GetDateTimeOffset(sqlRd.GetOrdinal("dto"))

conn
|> Db.newCommand "SELECT SYSDATETIMEOFFSET() AS dto"
|> Db.query mapRow

At first glance, I think this idea is our best approach. It's regression-proof and immediately, without any work allows people to plugin vendor specific consumption.

Thoughts?

from donald.

daniellittledev avatar daniellittledev commented on July 25, 2024

Hey, thanks for quick fix and all the detail!

Yeah I think that looks like a great path forward. Switching query to use generics provides easy accesses to the
more specific IDataReader type and looks like it's backwards compatible too!

from donald.

pimbrouwers avatar pimbrouwers commented on July 25, 2024

Ref: commit 41a7b6c

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.