scala - slick update fields dynamically -



scala - slick update fields dynamically -

i form play controller

class customertable(tag: tag) extends table[customer]("customer", tag) { def id = column[long]("id") ... def * = ... } case class customer( id: long, remarkname: string ... ) case class customerupdateform( id: long, remarkname: option[string], realname: option[string], birth: option[date], address: option[string], phone: option[string], qq: option[string], email: option[string])

and want update database nonempty fields of form, here's how did

def updatefield(form: customerupdateform) = { def updatefield0[t]( field: customertable => column[t], value: t) = { customertable .filer(_.id, form.id) .map(c => field(c) -> c.gmtmodified) .update(value -> new date) } var updated = 0 if (form.remarkname.nonempty) updatefield0(_.remarkname, form.remarkname) updated = updated + 1 if(form.realname.nonempty) updatefield0(_.realname, form.realname) updated = updated + 1 if(form.birth.nonempty) updatefield0(_.birth, form.birth) updated = updated + 1 if(form.address.nonempty) updatefield0(_.address, form.address) updated = updated + 1 if(form.phone.nonempty) updatefield0(_.phone, form.phone) updated = updated + 1 if(form.qq.nonempty) updatefield0(_.qq, form.qq) updated = updated + 1 if(form.email.nonempty) updatefield0(_.email, form.email) updated = updated + 1 if(updated > 1) 1 else 0 }

can update fields 1 time ?

scala playframework slick

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -