Skip to content

feat(pam): add SQL runner in data explorer#5954

Merged
bernie-g merged 47 commits into
mainfrom
feat/pam-sql-query-runner
Apr 10, 2026
Merged

feat(pam): add SQL runner in data explorer#5954
bernie-g merged 47 commits into
mainfrom
feat/pam-sql-query-runner

Conversation

@bernie-g
Copy link
Copy Markdown
Contributor

@bernie-g bernie-g commented Apr 6, 2026

Context

This implements a SQL runner and unifies the data explorer and terminal view into one view. It lets you create multiple tabs to run multiple SQL queries. Select, insert, update, and delete queries are all supported.

Screenshots

Screen.Recording.2026-04-06.at.5.50.33.PM.mov

Steps to verify the change

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

  • Title follows the conventional commit format: type(scope): short description (scope is optional, e.g., fix: prevent crash on sync or fix(api): handle null response).
  • Tested locally
  • Updated docs (if needed)
  • Updated CLAUDE.md files (if needed)
  • Read the contributing guide

@maidul98
Copy link
Copy Markdown
Collaborator

maidul98 commented Apr 6, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

- Add dynamic query tabs (Browse + closeable query tabs) with "New query" button
- Add CodeMirror 6 SQL editor with PostgreSQL syntax highlighting and Cmd+Enter shortcut
- Add resizable split pane between editor and results
- Reuse DataGrid component for query results with PK/FK/type metadata from tableDetail
- Show meaningful mutation messages (N rows inserted/updated/deleted) for non-SELECT queries
- Handle multi-statement queries by returning the last result (same as psql)
- Cap query results at 1000 rows server-side to prevent memory exhaustion
- Auto-switch to Browse tab when clicking a table in the sidebar
- Remove PamAccountAccessPage for Postgres (replaced by data explorer); restore it for SSH and Redis
@bernie-g bernie-g force-pushed the feat/pam-sql-query-runner branch from 1eb6e6f to 9460485 Compare April 7, 2026 00:25
@bernie-g bernie-g force-pushed the feat/pam-sql-query-runner branch from ad63915 to 5a4fc6c Compare April 7, 2026 00:52
@bernie-g bernie-g marked this pull request as ready for review April 7, 2026 01:00
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@bernie-g bernie-g requested a review from saifsmailbox98 April 7, 2026 01:02
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 7, 2026

Greptile Summary

This PR adds a SQL query runner to the PAM Data Explorer, unifying table browsing and ad-hoc SQL execution into a single tabbed interface. The backend change handles multi-statement queries and caps row results at 1,000; new frontend components (SqlEditor, QueryPanel, QueryResultsTable, useQueryTabs) manage the editor/results split-pane with multiple named tabs.

  • P1 – rowCount mismatch: the backend slices result.rows to MAX_ROWS = 1000 but forwards the original result.rowCount verbatim. For large queries the toolbar can show "50,000 rows" while the user can only access at most 1,000 (further cut to 500 by the frontend ResultsGrid). The backend should either cap rowCount to the slice boundary or add an isTruncated flag so the UI can show an accurate "Showing N of M rows" message.

Confidence Score: 4/5

Safe to merge with one P1 UX bug where the displayed row count can be far larger than what users can actually access.

The rowCount mismatch is a present defect on the primary query path — the toolbar reports the original PostgreSQL row count while rows are truncated to 1,000 (then 500) before display. All other findings are P2 style/quality concerns that don't block correctness.

backend/src/ee/services/pam-web-access/pam-postgres-session-handler.ts — rowCount should reflect actual rows sent, not the pre-truncation total

Important Files Changed

Filename Overview
backend/src/ee/services/pam-web-access/pam-postgres-session-handler.ts Adds multi-statement query support and row truncation; rowCount is not updated to match the truncated rows slice, misleading the UI
frontend/src/pages/pam/PamDataExplorerPage/use-query-tabs.ts New hook managing query tab state; tab switching and close fallback logic is correct
frontend/src/pages/pam/PamDataExplorerPage/data-explorer-utils.ts Simple column-indicator utility; no issues
frontend/src/pages/pam/PamDataExplorerPage/components/QueryPanel.tsx New split-pane query panel with drag-to-resize; clean implementation
frontend/src/pages/pam/PamDataExplorerPage/components/SqlEditor.tsx CodeMirror SQL editor with correct ref-based callback pattern to avoid stale closures
frontend/src/pages/pam/PamDataExplorerPage/components/QueryToolbar.tsx Toolbar works correctly but navigator.userAgent is evaluated at module scope, fragile in non-browser environments
frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx Read-only results grid with truncation indicator at 500 rows; no issues
frontend/src/pages/pam/PamDataExplorerPage/PamDataExplorerPage.tsx Unified data explorer integrating tab management and browse/query modes cleanly
frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx Minor modal update; no issues
docs/documentation/platform/pam/product-reference/web-access/postgresql.mdx Docs updated for SQL runner; ## section headers with ### children may not nest correctly in Mintlify
docs/documentation/platform/pam/product-reference/web-access/overview.mdx Terminology updated from 'SQL terminal' to 'SQL query runner'; no issues

Comments Outside Diff (1)

  1. backend/src/ee/services/pam-web-access/pam-postgres-session-handler.ts, line 209-213 (link)

    P1 Misleading rowCount after row truncation

    The backend truncates result.rows to 1,000 but returns the original result.rowCount unchanged. For a query returning 50,000 rows the frontend toolbar will display "50,000 rows" while only 1,000 rows were actually sent — and the frontend further truncates to 500 for display. The count shown to the user can be orders of magnitude larger than what they can actually access.

    Consider capping rowCount to the slice boundary or returning an explicit isTruncated flag alongside the original total:

    Then surface isTruncated in the toolbar (e.g. "Showing 1,000 of 50,000 rows").

Reviews (1): Last reviewed commit: "fix(pam): improve tab close button visib..." | Re-trigger Greptile

Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/QueryToolbar.tsx Outdated
Comment thread docs/documentation/platform/pam/product-reference/web-access/postgresql.mdx Outdated
@maidul98
Copy link
Copy Markdown
Collaborator

maidul98 commented Apr 7, 2026

@codex review this

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9db123d2fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx Outdated
bernie-g added 5 commits April 7, 2026 09:01
…to SQL query runner

- Cancel query via pg_cancel_backend on a separate connection
- Commit/Rollback buttons with transaction open badge when BEGIN detected
- Run Selection: executes selected text via button or Cmd+Enter
- Result pane shows contextual messages for BEGIN/COMMIT/ROLLBACK
- Fix Run button passing MouseEvent as SQL argument
Comment thread backend/src/ee/services/pam-web-access/pam-postgres-session-handler.ts Outdated
bernie-g added 4 commits April 7, 2026 16:07
…rows

Backend now sends isTruncated flag alongside rowCount so the toolbar
can display "Showing 1,000 of X rows" instead of the misleading raw DB count.
…ry errors

Backend now tracks transaction state across all results in a multi-statement
batch (e.g. BEGIN; INSERT ...) and resets it on error since ROLLBACK is always
issued. The authoritative transactionOpen flag is sent with every QueryResult
so the frontend no longer misreads the last command or fails to clear state on error.
Comment thread docs/documentation/platform/pam/product-reference/web-access/postgresql.mdx Outdated
Comment thread docs/documentation/platform/pam/product-reference/web-access/postgresql.mdx Outdated
Comment thread frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/QueryToolbar.tsx Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/QueryResultsTable.tsx Outdated
Comment thread docs/documentation/platform/pam/product-reference/web-access/postgresql.mdx Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/SqlEditor.tsx Outdated
bernie-g added 9 commits April 9, 2026 10:18
… shared utility

Apply [&::-webkit-scrollbar]:h-1 as a scoped Tailwind arbitrary variant on the
specific tab bar element instead of adding height to the shared thin-scrollbar
utility (which caused lint to reorder the class in 50+ unrelated files).

Also remove unused tableMeta prop from DataGridContextMenu ContextMenuImpl and
add SQL query runner screenshot to docs.
Comment thread frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx Outdated
Comment thread frontend/src/pages/pam/PamAccountsPage/components/PamAccessAccountModal.tsx Outdated
Comment thread docs/documentation/platform/pam/product-reference/web-access/postgresql.mdx Outdated
Comment thread frontend/src/components/v3/generic/DataGrid/data-grid-context-menu.tsx Outdated
Comment thread frontend/package.json Outdated
Comment thread frontend/package.json Outdated
Comment thread frontend/src/pages/pam/PamDataExplorerPage/components/SqlEditor.tsx
bernie-g added 14 commits April 9, 2026 20:50
Split multi-statement SQL using the real PostgreSQL C parser (libpg-query
WASM), then run each statement through pg-cursor which uses the Extended
Query Protocol to cap rows at the wire level. Removes the buffered query
path entirely so memory usage is bounded regardless of result set size.
Comment thread backend/src/ee/services/pam-web-access/pam-postgres-session-handler.ts Outdated
Comment thread frontend/package.json Outdated
@bernie-g bernie-g merged commit c507634 into main Apr 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants