How to return the list [User] when using sql with a spot

It seems to me that I can return List [User] from a raw SQL query.

implicit val getUserResult = GetResult(r => User(r.nextInt, ....))

sql"""
select * from users where id =1

""".as[User]

This seems like a compilation, but if I change this to return a list, and not a single result, I get an error.

.as[List[User]]

Error:

could not find implicit value for parameter rconv: scala.slick.jdbc.GetResult[List[User]]

How can I change the implicit GetResult to return a list?

Update

So, I created an implicit like:

implicit val getUserResult = GetResult (r => User (r.nextInt, ....))

val query: StaticQuery0 [User] = sql "....."

query.list ()

I can this error:

[PSQLException: Bad value for type int : asdf asdfs]

In psql, I see that I have "asdf asdfs" in some columns, but not in INT columns. If things compile, I'm not sure why I get this error, looks like an error?

+4
1

@goral , , , , id, :

import scala.slick.driver.JdbcDriver.backend.Database
import Database.dynamicSession
import scala.slick.jdbc.{GetResult, StaticQuery => Q}
import Q.interpolation

val t: StaticQuery0[User] = 
  sql"select * from users where id = 1".as[User]

val list: List[User] = t.list()

StaticQuery , list, first, firstOption .., Invoker.

case GetResult:

case class User(id: Int, name: String)

implicit val getUserResult = GetResult(r => User(r.nextInt, r.nextString))

val t: StaticQuery0[User] = sql"select * from adwords_ads where name = ".as[User]
val list: List[User] = t.list()

Edit:

, :

/** GetResult implicit for fetching SalesforceLogRow objects using plain SQL queries */
implicit def GetResultSalesforceLogRow(implicit e0: GR[Long], e1: GR[String], e2: GR[Int], e3: GR[java.sql.Timestamp], e4: GR[Option[java.sql.Timestamp]]): GR[myEntity] = GR {
  prs => import prs._
    myEntity.tupled((<<[Long], <<[Long], <<[String], <<[Int], <<[java.sql.Timestamp], <<[Long], <<?[java.sql.Timestamp]))
}

, , , , SQL.

+4

All Articles