def getAllWhere(cls, db, **kwargs): with db.get_session() as session: return ( session .query(cls) .filter_by(**kwargs) .order_by(cls.updated).all() )
def getRecent(cls, db, recent=24): recent_date = time_services.now() - datetime.timedelta(hours=recent) with db.get_session() as session: return ( session .query(cls) .filter(cls.updated > recent_date) .order_by(cls.updated).all() )
def deleteWhere(cls, db, **kwargs): with db.get_session() as session: deleteJobs = cls.getAllWhere(db, **kwargs) for job in deleteJobs: session.delete(job)
def delete(self, db): with db.get_session() as session: obj, = session.query(self.__class__).filter_by( project_name=self.project_name, change_num=self.change_num).all() session.delete(obj)
def update_database_record(self, db, **kwargs): with db.get_session() as session: for name, value in kwargs.iteritems(): setattr(self, name, value)