diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 37a95f8..35f2fc2 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -71,7 +71,7 @@ class Database: None.__class__: "TEXT", } columns_sql = ",\n".join( - " [{col_name}] {col_type} {primary_key} {references}".format( + " [{col_name}] {col_type}{primary_key}{references}".format( col_name=col_name, col_type=col_type_mapping[col_type], primary_key=" PRIMARY KEY" if (pk == col_name) else "", @@ -87,8 +87,8 @@ class Database: for col_name, col_type in column_items ) sql = """CREATE TABLE [{table}] ( - {columns_sql} - ){extra}; +{columns_sql} +){extra}; """.format( table=name, columns_sql=columns_sql, extra=extra ) diff --git a/tests/test_create.py b/tests/test_create.py index 80cb8d1..4bd0af5 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -28,6 +28,16 @@ def test_create_table(fresh_db): {"name": "bytes_col", "type": "BLOB"}, {"name": "datetime_col", "type": "TEXT"}, ] == [{"name": col.name, "type": col.type} for col in table.columns] + assert ( + "CREATE TABLE [test_table] (\n" + " [text_col] TEXT,\n" + " [float_col] FLOAT,\n" + " [int_col] INTEGER,\n" + " [bool_col] INTEGER,\n" + " [bytes_col] BLOB,\n" + " [datetime_col] TEXT\n" + ")" + ) == table.schema @pytest.mark.parametrize(