Ver código fonte

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

Mendie Uwemedimo 1 ano atrás
pai
commit
23fa6d5ec4
2 arquivos alterados com 6 adições e 1 exclusões
  1. 2 0
      reflex/constants.py
  2. 4 1
      reflex/model.py

+ 2 - 0
reflex/constants.py

@@ -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.

+ 4 - 1
reflex/model.py

@@ -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 {},
     )