gitscope
https://dev.kronoz.win/r/marzneshin.git
app/db/base.py · v0.5.0
Source
1 a47eb4c Dawsh 2y ago from sqlalchemy import create_engine
2 a47eb4c Dawsh 2y ago from sqlalchemy.orm import declarative_base
3 a47eb4c Dawsh 2y ago from sqlalchemy.orm import sessionmaker
4 a47eb4c Dawsh 2y ago
5 8111eb7 Dawsh 2y ago from app.config.env import SQLALCHEMY_DATABASE_URL
6 8111eb7 Dawsh 2y ago
7 01cdf2e Dawsh 2y ago IS_SQLITE = SQLALCHEMY_DATABASE_URL.startswith("sqlite")
8 a47eb4c Dawsh 2y ago
9 a47eb4c Dawsh 2y ago if IS_SQLITE:
10 a47eb4c Dawsh 2y ago engine = create_engine(
11 a47eb4c Dawsh 2y ago SQLALCHEMY_DATABASE_URL,
12 a47eb4c Dawsh 2y ago connect_args={"check_same_thread": False},
13 01cdf2e Dawsh 2y ago # echo=True
14 a47eb4c Dawsh 2y ago )
15 a47eb4c Dawsh 2y ago else:
16 a47eb4c Dawsh 2y ago engine = create_engine(
17 a47eb4c Dawsh 2y ago SQLALCHEMY_DATABASE_URL,
18 a47eb4c Dawsh 2y ago pool_size=10,
19 a47eb4c Dawsh 2y ago max_overflow=30,
20 a47eb4c Dawsh 2y ago pool_recycle=3600,
21 01cdf2e Dawsh 2y ago pool_timeout=10,
22 a47eb4c Dawsh 2y ago )
23 a47eb4c Dawsh 2y ago
24 a47eb4c Dawsh 2y ago SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
25 a47eb4c Dawsh 2y ago Base = declarative_base()