mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-28 12:54:15 +02:00
Handle dict/tuple/list mapping to TEXT, closes #338
This commit is contained in:
parent
84007dffa8
commit
9cda5b070f
2 changed files with 29 additions and 0 deletions
|
|
@ -168,6 +168,8 @@ COLUMN_TYPE_MAPPING = {
|
||||||
bool: "INTEGER",
|
bool: "INTEGER",
|
||||||
str: "TEXT",
|
str: "TEXT",
|
||||||
dict: "TEXT",
|
dict: "TEXT",
|
||||||
|
tuple: "TEXT",
|
||||||
|
list: "TEXT",
|
||||||
bytes.__class__: "BLOB",
|
bytes.__class__: "BLOB",
|
||||||
bytes: "BLOB",
|
bytes: "BLOB",
|
||||||
memoryview: "BLOB",
|
memoryview: "BLOB",
|
||||||
|
|
|
||||||
|
|
@ -1040,3 +1040,30 @@ def test_create_with_nested_bytes(fresh_db):
|
||||||
)
|
)
|
||||||
def test_quote(fresh_db, input, expected):
|
def test_quote(fresh_db, input, expected):
|
||||||
assert fresh_db.quote(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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue