|
| 1 | +""" |
| 2 | +This type stub file was generated by pyright. |
| 3 | +""" |
| 4 | + |
| 5 | +from abc import ABC, abstractmethod |
| 6 | +from typing import Any |
| 7 | + |
| 8 | +"""Database client abstraction for py-pglite. |
| 9 | +
|
| 10 | +Provides unified interface for both psycopg and asyncpg clients, |
| 11 | +allowing users to choose their preferred PostgreSQL driver. |
| 12 | +""" |
| 13 | +logger = ... |
| 14 | +class DatabaseClient(ABC): |
| 15 | + """Abstract database client interface.""" |
| 16 | + @abstractmethod |
| 17 | + def connect(self, connection_string: str) -> Any: |
| 18 | + """Create a connection to the database.""" |
| 19 | + ... |
| 20 | + |
| 21 | + @abstractmethod |
| 22 | + def execute_query(self, connection: Any, query: str, params: Any = ...) -> list[tuple]: |
| 23 | + """Execute a query and return results.""" |
| 24 | + ... |
| 25 | + |
| 26 | + @abstractmethod |
| 27 | + def test_connection(self, connection_string: str) -> bool: |
| 28 | + """Test if database connection is working.""" |
| 29 | + ... |
| 30 | + |
| 31 | + @abstractmethod |
| 32 | + def get_database_version(self, connection_string: str) -> str | None: |
| 33 | + """Get PostgreSQL version string.""" |
| 34 | + ... |
| 35 | + |
| 36 | + @abstractmethod |
| 37 | + def close_connection(self, connection: Any) -> None: |
| 38 | + """Close a database connection.""" |
| 39 | + ... |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +class PsycopgClient(DatabaseClient): |
| 44 | + """psycopg-based database client.""" |
| 45 | + def __init__(self) -> None: |
| 46 | + ... |
| 47 | + |
| 48 | + def connect(self, connection_string: str) -> Any: |
| 49 | + """Create a psycopg connection.""" |
| 50 | + ... |
| 51 | + |
| 52 | + def execute_query(self, connection: Any, query: str, params: Any = ...) -> list[tuple]: |
| 53 | + """Execute query using psycopg.""" |
| 54 | + ... |
| 55 | + |
| 56 | + def test_connection(self, connection_string: str) -> bool: |
| 57 | + """Test psycopg connection.""" |
| 58 | + ... |
| 59 | + |
| 60 | + def get_database_version(self, connection_string: str) -> str | None: |
| 61 | + """Get PostgreSQL version using psycopg.""" |
| 62 | + ... |
| 63 | + |
| 64 | + def close_connection(self, connection: Any) -> None: |
| 65 | + """Close psycopg connection.""" |
| 66 | + ... |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +class AsyncpgClient(DatabaseClient): |
| 71 | + """asyncpg-based database client.""" |
| 72 | + def __init__(self) -> None: |
| 73 | + ... |
| 74 | + |
| 75 | + def connect(self, connection_string: str) -> Any: |
| 76 | + """Create an asyncpg connection (sync wrapper).""" |
| 77 | + ... |
| 78 | + |
| 79 | + def execute_query(self, connection: Any, query: str, params: Any = ...) -> list[tuple]: |
| 80 | + """Execute query using asyncpg (sync wrapper).""" |
| 81 | + ... |
| 82 | + |
| 83 | + def test_connection(self, connection_string: str) -> bool: |
| 84 | + """Test asyncpg connection.""" |
| 85 | + ... |
| 86 | + |
| 87 | + def get_database_version(self, connection_string: str) -> str | None: |
| 88 | + """Get PostgreSQL version using asyncpg.""" |
| 89 | + ... |
| 90 | + |
| 91 | + def close_connection(self, connection: Any) -> None: |
| 92 | + """Close asyncpg connection.""" |
| 93 | + ... |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +def get_default_client() -> DatabaseClient: |
| 98 | + """Get the default database client. |
| 99 | +
|
| 100 | + Prefers psycopg if available, falls back to asyncpg. |
| 101 | + """ |
| 102 | + ... |
| 103 | + |
| 104 | +def get_client(client_type: str = ...) -> DatabaseClient: |
| 105 | + """Get a database client by type. |
| 106 | +
|
| 107 | + Args: |
| 108 | + client_type: "psycopg", "asyncpg", or "auto" (default) |
| 109 | +
|
| 110 | + Returns: |
| 111 | + DatabaseClient instance |
| 112 | + """ |
| 113 | + ... |
| 114 | + |
| 115 | +__all__ = ["DatabaseClient", "PsycopgClient", "AsyncpgClient", "get_default_client", "get_client"] |
0 commit comments