playframework - Slick orm for scala how can I retrieve a database column value -
i new slick orm using version 3.1.1 , in examples plain sql did not see how can retrieve value of database column http://slick.typesafe.com/doc/3.1.1/sql.html . simple example
def listfollowing() = action.async { val selectq=sql"""select model,id carsdb id=17""".as[(string,int)] // value of model , put in var // var model= model database.run(selectq).map {finished=> // value of model , put in var // var model= model ok(finished.tostring()) } }
how can value of column model so put in var or val ?
when do: database.run(selectq).map {finished=> ... }
finished
vector[(string,int)]
. if sure returns 1 row (because of "... id=17"
) can take headoption()
, check if there value in (it none if there no record id 17) , if there -> return else return error. code this:
def listfollowing() = action.async { val selectq = sql"""select model,id carsdb id=17""".as[(string, int)] db.run(selectq).map { finished => finished.headoption match { case s: (string, int) => ok(s._1) case none => ok("no car found requested id") } } }
Comments
Post a Comment