Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions sqlspec/adapters/aiosqlite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,6 @@ async def create_connection(self) -> Connection:
msg = f"Could not configure the Aiosqlite connection. Error: {e!s}"
raise ImproperConfigurationError(msg) from e

@asynccontextmanager
async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]:
"""Manage the lifecycle of a database connection.

Yields:
None

Raises:
ImproperConfigurationError: If the connection could not be established.
"""
connection = await self.create_connection()
try:
yield
finally:
await connection.close()

@asynccontextmanager
async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Connection, None]:
"""Create and provide a database connection.
Expand Down
17 changes: 0 additions & 17 deletions sqlspec/adapters/asyncmy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,6 @@ async def provide_pool(self, *args: Any, **kwargs: Any) -> Pool:
"""
return await self.create_pool()

@asynccontextmanager
async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]:
"""Manage the lifecycle of a database connection pool.

Yields:
None

Raises:
ImproperConfigurationError: If the pool could not be established.
"""
pool = await self.create_pool()
try:
yield
finally:
pool.close()
await pool.wait_closed()

@asynccontextmanager
async def provide_connection(self, *args: Any, **kwargs: Any) -> AsyncGenerator[Connection, None]:
"""Create and provide a database connection.
Expand Down
9 changes: 0 additions & 9 deletions sqlspec/adapters/asyncpg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,6 @@ async def create_pool(self) -> Pool:
)
return self.pool_instance

@asynccontextmanager
async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]:
db_pool = await self.create_pool()
try:
yield
finally:
db_pool.terminate()
await db_pool.close()

def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[Pool]:
"""Create a pool instance.

Expand Down
16 changes: 0 additions & 16 deletions sqlspec/adapters/duckdb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,6 @@ def create_connection(self) -> DuckDBPyConnection:
msg = f"Could not configure the DuckDB connection. Error: {e!s}"
raise ImproperConfigurationError(msg) from e

@contextmanager
def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]:
"""Manage the lifecycle of a database connection.

Yields:
None

Raises:
ImproperConfigurationError: If the connection could not be established.
"""
connection = self.create_connection()
try:
yield
finally:
connection.close()

@contextmanager
def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[DuckDBPyConnection, None, None]:
"""Create and provide a database connection.
Expand Down
8 changes: 0 additions & 8 deletions sqlspec/adapters/oracledb/config/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ async def create_pool(self) -> AsyncConnectionPool:
raise ImproperConfigurationError(msg)
return self.pool_instance

@asynccontextmanager
async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]:
db_pool = await self.create_pool()
try:
yield
finally:
await db_pool.close(force=True)

def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[AsyncConnectionPool]:
"""Create a pool instance.

Expand Down
7 changes: 0 additions & 7 deletions sqlspec/adapters/oracledb/config/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ def create_pool(self) -> ConnectionPool:
raise ImproperConfigurationError(msg)
return self.pool_instance

def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]:
db_pool = self.create_pool()
try:
yield
finally:
db_pool.close()

def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool:
"""Create a pool instance.

Expand Down
9 changes: 0 additions & 9 deletions sqlspec/adapters/psycopg/config/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ async def create_pool(self) -> AsyncConnectionPool:
raise ImproperConfigurationError(msg)
return self.pool_instance

@asynccontextmanager
async def lifespan(self, *args: Any, **kwargs: Any) -> AsyncGenerator[None, None]:
"""Manage the lifecycle of the connection pool."""
pool = await self.create_pool()
try:
yield
finally:
await pool.close()

def provide_pool(self, *args: Any, **kwargs: Any) -> Awaitable[AsyncConnectionPool]:
"""Create and return a connection pool."""
return self.create_pool()
Expand Down
9 changes: 0 additions & 9 deletions sqlspec/adapters/psycopg/config/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ def create_pool(self) -> ConnectionPool:
raise ImproperConfigurationError(msg)
return self.pool_instance

@contextmanager
def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]:
"""Manage the lifecycle of the connection pool."""
pool = self.create_pool()
try:
yield
finally:
pool.close()

def provide_pool(self, *args: Any, **kwargs: Any) -> ConnectionPool:
"""Create and return a connection pool."""
return self.create_pool()
Expand Down
16 changes: 0 additions & 16 deletions sqlspec/adapters/sqlite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,6 @@ def create_connection(self) -> Connection:
msg = f"Could not configure the SQLite connection. Error: {e!s}"
raise ImproperConfigurationError(msg) from e

@contextmanager
def lifespan(self, *args: Any, **kwargs: Any) -> Generator[None, None, None]:
"""Manage the lifecycle of a database connection.

Yields:
None

Raises:
ImproperConfigurationError: If the connection could not be established.
"""
connection = self.create_connection()
try:
yield
finally:
connection.close()

@contextmanager
def provide_connection(self, *args: Any, **kwargs: Any) -> Generator[Connection, None, None]:
"""Create and provide a database connection.
Expand Down
16 changes: 0 additions & 16 deletions tests/unit/test_adapters/test_duckdb/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,3 @@ def test_connection_creation_error(self) -> None:
config = DuckDBConfig()
with pytest.raises(ImproperConfigurationError, match="Could not configure"):
config.create_connection()

def test_connection_lifecycle(self, mock_duckdb_connection: MagicMock) -> None:
"""Test connection lifecycle management."""
config = DuckDBConfig()

# Test lifespan
with config.lifespan():
assert mock_duckdb_connection.close.call_count == 0
assert mock_duckdb_connection.close.call_count == 1

# Test provide_connection
mock_duckdb_connection.reset_mock()
with config.provide_connection() as conn:
assert conn is mock_duckdb_connection
assert mock_duckdb_connection.close.call_count == 0
assert mock_duckdb_connection.close.call_count == 1
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading