mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 12:54:15 +02:00
.insert(hash_id_columns=) parameter, closes #343
This commit is contained in:
parent
b6c9dfce0b
commit
931b1e1513
7 changed files with 158 additions and 15 deletions
|
|
@ -45,6 +45,30 @@ def test_upsert_with_hash_id(fresh_db):
|
|||
assert "a5e744d0164540d33b1d7ea616c28f2fa97e754a" == table.last_pk
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hash_id", (None, "custom_id"))
|
||||
def test_upsert_with_hash_id_columns(fresh_db, hash_id):
|
||||
table = fresh_db["table"]
|
||||
table.upsert({"a": 1, "b": 2, "c": 3}, hash_id=hash_id, hash_id_columns=("a", "b"))
|
||||
assert list(table.rows) == [
|
||||
{
|
||||
hash_id or "id": "4acc71e0547112eb432f0a36fb1924c4a738cb49",
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 3,
|
||||
}
|
||||
]
|
||||
assert table.last_pk == "4acc71e0547112eb432f0a36fb1924c4a738cb49"
|
||||
table.upsert({"a": 1, "b": 2, "c": 4}, hash_id=hash_id, hash_id_columns=("a", "b"))
|
||||
assert list(table.rows) == [
|
||||
{
|
||||
hash_id or "id": "4acc71e0547112eb432f0a36fb1924c4a738cb49",
|
||||
"a": 1,
|
||||
"b": 2,
|
||||
"c": 4,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
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