mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
.upsert() and upsert_all() require pk=, closes #73
This commit is contained in:
parent
1f3f902ea4
commit
489eda92bc
2 changed files with 18 additions and 3 deletions
|
|
@ -1,3 +1,7 @@
|
|||
from sqlite_utils.db import PrimaryKeyRequired
|
||||
import pytest
|
||||
|
||||
|
||||
def test_upsert(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
table.insert({"id": 1, "name": "Cleo"}, pk="id")
|
||||
|
|
@ -16,6 +20,14 @@ def test_upsert_all(fresh_db):
|
|||
assert 2 == table.last_pk
|
||||
|
||||
|
||||
def test_upsert_error_if_no_pk(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
with pytest.raises(PrimaryKeyRequired):
|
||||
table.upsert_all([{"id": 1, "name": "Cleo"}])
|
||||
with pytest.raises(PrimaryKeyRequired):
|
||||
table.upsert({"id": 1, "name": "Cleo"})
|
||||
|
||||
|
||||
def test_upsert_compound_primary_key(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
table.upsert_all(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue