Skip to content

A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.

C++

fix(redis): preserve per-command history database

Tobia0b4a97dcbde
diff --git a/macos/App/State/AppState.swift b/macos/App/State/AppState.swift
index a6ddcfd..5e887e9 100644
--- a/macos/App/State/AppState.swift
+++ b/macos/App/State/AppState.swift
@@ -124,6 +124,7 @@ final class AppState: ObservableObject {
let statement: String
let result: Result<QueryResult, Error>
let duration: TimeInterval
+ let databaseName: String
}
private(set) var redisSessionID: UUID?
@@ -205,13 +206,19 @@ final class AppState: ObservableObject {
/// Persist a user-executed SQL query to the sidebar History (SwiftData).
/// Called ONLY from the SQL query editor — not from data grid loads,
/// structure inspections, or internal DML. Survives app restarts.
- func recordQueryHistory(sql: String, duration: TimeInterval?, rowCount: Int? = nil, error: String? = nil) {
+ func recordQueryHistory(
+ sql: String,
+ duration: TimeInterval?,
+ rowCount: Int? = nil,
+ error: String? = nil,
+ database: String? = nil
+ ) {
guard let connectionId = activeConnectionId else { return }
- let database = currentDatabaseName ?? ""
+ let historyDatabase = database ?? currentDatabaseName ?? ""
let historyEntry = QueryHistoryEntry(
id: UUID(),
connectionId: connectionId,
- database: database,
+ database: historyDatabase,
sql: sql,
executedAt: Date(),
duration: duration ?? 0,
@@ -771,6 +778,7 @@ final class AppState: ObservableObject {
await Self.executeRedisCLICommands(
commands,
using: adapter,
+ databaseName: context.databaseName,
execute: execute
)
}
@@ -793,7 +801,8 @@ final class AppState: ObservableObject {
RedisCLIStatementExecution(
statement: command,
result: result,
- duration: Date().timeIntervalSince(start)
+ duration: Date().timeIntervalSince(start),
+ databaseName: currentDatabaseName ?? context.databaseName
)
)
if case .failure = result { break }
@@ -812,6 +821,7 @@ final class AppState: ObservableObject {
private static func executeRedisCLICommands(
_ commands: [String],
using adapter: RedisAdapter,
+ databaseName: String,
execute: (RedisAdapter, String) async throws -> QueryResult
) async -> [RedisCLIStatementExecution] {
var executions: [RedisCLIStatementExecution] = []
@@ -827,7 +837,8 @@ final class AppState: ObservableObject {
RedisCLIStatementExecution(
statement: command,
result: result,
- duration: Date().timeIntervalSince(start)
+ duration: Date().timeIntervalSince(start),
+ databaseName: databaseName
)
)
if case .failure = result { break }
diff --git a/macos/Presentation/Views/QueryEditor/QueryEditorView.swift b/macos/Presentation/Views/QueryEditor/QueryEditorView.swift
index 57c86e6..5e5e77f 100644
--- a/macos/Presentation/Views/QueryEditor/QueryEditorView.swift
+++ b/macos/Presentation/Views/QueryEditor/QueryEditorView.swift
@@ -381,7 +381,8 @@ struct QueryEditorView: View {
appState.recordQueryHistory(
sql: execution.statement,
duration: execution.duration,
- rowCount: result.rowCount
+ rowCount: result.rowCount,
+ database: execution.databaseName
)
if !result.columns.isEmpty {
lastResult = result
@@ -392,7 +393,8 @@ struct QueryEditorView: View {
appState.recordQueryHistory(
sql: execution.statement,
duration: execution.duration,
- error: error.localizedDescription
+ error: error.localizedDescription,
+ database: execution.databaseName
)
errorMessage = error.localizedDescription
appState.refreshSidebar()