def create_user(self, arg_dict): try: user = User(**arg_dict) except AssertionError as ex: raise falcon.HTTPBadRequest('Could not create User.', ex.message) try: return user.save() except (IntegrityError, InvalidRequestError) as ex: DB.rollback() raise falcon.HTTPBadRequest('Could not create User.', 'That email is already taken.')
def query(cls): return DB.query(cls)
def delete(self, commit=True): """Remove the record from the database.""" DB.delete(self) return commit and DB.commit()
def save(self, commit=True): """Save the record.""" DB.add(self) if commit: DB.commit() return self
def get(cls, id): """Get an instance from its id.""" return DB.query(cls).get(id)
def _query_collection(self, cls, schema): """Query a collection of a class passed in and return the JSON dump of its schema""" return json.dumps(json.loads(schema.dumps(DB.query(cls).all(), many=True).data))