Databases
Use Cloudflare Workers to connect your application to external databases, such as Postgres, MySQL, FaunaDB, Supabase, MongoDB Atlas, PlanetScale, Prisma, and more. To use these Cloudflare Workers integrations, you need to install the relevant packages for the databases you want to use.
Database | Library or Driver | Connection Method |
---|---|---|
Postgres | deno-postgres | Cloudflare Tunnel |
MySQL | deno-mysql | Cloudflare Tunnel |
FaunaDB | faunadb | API via client library |
PlanetScale | @planetscale/database | API via client library |
Supabase | @supabase/supabase-js | API via client library |
Mongo | realm-web | API via client library |
Prisma | prisma | API via client library |
Neon | @neondatabase/serverless | API via client library |
Hasura | API | GraphQL API via fetch() |
Once you have installed the necessary packages, use the APIs provided by these packages to connect to your database and perform operations on it. Refer to detailed links for service-specific instructions.
Authentication
If your database requires authentication, use Wrangler secrets to securely store your credentials. To do this, create a secret in your Cloudflare Workers project using the following wrangler secret
command:
wrangler secret put SECRET_NAME
Then, retrieve the secret value in your code using the following code snippet:
const secretValue = env.SECRET_NAME;
Use the secret value to authenticate with the external service. For example, if the external service requires an API key or database username and password for authentication, include these in using the relevant service’s library or API.
For services that require mTLS authentication, use mTLS certificates to present a client certificate.