From b436e0aa06c0b9a60965395a8833cbe5dec8689b Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 25 May 2017 21:18:30 +0200 Subject: [PATCH] Cleanup __init__ and add functions to convert SQLAchemy results into dict. --- accountant/models/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/accountant/models/__init__.py b/accountant/models/__init__.py index 7ce8b46..91107e3 100644 --- a/accountant/models/__init__.py +++ b/accountant/models/__init__.py @@ -2,14 +2,18 @@ # vim: set tw=80 ts=4 sw=4 sts=4: -import pkgutil - from flask_sqlalchemy import SQLAlchemy # pylint: disable=invalid-name db = SQLAlchemy() -__all__ = ['db'] -for loader, module_name, is_pkg in pkgutil.walk_packages(__path__): - __all__.append(module_name) +def row_as_dict(row): + """Return a SQLAlchemy row as dict.""" + return dict(zip(row.keys(), row)) + + +def result_as_dicts(query): + """Return SQLAlchemy query results as dictionnaries.""" + for row in query.all(): + yield row_as_dict(row)