File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,6 +104,9 @@ class Settings(BaseSettings):
104104 DB_PASS : str = ""
105105 DB_NAME : str = "app"
106106 DB_ECHO : bool = False
107+ DB_ECHO_POOL : bool = False
108+ DB_POOL_SIZE : int = 5
109+ DB_MAX_OVERFLOW : int = 10
107110
108111 # SQLAlchemy engine settings
109112 # The size of the pool to be maintained, defaults to 10
Original file line number Diff line number Diff line change @@ -40,11 +40,19 @@ def _setup_db(app: FastAPI) -> None: # pragma: no cover
4040
4141 :param app: fastAPI application.
4242 """
43- engine = create_async_engine (str (settings .db_url ), echo = settings .DB_ECHO )
43+ engine = create_async_engine (
44+ str (settings .db_url ),
45+ echo = settings .DB_ECHO ,
46+ echo_pool = settings .DB_ECHO_POOL ,
47+ pool_size = settings .DB_POOL_SIZE ,
48+ max_overflow = settings .DB_MAX_OVERFLOW ,
49+ )
4450 session_factory = async_sessionmaker (
4551 engine ,
4652 # See https://fastapi-users.github.io/fastapi-users/latest/configuration/databases/sqlalchemy/#asynchronous-driver
4753 expire_on_commit = False ,
54+ autoflush = False ,
55+ # autocommit=False,
4856 )
4957 app .state .db_engine = engine
5058 app .state .db_session_factory = session_factory
You can’t perform that action at this time.
0 commit comments