Skip to content
Start here

D1

ModelsExpand Collapse
D1 { created_at, file_size, jurisdiction, 5 more }

The details of the D1 database.

created_at?: string

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

formatdate-time
file_size?: number

The D1 database's size, in bytes.

jurisdiction?: "eu" | "fedramp" | null

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?: string

D1 database name.

num_tables?: number
read_replication?: ReadReplication { mode }

Configuration for D1 read replication.

mode: "auto" | "disabled"

The read replication mode for the database. Use 'auto' to create replicas and allow D1 automatically place them around the world, or 'disabled' to not use any database replicas (it can take a few hours for all replicas to be deleted).

One of the following:
"auto"
"disabled"
uuid?: string

D1 database identifier (UUID).

version?: string

D1Database

List D1 Databases
client.d1.database.list(DatabaseListParams { account_id, name, page, per_page } params, RequestOptionsoptions?): V4PagePaginationArray<DatabaseListResponse { created_at, jurisdiction, name, 2 more } >
GET/accounts/{account_id}/d1/database
Get D1 Database
client.d1.database.get(stringdatabaseId, DatabaseGetParams { account_id } params, RequestOptionsoptions?): D1 { created_at, file_size, jurisdiction, 5 more }
GET/accounts/{account_id}/d1/database/{database_id}
Create D1 Database
client.d1.database.create(DatabaseCreateParams { account_id, name, jurisdiction, primary_location_hint } params, RequestOptionsoptions?): D1 { created_at, file_size, jurisdiction, 5 more }
POST/accounts/{account_id}/d1/database
Update D1 Database
client.d1.database.update(stringdatabaseId, DatabaseUpdateParams { account_id, read_replication } params, RequestOptionsoptions?): D1 { created_at, file_size, jurisdiction, 5 more }
PUT/accounts/{account_id}/d1/database/{database_id}
Update D1 Database partially
client.d1.database.edit(stringdatabaseId, DatabaseEditParams { account_id, read_replication } params, RequestOptionsoptions?): D1 { created_at, file_size, jurisdiction, 5 more }
PATCH/accounts/{account_id}/d1/database/{database_id}
Delete D1 Database
client.d1.database.delete(stringdatabaseId, DatabaseDeleteParams { account_id } params, RequestOptionsoptions?): DatabaseDeleteResponse | null
DELETE/accounts/{account_id}/d1/database/{database_id}
Query D1 Database
client.d1.database.query(stringdatabaseId, DatabaseQueryParamsparams, RequestOptionsoptions?): SinglePage<QueryResult { meta, results, success } >
POST/accounts/{account_id}/d1/database/{database_id}/query
Raw D1 Database query
client.d1.database.raw(stringdatabaseId, DatabaseRawParamsparams, RequestOptionsoptions?): SinglePage<DatabaseRawResponse { meta, results, success } >
POST/accounts/{account_id}/d1/database/{database_id}/raw
Export D1 Database as SQL
client.d1.database.export(stringdatabaseId, DatabaseExportParams { account_id, output_format, current_bookmark, dump_options } params, RequestOptionsoptions?): DatabaseExportResponse { at_bookmark, error, messages, 4 more }
POST/accounts/{account_id}/d1/database/{database_id}/export
Import SQL into your D1 Database
client.d1.database.import(stringdatabaseId, DatabaseImportParamsparams, RequestOptionsoptions?): DatabaseImportResponse { at_bookmark, error, filename, 6 more }
POST/accounts/{account_id}/d1/database/{database_id}/import
ModelsExpand Collapse
QueryResult { meta, results, success }
meta?: Meta { changed_db, changes, duration, 8 more }
changed_db?: boolean

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

changes?: number

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

duration?: number

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

last_row_id?: 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?: number

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

rows_written?: number

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

served_by_colo?: string

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

served_by_primary?: boolean

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

served_by_region?: "WNAM" | "ENAM" | "WEUR" | 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?: number

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

timings?: Timings { sql_duration_ms }

Various durations for the query.

sql_duration_ms?: number

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

results?: Array<unknown>
success?: boolean
DatabaseListResponse { created_at, jurisdiction, name, 2 more }
created_at?: string

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

formatdate-time
jurisdiction?: "eu" | "fedramp" | null

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?: string

D1 database name.

uuid?: string

D1 database identifier (UUID).

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

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

changes?: number

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

duration?: number

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

last_row_id?: 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?: number

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

rows_written?: number

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

served_by_colo?: string

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

served_by_primary?: boolean

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

served_by_region?: "WNAM" | "ENAM" | "WEUR" | 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?: number

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

timings?: Timings { sql_duration_ms }

Various durations for the query.

sql_duration_ms?: number

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

results?: Results { columns, rows }
columns?: Array<string>
rows?: Array<Array<number | string | unknown>>
One of the following:
number
string
unknown
success?: boolean
DatabaseExportResponse { at_bookmark, error, messages, 4 more }
at_bookmark?: 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?: string

Only present when status = 'error'. Contains the error message.

messages?: Array<string>

Logs since the last time you polled

result?: Result { filename, signed_url }

Only present when status = 'complete'

filename?: string

The generated SQL filename.

signed_url?: string

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

status?: "complete" | "error"
One of the following:
"complete"
"error"
success?: boolean
type?: "export"
DatabaseImportResponse { at_bookmark, error, filename, 6 more }
at_bookmark?: 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?: string

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

filename?: string

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

messages?: Array<string>

Logs since the last time you polled

result?: Result { final_bookmark, meta, num_queries }

Only present when status = 'complete'

final_bookmark?: string

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

meta?: Meta { changed_db, changes, duration, 8 more }
changed_db?: boolean

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

changes?: number

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

duration?: number

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

last_row_id?: 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?: number

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

rows_written?: number

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

served_by_colo?: string

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

served_by_primary?: boolean

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

served_by_region?: "WNAM" | "ENAM" | "WEUR" | 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?: number

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

timings?: Timings { sql_duration_ms }

Various durations for the query.

sql_duration_ms?: number

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

num_queries?: number

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

status?: "complete" | "error"
One of the following:
"complete"
"error"
success?: boolean
type?: "import"
upload_url?: string

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

D1DatabaseTime Travel

Get D1 database bookmark
client.d1.database.timeTravel.getBookmark(stringdatabaseId, TimeTravelGetBookmarkParams { account_id, timestamp } params, RequestOptionsoptions?): TimeTravelGetBookmarkResponse { bookmark }
GET/accounts/{account_id}/d1/database/{database_id}/time_travel/bookmark
Restore D1 Database to a bookmark or point in time
client.d1.database.timeTravel.restore(stringdatabaseId, TimeTravelRestoreParams { account_id, bookmark, timestamp } params, RequestOptionsoptions?): TimeTravelRestoreResponse { bookmark, message, previous_bookmark }
POST/accounts/{account_id}/d1/database/{database_id}/time_travel/restore
ModelsExpand Collapse
TimeTravelGetBookmarkResponse { bookmark }
bookmark?: 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?: string

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

message?: string

A message describing the result of the restore operation.

previous_bookmark?: string

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