Skip to content

Commit

Permalink
feat: SQLALCHEMY_POOL_SIZE and SQLIALCHEMY_MAX_OVERFLOW variables
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Aug 5, 2024
1 parent f3e6197 commit cea7f2f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ UVICORN_PORT = 8000
# EXTERNAL_CONFIG = "config://..."

# SQLALCHEMY_DATABASE_URL = "sqlite:///db.sqlite3"
# SQLALCHEMY_POOL_SIZE = 10
# SQLIALCHEMY_MAX_OVERFLOW = 30

## Custom text for STATUS_TEXT variable
# ACTIVE_STATUS_TEXT = "Active"
Expand Down
8 changes: 5 additions & 3 deletions app/db/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from config import SQLALCHEMY_DATABASE_URL
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from config import (SQLALCHEMY_DATABASE_URL, SQLALCHEMY_POOL_SIZE,
SQLIALCHEMY_MAX_OVERFLOW)

IS_SQLITE = SQLALCHEMY_DATABASE_URL.startswith('sqlite')

if IS_SQLITE:
Expand All @@ -13,8 +15,8 @@
else:
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
pool_size=10,
max_overflow=30,
pool_size=SQLALCHEMY_POOL_SIZE,
max_overflow=SQLIALCHEMY_MAX_OVERFLOW,
pool_recycle=3600,
pool_timeout=10
)
Expand Down
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


SQLALCHEMY_DATABASE_URL = config("SQLALCHEMY_DATABASE_URL", default="sqlite:///db.sqlite3")

SQLALCHEMY_POOL_SIZE = config("SQLALCHEMY_POOL_SIZE", cast=int, default=10)
SQLIALCHEMY_MAX_OVERFLOW = config("SQLIALCHEMY_MAX_OVERFLOW", cast=int, default=30)

UVICORN_HOST = config("UVICORN_HOST", default="0.0.0.0")
UVICORN_PORT = config("UVICORN_PORT", cast=int, default=8000)
Expand Down

0 comments on commit cea7f2f

Please sign in to comment.