val customers = TableQuery[Customers]
val query = customers.filter(_.customerId == 5)
Now what?
All the tutorials and documentation I've read have said to use query.result (doesn't exist) or query.run (also doesn't exist)
I've been stuck on this for a few hours now and it has given me a headache (literally).
Thanks for any help!
class Customers(tag: Tag) extends Table[Customer](tag, "Customers") {
// columns here
def projection = LiftedCustomer(customerId.?, customerName)
override def * = projection
}
object CaseClassMappers {
implicit object CustomerShape extends CaseClassShape(LiftedCustomer.tupled, Customer.tupled)
}
// search a key in keys table on key_id
def findCard(cardId: String) = {
val qa: DBIO[Seq[Key]] = keys.filter(k => k.key_id === cardId).result
def res = bagira_db.run(qa)
res
}
works fine
import com.typesafe.slick.driver.db2.DB2Driver.api._
It says `simple` has been deprecated so I should import api instead.
// write a pass to passes table
def cdr(clId: Long,crdId: String,trmId: String) = {
val qa: DBIO[Int] = passes.map(p => p.forIns) += (clId,crdId,trmId)
Is 'x' a Future[Int] or Future [Nothing]?
(It always helps to add explicit types if your types don't add up)
--
Cheers,
√
——————
Viktor Klang
Chief Architect
Typesafe Inc.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/18d4e86b-c2ba-4150-bc5f-87bedd17538f%40googlegroups.com.
val response = (databaseActor ? CreateUser(user))
.mapTo[Future[Int]]
.flatMap(identity)
Not sure if there's a better way as it doesn't seem very nice to return a Future[Future[Int]] but this seems to work...
Thanks for the advice
What does the actor's receive method look like, I think you are missing a pipeTo
--
Cheers,
√
——————
Viktor Klang
Chief Architect
Typesafe Inc.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/a33d39bf-d2ef-4b7d-9ec3-cc7b90cc7857%40googlegroups.com.
If the function returns a future, you should use pipeTo sender.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/e0b9bdbe-e214-43e0-949d-8c0c95f43761%40googlegroups.com.
Assuming the UserDAO methods return futures:
def receive = {
case CreateUser(user) =>
UserDAO.createUser(user) pipeTo sender()
case GetUserById(id) =>
userDAO.getUserById(id) pipeTo sender()
}
--
Cheers,
√
——————
Viktor Klang
Chief Architect
Typesafe Inc.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/e0b9bdbe-e214-43e0-949d-8c0c95f43761%40googlegroups.com.
You're most welcome!
--
Cheers,
√
——————
Viktor Klang
Chief Architect
Typesafe Inc.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/2434d3c2-aa4f-4a89-8742-cd40625570c3%40googlegroups.com.
val qa: DBIO[Seq[Models.User]] = query.result
println(qa.statements.head)
Does anyone know how to view the SQL statements being executed by Slick?
The documentation here: http://slick.typesafe.com/doc/3.0.0-RC1/queries.html?highlight=statements says to use query_action.statements
But this doesn't compile for me:
val qa: DBIO[Seq[Models.User]] = query.result println(qa.statements.head)
val m = applicant.filter(_.id === "123").result
val query = db.run(m) // this is a future object
val name = query.map(_.name) //unfortunately val name is also a future and not a string
println(name) // will return scala.concurrent.impl.Promise$DefaultPromise@69ee8449
Await.result(db.run(users.map(_.name).result), Duration.Inf)