Cloudflare - v1.3.0
    Preparing search index...

    Class HyperdriveService<E>

    External-database capability, backed by Hyperdrive.

    Hyperdrive supplies a pooled, cached connection — not a client. The query itself runs through a driver (postgres, pg, mysql2, …) that this boilerplate does not depend on, so this capability hands the connection out and stops there:

    const sql = postgres(hyperdrive.connectionString(env), { max: 5 })
    

    Keep the pool small — each isolate opens its own, and Hyperdrive is already pooling on the far side.

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Implements

    • SqlConnectionProvider<E>
    Index
    • Returns a connection string for the pooled database.

      Parameters

      • env: E

        The Worker environment.

      Returns string

      A connection string accepted by the usual drivers and ORMs.

      The credentials in it are scoped to this Worker instance — never log it or return it to a client.

    • Returns the connection details as discrete fields.

      For drivers that take a credentials object rather than a URL.

      Parameters

      • env: E

        The Worker environment.

      Returns SqlCredentials

      Host, port, user, password, and database name.

    • Reports whether Hyperdrive is bound to this Worker.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Reports which database the binding points at.

      Deliberately excludes the password and the connection string, so this is safe to surface in a health check.

      Parameters

      • env: E

        The Worker environment.

      Returns SqlTarget

      The target host and database name, or null when unbound.