Where/Filter from Table object using a Dictionary (or **kwargs)

前端 未结 1 589

I\'m trying to update all Users in the users Table given some criteria.

update = ({\"username\" : \"user1\"}, {\"address\" : \"1234\", \"password\" : \"newpa         


        
1条回答
  •  庸人自扰
    2020-12-21 06:49

    you can create where clauses list and pass it to where()

    from sqlalchemy import and_
    
    update = ({"username" : "user1"}, {"address" : "1234", "password" : "newpass"})
    
    where_clauses = [users.c[key]==value for (key, value) in update[0].items()]
    users.update().where(and_(*where_clauses)).values(**update[1])
    

    0 讨论(0)
提交回复
热议问题