2024-12-15 10:51:32 +03:00
|
|
|
"""
|
|
|
|
This module initializes the database connection pool using asyncpg.
|
|
|
|
|
|
|
|
It reads database configuration from a YAML file and creates a connection pool
|
|
|
|
that can be used throughout the application for database operations.
|
|
|
|
"""
|
|
|
|
|
2024-12-14 23:21:28 +03:00
|
|
|
import asyncpg
|
|
|
|
|
2024-12-16 21:40:22 +03:00
|
|
|
from utils.load_config import load_config
|
2024-12-15 10:51:32 +03:00
|
|
|
|
|
|
|
config = load_config('config.yaml')
|
2024-12-14 23:21:28 +03:00
|
|
|
|
|
|
|
async def create_pool() -> asyncpg.pool.Pool:
|
2024-12-15 10:51:32 +03:00
|
|
|
"""
|
|
|
|
Creates and returns a connection pool for the PostgreSQL database.
|
|
|
|
|
|
|
|
The function uses configuration settings loaded from a YAML file to
|
|
|
|
establish the connection pool. The pool allows multiple database
|
|
|
|
connections to be reused efficiently across the application.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
asyncpg.pool.Pool: The connection pool object.
|
|
|
|
"""
|
2024-12-14 23:21:28 +03:00
|
|
|
pool = await asyncpg.create_pool(
|
|
|
|
user=config['database']['user'],
|
|
|
|
password=config['database']['password'],
|
|
|
|
database=config['database']['name'],
|
|
|
|
host=config['database']['host'],
|
|
|
|
port=config['database']['port'],
|
|
|
|
min_size=5,
|
|
|
|
max_size=20
|
|
|
|
)
|
|
|
|
|
2024-12-15 10:51:32 +03:00
|
|
|
return pool
|