码迷,mamicode.com
首页 > 数据库 > 详细

sqlalchemy动态组合查询语句。

时间:2018-08-26 11:42:41      阅读:587      评论:0      收藏:0      [点我收藏+]

标签:==   play   ESS   create   class   pre   code   type   status   

        if filter_type == 1:
            search = and_(GameRoom.status ==1,or_(
                and_(GameRoom.white_user_id == user_id,
                     GameRoom.active_player == 1),
                and_(GameRoom.black_user_id == user_id,
                     GameRoom.active_player == 0)))
        elif filter_type == 2:
            search = and_(GameRoom.status ==1,or_(
                and_(GameRoom.white_user_id == user_id,
                     GameRoom.active_player == 0),
                and_(GameRoom.black_user_id == user_id,
                     GameRoom.active_player == 1)))
        elif filter_type == 3:
            search = GameRoom.create_by == user_id
        
        db.session.query(GameRoom).filter(search).all()

 

sqlalchemy动态组合查询语句。

标签:==   play   ESS   create   class   pre   code   type   status   

原文地址:https://www.cnblogs.com/jackadam/p/9536368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!