generated from caltechlibrary/template
-
Notifications
You must be signed in to change notification settings - Fork 5
Notes about Peewee
Mike Hucka edited this page May 11, 2021
·
1 revision
Worth knowing: Peewee queries are lazy-executed: they return iterators that must be accessed before the query is actually executed. Thus, when selecting items, the following returns a Peewee ModelSelector
, and not a single result or a list of results:
Item.select().where(Item.barcode == barcode)
and you can't call something like Python's next(...)
on this because it's an iterator and not a generator. You have to either use a for
loop, or create a list from the above before you can do much with it. Creating lists in these cases would be inefficient, but we have so few items to deal with that it's not a concern currently.