Make square braces only return tables, not views

Breaking change for 4.0: db["name"] now only returns Table objects, never View objects.
This improves type safety since views lack methods like .insert().

Use db.view("view_name") to access views explicitly.

Closes #699
This commit is contained in:
Claude 2025-12-21 00:32:25 +00:00
commit c791a31047
No known key found for this signature in database
6 changed files with 18 additions and 15 deletions

View file

@ -12,6 +12,7 @@ from sqlite_utils.db import (
BadMultiValues,
DescIndex,
NoTable,
NoView,
quote_identifier,
)
from sqlite_utils.plugins import pm, get_plugins
@ -1796,9 +1797,10 @@ def drop_view(path, view, ignore, load_extension):
_register_db_for_cleanup(db)
_load_extensions(db, load_extension)
try:
db[view].drop(ignore=ignore)
except OperationalError:
raise click.ClickException('View "{}" does not exist'.format(view))
db.view(view).drop(ignore=ignore)
except NoView:
if not ignore:
raise click.ClickException('View "{}" does not exist'.format(view))
@cli.command()