Initial MinerOps working checkpoint
This commit is contained in:
commit
4c854374e0
103 files changed
+2400932
No files matched your search
@@ -0,0 +1,35 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
||||
|
||||
from app.config import settings
|
||||
|
||||
|
||||
def build_database_url() -> str:
|
||||
return (
|
||||
f"postgresql+psycopg://{settings.postgres_user}:"
|
||||
f"{settings.postgres_password}@{settings.postgres_host}:"
|
||||
f"{settings.postgres_port}/{settings.postgres_db}"
|
||||
)
|
||||
|
||||
|
||||
DATABASE_URL = build_database_url()
|
||||
|
||||
engine = create_engine(DATABASE_URL, pool_pre_ping=True)
|
||||
|
||||
SessionLocal = sessionmaker(
|
||||
autocommit=False,
|
||||
autoflush=False,
|
||||
bind=engine,
|
||||
)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Reference in new issue
Block a user