28 lines
550 B
Python
28 lines
550 B
Python
"""
|
|
Database utilities for authentication.
|
|
"""
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from .models import Base
|
|
|
|
|
|
def utcnow():
|
|
"""Return current UTC timestamp for database columns."""
|
|
from datetime import datetime
|
|
return datetime.utcnow()
|
|
|
|
|
|
def get_db() -> Session:
|
|
"""
|
|
Dependency factory that yields a database session.
|
|
|
|
Should be imported and used with Depends(get_db) in endpoint functions.
|
|
"""
|
|
from db.session import SessionLocal
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|