Skip to content
Start here

Database

List D1 Databases
GET/accounts/{account_id}/d1/database
Get D1 Database
GET/accounts/{account_id}/d1/database/{database_id}
Create D1 Database
POST/accounts/{account_id}/d1/database
Update D1 Database
PUT/accounts/{account_id}/d1/database/{database_id}
Update D1 Database partially
PATCH/accounts/{account_id}/d1/database/{database_id}
Delete D1 Database
DELETE/accounts/{account_id}/d1/database/{database_id}
Query D1 Database
POST/accounts/{account_id}/d1/database/{database_id}/query
Raw D1 Database query
POST/accounts/{account_id}/d1/database/{database_id}/raw
Export D1 Database as SQL
POST/accounts/{account_id}/d1/database/{database_id}/export
Import SQL into your D1 Database
POST/accounts/{account_id}/d1/database/{database_id}/import
ModelsExpand Collapse
QueryResult { meta, results, success }
meta: optional { changed_db, changes, duration, 8 more }
changed_db: optional boolean

Denotes if the database has been altered in some way, like deleting rows.

changes: optional number

Rough indication of how many rows were modified by the query, as provided by SQLite’s sqlite3_total_changes().

duration: optional number

The duration of the SQL query execution inside the database. Does not include any network communication.

last_row_id: optional number

The row ID of the last inserted row in a table with an INTEGER PRIMARY KEY as provided by SQLite. Tables created with WITHOUT ROWID do not populate this.

rows_read: optional number

Number of rows read during the SQL query execution, including indices (not all rows are necessarily returned).

rows_written: optional number

Number of rows written during the SQL query execution, including indices.

served_by_colo: optional string

The three letters airport code of the colo that handled the query.

served_by_primary: optional boolean

Denotes if the query has been handled by the database primary instance.

served_by_region: optional "WNAM" or "ENAM" or "WEUR" or 3 more

Region location hint of the database instance that handled the query.

One of the following:
"WNAM"
"ENAM"
"WEUR"
"EEUR"
"APAC"
"OC"
size_after: optional number

Size of the database after the query committed, in bytes.

timings: optional { sql_duration_ms }

Various durations for the query.

sql_duration_ms: optional number

The duration of the SQL query execution inside the database. Does not include any network communication.

results: optional array of unknown
success: optional boolean
DatabaseListResponse { created_at, jurisdiction, name, 2 more }
created_at: optional string

Specifies the timestamp the resource was created as an ISO8601 string.

formatdate-time
jurisdiction: optional "eu" or "fedramp"

Specify the location to restrict the D1 database to run and store data. If this option is present, the location hint is ignored.

One of the following:
"eu"
"fedramp"
name: optional string

D1 database name.

uuid: optional string

D1 database identifier (UUID).

version: optional string
DatabaseDeleteResponse = unknown
DatabaseRawResponse { meta, results, success }
meta: optional { changed_db, changes, duration, 8 more }
changed_db: optional boolean

Denotes if the database has been altered in some way, like deleting rows.

changes: optional number

Rough indication of how many rows were modified by the query, as provided by SQLite’s sqlite3_total_changes().

duration: optional number

The duration of the SQL query execution inside the database. Does not include any network communication.

last_row_id: optional number

The row ID of the last inserted row in a table with an INTEGER PRIMARY KEY as provided by SQLite. Tables created with WITHOUT ROWID do not populate this.

rows_read: optional number

Number of rows read during the SQL query execution, including indices (not all rows are necessarily returned).

rows_written: optional number

Number of rows written during the SQL query execution, including indices.

served_by_colo: optional string

The three letters airport code of the colo that handled the query.

served_by_primary: optional boolean

Denotes if the query has been handled by the database primary instance.

served_by_region: optional "WNAM" or "ENAM" or "WEUR" or 3 more

Region location hint of the database instance that handled the query.

One of the following:
"WNAM"
"ENAM"
"WEUR"
"EEUR"
"APAC"
"OC"
size_after: optional number

Size of the database after the query committed, in bytes.

timings: optional { sql_duration_ms }

Various durations for the query.

sql_duration_ms: optional number

The duration of the SQL query execution inside the database. Does not include any network communication.

results: optional { columns, rows }
columns: optional array of string
rows: optional array of array of number or string or unknown
One of the following:
number
string
unknown
success: optional boolean
DatabaseExportResponse { at_bookmark, error, messages, 4 more }
at_bookmark: optional string

The current time-travel bookmark for your D1, used to poll for updates. Will not change for the duration of the export task.

error: optional string

Only present when status = ‘error’. Contains the error message.

messages: optional array of string

Logs since the last time you polled

result: optional { filename, signed_url }

Only present when status = ‘complete’

filename: optional string

The generated SQL filename.

signed_url: optional string

The URL to download the exported SQL. Available for one hour.

status: optional "complete" or "error"
One of the following:
"complete"
"error"
success: optional boolean
type: optional "export"
DatabaseImportResponse { at_bookmark, error, filename, 6 more }
at_bookmark: optional string

The current time-travel bookmark for your D1, used to poll for updates. Will not change for the duration of the import. Only returned if an import process is currently running or recently finished.

error: optional string

Only present when status = ‘error’. Contains the error message that prevented the import from succeeding.

filename: optional string

Derived from the database ID and etag, to use in avoiding repeated uploads. Only returned when for the ‘init’ action.

messages: optional array of string

Logs since the last time you polled

result: optional { final_bookmark, meta, num_queries }

Only present when status = ‘complete’

final_bookmark: optional string

The time-travel bookmark if you need restore your D1 to directly after the import succeeded.

meta: optional { changed_db, changes, duration, 8 more }
changed_db: optional boolean

Denotes if the database has been altered in some way, like deleting rows.

changes: optional number

Rough indication of how many rows were modified by the query, as provided by SQLite’s sqlite3_total_changes().

duration: optional number

The duration of the SQL query execution inside the database. Does not include any network communication.

last_row_id: optional number

The row ID of the last inserted row in a table with an INTEGER PRIMARY KEY as provided by SQLite. Tables created with WITHOUT ROWID do not populate this.

rows_read: optional number

Number of rows read during the SQL query execution, including indices (not all rows are necessarily returned).

rows_written: optional number

Number of rows written during the SQL query execution, including indices.

served_by_colo: optional string

The three letters airport code of the colo that handled the query.

served_by_primary: optional boolean

Denotes if the query has been handled by the database primary instance.

served_by_region: optional "WNAM" or "ENAM" or "WEUR" or 3 more

Region location hint of the database instance that handled the query.

One of the following:
"WNAM"
"ENAM"
"WEUR"
"EEUR"
"APAC"
"OC"
size_after: optional number

Size of the database after the query committed, in bytes.

timings: optional { sql_duration_ms }

Various durations for the query.

sql_duration_ms: optional number

The duration of the SQL query execution inside the database. Does not include any network communication.

num_queries: optional number

The total number of queries that were executed during the import.

status: optional "complete" or "error"
One of the following:
"complete"
"error"
success: optional boolean
type: optional "import"
upload_url: optional string

The R2 presigned URL to use for uploading. Only returned when for the ‘init’ action.

DatabaseTime Travel

Get D1 database bookmark
GET/accounts/{account_id}/d1/database/{database_id}/time_travel/bookmark
Restore D1 Database to a bookmark or point in time
POST/accounts/{account_id}/d1/database/{database_id}/time_travel/restore
ModelsExpand Collapse
TimeTravelGetBookmarkResponse { bookmark }
bookmark: optional string

A bookmark representing a specific state of the database at a specific point in time.

TimeTravelRestoreResponse { bookmark, message, previous_bookmark }

Response from a time travel restore operation.

bookmark: optional string

The new bookmark representing the state of the database after the restore operation.

message: optional string

A message describing the result of the restore operation.

previous_bookmark: optional string

The bookmark representing the state of the database before the restore operation. Can be used to undo the restore if needed.