[storm] Store and values()

Adrian Klaver aklaver at comcast.net
Wed Jan 30 02:41:35 GMT 2008


On Tuesday 29 January 2008 6:12 pm, Jamu Kakar wrote:
> 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.
Thanks, it makes sense now.
-- 
Adrian Klaver
aklaver at comcast.net



More information about the storm mailing list