Пример #1
0
 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.')
Пример #2
0
 def query(cls):
     return DB.query(cls)
Пример #3
0
 def delete(self, commit=True):
     """Remove the record from the database."""
     DB.delete(self)
     return commit and DB.commit()
Пример #4
0
 def save(self, commit=True):
     """Save the record."""
     DB.add(self)
     if commit:
         DB.commit()
     return self
Пример #5
0
 def get(cls, id):
     """Get an instance from its id."""
     return DB.query(cls).get(id)
Пример #6
0
 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))