This module provide utility functions for update operation.

sqlalchemy_mate.crud.updating.update_all(engine, table, data, upsert=False)[source]

Update data by its primary_key column.

sqlalchemy_mate.crud.updating.upsert_all(engine, table, data)[source]

Update data by primary key columns. If not able to update, do insert.


# suppose in database we already have {"id": 1, "name": "Alice"}
>>> data = [
...     {"id": 1, "name": "Bob"}, # this will be updated
...     {"id": 2, "name": "Cathy"}, # this will be added
... ]
>>> upsert_all(engine, table_user, data)
>>> engine.execute(select([table_user])).fetchall()
[{"id": 1, "name": "Bob"}, {"id": 2, "name": "Cathy"}]


批量更新文档. 如果该表格定义了Primary Key, 则用Primary Key约束where语句. 对于 where语句无法找到的行, 自动进行批量bulk insert.