conditional partial update

137 views
Skip to first unread message

adam00

unread,
Apr 19, 2011, 5:21:48 PM4/19/11
to Squeryl
Hello,

I need to update some fields of table conditionaly, something like
this:

update(table1)(x =>
where(x.ObjId === objId)
set(x.FirstName := firstName.?,
x.LastName := lastName.?))

firstName and lastName are Option[String]. Will it work?

Option fields with ".?" could be use to build conditional where, it
could be nice if something like this will work for updates.

Kind Regards,
Adam

Maxime Lévesque

unread,
Apr 20, 2011, 9:17:13 AM4/20/11
to squ...@googlegroups.com

For the sake of uniformity it would be a good idea,


  http://www.assembla.com/spaces/squeryl/tickets/43-dynamic-set-clause-on-partial-update-satement

Meanwhile you can do something like this :


     update(table1)(x =>
       where(x.ObjId === objId)
       set(
        List(firstName.map(x.FirstName := _),
             lastName.map(x.LastName := _)).filter(_ != None).map(_.get)      
       )

adam00

unread,
Apr 20, 2011, 9:47:33 AM4/20/11
to Squeryl
Thanks for your code suggestion, my solution was a lot uglier :-)

Kind Regards,
Adam

Michael Bayne

unread,
Apr 21, 2011, 12:43:45 PM4/21/11
to squ...@googlegroups.com, Maxime Lévesque
2011/4/20 Maxime Lévesque <maxime....@gmail.com>:

>      update(table1)(x =>
>        where(x.ObjId === objId)
>        set(
>         List(firstName.map(x.FirstName := _),
>              lastName.map(x.LastName := _)).filter(_ != None).map(_.get)
>
>        )

I think you can just do:

List(firstName.map(x.FirstName := _), lastName.map(x.LastName := _)).flatten

-- m...@samskivert.com

Reply all
Reply to author
Forward
0 new messages