Base class for containing a DB connection. Parameters get passed as kwargs, and is mostly driver specific. .. attribute:: query_class :annotation: type[pypika_tortoise.Query] The PyPika Query dialect (low level dialect) .. attribute:: executor_class :anno
| 92 | |
| 93 | |
| 94 | class BaseDBAsyncClient(abc.ABC): |
| 95 | """ |
| 96 | Base class for containing a DB connection. |
| 97 | |
| 98 | Parameters get passed as kwargs, and is mostly driver specific. |
| 99 | |
| 100 | .. attribute:: query_class |
| 101 | :annotation: type[pypika_tortoise.Query] |
| 102 | |
| 103 | The PyPika Query dialect (low level dialect) |
| 104 | |
| 105 | .. attribute:: executor_class |
| 106 | :annotation: type[BaseExecutor] |
| 107 | |
| 108 | The executor dialect class (high level dialect) |
| 109 | |
| 110 | .. attribute:: schema_generator |
| 111 | :annotation: type[BaseSchemaGenerator] |
| 112 | |
| 113 | The DDL schema generator |
| 114 | |
| 115 | .. attribute:: capabilities |
| 116 | :annotation: Capabilities |
| 117 | |
| 118 | Contains the connection capabilities |
| 119 | """ |
| 120 | |
| 121 | _connection: Any |
| 122 | _parent: BaseDBAsyncClient |
| 123 | _pool: Any |
| 124 | _bound_loop: asyncio.AbstractEventLoop | None = None |
| 125 | connection_name: str |
| 126 | query_class: type[Query] = Query |
| 127 | executor_class: type[BaseExecutor] = BaseExecutor |
| 128 | schema_generator: type[BaseSchemaGenerator] = BaseSchemaGenerator |
| 129 | capabilities: Capabilities = Capabilities("") |
| 130 | |
| 131 | def __init__(self, connection_name: str, fetch_inserted: bool = True, **kwargs: Any) -> None: |
| 132 | self.log = db_client_logger |
| 133 | self.connection_name = connection_name |
| 134 | self.fetch_inserted = fetch_inserted |
| 135 | |
| 136 | def _check_loop(self) -> bool: |
| 137 | """Check if the current event loop matches the one this client was created on.""" |
| 138 | try: |
| 139 | current = asyncio.get_running_loop() |
| 140 | except RuntimeError: |
| 141 | return True # No running loop — can't validate |
| 142 | if self._bound_loop is None: |
| 143 | return True # Not yet bound (pool not created yet) |
| 144 | return self._bound_loop is current |
| 145 | |
| 146 | async def _post_connect(self) -> None: |
| 147 | """Called after pool/connection is created. Records the bound loop.""" |
| 148 | self._bound_loop = asyncio.get_running_loop() |
| 149 | |
| 150 | async def create_connection(self, with_db: bool) -> None: |
| 151 | """ |
searching dependent graphs…