def get_articles_by_search(cls, search_text): t = db.article if isinstance(search_text, unicode): search_text.encode('utf-8') sql = select([t]).where(t.c.title.like('%' + search_text + '%')).order_by(t.c.id.desc()) return db.execute(sql).fetchall()
def get_by_ids_v2(cls, ids): t = db.article_tag sql = select([t]).where(t.c.id.in_(ids)) sql = sql.order_by(t.c.id.desc()) return db.execute(sql).fetchall()
def create_comment(cls, fields): t = db.article_comment ins = t.insert().values(**fields) return db.execute(ins).inserted_primary_key[0]
def get_all_comments_by_article_ids(cls, article_ids): t = db.article_comment sql = select([t]).where(t.c.article_id.in_(article_ids)) sql = sql.order_by(t.c.id.desc()) return db.execute(sql).fetchall()
def get_articles_by_date(cls, start, end): t = db.article sql = select([t]).order_by(t.c.id.desc()) sql = sql.where( and_(t.c.created >= str(start), t.c.created <= str(end))) return db.execute(sql).fetchall()
def get_all_articles(cls): t = db.article sql = select([t]).order_by(t.c.id.desc()) return db.execute(sql).fetchall()
def get_by_ids(cls, ids): t = db.category sql = select([t]).where(t.c.id.in_(ids)) sql = sql.order_by(t.c.id.desc()) return db.execute(sql).fetchall()