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

Apply[Read].ap reads the columns in the wrong order #851

Open
nigredo-tori opened this issue Apr 1, 2019 · 1 comment
Open

Apply[Read].ap reads the columns in the wrong order #851

nigredo-tori opened this issue Apr 1, 2019 · 1 comment

Comments

@nigredo-tori
Copy link
Contributor

nigredo-tori commented Apr 1, 2019

Currently Apply[Read].ap is implemented like this:

def ap[A, B](ff: Read[A => B])(fa: Read[A]): Read[B] = fa.ap(ff)

That is, it first reads fa, and then ff. This leads to surprising results when manually building a Read instance:

scala> val read = (Read[Int], Read[String]).tupled
read: doobie.util.Read[(Int, String)] = doobie.util.Read@4fb0497f

scala> val query = sql"select 1, 'foo'".query(read)
query: doobie.Query0[(Int, String)] = doobie.util.query$Query$$anon$3@419a4cd0

scala> query.check.unsafeRunSync
  Query0[(Int, String)] defined at <console>:50
  select 1, 'foo'
  ✓ SQL Compiles and TypeChecks
  ✕ C01 ?column? INTEGER (int4) NULL?  →  String
    INTEGER (int4) is ostensibly coercible to String according to the
    JDBC specification but is not a recommended target type. Expected
    schema type was CHAR or VARCHAR or LONGVARCHAR or NCHAR or
    NVARCHAR or LONGNVARCHAR.
  ✕ C02 ?column? VARCHAR (text) NULL?  →  Int
    VARCHAR (text) is ostensibly coercible to Int according to the
    JDBC specification but is not a recommended target type. Expected
    schema type was INTEGER.
@nigredo-tori nigredo-tori changed the title Apply[Read].ap reads the arguments in the wrong order Apply[Read].ap reads the columns in the wrong order Apr 1, 2019
@nigredo-tori
Copy link
Contributor Author

Discussion on a similar topic: typelevel/cats#2172

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

1 participant