Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Cloudflare D1 - Serverless SQL Database
[go: Go Back, main page]

D1

The easiest way to add SQL to your application

D1 is built into the Cloudflare Workers Platform with out-of-the-box integration with Workers. Applications need to save data. SQLite offers a familiar, relational database with SQL querying.
Familiar SQL at the Edge

Build applications with the power and familiarity of a relational, SQL-based database that lives on the edge, close to your users. Leverage your existing SQL knowledge to query structured data with low latency, without having to learn a new query language.

Native Worker Integration

Query your database with near-zero latency directly from your serverless functions, as D1 is built to be the stateful backend for the Cloudflare Workers ecosystem.

Scale for Vibe-Coding Platforms

Create millions of D1 databases, per account or per user, and scale out your vibe-coding platform to support everyone. Pay only when databases are used.

Built for Data-Driven Applications

Background Pattern
Global Read Replication

Automatically create read-only copies of your database across Cloudflare's global network, allowing you to serve data from a location near your users for incredibly fast read performance.

Background Pattern
Native Worker Integration

Query your database with near-zero latency directly from your serverless functions, as D1 is built to be the stateful backend for the Cloudflare Workers ecosystem.

Background Pattern
Modern ORM Support

Develop faster and with full type-safety by using your favorite Object-Relational Mappers, with first-class support for popular tools like Prisma and Drizzle ORM.

Background Pattern
Time Travel Backups

Effortlessly restore your entire database to any minute within the last 30 days, providing powerful point-in-time recovery to protect against accidental data loss or corruption.

Background Pattern
Generated Columns

Define columns that automatically compute their values from other columns or JSON data, simplifying your application logic by offloading transformations and calculations directly to the database.

Background Pattern
Secure and easy Worker Bindings

Securely connect your D1 databases to your code with a simple binding in your configuration, streamlining both production deployments and local development with the Wrangler CLI.

Background Pattern
D1

Perfect for Structured Data at the Edge

You can use D1 to:

View docs

Vibe-coding platforms

Instantly provision an isolated database for each user's project on your platform, providing fast, sandboxed data storage for online IDEs, CMS platforms, or multi-tenant SaaS applications. Provide your users with a full-featured SQL database without managing complex infrastructure.

Familiar SQL at the Edge

Build applications with the power and familiarity of a relational, SQL-based database that lives on the edge, close to your users. Leverage your existing SQL knowledge to query structured data with low latency, without having to learn a new query language.

User Profile & Configuration Storage

Store user-specific application settings, profiles, and personalization data directly at the edge to deliver fast, customized experiences. Reduce read latency for frequently accessed data and improve your application's responsiveness globally.

From schema to scale

Practical examples for building and scaling SQL-backed apps on the edge.

Background Pattern
export default {
  async fetch(request, env) {
    // Create a table
    await env.DB.exec(`CREATE TABLE IF NOT EXISTS users (
      id INTEGER PRIMARY KEY,
      name TEXT NOT NULL,
      email TEXT UNIQUE NOT NULL,
      created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    )`);

    // Insert data
    const { results } = await env.DB.prepare(
      `INSERT INTO users (name, email) VALUES (?, ?)`
    ).bind('John Doe', 'john@example.com').run();

    // Query data
    const { results: users } = await env.DB.prepare(
      `SELECT * FROM users WHERE email = ?`
    ).bind('john@example.com').all();

    return new Response(JSON.stringify(users), {
      headers: { 'Content-Type': 'application/json' }
    });
  }
};

D1 Pricing

Serverless SQL that scales horizontally. View Storage & Data pricing details

Storage

Free

5 GB (total)

Paid

$0.75 / GB-month

Rows Read

Free

5 million / day

Paid

$0.001 / million rows

Rows Written

Free

100,000 / day

Paid

$1.00 / million rows

SiteGPT

We use Cloudflare for everything – storage, cache, queues, and most importantly for training data and deploying the app on the edge, so I can ensure the product is reliable and fast. It's also been the most affordable option, with competitors costing more for a single day's worth of requests than Cloudflare costs in a month. ”

Bhanu Teja Pachipulusu
Bhanu Teja Pachipulusu Founder

Powerful primitives, seamlessly integrated

Built on systems powering 20% of the Internet, D1 runs on the same infrastructure Cloudflare uses to build Cloudflare. Enterprise-grade reliability, security, and performance are standard.

Build without boundaries

Join thousands of developers who've eliminated infrastructure complexity and deployed globally with Cloudflare. Start building for free — no credit card required.