git.iko.soy/parseable-macos
on master help sign in
Auto-run query when selecting a dataset (#9)

When a user selects a stream, automatically execute the default query so results appear immediately without requiring a manual "Run" click. The auto-execution only fires when the query text is the auto-generated default (not user-customized SQL). Also auto-executes on initial appear of the query tab when no results are loaded yet. https://claude.ai/code/session_01Pzdd6faAqPTBEQitHjs5nq Co-authored-by: Claude <noreply@anthropic.com>

commit8e59dd6ebc3d2be6308d4da5dd72508bbe40f6f7 authoriko <mail@iko.soy> dateSun 15 Feb 2026, 12:47 (8 months ago) parent2d089aa
2 files changed+23−3
ParseableViewer/ViewModels/QueryViewModel.swift+5−1 ParseableViewer/Views/QueryView.swift+18−2
ParseableViewer/ViewModels/QueryViewModel.swift+5−1
@@ -284,7 +284,10 @@ final class QueryViewModel {
284284 resultsTruncated = false
285285 }
286286
287− func setDefaultQuery(stream: String, previousStream: String? = nil) {
287+ /// Sets the default query for the given stream, returning `true` if the
288+ /// query text was replaced (i.e. the user hadn't customized it).
289+ @discardableResult
290+ func setDefaultQuery(stream: String, previousStream: String? = nil) -> Bool {
288291 // Replace the query if it's empty or still matches the auto-generated
289292 // default for the previous stream. If the user edited the SQL, keep it.
290293 let shouldReplace: Bool
@@ -300,6 +303,7 @@ final class QueryViewModel {
300303 if shouldReplace {
301304 sqlQuery = "SELECT * FROM \(Self.escapeSQLIdentifier(stream)) ORDER BY p_timestamp DESC LIMIT \(queryLimit)"
302305 }
306+ return shouldReplace
303307 }
304308
305309 /// Escapes a SQL identifier by doubling internal double-quotes, then wrapping in double-quotes.
ParseableViewer/Views/QueryView.swift+18−2
@@ -197,12 +197,28 @@ struct QueryView: View {
197197 .onChange(of: appState.selectedStream) { oldValue, newValue in
198198 viewModel.clearResults()
199199 if let stream = newValue {
200− viewModel.setDefaultQuery(stream: stream, previousStream: oldValue)
200+ let didSetDefault = viewModel.setDefaultQuery(stream: stream, previousStream: oldValue)
201+ if didSetDefault {
202+ Task {
203+ await viewModel.executeQuery(
204+ client: appState.client,
205+ stream: stream
206+ )
207+ }
208+ }
201209 }
202210 }
203211 .onAppear {
204212 if let stream = appState.selectedStream {
205− viewModel.setDefaultQuery(stream: stream)
213+ let didSetDefault = viewModel.setDefaultQuery(stream: stream)
214+ if didSetDefault && viewModel.results.isEmpty {
215+ Task {
216+ await viewModel.executeQuery(
217+ client: appState.client,
218+ stream: stream
219+ )
220+ }
221+ }
206222 }
207223 }
208224 .onDisappear {