Skip to content

Commit

Permalink
Handle dict/tuple/list mapping to TEXT, closes #338
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 15, 2021
1 parent 84007df commit 9cda5b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sqlite_utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class Default:
bool: "INTEGER",
str: "TEXT",
dict: "TEXT",
tuple: "TEXT",
list: "TEXT",
bytes.__class__: "BLOB",
bytes: "BLOB",
memoryview: "BLOB",
Expand Down
27 changes: 27 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,30 @@ def test_create_with_nested_bytes(fresh_db):
)
def test_quote(fresh_db, input, expected):
assert fresh_db.quote(input) == expected


@pytest.mark.parametrize(
"columns,expected_sql_middle",
(
(
{"id": int},
"[id] INTEGER",
),
(
{"col": dict},
"[col] TEXT",
),
(
{"col": tuple},
"[col] TEXT",
),
(
{"col": list},
"[col] TEXT",
),
),
)
def test_create_table_sql(fresh_db, columns, expected_sql_middle):
sql = fresh_db.create_table_sql("t", columns)
middle = sql.split("(")[1].split(")")[0].strip()
assert middle == expected_sql_middle

0 comments on commit 9cda5b0

Please sign in to comment.