Cloudflare Docs
Workers
Visit Workers on GitHub
Set theme to dark (⇧+D)

Connect to databases

Cloudflare Workers can connect to and query your data in both SQL and NoSQL databases, including:

  • Traditional hosted relational databases, including Postgres and MySQL.
  • Serverless databases: Supabase, MongoDB Atlas, PlanetScale, FaunaDB, and Prisma.
  • Cloudflare’s own D1, a serverless SQL-based database.

​​ Connect to a database from a Worker

There are three ways to connect to a database from a Worker:

  1. Database Integrations: Simplifies authentication by managing credentials on your behalf and includes support for PlanetScale, Neon and Supabase.
  2. TCP Socket API: A direct TCP connection to a database. TCP is the de-facto standard protocol that many databases, such as PostgreSQL and MySQL, use for client connectivity.
  3. HTTP- or WebSocket-based serverless drivers: Many hosted databases support a HTTP or WebSocket API to enable either clients to connect from environments that do not support TCP, or as their preferred connection protocol.

​​ Next steps