scala - Slick update return the updated object -
i'm trying have function return updated object after db runs update method on query right now, can't figure out how return object. function wrote using examples found, extend q.update(cat) return future[cat].
def update(id: long, cat: cat): future[unit] = db.run { val q = { c <- cats if c.id === id } yield c q.update(cat).map(_ => ()) }
you should try following:
def update(id: long, cat: cat): future[option[cat]] = db.run { cats.filter(_.id === id).update(cat).map { case 0 => none case _ => some(cat) } }
you should return future[option[cat]]
instead of future[cat]
, because cat provided id might not exist (the update
method returns 0
value then). violating integrity constraints result in failure
of future
.
Comments
Post a Comment