Skip to content
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

Support IF NOT EXISTS for table creation #397

Closed
rafguns opened this issue Feb 4, 2022 · 3 comments
Closed

Support IF NOT EXISTS for table creation #397

rafguns opened this issue Feb 4, 2022 · 3 comments
Labels
enhancement New feature or request python-library

Comments

@rafguns
Copy link

rafguns commented Feb 4, 2022

Currently, I have a bunch of code that looks like this:

subjects = db["subjects"] if db["subjects"].exists() else db["subjects"].create({
    ...
})

It would be neat if sqlite-utils could simplify that by supporting CREATE TABLE IF NOT EXISTS, so that I'd be able to write, e.g.

subjects = db["subjects"].create({...}, if_not_exists=True)
@simonw
Copy link
Owner

simonw commented Feb 6, 2022

This is a good idea. We already have that parameter for the table.create_index() method: https://sqlite-utils.datasette.io/en/stable/reference.html#sqlite_utils.db.Table.create_index

@simonw simonw added enhancement New feature or request python-library labels Feb 6, 2022
@simonw
Copy link
Owner

simonw commented Feb 6, 2022

Just noticed there's no explicit test coverage for the db["table"].create(...) method.

@simonw
Copy link
Owner

simonw commented Feb 6, 2022

Updated documentation is here: https://sqlite-utils.datasette.io/en/latest/python-api.html#explicitly-creating-a-table

simonw added a commit that referenced this issue Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python-library
Projects
None yet
Development

No branches or pull requests

2 participants