feat: add per-connection read-only mode
Connections default to read-only. SQL editor wraps queries in a read-only transaction so PostgreSQL rejects mutations. Data mutation commands (update_row, insert_row, delete_rows) are blocked at the Rust layer. Toolbar toggle with confirmation dialog lets users switch to read-write. Badges shown in workspace, table viewer, and status bar. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ interface AppState {
|
||||
activeConnectionId: string | null;
|
||||
currentDatabase: string | null;
|
||||
connectedIds: Set<string>;
|
||||
readOnlyMap: Record<string, boolean>;
|
||||
tabs: Tab[];
|
||||
activeTabId: string | null;
|
||||
sidebarWidth: number;
|
||||
@@ -16,6 +17,7 @@ interface AppState {
|
||||
setCurrentDatabase: (db: string | null) => void;
|
||||
addConnectedId: (id: string) => void;
|
||||
removeConnectedId: (id: string) => void;
|
||||
setReadOnly: (connectionId: string, readOnly: boolean) => void;
|
||||
setPgVersion: (version: string | null) => void;
|
||||
|
||||
addTab: (tab: Tab) => void;
|
||||
@@ -30,6 +32,7 @@ export const useAppStore = create<AppState>((set) => ({
|
||||
activeConnectionId: null,
|
||||
currentDatabase: null,
|
||||
connectedIds: new Set(),
|
||||
readOnlyMap: {},
|
||||
tabs: [],
|
||||
activeTabId: null,
|
||||
sidebarWidth: 260,
|
||||
@@ -41,13 +44,19 @@ export const useAppStore = create<AppState>((set) => ({
|
||||
addConnectedId: (id) =>
|
||||
set((state) => ({
|
||||
connectedIds: new Set([...state.connectedIds, id]),
|
||||
readOnlyMap: { ...state.readOnlyMap, [id]: true },
|
||||
})),
|
||||
removeConnectedId: (id) =>
|
||||
set((state) => {
|
||||
const next = new Set(state.connectedIds);
|
||||
next.delete(id);
|
||||
return { connectedIds: next };
|
||||
const { [id]: _, ...restRo } = state.readOnlyMap;
|
||||
return { connectedIds: next, readOnlyMap: restRo };
|
||||
}),
|
||||
setReadOnly: (connectionId, readOnly) =>
|
||||
set((state) => ({
|
||||
readOnlyMap: { ...state.readOnlyMap, [connectionId]: readOnly },
|
||||
})),
|
||||
setPgVersion: (version) => set({ pgVersion: version }),
|
||||
|
||||
addTab: (tab) =>
|
||||
|
||||
Reference in New Issue
Block a user