You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support pool connection for mysql and postgresql #202
connection pooling would be required to implement transactions support (#49).
a db connection should never accidentally run an unrelated query between opening and closing a transaction, meaning that if the client only has one connection it has to block all other queries until the transaction is finished.
ive been trying my hand at an implementation based on what ive seen from other db clients that looks like this:
Connector gets a new acquireConnection function that returns a Connection instance. A Connection is pretty much a Database except it calls the db client via whatever connection pooling interface it uses, or blocks other queries until the connection is released if pooling doesnt exist (e.g. sqlite)
then Database also gets a acquireConnection function that users can use to execute queries without worrying about other queries interfering.
constdb=createDatabase(x)awaitdb.acquireConnection(async(conn)=>{awaitconn.sql`DELETE FROM users;`})
internally, the database automatically disposes of the connection when the function is done
as for things im unsure about is the naming of various things, as well as whether it would be good to also expose a function on Database that just returns a raw connection
For the non-pooling Connector, the getInstance method returns the database client directly.
For the pooling Connector, the getInstance method returns the connection pool.
You can call useDatabase().getInstance().connect() to retrieve a PostgreSQL pool client for transactions.
However, a key distinction is that while you can execute queries directly on the pool using syntax like
db.sql`SOME SQL STATEMENT`
And that is not supported on the pool client itself.
Therefore, to enable a consistent query interface for the pool client, we need to implement a wrapper around it.
Activity
beeequeue commentedon Jan 23, 2026
connection pooling would be required to implement transactions support (#49).
a db connection should never accidentally run an unrelated query between opening and closing a transaction, meaning that if the client only has one connection it has to block all other queries until the transaction is finished.
ive been trying my hand at an implementation based on what ive seen from other db clients that looks like this:
Connectorgets a newacquireConnectionfunction that returns aConnectioninstance. AConnectionis pretty much aDatabaseexcept it calls the db client via whatever connection pooling interface it uses, or blocks other queries until the connection is released if pooling doesnt exist (e.g. sqlite)then
Databasealso gets aacquireConnectionfunction that users can use to execute queries without worrying about other queries interfering.internally, the database automatically disposes of the connection when the function is done
as for things im unsure about is the naming of various things, as well as whether it would be good to also expose a function on
Databasethat just returns a raw connectionITsPro-CN commentedon Jan 27, 2026
Yes, this has been taken into consideration.
For the non-pooling Connector, the
getInstancemethod returns the database client directly.For the pooling Connector, the
getInstancemethod returns the connection pool.You can call
useDatabase().getInstance().connect()to retrieve a PostgreSQL pool client for transactions.However, a key distinction is that while you can execute queries directly on the pool using syntax like
And that is not supported on the pool client itself.
Therefore, to enable a consistent query interface for the pool client, we need to implement a wrapper around it.
It looks like this PR hasn’t been reviewed yet.