sqlalchemy的批量添加

bulk_save_objects:速度中等,稳定高
test_table:需要添加的数据列表

User:添加的实体对象

for k,v in enumerate(test_table):
    session.bulk_save_objects(
        [
            User(rank=k+1)
        ]
    )
session.commit()

sqlalchemy的批量修改

session.query(User).filter(User.district=='shandong').update({User.arrress: '中国'})
session.commit()

sqlalchemy的批量删除

session.query(User).filter(User.district=='shandong').delete()
session.commit()
Last modification:September 15th, 2020 at 05:46 pm
If you think my article is useful to you, please feel free to appreciate