mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-10 05:42:58 +00:00
refactor: rename drop_db / drop_database to drop_all_tables, expose database from connection (#2098)
If we start supporting external catalogs then "drop database" may be misleading (and not possible). We should be more clear that this is a utility method to drop all tables. This is also a nice chance for some consistency cleanup as it was `drop_db` in rust, `drop_database` in python, and non-existent in typescript. This PR also adds a public accessor to get the database trait from a connection. BREAKING CHANGE: the `drop_database` / `drop_db` methods are now deprecated.
This commit is contained in:
@@ -14,6 +14,7 @@ from overrides import EnforceOverrides, override # type: ignore
|
||||
from lancedb.common import data_to_reader, sanitize_uri, validate_schema
|
||||
from lancedb.background_loop import LOOP
|
||||
|
||||
from . import __version__
|
||||
from ._lancedb import connect as lancedb_connect # type: ignore
|
||||
from .table import (
|
||||
AsyncTable,
|
||||
@@ -26,6 +27,8 @@ from .util import (
|
||||
validate_table_name,
|
||||
)
|
||||
|
||||
import deprecation
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import pyarrow as pa
|
||||
from .pydantic import LanceModel
|
||||
@@ -294,6 +297,12 @@ class DBConnection(EnforceOverrides):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def drop_all_tables(self):
|
||||
"""
|
||||
Drop all tables from the database
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def uri(self) -> str:
|
||||
return self._uri
|
||||
@@ -486,9 +495,19 @@ class LanceDBConnection(DBConnection):
|
||||
"""
|
||||
LOOP.run(self._conn.drop_table(name, ignore_missing=ignore_missing))
|
||||
|
||||
@override
|
||||
def drop_all_tables(self):
|
||||
LOOP.run(self._conn.drop_all_tables())
|
||||
|
||||
@deprecation.deprecated(
|
||||
deprecated_in="0.15.1",
|
||||
removed_in="0.17",
|
||||
current_version=__version__,
|
||||
details="Use drop_all_tables() instead",
|
||||
)
|
||||
@override
|
||||
def drop_database(self):
|
||||
LOOP.run(self._conn.drop_database())
|
||||
LOOP.run(self._conn.drop_all_tables())
|
||||
|
||||
|
||||
class AsyncConnection(object):
|
||||
@@ -848,9 +867,19 @@ class AsyncConnection(object):
|
||||
if f"Table '{name}' was not found" not in str(e):
|
||||
raise e
|
||||
|
||||
async def drop_all_tables(self):
|
||||
"""Drop all tables from the database."""
|
||||
await self._inner.drop_all_tables()
|
||||
|
||||
@deprecation.deprecated(
|
||||
deprecated_in="0.15.1",
|
||||
removed_in="0.17",
|
||||
current_version=__version__,
|
||||
details="Use drop_all_tables() instead",
|
||||
)
|
||||
async def drop_database(self):
|
||||
"""
|
||||
Drop database
|
||||
This is the same thing as dropping all the tables
|
||||
"""
|
||||
await self._inner.drop_db()
|
||||
await self._inner.drop_all_tables()
|
||||
|
||||
@@ -499,6 +499,10 @@ def test_delete_table(tmp_db: lancedb.DBConnection):
|
||||
# if ignore_missing=True
|
||||
tmp_db.drop_table("does_not_exist", ignore_missing=True)
|
||||
|
||||
tmp_db.drop_all_tables()
|
||||
|
||||
assert tmp_db.table_names() == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_table_async(tmp_db: lancedb.DBConnection):
|
||||
|
||||
Reference in New Issue
Block a user