Skip to content

Commit 2102fcf

Browse files
committed
database: add echo option and disable echo by default
1 parent 3b91675 commit 2102fcf

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

fastapi_framework/database.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, driver: str, options=None, **kwargs):
5656
if options is None:
5757
options = {"pool_size": 20, "max_overflow": 20}
5858
url = URL.create(drivername=driver, **kwargs)
59-
self._engine = create_async_engine(url, echo=True, pool_pre_ping=True, pool_recycle=300, **options)
59+
self._engine = create_async_engine(url, pool_pre_ping=True, pool_recycle=300, **options)
6060
self._session = async_sessionmaker(self._engine, expire_on_commit=False)()
6161

6262
async def create_tables(self):
@@ -112,7 +112,8 @@ async def commit(self):
112112
DB_PASSWORD = getenv("DB_PASSWORD", "")
113113
DB_POOL_SIZE = getenv("DB_POOL_SIZE", "20")
114114
DB_MAX_OVERFLOW = getenv("DB_MAX_OVERFLOW", "20")
115-
DB_POOL = True if getenv("DB_POOL", "True").lower() == "true" else False
115+
DB_POOL = getenv("DB_POOL", "True").lower() == "true"
116+
DB_ECHO = getenv("DB_ECHO", "False").lower() == "true"
116117

117118

118119
class DatabaseDependency:
@@ -134,6 +135,7 @@ def __init__(self):
134135
"pool_size": DB_POOL_SIZE,
135136
"max_overflow": DB_MAX_OVERFLOW,
136137
"poolclass": DB_POOL,
138+
"echo": DB_ECHO,
137139
}
138140
self.engine_options = dict([(k, int(v)) for k, v in self.engine_options.items() if v != ""])
139141
if self.engine_options["poolclass"] == 0:

test.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ DB_DATABASE=":memory:"
66
DB_POOL_SIZE=""
77
DB_MAX_OVERFLOW=""
88
DB_POOL="True"
9+
DB_ECHO="True"
910

1011
REDIS_HOST="redis"
1112

@@ -16,4 +17,4 @@ JWT_ALGORITHM="HS256"
1617
JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 30
1718
JWT_REFRESH_TOKEN_EXPIRE_MINUTES = 240
1819

19-
DISABLED_MODULES=""
20+
DISABLED_MODULES=""

0 commit comments

Comments
 (0)