init commit. Skeleton prepared
This commit is contained in:
0
services/auth/src/app/db/__init__.py
Normal file
0
services/auth/src/app/db/__init__.py
Normal file
26
services/auth/src/app/db/session.py
Normal file
26
services/auth/src/app/db/session.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
||||
from typing import Generator
|
||||
|
||||
DEFAULT_DB_URL = "postgresql+psycopg2://postgres:postgres@postgres:5432/auth_db"
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", DEFAULT_DB_URL)
|
||||
|
||||
engine = create_engine(
|
||||
DATABASE_URL,
|
||||
pool_pre_ping=True,
|
||||
future=True,
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
||||
|
||||
def get_db() -> Generator:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user