[storm] Calculated attributes

Gerdus van Zyl gerdusvanzyl at gmail.com
Fri Jan 11 14:02:06 GMT 2008


Hi,

Is there an easy way to get SQL calculated attributes using storm?

my class:
class Account(object):
    __storm_table__ = "account"
    id = Int(primary=True)
    name = Unicode()

    def getBalance(self):
        balance = SQL("SELECT sum(amount) FROM entry")
        r = store.execute(balance).get_one()[0]
        return r

I want to turn getBalance into balance property.
e.g: balance = SQLvalue("SELECT sum(amount) FROM entry")
I know it can be done using balance = property(getBalance) etc, but a
convenience function would be great.

Also is there a method that is called on an Entity when it is retrieve
from the store?  __init__ does not seem to be called.


Thank you,
Gerdus van Zyl



More information about the storm mailing list