[storm] Store and values()
Jamu Kakar
jamshed.kakar at canonical.com
Wed Jan 30 02:12:04 GMT 2008
Hi Adrian,
Adrian Klaver wrote:
> Could someone enlighten me on the proper way to use
> Store.ResultSet.values(). I would like to retrieve only a couple of
> columns from a Store.
You need to pass the names of the columns you want to values(). For
example:
>>> from storm.locals import Storm, Store, Int, Unicode, create_database
>>> store = Store(create_database("sqlite:"))
>>> store.execute("CREATE TABLE person ("
... " id INTEGER PRIMARY KEY,"
... " name TEXT NOT NULL,"
... " city TEXT)", noresult=True)
>>> store.commit()
>>> class Person(Storm):
... __storm_table__ = "person"
... id = Int(primary=True, allow_none=False)
... name = Unicode(allow_none=False)
... city = Unicode()
... def __init__(self, name, city=None):
... self.name = name
... self.city = city
...
>>> store.add(Person(u"John"))
<__main__.Person object at 0xb7abbcac>
>>> store.add(Person(u"Jane", u"Tehran"))
<__main__.Person object at 0xb7ceed6c>
>>> result = store.find(Person)
>>> list(result.values(Person.name, Person.city))
[(u'John', None), (u'Jane', u'Tehran')]
Thanks,
J.
More information about the storm
mailing list