On Fri, Oct 10, 2008 at 1:25 PM, Jamu Kakar <[EMAIL PROTECTED]> wrote:
> > To solve the original poster's issue, where one needs to determine > if an object exists and then create or update it, I'd use something > like: > > customer = store.find(Customer, Customer.last_name == u"Sparrow").one() > if not customer: > customer = store.add(Customer(u"Jack", u"Sparrow")) > else: > customer.first_name = u"Jack" > customer.last_name = u"Sparrow" > > You need to use a query that will only ever return 0 or 1 row when > you use ResultSet.one. If more than 1 row is returned a NotOneError > will be raised. > I'm using this pattern but have found that Storm selects all the columns when doing store.find, which is often unnecessary and exacts a performance penalty. Storm .13 release notes say it's possible now to address this problem: - Expressions can be passed to Store.find() as well as classes. This makes it possible to request individual columns from a table, computed expressions or aggregates. 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. I haven't tried messing around with directly setting obj_info['pending']; that seems kind of kludgy... (I'm still using an older branch of storm, closer to .12 than to .13. Still haven't had time to upgrade and test everything with new Storm...) -- ZeOmega Open Minds' Open Solutions 3010 Gaylord Parkway, Ste. 210 Frisco TX, 75034 http://www.zeomega.com Brad Allen 214-618-9880 (ext. 8006)
-- storm mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
