Skip to content

Commit 1c1ab49

Browse files
authored
fix(cli): allow --performance free for query run / run-sql (#55)
1 parent 133c977 commit 1c1ab49

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Manage and execute Dune queries.
3535
| `query get <query-id>` | Get a saved query's details and SQL |
3636
| `query update <query-id> [--name] [--sql] [--description] [--private] [--tags]` | Update an existing query |
3737
| `query archive <query-id>` | Archive a saved query |
38-
| `query run <query-id> [--param key=value] [--performance small\|medium\|large] [--limit] [--timeout] [--no-wait]` | Execute a saved query and display results |
39-
| `query run-sql --sql <sql> [--param key=value] [--performance small\|medium\|large] [--limit] [--timeout] [--no-wait]` | Execute raw SQL directly |
38+
| `query run <query-id> [--param key=value] [--performance free\|small\|medium\|large] [--limit] [--timeout] [--no-wait]` | Execute a saved query and display results |
39+
| `query run-sql --sql <sql> [--param key=value] [--performance free\|small\|medium\|large] [--limit] [--timeout] [--no-wait]` | Execute raw SQL directly |
4040

4141
### `dune execution`
4242

cmd/query/helpers.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ func parseQueryID(arg string) (int, error) {
2222

2323
func parsePerformance(cmd *cobra.Command) (string, error) {
2424
performance, _ := cmd.Flags().GetString("performance")
25-
if performance != "small" && performance != "medium" && performance != "large" {
25+
switch performance {
26+
case "small", "medium", "large", "free":
27+
return performance, nil
28+
default:
2629
return "", fmt.Errorf(
27-
"invalid performance tier %q: must be \"small\", \"medium\" or \"large\"",
30+
"invalid performance tier %q: must be \"free\", \"small\", \"medium\" or \"large\"",
2831
performance,
2932
)
3033
}
31-
return performance, nil
3234
}
3335

3436
func waitAndDisplay(cmd *cobra.Command, exec dune.Execution, timeout int) error {

cmd/query/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newRunCmd() *cobra.Command {
1919
"Use --no-wait to submit the execution and exit immediately with just the\n" +
2020
"execution ID; then fetch results later with 'dune execution results <execution-id>'.\n\n" +
2121
"Credits are consumed based on actual compute resources used. Use --performance\n" +
22-
"to select the engine size (medium or large).\n\n" +
22+
"with the tier name your plan exposes via the API (e.g. community plans often use \"free\").\n\n" +
2323
"Important: if the query targets tables with known partition columns (returned by\n" +
2424
"'dune dataset search' or 'dune dataset search-by-contract'), ensure the SQL includes\n" +
2525
"a WHERE filter on those partition columns (e.g. WHERE block_date >= CURRENT_DATE -\n" +
@@ -35,7 +35,7 @@ func newRunCmd() *cobra.Command {
3535
}
3636

3737
cmd.Flags().StringArray("param", nil, "typed query parameter in key=value format (repeatable); supported types: text, number (stringified, e.g. '30'), datetime (YYYY-MM-DD HH:mm:ss), enum")
38-
cmd.Flags().String("performance", "medium", `engine size for the execution: "small", "medium" (default) or "large"; credits are consumed based on actual compute resources used`)
38+
cmd.Flags().String("performance", "medium", `engine tier name (plan-specific; community often uses "free"): "free", "small", "medium" (default), or "large"; credits reflect actual compute`)
3939
cmd.Flags().Int("limit", 0, "maximum number of result rows to return (0 = all available rows)")
4040
cmd.Flags().Bool("no-wait", false, "submit the execution and exit immediately, printing only the execution ID and state")
4141
cmd.Flags().Int("timeout", 300, "maximum seconds to wait for the execution to complete before timing out")

cmd/query/run_sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func newRunSQLCmd() *cobra.Command {
3636
cmd.Flags().String("sql", "", "the SQL query text in DuneSQL dialect (required)")
3737
_ = cmd.MarkFlagRequired("sql")
3838
cmd.Flags().StringArray("param", nil, "typed query parameter in key=value format (repeatable); supported types: text, number (stringified, e.g. '30'), datetime (YYYY-MM-DD HH:mm:ss), enum")
39-
cmd.Flags().String("performance", "medium", `engine size for the execution: "small", "medium" (default) or "large"; credits are consumed based on actual compute resources used`)
39+
cmd.Flags().String("performance", "medium", `engine tier name for the execution (plan-specific; community often uses "free"): "free", "small", "medium" (default), or "large"; credits reflect actual compute`)
4040
cmd.Flags().Int("limit", 0, "maximum number of result rows to return (0 = all available rows)")
4141
cmd.Flags().Bool("no-wait", false, "submit the execution and exit immediately, printing only the execution ID and state")
4242
cmd.Flags().Int("timeout", 300, "maximum seconds to wait for the execution to complete before timing out")

cmd/query/run_sql_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ func TestRunSQLWithPerformance(t *testing.T) {
112112
assert.Equal(t, "large", captured.Performance)
113113
}
114114

115+
func TestRunSQLWithPerformanceFree(t *testing.T) {
116+
var captured models.ExecuteSQLRequest
117+
mock := &mockClient{
118+
runSQLFn: func(req models.ExecuteSQLRequest) (dune.Execution, error) {
119+
captured = req
120+
return &mockExecution{
121+
id: "01ABC",
122+
waitGetResultsFn: func(_ time.Duration, _ int) (*models.ResultsResponse, error) {
123+
return testResultsResponse, nil
124+
},
125+
}, nil
126+
},
127+
}
128+
129+
root, _ := newTestRoot(mock)
130+
root.SetArgs([]string{"query", "run-sql", "--sql", "SELECT 1", "--performance", "free"})
131+
require.NoError(t, root.Execute())
132+
133+
assert.Equal(t, "free", captured.Performance)
134+
}
135+
115136
func TestRunSQLExecutionFailed(t *testing.T) {
116137
failedResp := &models.ResultsResponse{
117138
QueryID: 4125432,

0 commit comments

Comments
 (0)