This is necessary because SQLModel only spits out the first column of
any custom queries.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
# #
###############################################################################
+import collections
import functools
import logging
import sqlalchemy.orm
# Return the object
return object
+ def select(self, stmt, batch_size=128):
+ """
+ Selects custom queries
+ """
+ result = self.execute(stmt)
+
+ # Process the result in batches
+ if batch_size:
+ result = result.yield_per(batch_size)
+
+ # Return all objects
+ for object in result.mappings():
+ row = collections.namedtuple("Row", object.keys())
+
+ yield row(**object)
+
def fetch(self, stmt, batch_size=128):
"""
Fetches objects of the given type