Files

1.9 KiB

D1 API Reference

Fetch the relevant API page before writing queries or assuming method signatures and return types.

Task Current documentation
Bind values and choose a query execution method Prepared statement methods
Execute batches and understand transaction rollback; use database sessions D1 Database API
Interpret results and query metadata Return objects
Choose supported JavaScript values and TypeScript result types Workers Binding API
Choose consistency constraints and carry bookmarks between requests Read replication and Sessions API
Query from a server-side script outside Workers REST query API
Handle query failures and transient errors Debug D1 and retry queries
Test database queries and apply migrations in tests Workers Vitest APIs: D1

Bind untrusted values with prepared statements; do not interpolate them into SQL. Parameters do not replace identifiers: choose dynamic table, column, or sort names from an application-controlled allowlist.

D1 sessions provide sequential consistency for replicated queries. They are not a way to extend query execution limits. Choose the starting constraint or bookmark from the application's consistency requirements using the replication guide.