mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
pk=['id'] now equivalent to pk='id', closes #181
This commit is contained in:
parent
7eda0532e8
commit
7c0ef116ed
2 changed files with 8 additions and 5 deletions
|
|
@ -330,6 +330,8 @@ class Database:
|
|||
column_defs = []
|
||||
# ensure pk is a tuple
|
||||
single_pk = None
|
||||
if isinstance(pk, list) and len(pk) == 1 and isinstance(pk[0], str):
|
||||
pk = pk[0]
|
||||
if isinstance(pk, str):
|
||||
single_pk = pk
|
||||
if pk not in [c[0] for c in column_items]:
|
||||
|
|
|
|||
|
|
@ -73,11 +73,12 @@ def test_create_table_compound_primary_key(fresh_db):
|
|||
assert ["id1", "id2"] == table.pks
|
||||
|
||||
|
||||
def test_create_table_with_bad_defaults(fresh_db):
|
||||
with pytest.raises(AssertionError):
|
||||
fresh_db.create_table(
|
||||
"players", {"name": str, "score": int}, defaults={"mouse": 1}
|
||||
)
|
||||
@pytest.mark.parametrize("pk", ("id", ["id"]))
|
||||
def test_create_table_with_single_primary_key(fresh_db, pk):
|
||||
fresh_db["foo"].insert({"id": 1}, pk=pk)
|
||||
assert (
|
||||
fresh_db["foo"].schema == "CREATE TABLE [foo] (\n [id] INTEGER PRIMARY KEY\n)"
|
||||
)
|
||||
|
||||
|
||||
def test_create_table_with_invalid_column_characters(fresh_db):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue