-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
table.create(..., replace=True) #568
Comments
https://sqlite-utils.datasette.io/en/stable/cli-reference.html#create-table sqlite-utils create-table ... --replace That also has
|
Here's where those are implemented for the sqlite-utils/sqlite_utils/cli.py Lines 1543 to 1564 in f7af238
|
I think this is |
Demo: >>> from sqlite_utils import Database
>>> db = Database(memory=True)
>>> db["foo"].create({"id": int})
<Table foo (id)>
>>> db["foo"].create({"id": int})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/db.py", line 1647, in create
self.db.create_table(
File "/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/db.py", line 1030, in create_table
self.execute(sql)
File "/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/db.py", line 510, in execute
return self.conn.execute(sql)
^^^^^^^^^^^^^^^^^^^^^^
sqlean.dbapi2.OperationalError: table [foo] already exists
>>> db["foo"].create({"id": int}, ignore=True)
<Table foo (id)>
>>> db["foo"].create({"id": int, "name": str}, replace=True)
<Table foo (id, name)>
>>> db["foo"].create({"id": int, "name": str, "age": int}, transform=True)
<Table foo (id, name, age)> |
Manual testing of CLI command as well:
|
I think this broke a test:
|
Here's why that test broke: sqlite-utils/sqlite_utils/db.py Lines 960 to 964 in 58b5772
I added an extra |
Found myself using this pattern to quickly prototype a schema:
Using
replace=True
to drop and then recreate the table would be neat here, and would be consistent with other places that usereplace=True
.The text was updated successfully, but these errors were encountered: