mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-25 18:34:32 +02:00
hash_id= mechanism for setting ID using content hash, closes #13
This commit is contained in:
parent
e615d22c55
commit
dbf239e3fc
3 changed files with 93 additions and 7 deletions
|
|
@ -206,6 +206,17 @@ def test_insert_thousands_ignores_extra_columns_after_first_100(fresh_db):
|
|||
assert [{"i": 101, "word": None}] == rows
|
||||
|
||||
|
||||
def test_insert_hash_id(fresh_db):
|
||||
dogs = fresh_db["dogs"]
|
||||
id = dogs.upsert({"name": "Cleo", "twitter": "cleopaws"}, hash_id="id").last_pk
|
||||
assert "f501265970505d9825d8d9f590bfab3519fb20b1" == id
|
||||
assert 1 == dogs.count
|
||||
# Upserting a second time should not create a new row
|
||||
id2 = dogs.upsert({"name": "Cleo", "twitter": "cleopaws"}, hash_id="id").last_pk
|
||||
assert "f501265970505d9825d8d9f590bfab3519fb20b1" == id2
|
||||
assert 1 == dogs.count
|
||||
|
||||
|
||||
def test_create_view(fresh_db):
|
||||
fresh_db["data"].insert({"foo": "foo", "bar": "bar"})
|
||||
fresh_db.create_view("bar", "select bar from data")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue