예제 #1
0
 def one(self, pk):
     """
     Get one article
     return {obj} or None
     raises on error
     """
     try:
         with self.db_engine.session_scope() as session:
             auth_user, article = session.query(
                 eureka.model.auth.AuthUser,
                 eureka.model.article.Article,
             ).join(eureka.model.article.Article).filter(
                 (
                     eureka.model.auth.AuthUser.id ==
                     eureka.model.article.Article.auth_id
                 ) & (
                     eureka.model.article.Article.id == pk
                 )
             ).order_by(
                 eureka.model.article.Article.id.desc()
             ).one()
             result = {'auth_email': auth_user.email}
             result.update(article.to_dict())
             return result
     except sqlalchemy.orm.exc.NoResultFound:
         raise NotExists(pk)
예제 #2
0
 def all(self):
     """
     Get all articles
     return [{obj}, ...]
     """
     with self.db_engine.session_scope() as session:
         query = session.query(
             eureka.model.auth.AuthUser,
             eureka.model.article.Article,
         ).join(eureka.model.article.Article).filter(
             eureka.model.auth.AuthUser.id ==
             eureka.model.article.Article.auth_id
         ).order_by(
             eureka.model.article.Article.id.desc()
         )
         result = []
         for auth_user, article in query.all():
             dct = {'auth_email': auth_user.email}
             dct.update(article.to_dict())
             result.append(dct)
         return result