From 9cda5b070f885a7995f0c307bcc4f45f0812994a Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 14 Nov 2021 16:36:00 -0800 Subject: [PATCH] Handle dict/tuple/list mapping to TEXT, closes #338 --- sqlite_utils/db.py | 2 ++ tests/test_create.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 9667641a9..828ef6812 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -168,6 +168,8 @@ class Default: bool: "INTEGER", str: "TEXT", dict: "TEXT", + tuple: "TEXT", + list: "TEXT", bytes.__class__: "BLOB", bytes: "BLOB", memoryview: "BLOB", diff --git a/tests/test_create.py b/tests/test_create.py index acaeaeebd..c9568d9cd 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -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