SaaSActive

Cloudflare D1

Serverless SQL database with Time Travel point-in-time recovery.

Open source page ↗

Field note

What it does

Cloudflare D1 is a serverless SQL database. Time Travel provides always-on backups, restoring a database to any minute within the last 30 days.

Capabilities

Available capabilities

Tags

Tags

Ways to use it

Ways to use it

rest

Not filed / https://developers.cloudflare.com/d1/

cli

Not filed / Not filed

sdk

javascript / https://developers.cloudflare.com/d1/worker-api/

rest

Not filed / https://developers.cloudflare.com/api/operations/cloudflare-d1

cli

Not filed / wrangler

sdk

JavaScript, Python / https://developers.cloudflare.com/d1/worker-api/d1-database/

Product features

Product features

AES-256 GCM Encryption

Objects are encrypted using AES-256 with GCM (Galois/Counter Mode) as the preferred mode.

ALTER TABLE ADD COLUMN

Add VIRTUAL generated columns to existing tables.

Analytics API

Read and write volumes are available in the dashboard and the analytics API.

Apply migrations

Apply remaining migrations in sequential order.

Automatic Encryption

Encryption and decryption are automatic, require no user configuration, and do not impact effective performance.

Download backup locally

Download a backup as a native SQLite3 file via wrangler d1 backup download.

Restore a backup

Restore overwrites the current database in-place with the selected backup.

batch()

Sends multiple SQL statements in a single call, reducing network round trips.

Bookmarks

Bookmarks represent a database state at a point in time; lexicographically sortable and derived from Unix timestamps.

D1 Client API

Execute SQL queries via the D1 Client API.

D1Database::batch

Executes multiple statements.

D1Database::exec

Executes raw SQL without parameters.

D1PreparedStatement::first

Returns the first row only.

D1PreparedStatement::raw

Returns an array of arrays.

D1PreparedStatement::run

Returns the full D1Result object.

Dashboard management

Create and manage D1 databases through the Cloudflare dashboard.

dump

Exports the D1 database contents.

exec()

Executes SQL statements against the D1 database.

Export D1 into R2 using Workflows

Automatically export a D1 database into R2 storage via REST API and Cloudflare Workflows.

Foreign key constraints

Temporarily disable foreign key constraints during a migration with PRAGMA defer_foreign_keys = true.

Free plan prototyping

The Workers Free plan always includes the ability to prototype and experiment with D1 for free.

getBookmark()

Returns a bookmark from a D1DatabaseSession.

Global Read Replication

Add read-only database copies across regions to lower read latency and scale read throughput.

JSON extract columns

Define generated columns using json_extract on raw JSON data.

List unapplied migrations

List migrations that have not yet been applied.

Location hint

Optional parameter indicating the desired geographical location for a database.

Managed Encryption Keys

Encryption keys are managed by Cloudflare and stored in the same key management systems used across Cloudflare.

SQL migration files

Each migration is stored as an .sql file in your migrations folder with a version number in the filename.

Nested migration layouts

Use migrations_pattern glob to discover nested migrations, e.g. for ORMs like Drizzle.

No additional compute charge

D1 itself does not charge for additional compute; Workers computing results are billed per Workers pricing.

No data transfer / egress charges

D1 does not charge for data transfer or egress.

prepare()

Prepares a query statement to be later executed.

Primary database instance

The original instance of a database, existing in only one location in the world.

Query meta usage counts

Every query returns a meta object with rows_read and rows_written for billing estimation.

Query planner

Generates the most efficient query plan, deciding which indices to use or which table to access first.

Read replica

An eventually-replicated copy of the primary database instance that only serves read requests.

Replica lag

The time it takes for the primary database instance to replicate its changes to a read replica.

REST API

Create and manage your D1 database through the control plane.

Restore a database

Restore a database to a point in time; destructive, overwrites in place, cancels in-flight queries.

Session

Encapsulates all the queries from one logical session for your application.

SQLite SQL semantics

Execute SQL with SQLite's SQL compatibility and the D1 Client API.

STORED generated columns

Generated when the row is written, improving read performance.

Time Travel

D1's approach to backups and point-in-time recovery, restoring a database to any minute within the last 30 days.

Timestamps

Supports Unix timestamps and JavaScript date-time string format.

TLS/SSL Data Transfer

Data transfer between Workers, network nodes, and D1 is secured using TLS/SSL, including HTTP API and wrangler CLI access.

TypeScript support

Fully-typed via wrangler types and generic row types on run, raw and first.

Undo a restore

Undo a restore by using the previous bookmark or restoring to an earlier bookmark.

VIRTUAL generated columns

Generated on read, saving storage but increasing compute time.

withSession()

Creates a D1DatabaseSession for sequential consistency.

Worker and HTTP API access

Interact with your database directly from Workers or Pages, or via the HTTP API.

Worker bindings

Bind a Worker to a D1 database via the Wrangler configuration file.

Workers Binding API

Query your D1 database from a Worker by binding, preparing, and running statements.

Wrangler CLI management

Create and manage D1 databases from the terminal with wrangler d1 commands.

Wrangler commands

Query a D1 database using Wrangler commands, which use REST APIs.

Wrangler customizations

Customize migrations_table, migrations_dir and migrations_pattern in the D1 binding in your Wrangler file.