add yield_per_query() helper
This commit is contained in:
parent
01cc9fe388
commit
b2e4578953
|
@ -65,6 +65,11 @@ class ModelMixin(object):
|
|||
def query(cls):
|
||||
return Session.query(cls)
|
||||
|
||||
@classmethod
|
||||
def yield_per_query(cls, page=1000):
|
||||
"""to be used when iterating on a big table to avoid taking all the memory"""
|
||||
return Session.query(cls).yield_per(page).enable_eagerloads(False)
|
||||
|
||||
@classmethod
|
||||
def get(cls, id):
|
||||
return Session.query(cls).get(id)
|
||||
|
|
Loading…
Reference in New Issue