Database
AsyncDatabaseConnection
¶
Bases: Generic[T], ABC
Abstract base class for asynchronous database connections.
This class defines the interface for establishing and closing asynchronous connections to a database or similar resource. Intended to be used with dependency injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Variable length argument list for subclasses. |
()
|
|
**kwargs
|
Arbitrary keyword arguments for subclasses. |
{}
|
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/base.py
__init__(*args, **kwargs)
¶
Initialize the connection instance.
Subclasses may override this to accept parameters such as database URLs or credentials.
close()
abstractmethod
async
¶
Close the database connection.
This method should be overridden by subclasses to implement proper cleanup and resource deallocation.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/base.py
connect()
abstractmethod
async
¶
Establish and return the asynchronous database connection.
This method should be overridden by subclasses to implement the logic for creating the actual connection.
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
An instance representing the database connection. |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/base.py
ElasticConnection
¶
Bases: AsyncDatabaseConnection[AsyncElasticsearch]
Concrete implementation of AsyncDatabaseConnection for ElasticSearch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dsn
|
str
|
The connection string or DSN for ElasticSearch. |
required |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/elastic.py
close()
async
¶
Close the AsyncElasticsearch client connection.
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/elastic.py
connect()
async
¶
Establish and return an AsyncElasticsearch client instance.
Returns:
| Name | Type | Description |
|---|---|---|
AsyncElasticsearch |
AsyncElasticsearch
|
The ElasticSearch async client. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If connection to ElasticSearch fails. |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/elastic.py
MongoConnection
¶
Bases: AsyncDatabaseConnection[AsyncIOMotorClient]
Concrete implementation of AsyncDatabaseConnection for MongoDB using Motor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dsn
|
str
|
MongoDB connection string. |
required |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/mongo.py
close()
async
¶
Close the MongoDB client connection.
connect()
async
¶
Establish and return an AsyncIOMotorClient instance.
Returns:
| Name | Type | Description |
|---|---|---|
AsyncIOMotorClient |
AsyncIOMotorClient
|
The async MongoDB client. |
Raises:
| Type | Description |
|---|---|
ConnectionFailure
|
If connection to MongoDB fails. |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/mongo.py
ValkeyConnection
¶
Bases: AsyncDatabaseConnection[Valkey]
Concrete implementation of AsyncDatabaseConnection for Valkey client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Valkey host address. |
required |
port
|
int
|
Valkey port. |
required |
password
|
str
|
Password for Valkey authentication. |
required |
Source code in .venv/lib/python3.12/site-packages/ytindexer/database/valkey.py
close()
async
¶
Close the Valkey client connection.
connect()
async
¶
Establish and return a Valkey client connection.
Returns:
| Type | Description |
|---|---|
Valkey
|
valkey.client.Valkey: The Valkey client instance. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If connection to Valkey fails. |