Skip to main content
Execute SQL queries and database operations with automatic binding resolution.
For simple key-value or object storage, see the storage operation.

Configuration

D1 (SQL Database)

Serverless SQLite database for relational data with full SQL support.

Query Operation

Output:

Parameterized Queries

Always use parameterized queries to prevent SQL injection:

INSERT with RETURNING

UPDATE Operation

DELETE Operation

Transactions

Execute multiple statements atomically:

Batch Operations

Execute multiple queries (non-atomic):

Vectorize (Vector Database)

Vector search for semantic similarity, embeddings, and AI applications.

Insert Vectors

Query by Vector

Output:

Metadata Filtering

External Databases via Plugins

Hyperdrive (Postgres, MySQL)

Connect to external databases with automatic connection pooling and edge caching. Configuration options:
PostgreSQL Example:
MySQL Example:
Output:
Wrangler configuration:
Hyperdrive automatically handles connection pooling, so you don’t need to manage connections manually. This dramatically reduces latency compared to direct database connections.

Supabase Plugin

Neon Plugin

PlanetScale Plugin

Best Practices

SQL Injection Prevention

Never concatenate user input:
Always use parameterized queries:

Connection Pooling

For external databases, use Hyperdrive for automatic connection pooling:

Transaction Handling

Use transactions for operations that must succeed or fail together:

Error Handling

Choosing the Right Backend

When to Use data vs storage

Use data when you need:
  • ✅ SQL queries
  • ✅ Relational data
  • ✅ Transactions
  • ✅ Complex queries with JOINs
  • ✅ Vector search
Use storage when you need:
  • ❌ Simple key-value lookups
  • ❌ Object/file storage
  • ❌ Temporary caching
  • ❌ Global edge caching
See storage operation for key-value and object storage.
  • storage - Key-value and object storage
  • http - HTTP requests
  • think - AI reasoning