Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrorReqUnsuccessful = errors.New("request was not successful")
var ErrorRetriesExhausted = errors.New("retries have been exhausted")
Functions ¶
func NewDuneClient ¶
NewDuneClient instantiates a new stateless DuneAPI client. Env contains information about the API key and target host (which shouldn't be changed, unless you want to run it through a custom proxy).
func NewExecution ¶
func NewExecution(client DuneClient, ID string) *execution
NewExecution is used to instantiate a new execution object given an Dune client object and existing execution ID. It is used to run further interactions with the execution, e.g. retrieve its status, get results, cancel, etc.
func NewPipeline ¶ added in v0.3.0
func NewPipeline(client DuneClient, ID string) *pipeline
Types ¶
type APIError ¶ added in v0.7.0
type APIError struct {
StatusCode int
// Message is the error message from the response body.
Message string
// Code is a stable, machine-readable error code. Only some endpoints set it.
Code string
// Details carries endpoint-specific context; decode it into the endpoint's details type.
Details json.RawMessage
}
APIError is returned for every non-2xx response. It wraps ErrorReqUnsuccessful, so errors.Is(err, ErrorReqUnsuccessful) keeps working; use errors.As to read the status code and the error body.
type DuneClient ¶
type DuneClient interface {
// New APIs to read results in a more flexible way
// returns the results or status of an execution, depending on whether it has completed
QueryResultsV2(executionID string, options models.ResultOptions) (*models.ResultsResponse, error)
// returns the results of a QueryID, depending on whether it has completed
ResultsByQueryID(queryID string, options models.ResultOptions) (*models.ResultsResponse, error)
// RunQuery submits a query for execution and returns an Execution object
RunQuery(req models.ExecuteRequest) (Execution, error)
// RunQueryGetRows submits a query for execution, blocks until execution is finished, and returns just the result rows
RunQueryGetRows(req models.ExecuteRequest) ([]map[string]any, error)
// QueryCancel cancels the execution of an execution in the pending or executing state
QueryCancel(executionID string) error
// QueryExecute submits a query to execute with the provided parameters
QueryExecute(req models.ExecuteRequest) (*models.ExecuteResponse, error)
// SQLExecute executes raw SQL with optional performance parameter
SQLExecute(req models.ExecuteSQLRequest) (*models.ExecuteResponse, error)
// QueryPipelineExecute submits a query pipeline for execution with optional performance parameter
QueryPipelineExecute(req models.PipelineExecuteRequest) (*models.PipelineExecuteResponse, error)
// PipelineStatus returns the current pipeline execution status
PipelineStatus(pipelineExecutionID string) (*models.PipelineStatusResponse, error)
// RunSQL submits raw SQL for execution and returns an Execution object
RunSQL(req models.ExecuteSQLRequest) (Execution, error)
// QueryStatus returns the current execution status
QueryStatus(executionID string) (*models.StatusResponse, error)
// QueryResults returns the results or status of an execution, depending on whether it has completed
// DEPRECATED, use QueryResultsV2 instead
QueryResults(executionID string) (*models.ResultsResponse, error)
// QueryResultsCSV returns the results of an execution, as CSV text stream if the execution has completed
QueryResultsCSV(executionID string) (io.Reader, error)
// QueryResultsByQueryID returns the results of the lastest execution for a given query ID
// DEPRECATED, use ResultsByQueryID instead
QueryResultsByQueryID(queryID string) (*models.ResultsResponse, error)
// QueryResultsCSVByQueryID returns the results of the lastest execution for a given query ID
// as CSV text stream if the execution has completed
QueryResultsCSVByQueryID(queryID string) (io.Reader, error)
// GetUsage returns usage statistics for the current billing period
GetUsage() (*models.UsageResponse, error)
// GetUsageForDates returns usage statistics for a specified time range
GetUsageForDates(startDate, endDate string) (*models.UsageResponse, error)
// ListDatasets returns a paginated list of datasets with optional filtering
ListDatasets(limit, offset int, ownerHandle, datasetType string) (*models.ListDatasetsResponse, error)
// GetDataset returns detailed information about a specific dataset by slug
GetDataset(slug string) (*models.DatasetResponse, error)
// ListUploads returns a paginated list of uploaded tables
ListUploads(limit, offset int) (*models.UploadsListResponse, error)
// CreateUpload creates an empty table with defined schema
CreateUpload(req models.UploadsCreateRequest) (*models.UploadsCreateResponse, error)
// UploadCSV uploads CSV data to create a new table
UploadCSV(req models.UploadsCSVRequest) (*models.UploadsCSVResponse, error)
// DeleteUpload permanently deletes a table and all its data
DeleteUpload(namespace, tableName string) (*models.UploadsDeleteResponse, error)
// ClearUpload removes all data from a table while preserving schema
ClearUpload(namespace, tableName string) (*models.UploadsClearResponse, error)
// InsertIntoUpload inserts data into an existing table (CSV or NDJSON format)
InsertIntoUpload(namespace, tableName, data, contentType string) (*models.UploadsInsertResponse, error)
// DEPRECATED: Use ListUploads instead. Will be removed March 1, 2026.
ListTables(limit, offset int) (*models.UploadsListResponse, error)
// DEPRECATED: Use CreateUpload instead. Will be removed March 1, 2026.
CreateTable(req models.UploadsCreateRequest) (*models.UploadsCreateResponse, error)
// DEPRECATED: Use UploadCSV instead. Will be removed March 1, 2026.
UploadCSVDeprecated(req models.UploadsCSVRequest) (*models.UploadsCSVResponse, error)
// DEPRECATED: Use DeleteUpload instead. Will be removed March 1, 2026.
DeleteTable(namespace, tableName string) (*models.UploadsDeleteResponse, error)
// DEPRECATED: Use ClearUpload instead. Will be removed March 1, 2026.
ClearTable(namespace, tableName string) (*models.UploadsClearResponse, error)
// DEPRECATED: Use InsertIntoUpload instead. Will be removed March 1, 2026.
InsertTable(namespace, tableName, data, contentType string) (*models.UploadsInsertResponse, error)
// CreateQuery creates a new saved query
CreateQuery(req models.CreateQueryRequest) (*models.CreateQueryResponse, error)
// GetQuery retrieves a saved query by ID
GetQuery(queryID int) (*models.GetQueryResponse, error)
// UpdateQuery updates an existing saved query
UpdateQuery(queryID int, req models.UpdateQueryRequest) (*models.UpdateQueryResponse, error)
// ArchiveQuery archives a saved query
ArchiveQuery(queryID int) (*models.UpdateQueryResponse, error)
// UnarchiveQuery restores an archived query
UnarchiveQuery(queryID int) (*models.UpdateQueryResponse, error)
// MakeQueryPrivate makes a query private
MakeQueryPrivate(queryID int) (*models.UpdateQueryResponse, error)
// MakeQueryPublic makes a private query public
MakeQueryPublic(queryID int) (*models.UpdateQueryResponse, error)
// ListQueries lists the queries owned by the API key's owner
ListQueries(limit, offset int) (*models.ListQueriesResponse, error)
// ListFolders lists the folders under a folder or the library root
ListFolders(opts models.ListFoldersOptions) (*models.ListFoldersResponse, error)
// GetFolder returns a folder, its subfolders, and its queries and dashboards
GetFolder(folderID string, opts models.GetFolderOptions) (*models.GetFolderResponse, error)
// CreateFolder creates a folder
CreateFolder(req models.CreateFolderRequest) (*models.Folder, error)
// UpdateFolder changes a folder's name, description, icon, or color
UpdateFolder(folderID string, req models.UpdateFolderRequest) (*models.Folder, error)
// MoveFolder moves a folder under another folder or to the library root
MoveFolder(folderID string, req models.MoveFolderRequest) (*models.Folder, error)
// DeleteFolder deletes a folder; recursive deletes a folder that is not empty
DeleteFolder(folderID string, recursive bool) (*models.DeleteFolderResponse, error)
// MoveContent moves queries and dashboards into a folder or out of folders
MoveContent(req models.MoveContentRequest) (*models.MoveContentResponse, error)
// ListSchedules lists query, dashboard, and materialized view schedules
ListSchedules(opts models.ListSchedulesOptions) (*models.ListSchedulesResponse, error)
// SetQuerySchedule creates or replaces a query's schedule
SetQuerySchedule(queryID int, req models.SetScheduleRequest) (*models.SetScheduleResponse, error)
// DeleteQuerySchedule deletes a query's schedule
DeleteQuerySchedule(queryID int) (*models.DeleteScheduleResponse, error)
// SetDashboardSchedule creates or replaces a dashboard's refresh schedule
SetDashboardSchedule(dashboardID int, req models.SetScheduleRequest) (*models.SetScheduleResponse, error)
// DeleteDashboardSchedule deletes a dashboard's schedule
DeleteDashboardSchedule(dashboardID int) (*models.DeleteScheduleResponse, error)
// SearchDatasets searches for datasets across the catalog with advanced filters
SearchDatasets(req models.SearchDatasetsRequest) (*models.SearchDatasetsResponse, error)
// SearchDatasetsByContractAddress finds decoded datasets associated with a smart contract address
SearchDatasetsByContractAddress(req models.SearchDatasetsByContractAddressRequest) (*models.SearchDatasetsResponse, error)
// WhoAmI returns the identity associated with the current API key
WhoAmI() (*models.WhoAmIResponse, error)
// SubmitContracts submits up to 100 contracts for decoding and returns a per-item result
SubmitContracts(req models.SubmitContractsRequest) (*models.SubmitContractsResponse, error)
// ListContractSubmissions lists the caller's contract decoding submissions, newest first
ListContractSubmissions(opts models.ListContractSubmissionsOptions) (*models.ListContractSubmissionsResponse, error)
// CreateVisualization creates a new visualization on an existing query
CreateVisualization(req models.CreateVisualizationRequest) (*models.CreateVisualizationResponse, error)
// GetVisualization retrieves a visualization by ID
GetVisualization(visualizationID int) (*models.GetVisualizationResponse, error)
// UpdateVisualization updates an existing visualization
UpdateVisualization(visualizationID int, req models.UpdateVisualizationRequest) (*models.UpdateVisualizationResponse, error)
// DeleteVisualization deletes a visualization by ID
DeleteVisualization(visualizationID int) (*models.DeleteVisualizationResponse, error)
// ListQueryVisualizations returns a paginated list of visualizations for a query
ListQueryVisualizations(queryID, limit, offset int) (*models.ListVisualizationsResponse, error)
// CreateDashboard creates a new dashboard
CreateDashboard(req models.CreateDashboardRequest) (*models.DashboardResponse, error)
// GetDashboard retrieves a dashboard by ID
GetDashboard(dashboardID int) (*models.DashboardResponse, error)
// GetDashboardBySlug retrieves a dashboard by owner handle and slug
GetDashboardBySlug(ownerHandle, slug string) (*models.DashboardResponse, error)
// UpdateDashboard updates an existing dashboard
UpdateDashboard(dashboardID int, req models.UpdateDashboardRequest) (*models.DashboardResponse, error)
// ArchiveDashboard archives a dashboard by ID
ArchiveDashboard(dashboardID int) (*models.ArchiveDashboardResponse, error)
// UpsertMaterializedView creates or replaces a materialized view from a saved query
UpsertMaterializedView(req models.UpsertMaterializedViewRequest) (*models.UpsertMaterializedViewResponse, error)
// GetMaterializedView retrieves a materialized view by its fully-qualified SQL name
GetMaterializedView(name string) (*models.GetMaterializedViewResponse, error)
// ListMaterializedViews returns a paginated list of materialized views owned by the caller
ListMaterializedViews(limit, offset int) (*models.ListMaterializedViewsResponse, error)
// RefreshMaterializedView triggers a refresh of a materialized view by name
RefreshMaterializedView(name string, req models.RefreshMaterializedViewRequest) (*models.RefreshMaterializedViewResponse, error)
// DeleteMaterializedView deletes a materialized view by name
DeleteMaterializedView(name string) (*models.DeleteMaterializedViewResponse, error)
}
DuneClient represents all operations available to call externally
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
// Code is a stable, machine-readable error code. Only some endpoints, such as the
// folder endpoints, set it.
Code string `json:"code,omitempty"`
// Details carries endpoint-specific context, such as the existing folder for
// folder_already_exists. Decode it into the endpoint's details type.
Details json.RawMessage `json:"details,omitempty"`
}
type Execution ¶
type Execution interface {
// QueryCancel cancels the execution
Cancel() error
// GetResults returns the results or status of the execution, depending on whether it has completed
GetResults() (*models.ResultsResponse, error)
// GetResultsCSV returns the results in CSV format
GetResultsCSV() (io.Reader, error)
// QueryStatus returns the current execution status
GetStatus() (*models.StatusResponse, error)
// GetResultsV2 returns the results or status of the execution, depending on whether it has completed
// it uses options to refine futher what results to get
GetResultsV2(options models.ResultOptions) (*models.ResultsResponse, error)
// RunQueryGetResults blocks until the execution is finished and returns the result
// maxRetries is used when using the RunQueryToCompletion method, to limit the number of times the method
// will tolerate API errors before giving up. A value of zero will disable the retry limit.
// It is recommended to set this to something non-zero, as there is a risk that this will block indefinitely
// if the Dune API is unreachable or returns an error. The pollInterval determines how long to wait between
// GetResult requests. It is recommended to set to at least 5 seconds to prevent rate-limiting.
WaitGetResults(pollInterval time.Duration, maxRetries int) (*models.ResultsResponse, error)
// GetID returns the execution ID
GetID() string
}