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(postgres): populate macOS schema picker (#80)
Tobi867543046ab3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3e63888..0a65bda 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,11 @@All notable changes to Gridex are documented in this file. Gridex ships native apps for **macOS** (Swift/AppKit) and **Windows** (C++/WinUI 3). Unless noted otherwise, changes apply to both platforms.+## [Unreleased]++### Fixed+- **macOS PostgreSQL schemas** — The sidebar now lists and operates on the selected accessible schema instead of always using public.+## [0.23.0] - 2026-04-12### Addeddiff --git a/macos/App/State/AppState.swift b/macos/App/State/AppState.swiftindex 8a8c57d..dd96e99 100644--- a/macos/App/State/AppState.swift+++ b/macos/App/State/AppState.swift@@ -27,12 +27,16 @@ final class AppState: ObservableObject {/// Tables the user has marked for deletion in the sidebar./// They are NOT dropped until the user clicks the commit button in the sidebar header.- /// Key is the table name (per active connection / schema).- @Published var pendingTableDeletions: [String: PendingTableDeletion] = [:]- @Published var pendingTableTruncations: Set<String> = []+ @Published var pendingTableDeletions: [TableReference: PendingTableDeletion] = [:]+ @Published var pendingTableTruncations: Set<TableReference> = []++ struct TableReference: Hashable {+ let name: String+ let schema: String?+ }struct PendingTableDeletion {- var tableName: String+ let reference: TableReferencevar cascade: Boolvar ignoreForeignKeys: Bool}@@ -62,6 +66,8 @@ final class AppState: ObservableObject {@Published var activeAdapter: (any DatabaseAdapter)?@Published var activeConfig: ConnectionConfig?@Published var sidebarItems: [SidebarItem] = []+ @Published private(set) var sidebarSchemas: [String] = []+ @Published var selectedSidebarSchema: String?@Published var connectionTitle: String = "Gridex"@Published var isConnecting: Bool = false@Published var connectionError: String?@@ -270,7 +276,12 @@ final class AppState: ObservableObject {isConnecting = false// Load sidebar immediately (most important for user)- await loadSidebar(config: config, adapter: connection.adapter)+ await loadSidebarSchemas(config: config, adapter: connection.adapter)+ await loadSidebar(+ config: config,+ adapter: connection.adapter,+ schema: selectedSidebarSchema+ )// Fetch metadata in background — all parallelTask { [weak self] in@@ -333,13 +344,39 @@ final class AppState: ObservableObject {}}- func loadSidebar(config: ConnectionConfig, adapter: any DatabaseAdapter) async {+ func loadSidebarSchemas(config: ConnectionConfig, adapter: any DatabaseAdapter) async {+ guard config.databaseType == .postgresql else {+ sidebarSchemas = []+ selectedSidebarSchema = nil+ return+ }++ do {+ let schemas = try await adapter.listSchemas(database: config.database)+ sidebarSchemas = Array(Set(schemas)).sorted()+ selectedSidebarSchema = SidebarSchemaSelection.resolve(+ previous: selectedSidebarSchema,+ for: config.databaseType,+ schemas: sidebarSchemas+ )+ } catch {+ sidebarSchemas = []+ selectedSidebarSchema = nil+ print("Sidebar schema load error: \(error)")+ }+ }++ func loadSidebar(+ config: ConnectionConfig,+ adapter: any DatabaseAdapter,+ schema: String? = nil+ ) async {do {// Run all queries in parallel instead of sequential- async let tablesTask = adapter.listTables(schema: nil)- async let viewsTask = adapter.listViews(schema: nil)- async let functionsTask = adapter.listFunctions(schema: nil)- async let proceduresTask = adapter.listProcedures(schema: nil)+ async let tablesTask = adapter.listTables(schema: schema)+ async let viewsTask = adapter.listViews(schema: schema)+ async let functionsTask = adapter.listFunctions(schema: schema)+ async let proceduresTask = adapter.listProcedures(schema: schema)let tables = try await tablesTasklet views = try await viewsTask@@ -347,32 +384,32 @@ final class AppState: ObservableObject {let procedures = (try? await proceduresTask) ?? []let tableItems = tables.map { t in- SidebarItem(title: t.name, type: .table(t.name), iconName: "")+ SidebarItem(title: t.name, type: .table(t.name), schema: schema, iconName: "")}let viewItems = views.map { v in- SidebarItem(title: v.name, type: .view(v.name), iconName: "")+ SidebarItem(title: v.name, type: .view(v.name), schema: schema, iconName: "")}let functionItems = functions.map { f in- SidebarItem(title: f, type: .function(f), iconName: "")+ SidebarItem(title: f, type: .function(f), schema: schema, iconName: "")}let procedureItems = procedures.map { p in- SidebarItem(title: p, type: .procedure(p), iconName: "")+ SidebarItem(title: p, type: .procedure(p), schema: schema, iconName: "")}var items: [SidebarItem] = []if !functionItems.isEmpty {- items.append(SidebarItem(title: "Functions", type: .group("functions"), iconName: "", children: functionItems))+ items.append(SidebarItem(title: "Functions", type: .group("functions"), schema: schema, iconName: "", children: functionItems))}if !procedureItems.isEmpty {- items.append(SidebarItem(title: "Procedures", type: .group("procedures"), iconName: "", children: procedureItems))+ items.append(SidebarItem(title: "Procedures", type: .group("procedures"), schema: schema, iconName: "", children: procedureItems))}- items.append(SidebarItem(title: "Tables", type: .group("tables"), iconName: "", children: tableItems))+ items.append(SidebarItem(title: "Tables", type: .group("tables"), schema: schema, iconName: "", children: tableItems))if !viewItems.isEmpty {- items.append(SidebarItem(title: "Views", type: .group("views"), iconName: "", children: viewItems))+ items.append(SidebarItem(title: "Views", type: .group("views"), schema: schema, iconName: "", children: viewItems))}sidebarItems = items@@ -653,7 +690,8 @@ final class AppState: ObservableObject {// Reload sidebar for the new databaseif let cfg = activeConfig, let adp = activeAdapter {- await loadSidebar(config: cfg, adapter: adp)+ await loadSidebarSchemas(config: cfg, adapter: adp)+ await loadSidebar(config: cfg, adapter: adp, schema: selectedSidebarSchema)}} catch {print("Switch database failed: \(error)")@@ -708,6 +746,8 @@ final class AppState: ObservableObject {currentDatabaseName = nilavailableDatabases.removeAll()sidebarItems.removeAll()+ sidebarSchemas.removeAll()+ selectedSidebarSchema = nilselectedSidebarItem = nilselectedRowDetails = nilonDetailFieldEdit = nil@@ -723,7 +763,10 @@ final class AppState: ObservableObject {func refreshSidebar() {guard let adapter = activeAdapter, let config = activeConfig else { return }- Task { await loadSidebar(config: config, adapter: adapter) }+ Task {+ await loadSidebarSchemas(config: config, adapter: adapter)+ await loadSidebar(config: config, adapter: adapter, schema: selectedSidebarSchema)+ }}/// Re-fetch the database list from the active adapter and publish it.diff --git a/macos/Presentation/Views/Main/MainView.swift b/macos/Presentation/Views/Main/MainView.swiftindex b000188..7bf2814 100644--- a/macos/Presentation/Views/Main/MainView.swift+++ b/macos/Presentation/Views/Main/MainView.swift@@ -84,7 +84,7 @@ struct MainView: View {DatabaseSwitcherDialog()}.sheet(isPresented: $appState.showNewTableSheet) {- NewTableSheet(schema: "public")+ NewTableSheet(schema: appState.selectedSidebarSchema)}.onChange(of: appState.showConnectionForm) { _, show inif show {@@ -1153,7 +1153,7 @@ struct WorkspaceView: View {// ER Diagram (SQL databases only)if appState.activeConfig?.databaseType.isSQL == true {- Button { appState.openERDiagram(schema: nil) } label: {+ Button { appState.openERDiagram(schema: appState.selectedSidebarSchema) } label: {Image(systemName: "point.3.connected.trianglepath.dotted")}.help("ER Diagram")}diff --git a/macos/Presentation/Views/Sidebar/ExportTableSheet.swift b/macos/Presentation/Views/Sidebar/ExportTableSheet.swiftindex d59de7b..c1ad071 100644--- a/macos/Presentation/Views/Sidebar/ExportTableSheet.swift+++ b/macos/Presentation/Views/Sidebar/ExportTableSheet.swift@@ -13,6 +13,7 @@ enum ExportFormat: String, CaseIterable {struct ExportTableSheet: View {let tableName: String+ let schema: String?@EnvironmentObject private var appState: AppState@Environment(\.dismiss) private var dismiss@@ -327,7 +328,7 @@ struct ExportTableSheet: View {private func exportTable(_ table: String, to url: URL, adapter: any DatabaseAdapter) async throws {let d = adapter.databaseType.sqlDialect- let sql = "SELECT * FROM \(d.quoteIdentifier(table))"+ let sql = "SELECT * FROM \(d.qualifiedIdentifier(table, schema: schema))"var result = try await adapter.executeRaw(sql: sql)if convertNullToEmpty {@@ -342,7 +343,7 @@ struct ExportTableSheet: View {case .sql:// Full-fidelity SQL export — fetch structure first so we can emit// DROP/CREATE/sequences/indices alongside the INSERT rows.- let description = try await adapter.describeTable(name: table, schema: nil)+ let description = try await adapter.describeTable(name: table, schema: schema)try await ExportService().exportTableSQL(description: description,rows: result.rows,diff --git a/macos/Presentation/Views/Sidebar/ImportCSVSheet.swift b/macos/Presentation/Views/Sidebar/ImportCSVSheet.swiftindex 603dad3..7a946b1 100644--- a/macos/Presentation/Views/Sidebar/ImportCSVSheet.swift+++ b/macos/Presentation/Views/Sidebar/ImportCSVSheet.swift@@ -9,6 +9,7 @@ import AppKitstruct ImportCSVSheet: View {let tableName: String+ let schema: String?@EnvironmentObject private var appState: AppState@Environment(\.dismiss) private var dismiss@@ -245,7 +246,7 @@ struct ImportCSVSheet: View {private func loadTableColumns() async {guard let adapter = appState.activeAdapter else { return }- if let desc = try? await adapter.describeTable(name: tableName, schema: nil) {+ if let desc = try? await adapter.describeTable(name: tableName, schema: schema) {tableColumns = desc.columns.map(\.name)}}@@ -289,7 +290,8 @@ struct ImportCSVSheet: View {return "'\(raw.replacingOccurrences(of: "'", with: "''"))'"}.joined(separator: ", ")- let sql = "INSERT INTO \(d.quoteIdentifier(tableName)) (\(colList)) VALUES (\(values))"+ let table = d.qualifiedIdentifier(tableName, schema: schema)+ let sql = "INSERT INTO \(table) (\(colList)) VALUES (\(values))"_ = try await adapter.executeRaw(sql: sql)importedCount += 1}diff --git a/macos/Presentation/Views/Sidebar/SidebarItem.swift b/macos/Presentation/Views/Sidebar/SidebarItem.swiftindex a128d60..3ff8e80 100644--- a/macos/Presentation/Views/Sidebar/SidebarItem.swift+++ b/macos/Presentation/Views/Sidebar/SidebarItem.swift@@ -7,6 +7,7 @@ class SidebarItem: Identifiable {let id: UUIDlet title: Stringlet type: SidebarItemType+ let schema: String?let iconName: Stringvar children: [SidebarItem]var badge: String?@@ -16,6 +17,7 @@ class SidebarItem: Identifiable {id: UUID = UUID(),title: String,type: SidebarItemType,+ schema: String? = nil,iconName: String = "",children: [SidebarItem] = [],badge: String? = nil,@@ -24,6 +26,7 @@ class SidebarItem: Identifiable {self.id = idself.title = titleself.type = type+ self.schema = schemaself.iconName = iconNameself.children = childrenself.badge = badgediff --git a/macos/Presentation/Views/Sidebar/SidebarSchemaSelection.swift b/macos/Presentation/Views/Sidebar/SidebarSchemaSelection.swiftnew file mode 100644index 0000000..b56ab3e--- /dev/null+++ b/macos/Presentation/Views/Sidebar/SidebarSchemaSelection.swift@@ -0,0 +1,16 @@+// SidebarSchemaSelection.swift+// Gridex++enum SidebarSchemaSelection {+ static func resolve(+ previous: String?,+ for databaseType: DatabaseType,+ schemas: [String]+ ) -> String? {+ guard databaseType == .postgresql else { return nil }+ let available = Array(Set(schemas)).sorted()+ if let previous, available.contains(previous) { return previous }+ if available.contains("public") { return "public" }+ return available.first+ }+}diff --git a/macos/Presentation/Views/Sidebar/SidebarView.swift b/macos/Presentation/Views/Sidebar/SidebarView.swiftindex d6ee079..868e8e3 100644--- a/macos/Presentation/Views/Sidebar/SidebarView.swift+++ b/macos/Presentation/Views/Sidebar/SidebarView.swift@@ -27,7 +27,6 @@ struct SidebarView: View {@EnvironmentObject private var appState: AppState@State private var searchText = ""@State private var activeTab: SidebarTab = .items- @State private var selectedSchema = "public"@State private var showNewTableSheet = false@State private var deleteErrorMessage: String?@@ -118,13 +117,15 @@ struct SidebarView: View {private func commitPendingTruncations() async {guard let adapter = appState.activeAdapter else { return }let d = adapter.databaseType.sqlDialect- for name in appState.pendingTableTruncations {- let quoted = d.quoteIdentifier(name)+ for reference in appState.pendingTableTruncations {+ let table = adapter.databaseType == .postgresql+ ? d.qualifiedIdentifier(reference.name, schema: reference.schema)+ : d.quoteIdentifier(reference.name)let sql: Stringif adapter.databaseType == .sqlite {- sql = "DELETE FROM \(quoted)"+ sql = "DELETE FROM \(table)"} else {- sql = "TRUNCATE TABLE \(quoted)"+ sql = "TRUNCATE TABLE \(table)"}_ = try? await adapter.executeRaw(sql: sql)}@@ -136,7 +137,8 @@ struct SidebarView: View {private func commitPendingDeletions() async {guard let adapter = appState.activeAdapter else { return }let d = adapter.databaseType.sqlDialect- let schemaName = "public" // TODO: use selected schema+ // Preserve the existing default qualification for non-PostgreSQL engines.+ let schemaName = "public"// MySQL-specific: disable FK checks globally if any table has ignoreForeignKeyslet shouldIgnoreFK = appState.pendingTableDeletions.values.contains { $0.ignoreForeignKeys }@@ -144,14 +146,17 @@ struct SidebarView: View {_ = try? await adapter.executeRaw(sql: "SET FOREIGN_KEY_CHECKS = 0")}- var failedTables: [String: String] = [:]+ var failedTables: [AppState.TableReference: String] = [:]for pending in appState.pendingTableDeletions.values {+ let reference = pending.referencelet qualified: Stringif adapter.databaseType == .sqlite {- qualified = d.quoteIdentifier(pending.tableName)+ qualified = d.quoteIdentifier(reference.name)+ } else if adapter.databaseType == .postgresql {+ qualified = d.qualifiedIdentifier(reference.name, schema: reference.schema)} else {- qualified = "\(d.quoteIdentifier(schemaName)).\(d.quoteIdentifier(pending.tableName))"+ qualified = "\(d.quoteIdentifier(schemaName)).\(d.quoteIdentifier(reference.name))"}var sql = "DROP TABLE IF EXISTS \(qualified)"if pending.cascade && adapter.databaseType == .postgresql {@@ -160,10 +165,14 @@ struct SidebarView: View {do {_ = try await adapter.executeRaw(sql: sql)// Close any open tabs for this table- appState.tabs.removeAll { $0.tableName == pending.tableName && $0.type == .dataGrid }- appState.pendingTableDeletions.removeValue(forKey: pending.tableName)+ appState.tabs.removeAll {+ $0.tableName == reference.name+ && $0.schema == reference.schema+ && $0.type == .dataGrid+ }+ appState.pendingTableDeletions.removeValue(forKey: reference)} catch {- failedTables[pending.tableName] = error.localizedDescription+ failedTables[reference] = error.localizedDescription}}@@ -172,7 +181,10 @@ struct SidebarView: View {}if !failedTables.isEmpty {- let details = failedTables.map { "\($0.key): \($0.value)" }.joined(separator: "\n")+ let details = failedTables.map { reference, message in+ let name = reference.schema.map { "\($0).\(reference.name)" } ?? reference.name+ return "\(name): \(message)"+ }.joined(separator: "\n")deleteErrorMessage = "Failed to delete:\n\(details)"}@@ -232,13 +244,25 @@ struct SidebarView: View {Spacer()- Picker("", selection: $selectedSchema) {- Text("public").tag("public")+ if appState.activeConfig?.databaseType == .postgresql {+ Picker("", selection: Binding(+ get: { appState.selectedSidebarSchema },+ set: { schema in+ guard schema != appState.selectedSidebarSchema else { return }+ appState.selectedSidebarSchema = schema+ appState.selectedSidebarItem = nil+ appState.refreshSidebar()+ }+ )) {+ ForEach(appState.sidebarSchemas, id: \.self) { schema in+ Text(schema).tag(Optional(schema))+ }+ }+ .labelsHidden()+ .pickerStyle(.menu)+ .font(.system(size: 12))+ .frame(width: 100)}- .labelsHidden()- .pickerStyle(.menu)- .font(.system(size: 12))- .frame(width: 80)}.padding(.horizontal, 6).padding(.vertical, 4)@@ -271,7 +295,7 @@ struct SidebarView: View {}let matched = item.children.compactMap { filterItem($0, query: query) }if matched.isEmpty && !item.title.lowercased().contains(query) { return nil }- return SidebarItem(id: item.id, title: item.title, type: item.type, iconName: item.iconName,+ return SidebarItem(id: item.id, title: item.title, type: item.type, schema: item.schema, iconName: item.iconName,children: matched.isEmpty ? item.children : matched, badge: item.badge)}}@@ -303,13 +327,13 @@ struct SidebarItemRow: View {let isActive = appState.selectedSidebarItem == item.typelet isPendingDelete: Bool = {if case .table(let name) = item.type {- return appState.pendingTableDeletions[name] != nil+ return appState.pendingTableDeletions[tableReference(name)] != nil}return false}()let isPendingTruncate: Bool = {if case .table(let name) = item.type {- return appState.pendingTableTruncations.contains(name)+ return appState.pendingTableTruncations.contains(tableReference(name))}return false}()@@ -347,7 +371,7 @@ struct SidebarItemRow: View {.onTapGesture(count: 2) {switch item.type {case .table(let name), .view(let name):- appState.openTable(name: name, schema: nil)+ appState.openTable(name: name, schema: item.schema)NotificationCenter.default.post(name: .reloadData, object: nil)default:break@@ -358,13 +382,13 @@ struct SidebarItemRow: View {// Open table/view on single clickswitch item.type {case .table(let name):- appState.openTable(name: name, schema: nil)+ appState.openTable(name: name, schema: item.schema)case .view(let name):- appState.openTable(name: name, schema: nil)+ appState.openTable(name: name, schema: item.schema)case .function(let name):- appState.openFunction(name: name, schema: nil)+ appState.openFunction(name: name, schema: item.schema)case .procedure(let name):- appState.openProcedure(name: name, schema: nil)+ appState.openProcedure(name: name, schema: item.schema)default:break}@@ -374,7 +398,7 @@ struct SidebarItemRow: View {Button("Cancel", role: .cancel) {}Button("Truncate", role: .destructive) {if case .table(let name) = item.type {- appState.pendingTableTruncations.insert(name)+ appState.pendingTableTruncations.insert(tableReference(name))}}} message: {@@ -385,8 +409,9 @@ struct SidebarItemRow: View {.sheet(isPresented: $showDeleteSheet) {if case .table(let name) = item.type {DeleteTableSheet(tableName: name) { cascade, ignoreFK in- appState.pendingTableDeletions[name] = AppState.PendingTableDeletion(- tableName: name,+ let reference = tableReference(name)+ appState.pendingTableDeletions[reference] = AppState.PendingTableDeletion(+ reference: reference,cascade: cascade,ignoreForeignKeys: ignoreFK)@@ -395,12 +420,12 @@ struct SidebarItemRow: View {}.sheet(isPresented: $showExportSheet) {if case .table(let name) = item.type {- ExportTableSheet(tableName: name)+ ExportTableSheet(tableName: name, schema: item.schema)}}.sheet(isPresented: $showImportCSVSheet) {if case .table(let name) = item.type {- ImportCSVSheet(tableName: name)+ ImportCSVSheet(tableName: name, schema: item.schema)}}.sheet(item: $importSQLFile, onDismiss: {@@ -434,7 +459,7 @@ struct SidebarItemRow: View {.foregroundStyle(.secondary).onTapGesture {if case .group(let kind) = item.type, kind == "tables" {- appState.openTableList(schema: nil)+ appState.openTableList(schema: appState.selectedSidebarSchema)}}Spacer()@@ -447,7 +472,7 @@ struct SidebarItemRow: View {// Inline "+" button for the Tables group to create a new tableif case .group(let kind) = item.type, kind == "tables" {Button {- appState.openCreateTable(schema: nil)+ appState.openCreateTable(schema: appState.selectedSidebarSchema)} label: {Image(systemName: "plus").font(.system(size: 10, weight: .semibold))@@ -471,13 +496,13 @@ struct SidebarItemRow: View {switch kind {case "tables":Button("New Table…") {- appState.openCreateTable(schema: nil)+ appState.openCreateTable(schema: appState.selectedSidebarSchema)}Button("Open Table List") {- appState.openTableList(schema: nil)+ appState.openTableList(schema: appState.selectedSidebarSchema)}Button("ER Diagram") {- appState.openERDiagram(schema: nil)+ appState.openERDiagram(schema: appState.selectedSidebarSchema)}Divider()Button("Refresh") { appState.refreshSidebar() }@@ -539,17 +564,17 @@ struct SidebarItemRow: View {}} else if case .table(let name) = item.type {Button("Open in new tab") {- appState.openTable(name: name, schema: nil)+ appState.openTable(name: name, schema: item.schema)}Button("Open structure") {- appState.openTableStructure(name: name, schema: nil)+ appState.openTableStructure(name: name, schema: item.schema)}Divider()Button("New Table…") {- appState.openCreateTable(schema: nil)+ appState.openCreateTable(schema: appState.selectedSidebarSchema)}Button("Copy name") {@@ -583,7 +608,7 @@ struct SidebarItemRow: View {Task { await copyCreateScript(name) }}Button("SELECT") {- copyToClipboard("SELECT * FROM \(quoted(name)) LIMIT 100;")+ copyToClipboard("SELECT * FROM \(qualified(name)) LIMIT 100;")}Button("INSERT") {Task { await copyInsertScript(name) }@@ -592,15 +617,15 @@ struct SidebarItemRow: View {Task { await copyUpdateScript(name) }}Button("DELETE") {- copyToClipboard("DELETE FROM \(quoted(name)) WHERE <condition>;")+ copyToClipboard("DELETE FROM \(qualified(name)) WHERE <condition>;")}}Divider()- if appState.pendingTableTruncations.contains(name) {+ if appState.pendingTableTruncations.contains(tableReference(name)) {Button("Undo Truncate") {- appState.pendingTableTruncations.remove(name)+ appState.pendingTableTruncations.remove(tableReference(name))}} else {Button("Truncate...") {@@ -608,9 +633,9 @@ struct SidebarItemRow: View {}}- if appState.pendingTableDeletions[name] != nil {+ if appState.pendingTableDeletions[tableReference(name)] != nil {Button("Undo Delete") {- appState.pendingTableDeletions.removeValue(forKey: name)+ appState.pendingTableDeletions.removeValue(forKey: tableReference(name))}} else {Button("Delete...") {@@ -619,7 +644,7 @@ struct SidebarItemRow: View {}} else {Button("New Table…") {- appState.openCreateTable(schema: nil)+ appState.openCreateTable(schema: appState.selectedSidebarSchema)}Divider()Button("Refresh") { appState.refreshSidebar() }@@ -628,9 +653,13 @@ struct SidebarItemRow: View {// MARK: - Context Menu Actions- private func quoted(_ name: String) -> String {+ private func tableReference(_ name: String) -> AppState.TableReference {+ AppState.TableReference(name: name, schema: item.schema)+ }++ private func qualified(_ name: String) -> String {guard let adapter = appState.activeAdapter else { return "\"\(name)\"" }- return adapter.databaseType.sqlDialect.quoteIdentifier(name)+ return adapter.databaseType.sqlDialect.qualifiedIdentifier(name, schema: item.schema)}private func copyToClipboard(_ text: String) {@@ -640,7 +669,7 @@ struct SidebarItemRow: View {private func copyCreateScript(_ name: String) async {guard let adapter = appState.activeAdapter else { return }- if let desc = try? await adapter.describeTable(name: name, schema: nil) {+ if let desc = try? await adapter.describeTable(name: name, schema: item.schema) {let ddl = desc.toDDL(dialect: adapter.databaseType.sqlDialect)copyToClipboard(ddl)}@@ -648,20 +677,20 @@ struct SidebarItemRow: View {private func copyInsertScript(_ name: String) async {guard let adapter = appState.activeAdapter else { return }- if let desc = try? await adapter.describeTable(name: name, schema: nil) {+ if let desc = try? await adapter.describeTable(name: name, schema: item.schema) {let cols = desc.columns.map { adapter.databaseType.sqlDialect.quoteIdentifier($0.name) }.joined(separator: ", ")let vals = desc.columns.map { _ in "?" }.joined(separator: ", ")- copyToClipboard("INSERT INTO \(quoted(name)) (\(cols)) VALUES (\(vals));")+ copyToClipboard("INSERT INTO \(qualified(name)) (\(cols)) VALUES (\(vals));")}}private func copyUpdateScript(_ name: String) async {guard let adapter = appState.activeAdapter else { return }- if let desc = try? await adapter.describeTable(name: name, schema: nil) {+ if let desc = try? await adapter.describeTable(name: name, schema: item.schema) {let sets = desc.columns.filter { !$0.isPrimaryKey }.map { "\(adapter.databaseType.sqlDialect.quoteIdentifier($0.name)) = ?" }.joined(separator: ", ")let pk = desc.columns.first(where: \.isPrimaryKey)let whereClause = pk.map { "\(adapter.databaseType.sqlDialect.quoteIdentifier($0.name)) = ?" } ?? "<condition>"- copyToClipboard("UPDATE \(quoted(name)) SET \(sets) WHERE \(whereClause);")+ copyToClipboard("UPDATE \(qualified(name)) SET \(sets) WHERE \(whereClause);")}}@@ -813,7 +842,7 @@ struct SidebarItemRow: View {// MARK: - New Table Sheetstruct NewTableSheet: View {- let schema: String+ let schema: String?@EnvironmentObject private var appState: AppState@Environment(\.dismiss) private var dismiss@@ -844,7 +873,7 @@ struct NewTableSheet: View {}GridRow {Text("Schema:").font(.system(size: 12))- Text(schema)+ Text(schema ?? "Default").font(.system(size: 12)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading)@@ -891,9 +920,7 @@ struct NewTableSheet: View {defer { isCreating = false }let d = adapter.databaseType.sqlDialect- let qualifiedTable = adapter.databaseType == .sqlite- ? d.quoteIdentifier(tableName)- : "\(d.quoteIdentifier(schema)).\(d.quoteIdentifier(tableName))"+ let qualifiedTable = d.qualifiedIdentifier(tableName, schema: schema)// Create table with a default id columnlet idType: String