mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-11 19:14:10 +02:00
New upsert implementation, refs #66
This commit is contained in:
parent
cfbc09967e
commit
84bcabd093
4 changed files with 156 additions and 48 deletions
16
tests/test_upsert.py
Normal file
16
tests/test_upsert.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
def test_upsert(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
table.insert({"id": 1, "name": "Cleo"}, pk="id")
|
||||
table.upsert({"id": 1, "age": 5}, pk="id", alter=True)
|
||||
assert [{"id": 1, "name": "Cleo", "age": 5}] == list(table.rows)
|
||||
|
||||
|
||||
def test_upsert_all(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
table.upsert_all([{"id": 1, "name": "Cleo"}, {"id": 2, "name": "Nixie"}], pk="id")
|
||||
table.upsert_all([{"id": 1, "age": 5}, {"id": 2, "age": 5}], pk="id", alter=True)
|
||||
assert [
|
||||
{"id": 1, "name": "Cleo", "age": 5},
|
||||
{"id": 2, "name": "Nixie", "age": 5},
|
||||
] == list(table.rows)
|
||||
assert 2 == table.last_pk
|
||||
Loading…
Add table
Add a link
Reference in a new issue