mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
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.
31 lines
756 B
Python
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()
|