Cloudflare - v1.3.0
    Preparing search index...

    Class HyperdriveBinding<E>

    Accessor for the Hyperdrive binding (hyperdrive in wrangler.json), which pools and caches connections to an external SQL database.

    const hyperdrive = new HyperdriveBinding() // binding name from the configuration layer
    const client = new Client({ connectionString: hyperdrive.connectionString(ctx.env) })

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Type Parameters

    Hierarchy (View Summary)

    • Binding<Hyperdrive, E>
      • HyperdriveBinding
    Index
    • get name(): string

      The binding name this instance resolves.

      Returns string

      The binding name as declared in wrangler.json.

    • 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 this string are scoped to the running Worker instance — never log it or hand it to a client.

      MissingBindingError When the Hyperdrive binding is absent.

    • Returns the connection details as discrete fields.

      Use this with drivers that take a credentials object rather than a URL.

      Parameters

      • env: E

        The Worker environment.

      Returns SqlCredentials

      The host, port, user, password, and database name.

    • Checks whether the binding is available on the given environment.

      Use this to degrade gracefully when a binding is optional.

      Parameters

      • env: E

        The Worker environment.

      Returns boolean

      true when the binding is present.

    • Resolves the binding without throwing.

      Parameters

      • env: E

        The Worker environment.

      Returns Hyperdrive

      The resolved binding, or null when it is not configured.