mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-26 19:04:32 +02:00
create_table now handles compound primary keys, closes #36
This commit is contained in:
parent
90edd0d817
commit
d5dc92876e
2 changed files with 45 additions and 12 deletions
|
|
@ -55,6 +55,21 @@ def test_create_table(fresh_db):
|
|||
) == table.schema
|
||||
|
||||
|
||||
def test_create_table_compound_primary_key(fresh_db):
|
||||
table = fresh_db.create_table(
|
||||
"test_table", {"id1": str, "id2": str, "value": int}, pk=("id1", "id2")
|
||||
)
|
||||
assert (
|
||||
"CREATE TABLE [test_table] (\n"
|
||||
" [id1] TEXT,\n"
|
||||
" [id2] TEXT,\n"
|
||||
" [value] INTEGER,\n"
|
||||
" PRIMARY KEY ([id1], [id2])\n"
|
||||
")"
|
||||
) == table.schema
|
||||
assert ["id1", "id2"] == table.pks
|
||||
|
||||
|
||||
def test_create_table_with_bad_defaults(fresh_db):
|
||||
with pytest.raises(AssertionError):
|
||||
fresh_db.create_table(
|
||||
|
|
@ -122,6 +137,13 @@ def test_create_table_from_example(fresh_db, example, expected_columns):
|
|||
]
|
||||
|
||||
|
||||
def test_create_table_from_example_with_compound_primary_keys(fresh_db):
|
||||
record = {"name": "Zhang", "group": "staff", "employee_id": 2}
|
||||
table = fresh_db["people"].insert(record, pk=("group", "employee_id"))
|
||||
assert ["group", "employee_id"] == table.pks
|
||||
assert record == table.get(("staff", 2))
|
||||
|
||||
|
||||
def test_create_table_column_order(fresh_db):
|
||||
fresh_db["table"].insert(
|
||||
collections.OrderedDict(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue