1. 程式人生 > >sqlalchemy動態組合查詢語句。

sqlalchemy動態組合查詢語句。

alc 查詢語句 creat ear roo player active 組合查詢 arch

        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動態組合查詢語句。