add yield_per_query() helper

This commit is contained in:
Son 2022-01-06 18:50:54 +01:00
parent 01cc9fe388
commit b2e4578953
1 changed files with 5 additions and 0 deletions

View File

@ -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)