← Back to context Comment by alfons_foobar 11 hours ago I might be outing myself as a noob here, but... what is the (better) alternative? 2 comments alfons_foobar Reply 0x696C6961 10 hours ago You inject the pool itself. alfons_foobar 24 minutes ago Sorry, I am being dense... how does that solve the problem?I still have to get a connection from the pool, I just do it inside the function body now, right?So this @app.get("/users") def get_users(conn = Depends[get_db_conn]): users = conn.execute("SELECT * FROM users") return users would become that instead: @app.get("/users") def get_users(pool = Depends[get_db_pool]): with pool.get_conn() as conn: users = conn.execute("SELECT * FROM users") return users But I still need enough connections in the pool to handle all concurrent requests, no?
0x696C6961 10 hours ago You inject the pool itself. alfons_foobar 24 minutes ago Sorry, I am being dense... how does that solve the problem?I still have to get a connection from the pool, I just do it inside the function body now, right?So this @app.get("/users") def get_users(conn = Depends[get_db_conn]): users = conn.execute("SELECT * FROM users") return users would become that instead: @app.get("/users") def get_users(pool = Depends[get_db_pool]): with pool.get_conn() as conn: users = conn.execute("SELECT * FROM users") return users But I still need enough connections in the pool to handle all concurrent requests, no?
alfons_foobar 24 minutes ago Sorry, I am being dense... how does that solve the problem?I still have to get a connection from the pool, I just do it inside the function body now, right?So this @app.get("/users") def get_users(conn = Depends[get_db_conn]): users = conn.execute("SELECT * FROM users") return users would become that instead: @app.get("/users") def get_users(pool = Depends[get_db_pool]): with pool.get_conn() as conn: users = conn.execute("SELECT * FROM users") return users But I still need enough connections in the pool to handle all concurrent requests, no?
You inject the pool itself.
Sorry, I am being dense... how does that solve the problem?
I still have to get a connection from the pool, I just do it inside the function body now, right?
So this
would become that instead:
But I still need enough connections in the pool to handle all concurrent requests, no?