[storm] Lazy value loading

Adrian Adamiak adamiak at gmail.com
Fri Oct 24 13:16:25 BST 2008


Hi. I've got a question about lazy value loading.

Let's say that I have an ORM mapping for table 'book':

class Book(object):
    __storm_table__ = "book"
    id = Int(primary=True)
    author = Unicode()
    title = Unicode()
    contents = Unicode()     # this can be big

Sometimes I need to display a list of titles and authors of all books, so I use:

books = store.find(Book)

Unfortunately this produces query which loads all fields, including
'contents', which is unnecessary and takes a lot of time. I'd like to
make the 'contents' field lazy, i.e.

 contents = Unicode(lazy=True)    # (in Book class definition)

so that it would load only after I access this field (i.e.
books[0].contents). Is it possible?

Thanks,
Adrian

PS. I know I can do store.find((Book.author, Book.title)), but it
doesn't return Book objects, which I use later to update values.



More information about the storm mailing list