Creates a PostgreSQL adapter wired to a Hyperdrive binding.
The client is created once per request and reused for every statement in that
request, which is the pattern Cloudflare documents: Hyperdrive pools the
underlying connection, so creating a client is cheap, but each connect()
still acquires a pooled connection and the pooler runs in transaction mode.
Opening one per statement therefore acquires and releases a pooled connection
per statement and forfeits named prepared statements.
Caching a client in module scope is not the alternative: Workers reject I/O
created by one request and used by another. Either pass scope so the
provider can key its client on the current request, or call
HyperdriveProvider.dispose at the end of each request.
The factory must return one connection, such as a pgClient. The provider
has a SQLDatabase.runBatch that runs its group in one transaction on
that connection and declares SQLDatabase.atomicBatch. A batch runs
alone: a plain statement from the same request waits until it commits, so it
cannot slip into the open transaction.
Creates a PostgreSQL adapter wired to a Hyperdrive binding.
The client is created once per request and reused for every statement in that request, which is the pattern Cloudflare documents: Hyperdrive pools the underlying connection, so creating a client is cheap, but each
connect()still acquires a pooled connection and the pooler runs in transaction mode. Opening one per statement therefore acquires and releases a pooled connection per statement and forfeits named prepared statements.Caching a client in module scope is not the alternative: Workers reject I/O created by one request and used by another. Either pass
scopeso the provider can key its client on the current request, or call HyperdriveProvider.dispose at the end of each request.The factory must return one connection, such as a
pgClient. The provider has a SQLDatabase.runBatch that runs its group in one transaction on that connection and declares SQLDatabase.atomicBatch. A batch runs alone: a plain statement from the same request waits until it commits, so it cannot slip into the open transaction.