## Export D1 Database as SQL `client.D1.Database.Export(ctx, databaseID, params) (*DatabaseExportResponse, error)` **post** `/accounts/{account_id}/d1/database/{database_id}/export` Returns a URL where the SQL contents of your D1 can be downloaded. Note: this process may take some time for larger DBs, during which your D1 will be unavailable to serve queries. To avoid blocking your DB unnecessarily, an in-progress export must be continually polled or will automatically cancel. ### Parameters - `databaseID string` D1 database identifier (UUID). - `params DatabaseExportParams` - `AccountID param.Field[string]` Path param: Account identifier tag. - `OutputFormat param.Field[DatabaseExportParamsOutputFormat]` Body param: Specifies that you will poll this endpoint until the export completes - `const DatabaseExportParamsOutputFormatPolling DatabaseExportParamsOutputFormat = "polling"` - `CurrentBookmark param.Field[string]` Body param: To poll an in-progress export, provide the current bookmark (returned by your first polling response) - `DumpOptions param.Field[DatabaseExportParamsDumpOptions]` Body param - `NoData bool` Export only the table definitions, not their contents - `NoSchema bool` Export only each table's contents, not its definition - `Tables []string` Filter the export to just one or more tables. Passing an empty array is the same as not passing anything and means: export all tables. ### Returns - `type DatabaseExportResponse struct{…}` - `AtBookmark 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 []string` Logs since the last time you polled - `Result DatabaseExportResponseResult` Only present when status = 'complete' - `Filename string` The generated SQL filename. - `SignedURL string` The URL to download the exported SQL. Available for one hour. - `Status DatabaseExportResponseStatus` - `const DatabaseExportResponseStatusComplete DatabaseExportResponseStatus = "complete"` - `const DatabaseExportResponseStatusError DatabaseExportResponseStatus = "error"` - `Success bool` - `Type DatabaseExportResponseType` - `const DatabaseExportResponseTypeExport DatabaseExportResponseType = "export"` ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/d1" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) response, err := client.D1.Database.Export( context.TODO(), "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", d1.DatabaseExportParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), OutputFormat: cloudflare.F(d1.DatabaseExportParamsOutputFormatPolling), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.AtBookmark) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "result": { "at_bookmark": "at_bookmark", "error": "error", "messages": [ "string" ], "result": { "filename": "filename", "signed_url": "signed_url" }, "status": "complete", "success": true, "type": "export" }, "success": true } ```