diff --git a/sqlite_utils/utils.py b/sqlite_utils/utils.py index ee6695b55..92411d2c8 100644 --- a/sqlite_utils/utils.py +++ b/sqlite_utils/utils.py @@ -182,6 +182,8 @@ def column_affinity(column_type: str) -> type: return bytes if "REAL" in column_type or "FLOA" in column_type or "DOUB" in column_type: return float + if "BOOL" in column_type: + return int if column_type == "ANY": return ANY # Default is 'NUMERIC', which we currently also treat as float diff --git a/tests/test_utils.py b/tests/test_utils.py index 360a4436a..03f63455d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -102,3 +102,22 @@ def test_flatten(input, expected): ) def test_dedupe_keys(input, expected): assert utils.dedupe_keys(input) == expected + + +@pytest.mark.parametrize( + "column_type,expected", + ( + ("BOOLEAN", int), + ("BOOL", int), + ("INTEGER", int), + ("TEXT", str), + ("REAL", float), + ("BLOB", bytes), + ("VARCHAR(255)", str), + ("DOUBLE PRECISION", float), + ("NUMERIC", float), + ("", str), + ), +) +def test_column_affinity(column_type, expected): + assert utils.column_affinity(column_type) is expected