lucidsoftware / relate

Performant database access in Scala
http://lucidsoftware.github.io/relate/
Apache License 2.0
161 stars 15 forks source link

RowParser single column parsers should return RowParsers #50

Closed msiebert closed 7 years ago

msiebert commented 7 years ago

example: RowParser.long returns (SqlRow) => Long, which isn't compatible with the new .as[A] syntax. It should return RowParser[Long] instead.

gregghz commented 7 years ago

RowParser(RowParser.long("col"))

It's not already a RowParser because making it implicit generally doesn't make sense. You have to globally (ish) say what column name maps to a Long so any call to as[Long] will also demand a single column name. If you want this in your application, I suggest creating it yourself.

msiebert commented 7 years ago

That's what I've done locally and I don't want to make an implicit val for reading Longs. I just think that it makes more sense to do:

implicit val longParser = RowParser.long("column")

than

implicit val longParser = RowParser(RowParser.long("column"))
gregghz commented 7 years ago

I don't follow.

I don't want to make an implicit val for reading Longs

And then you make an implicit val for reading longs?

msiebert commented 7 years ago

Sorry, I meant that I don't want to make it an implicit val in the RowParser object. I just wanted to put the invocation of RowParser.apply in the RowParser.long function. I just created this issue so that I'd remember to do it and make a pull request later.

So it should look like:

def long(columnLabel: String) = RowParser((row: SqlRow) => row.long(columnLabel))
gregghz commented 7 years ago

makes sense. I've created a PR: https://github.com/lucidsoftware/relate/pull/51