Skip to content
Start here

D1

ModelsExpand Collapse
class D1:

The details of the D1 database.

created_at: Optional[datetime]

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

formatdate-time
file_size: Optional[float]

The D1 database's size, in bytes.

jurisdiction: Optional[Literal["eu", "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[str]

D1 database name.

num_tables: Optional[float]
read_replication: Optional[ReadReplication]

Configuration for D1 read replication.

mode: Literal["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: Optional[str]

D1 database identifier (UUID).

version: Optional[str]

D1Database

List D1 Databases
d1.database.list(DatabaseListParams**kwargs) -> SyncV4PagePaginationArray[DatabaseListResponse]
GET/accounts/{account_id}/d1/database
Get D1 Database
d1.database.get(strdatabase_id, DatabaseGetParams**kwargs) -> D1
GET/accounts/{account_id}/d1/database/{database_id}
Create D1 Database
d1.database.create(DatabaseCreateParams**kwargs) -> D1
POST/accounts/{account_id}/d1/database
Update D1 Database
d1.database.update(strdatabase_id, DatabaseUpdateParams**kwargs) -> D1
PUT/accounts/{account_id}/d1/database/{database_id}
Update D1 Database partially
d1.database.edit(strdatabase_id, DatabaseEditParams**kwargs) -> D1
PATCH/accounts/{account_id}/d1/database/{database_id}
Delete D1 Database
d1.database.delete(strdatabase_id, DatabaseDeleteParams**kwargs) -> object
DELETE/accounts/{account_id}/d1/database/{database_id}
Query D1 Database
d1.database.query(strdatabase_id, DatabaseQueryParams**kwargs) -> SyncSinglePage[QueryResult]
POST/accounts/{account_id}/d1/database/{database_id}/query
Raw D1 Database query
d1.database.raw(strdatabase_id, DatabaseRawParams**kwargs) -> SyncSinglePage[DatabaseRawResponse]
POST/accounts/{account_id}/d1/database/{database_id}/raw
Export D1 Database as SQL
d1.database.export(strdatabase_id, DatabaseExportParams**kwargs) -> DatabaseExportResponse
POST/accounts/{account_id}/d1/database/{database_id}/export
Import SQL into your D1 Database
d1.database.import_(strdatabase_id, DatabaseImportParams**kwargs) -> DatabaseImportResponse
POST/accounts/{account_id}/d1/database/{database_id}/import
ModelsExpand Collapse
class QueryResult:
meta: Optional[Meta]
changed_db: Optional[bool]

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

changes: Optional[float]

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

duration: Optional[float]

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

last_row_id: Optional[float]

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[float]

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

rows_written: Optional[float]

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

served_by_colo: Optional[str]

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

served_by_primary: Optional[bool]

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

served_by_region: Optional[Literal["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: Optional[float]

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

timings: Optional[MetaTimings]

Various durations for the query.

sql_duration_ms: Optional[float]

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

results: Optional[List[object]]
success: Optional[bool]
class DatabaseListResponse:
created_at: Optional[datetime]

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

formatdate-time
jurisdiction: Optional[Literal["eu", "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[str]

D1 database name.

uuid: Optional[str]

D1 database identifier (UUID).

version: Optional[str]
class DatabaseRawResponse:
meta: Optional[Meta]
changed_db: Optional[bool]

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

changes: Optional[float]

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

duration: Optional[float]

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

last_row_id: Optional[float]

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[float]

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

rows_written: Optional[float]

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

served_by_colo: Optional[str]

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

served_by_primary: Optional[bool]

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

served_by_region: Optional[Literal["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: Optional[float]

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

timings: Optional[MetaTimings]

Various durations for the query.

sql_duration_ms: Optional[float]

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

results: Optional[Results]
columns: Optional[List[str]]
rows: Optional[List[List[Union[float, str, object]]]]
One of the following:
float
str
object
success: Optional[bool]
class DatabaseExportResponse:
at_bookmark: Optional[str]

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[str]

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

messages: Optional[List[str]]

Logs since the last time you polled

result: Optional[Result]

Only present when status = 'complete'

filename: Optional[str]

The generated SQL filename.

signed_url: Optional[str]

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

status: Optional[Literal["complete", "error"]]
One of the following:
"complete"
"error"
success: Optional[bool]
type: Optional[Literal["export"]]
class DatabaseImportResponse:
at_bookmark: Optional[str]

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[str]

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

filename: Optional[str]

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

messages: Optional[List[str]]

Logs since the last time you polled

result: Optional[Result]

Only present when status = 'complete'

final_bookmark: Optional[str]

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

meta: Optional[ResultMeta]
changed_db: Optional[bool]

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

changes: Optional[float]

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

duration: Optional[float]

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

last_row_id: Optional[float]

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[float]

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

rows_written: Optional[float]

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

served_by_colo: Optional[str]

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

served_by_primary: Optional[bool]

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

served_by_region: Optional[Literal["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: Optional[float]

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

timings: Optional[ResultMetaTimings]

Various durations for the query.

sql_duration_ms: Optional[float]

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

num_queries: Optional[float]

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

status: Optional[Literal["complete", "error"]]
One of the following:
"complete"
"error"
success: Optional[bool]
type: Optional[Literal["import"]]
upload_url: Optional[str]

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

D1DatabaseTime Travel

Get D1 database bookmark
d1.database.time_travel.get_bookmark(strdatabase_id, TimeTravelGetBookmarkParams**kwargs) -> TimeTravelGetBookmarkResponse
GET/accounts/{account_id}/d1/database/{database_id}/time_travel/bookmark
Restore D1 Database to a bookmark or point in time
d1.database.time_travel.restore(strdatabase_id, TimeTravelRestoreParams**kwargs) -> TimeTravelRestoreResponse
POST/accounts/{account_id}/d1/database/{database_id}/time_travel/restore
ModelsExpand Collapse
class TimeTravelGetBookmarkResponse:
bookmark: Optional[str]

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

class TimeTravelRestoreResponse:

Response from a time travel restore operation.

bookmark: Optional[str]

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

message: Optional[str]

A message describing the result of the restore operation.

previous_bookmark: Optional[str]

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