scala - Insert or get in Slick 3 -


i trying insert if not exists, , row if does. come this:

def saveorget(u: user) = (for {   userget <- get(u.name).map(r => (r.id, r.active)).result.headoption   id <- save(u) if userget.isempty } yield {   userget match {     case some((id, active)) => (user(some(id), u.name, active), false)     case none               => (user(some(id), u.name, u.active), true)   } }).transactionally  private def get(name: string) = users.filter(_.name === name).take(1)  private def save(u: user) = users returning users.map(_.id) += u 

edit

after making modifications, get:

java.util.nosuchelementexception: action.withfilter failed 

regards

try using case _, because seems it's possible have empty rather none

userget match {     case some((id, active)) => (user(some(id), u.name, active), false)     case _                  => (user(some(id), u.name, u.active), true) } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -