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
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
Metadata Filtering
External Databases via Plugins
Hyperdrive (Postgres, MySQL)
Connect to external databases with automatic connection pooling and edge caching. Configuration options: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: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
- ❌ Simple key-value lookups
- ❌ Object/file storage
- ❌ Temporary caching
- ❌ Global edge caching

