Cleanup __init__ and add functions to convert SQLAchemy results into dict.

This commit is contained in:
Alexis Lahouze 2017-05-25 21:18:30 +02:00
parent 01a509d348
commit b436e0aa06

View File

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