Skip to content

Commit b192bd1

Browse files
authored
Allow small, medium and large engines (#58)
1 parent 582e7cb commit b192bd1

6 files changed

Lines changed: 57 additions & 9 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 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 |
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 |
4040

4141
### `dune execution`
4242

cmd/query/helpers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ func parseQueryID(arg string) (int, error) {
2323
func parsePerformance(cmd *cobra.Command) (string, error) {
2424
performance, _ := cmd.Flags().GetString("performance")
2525
switch performance {
26-
case "", "free", "medium", "large":
26+
// "free" is accepted for backwards compatibility but not advertised. New callers should
27+
// use "small".
28+
case "", "small", "medium", "large", "free":
2729
return performance, nil
2830
default:
2931
return "", fmt.Errorf(
30-
"invalid performance tier %q: must be \"free\", \"medium\" or \"large\"",
32+
"invalid performance tier %q: must be \"small\", \"medium\" or \"large\"",
3133
performance,
3234
)
3335
}

cmd/query/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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", "", `engine tier override: "free", "medium", or "large"; omit to let the API auto-select based on your plan`)
38+
cmd.Flags().String("performance", "", `engine tier override: "small", "medium", or "large"; omit to let the API auto-select based on your plan`)
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
@@ -37,7 +37,7 @@ func newRunSQLCmd() *cobra.Command {
3737
cmd.Flags().String("sql", "", "the SQL query text in DuneSQL dialect (required)")
3838
_ = cmd.MarkFlagRequired("sql")
3939
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")
40-
cmd.Flags().String("performance", "", `engine tier override: "free", "medium", or "large"; omit to let the API auto-select based on your plan`)
40+
cmd.Flags().String("performance", "", `engine tier override: "small", "medium", or "large"; omit to let the API auto-select based on your plan`)
4141
cmd.Flags().Int("limit", 0, "maximum number of result rows to return (0 = all available rows)")
4242
cmd.Flags().Bool("no-wait", false, "submit the execution and exit immediately, printing only the execution ID and state")
4343
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: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestRunSQLWithPerformance(t *testing.T) {
133133
assert.Equal(t, "large", captured.Performance)
134134
}
135135

136-
func TestRunSQLWithPerformanceFree(t *testing.T) {
136+
func TestRunSQLWithPerformanceSmall(t *testing.T) {
137137
var captured models.ExecuteSQLRequest
138138
mock := &mockClient{
139139
runSQLFn: func(req models.ExecuteSQLRequest) (dune.Execution, error) {
@@ -148,10 +148,10 @@ func TestRunSQLWithPerformanceFree(t *testing.T) {
148148
}
149149

150150
root, _ := newTestRoot(mock)
151-
root.SetArgs([]string{"query", "run-sql", "--sql", "SELECT 1", "--performance", "free"})
151+
root.SetArgs([]string{"query", "run-sql", "--sql", "SELECT 1", "--performance", "small"})
152152
require.NoError(t, root.Execute())
153153

154-
assert.Equal(t, "free", captured.Performance)
154+
assert.Equal(t, "small", captured.Performance)
155155
}
156156

157157
func TestRunSQLExecutionFailed(t *testing.T) {
@@ -255,6 +255,29 @@ func TestRunSQLInvalidPerformance(t *testing.T) {
255255
assert.Contains(t, err.Error(), "invalid performance tier")
256256
}
257257

258+
// TestRunSQLAcceptsLegacyFreePerformance pins backwards compatibility: "free" is no longer
259+
// advertised but must still be accepted and forwarded so existing scripts keep working.
260+
func TestRunSQLAcceptsLegacyFreePerformance(t *testing.T) {
261+
var captured models.ExecuteSQLRequest
262+
mock := &mockClient{
263+
runSQLFn: func(req models.ExecuteSQLRequest) (dune.Execution, error) {
264+
captured = req
265+
return &mockExecution{
266+
id: "01ABC",
267+
waitGetResultsFn: func(_ time.Duration, _ int) (*models.ResultsResponse, error) {
268+
return testResultsResponse, nil
269+
},
270+
}, nil
271+
},
272+
}
273+
274+
root, _ := newTestRoot(mock)
275+
root.SetArgs([]string{"query", "run-sql", "--sql", "SELECT 1", "--performance", "free"})
276+
require.NoError(t, root.Execute())
277+
278+
assert.Equal(t, "free", captured.Performance)
279+
}
280+
258281
func TestRunSQLInvalidParam(t *testing.T) {
259282
root, _ := newTestRoot(&mockClient{})
260283
root.SetArgs([]string{"query", "run-sql", "--sql", "SELECT 1", "--param", "noequalssign"})

cmd/query/run_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,26 @@ func TestRunInvalidPerformance(t *testing.T) {
272272
require.Error(t, err)
273273
assert.Contains(t, err.Error(), "invalid performance tier")
274274
}
275+
276+
// TestRunAcceptsLegacyFreePerformance pins backwards compatibility: "free" is no longer
277+
// advertised but must still be accepted and forwarded so existing scripts keep working.
278+
func TestRunAcceptsLegacyFreePerformance(t *testing.T) {
279+
var captured models.ExecuteRequest
280+
mock := &mockClient{
281+
runQueryFn: func(req models.ExecuteRequest) (dune.Execution, error) {
282+
captured = req
283+
return &mockExecution{
284+
id: "01ABC",
285+
waitGetResultsFn: func(_ time.Duration, _ int) (*models.ResultsResponse, error) {
286+
return testResultsResponse, nil
287+
},
288+
}, nil
289+
},
290+
}
291+
292+
root, _ := newTestRoot(mock)
293+
root.SetArgs([]string{"query", "run", "4125432", "--performance", "free"})
294+
require.NoError(t, root.Execute())
295+
296+
assert.Equal(t, "free", captured.Performance)
297+
}

0 commit comments

Comments
 (0)