enable SQL statements echo with SQLALCHEMY_ECHO config constant for debugging (#1369)

This commit is contained in:
Mendie Uwemedimo 2023-07-19 22:06:17 +01:00 committed by GitHub
parent bfec196d84
commit 23fa6d5ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -124,6 +124,8 @@ RUN_BACKEND_PROD_WINDOWS = f"uvicorn --timeout-keep-alive {TIMEOUT}".split()
# Socket.IO web server
PING_INTERVAL = 25
PING_TIMEOUT = 120
# flag to make the engine print all the SQL statements it executes
SQLALCHEMY_ECHO = get_value("SQLALCHEMY_ECHO", False, type_=bool)
# Compiler variables.
# The extension for compiled Javascript files.

View File

@ -40,9 +40,12 @@ def get_engine(url: Optional[str] = None):
console.print(
"[red]Database is not initialized, run [bold]reflex db init[/bold] first."
)
echo_db_query = False
if conf.env == constants.Env.DEV and constants.SQLALCHEMY_ECHO:
echo_db_query = True
return sqlmodel.create_engine(
url,
echo=False,
echo=echo_db_query,
connect_args={"check_same_thread": False} if conf.admin_dash else {},
)