26 lines
753 B
Python
26 lines
753 B
Python
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
|
import os
|
|
|
|
# Set up the database URL (adjust to your psycopg3 format)
|
|
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+psycopg://postgres:postgresbro@10.0.0.124/scrap")
|
|
|
|
# Create the async engine with psycopg3
|
|
engine = create_async_engine(DATABASE_URL, echo=True)
|
|
|
|
# Create the sessionmaker for async sessions
|
|
SessionLocal = sessionmaker(
|
|
bind=engine,
|
|
class_=AsyncSession,
|
|
autocommit=False,
|
|
autoflush=False,
|
|
)
|
|
|
|
Base = declarative_base()
|
|
|
|
# Dependency for getting the database session
|
|
async def get_db():
|
|
async with SessionLocal() as session:
|
|
yield session
|