27 lines
627 B
Python
27 lines
627 B
Python
"""
|
|
pip install asyncpg
|
|
"""
|
|
import asyncpg
|
|
|
|
from Config.Config import *
|
|
|
|
# PostgreSQL 配置
|
|
POSTGRES_CONFIG = {
|
|
"host": POSTGRES_HOST,
|
|
"port": POSTGRES_PORT,
|
|
"user": POSTGRES_USER,
|
|
"password": POSTGRES_PASSWORD,
|
|
"database": POSTGRES_DATABASE,
|
|
"min_size": 1, # 设置为0表示不保留空闲连接
|
|
"max_size": 20,
|
|
"command_timeout": 60
|
|
}
|
|
|
|
# 初始化 PostgreSQL 连接池
|
|
async def init_postgres_pool():
|
|
return await asyncpg.create_pool(**POSTGRES_CONFIG)
|
|
|
|
# 添加连接池销毁函数
|
|
async def close_postgres_pool(pool):
|
|
if pool:
|
|
await pool.close() |