def create_mock(): form = CreateMockForm().execute_validate() result = Mock.insert(form) if result: return Success() else: return DatabaseError()
def update_mock(id): form = CreateMockForm().execute_validate() result = Mock.update_mock(id, form) if result: return Success() else: return DatabaseError()
def register(): form = UserRegisterForm().execute_validate() result = User.register_by_email(form['email'], form['password']) if result: return Success() else: return DatabaseError()
def update_project(id): form = CreateProjectForm().execute_validate() result = Project.update_project(id, form) if result: return Success() else: return DatabaseError()
def create_project(): form = CreateProjectForm().execute_validate() result = Project.insert(form['name'], form['desc']) if result: return Success() else: return DatabaseError()
def auto_commit(self): try: yield self.session.commit() except Exception as e: db.session.rollback() # raise e print(e) raise DatabaseError()
def delete(cls, key, value): table_name = cls.__name__.lower() sql = "update {} set deleted=1 where {} = {}".format(table_name, key, value) if not isinstance(value, int): sql = "update {} set deleted=1 where {} = '{}'".format(table_name, key, value) try: with db.auto_commit(): db.session.execute(sql) except ProgrammingError as e: print(e) return DatabaseError()