Handle dict/tuple/list mapping to TEXT, closes #338

This commit is contained in:
Simon Willison 2021-11-14 16:36:00 -08:00
commit 9cda5b070f
2 changed files with 29 additions and 0 deletions

View file

@ -168,6 +168,8 @@ COLUMN_TYPE_MAPPING = {
bool: "INTEGER",
str: "TEXT",
dict: "TEXT",
tuple: "TEXT",
list: "TEXT",
bytes.__class__: "BLOB",
bytes: "BLOB",
memoryview: "BLOB",

View file

@ -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