lab3 completed
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
import asyncpg
|
||||
|
||||
DATABASE_URL = os.getenv(
|
||||
"DATABASE_URL",
|
||||
"postgresql://messenger:secret_password@postgres:5432/messenger_db"
|
||||
)
|
||||
|
||||
pool: asyncpg.Pool = None
|
||||
|
||||
|
||||
async def init_db():
|
||||
global pool
|
||||
pool = await asyncpg.create_pool(
|
||||
DATABASE_URL,
|
||||
min_size=2,
|
||||
max_size=10
|
||||
)
|
||||
|
||||
|
||||
async def close_db():
|
||||
global pool
|
||||
if pool:
|
||||
await pool.close()
|
||||
|
||||
|
||||
def get_pool() -> asyncpg.Pool:
|
||||
return pool
|
||||
Reference in New Issue
Block a user