I'm new to Scala, Slick, and Play, but I'm trying to make a little maintenance using this technology. I have a problem with the correct way to check for an element in the database.
Playback action - just see the output in the browser:
val id = 5
val name = "xx"
def show(): Action async {
dao.isExist(id,name).map(c => Ok(c.toString)
}
Tao
User = TableQuery[UserRow]
def isExist(id:Int, name:String) = {
val res = db.run(User.filter(i => (i.id === id || i.name === name)).result)}
if (res.length > 0) true else false
res match {
case 0 => Future(true)
case _ => Future(false)
}
val trueRes = Await.result(res, Duratin.Inf)
I think I should avoid using Await, but in this case I need to do some action based on the fact that the DB will return. Could you advise what would be the best model for resolving this matter?
source
share