Initial commit with authentication and routes for registering/login already set up
This commit is contained in:
25
app/database.py
Normal file
25
app/database.py
Normal file
@ -0,0 +1,25 @@
|
||||
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
|
||||
Reference in New Issue
Block a user