Hyperdrive
Cloudflare Hyperdrive accelerates access to existing databases with connection pooling and global caching.
Props
Name of the Hyperdrive configuration.
${app}-${stage}-${id}
origin
HyperdriveOriginInput
required
Database connection origin configuration.Can be:
- Connection string (e.g.,
"postgres://user:pass@host:5432/db")
- Secret containing connection string
HyperdrivePublicOrigin object
HyperdriveOriginWithAccess object
Show HyperdrivePublicOrigin properties
Database password. Use alchemy.secret() to securely store this value.
Database port.
5432 for postgres, 3306 for mysql
scheme
postgres | mysql
default:"postgres"
Connection scheme.
Show HyperdriveOriginWithAccess properties
Access client secret. Use alchemy.secret() to securely store this value.
Database port.
5432 for postgres, 3306 for mysql
scheme
postgres | mysql
default:"postgres"
Connection scheme.
Caching configuration.Show HyperdriveCachingEnabled properties
Whether caching is disabled.
Maximum duration items should persist in the cache (in seconds).
Number of seconds the cache may serve a stale response (in seconds).
Show HyperdriveCachingDisabled properties
Whether caching is disabled.
mTLS configuration for Hyperdrive.
sslmode
verify-ca | verify-full
default:"verify-full"
SSL mode.
Whether to adopt an existing hyperdrive config.
Whether to delete the hyperdrive config when the resource is deleted.
Output
Name of the Hyperdrive configuration.
The Cloudflare-generated UUID of the hyperdrive.
origin
HyperdrivePublicOrigin | HyperdriveOriginWithAccess
Database connection origin configuration.
Type identifier for the binding.
Examples
PostgreSQL Connection
const hyperdrive = await Hyperdrive("postgres-db", {
name: "my-postgres-db",
origin: {
database: "postgres",
host: "database.example.com",
password: alchemy.secret(process.env.DB_PASSWORD),
port: 5432,
user: "postgres"
}
});
const worker = await Worker("api", {
entrypoint: "./src/api.ts",
bindings: {
DATABASE: hyperdrive
}
});
MySQL Connection
const hyperdrive = await Hyperdrive("mysql-db", {
name: "my-mysql-db",
origin: {
database: "mydb",
host: "mysql.example.com",
password: alchemy.secret(process.env.DB_PASSWORD),
port: 3306,
scheme: "mysql",
user: "mysql_user"
}
});
Connection String
const hyperdrive = await Hyperdrive("db", {
origin: alchemy.secret(process.env.DATABASE_URL)
});
Hyperdrive with Caching Disabled
const hyperdrive = await Hyperdrive("no-cache-db", {
name: "no-cache-db",
origin: {
database: "postgres",
host: "database.example.com",
password: alchemy.secret(process.env.DB_PASSWORD),
port: 5432,
user: "postgres"
},
caching: {
disabled: true
}
});
Hyperdrive with mTLS
const hyperdrive = await Hyperdrive("secure-db", {
name: "secure-db",
origin: {
database: "postgres",
host: "database.example.com",
password: alchemy.secret(process.env.DB_PASSWORD),
port: 5432,
user: "postgres"
},
mtls: {
ca_certificate_id: "00000000-0000-0000-0000-0000000000",
mtls_certificate_id: "00000000-0000-0000-0000-0000000000",
sslmode: "verify-full"
}
});
Hyperdrive with Access Client Credentials
const hyperdrive = await Hyperdrive("access-db", {
name: "access-db",
origin: {
database: "postgres",
host: "database.example.com",
access_client_id: "client-id",
access_client_secret: alchemy.secret(process.env.ACCESS_CLIENT_SECRET),
port: 5432,
user: "postgres"
}
});