[storm] Update or add pattern with Storm
Jamu Kakar
jkakar at canonical.com
Sun Nov 2 16:25:24 GMT 2008
Hi Brad,
Brad Allen wrote:
> Is that the only way to get around this? It would be nice if I could
> perform a database update without doing any select at all. Sometimes the
> id value of the primary key is already available, and I just want to do
> an update without selecting first.
>
> In those situations, it would be nice if we could just do something like:
>
> customer = Customer (id=123, first_name = u'Jack', last_name = u'Sparrow')
>
> However, we can't use store.add for this object if we want it to
> generate an update statement; Storm usually generates an insert
> statement for store.add unless the object was already in the store as a
> result of store.find or store.get.
You can use ResultSet.set to run an update without invoking object
creation and caching behaviour:
result = store.find(Customer, Customer.id=123)
result.set(last_name=u"Sparrow-Hawk")
If Store.find returns many rows, ResultSet.set will run an UPDATE
that affects all of them.
Thanks,
J.
More information about the storm
mailing list