refactor(chart): Added docstring in each file and function. Fixed long lines

This commit is contained in:
Данил 2024-12-15 10:51:32 +03:00
parent c5d3d9fe9b
commit ed8cf91558
7 changed files with 190 additions and 30 deletions

View file

@ -1,9 +1,27 @@
import asyncpg
import yaml
"""
This module initializes the database connection pool using asyncpg.
config = yaml.safe_load(open("config.yaml", "r"))
It reads database configuration from a YAML file and creates a connection pool
that can be used throughout the application for database operations.
"""
import asyncpg
from chart.utils.load_config import load_config
config = load_config('config.yaml')
async def create_pool() -> asyncpg.pool.Pool:
"""
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.
"""
pool = await asyncpg.create_pool(
user=config['database']['user'],
password=config['database']['password'],
@ -14,4 +32,4 @@ async def create_pool() -> asyncpg.pool.Pool:
max_size=20
)
return pool
return pool