gitscope
https://dev.kronoz.win/r/marzneshin.git
app/db/base.py · v0.7.4
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 d961199 Erfan 2y ago from app.config.env import (
6 d961199 Erfan 2y ago SQLALCHEMY_DATABASE_URL,
7 d961199 Erfan 2y ago SQLALCHEMY_CONNECTION_POOL_SIZE,
8 d961199 Erfan 2y ago SQLALCHEMY_CONNECTION_MAX_OVERFLOW,
9 d961199 Erfan 2y ago )
10 8111eb7 Dawsh 2y ago
11 01cdf2e Dawsh 2y ago IS_SQLITE = SQLALCHEMY_DATABASE_URL.startswith("sqlite")
12 a47eb4c Dawsh 2y ago
13 a47eb4c Dawsh 2y ago if IS_SQLITE:
14 a47eb4c Dawsh 2y ago engine = create_engine(
15 a47eb4c Dawsh 2y ago SQLALCHEMY_DATABASE_URL,
16 a47eb4c Dawsh 2y ago connect_args={"check_same_thread": False},
17 01cdf2e Dawsh 2y ago # echo=True
18 a47eb4c Dawsh 2y ago )
19 a47eb4c Dawsh 2y ago else:
20 a47eb4c Dawsh 2y ago engine = create_engine(
21 a47eb4c Dawsh 2y ago SQLALCHEMY_DATABASE_URL,
22 d961199 Erfan 2y ago pool_size=SQLALCHEMY_CONNECTION_POOL_SIZE,
23 d961199 Erfan 2y ago max_overflow=SQLALCHEMY_CONNECTION_MAX_OVERFLOW,
24 a47eb4c Dawsh 2y ago pool_recycle=3600,
25 01cdf2e Dawsh 2y ago pool_timeout=10,
26 a47eb4c Dawsh 2y ago )
27 a47eb4c Dawsh 2y ago
28 a47eb4c Dawsh 2y ago SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
29 a47eb4c Dawsh 2y ago Base = declarative_base()