Files
notifications-api/app/dao/__init__.py
Leo Hemsted 5e702449cb move days_ago to utils and make it tz aware
it's used in a few places - it should definitely know what timezones
are and return datetimes rather than dates, which are hard to work with
in terms of figuring out how tz aware they are.
2018-04-30 11:13:21 +01:00

31 lines
756 B
Python

from sqlalchemy.exc import SQLAlchemyError
from app import db
# Should I use SQLAlchemyError?
class DAOException(SQLAlchemyError):
pass
class DAOClass(object):
class Meta:
model = None
def create_instance(self, inst, _commit=True):
db.session.add(inst)
if _commit:
db.session.commit()
def update_instance(self, inst, update_dict, _commit=True):
# Make sure the id is not included in the update_dict
update_dict.pop('id')
self.Meta.model.query.filter_by(id=inst.id).update(update_dict)
if _commit:
db.session.commit()
def delete_instance(self, inst, _commit=True):
db.session.delete(inst)
if _commit:
db.session.commit()