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