Skip to content

Add Full Support for Views Listing and Definitions#312

Open
danvergara wants to merge 7 commits into
mainfrom
show-views
Open

Add Full Support for Views Listing and Definitions#312
danvergara wants to merge 7 commits into
mainfrom
show-views

Conversation

@danvergara

@danvergara danvergara commented May 28, 2026

Copy link
Copy Markdown
Owner

Add Full Support for Views Listing and Definitions

Description

This PR adds comprehensive support for listing database views and displaying their definitions across all supported database drivers (PostgreSQL, MySQL, SQLite, Oracle, and SQL Server).

Previously, dblab only displayed tables in the sidebar catalog. With this change, views are now listed alongside tables (visually distinguished with a v suffix) and selecting a view shows its definition and column data in the result panel.

Screenshot From 2026-06-07 12-26-53

Changes

Core Client (pkg/client/)

  • New ViewRef struct — mirrors TableRef for referencing views with schema-qualified names.
  • New EntityName field on DBNode — separates the display name (with type suffix) from the actual entity name used in queries.
  • New databaseQuerier method GetViewDefinition — each driver implements this to retrieve the DDL/definition of a view.
  • New ViewMetadata method on Client — fetches both the view definition and its content (rows).
  • New viewContent method — queries the view data with pagination support across all drivers.
  • Improved []byte handling in Query — properly distinguishes BLOB/BYTEA columns from text columns returned as []byte, preventing raw binary output.

Driver Implementations

  • PostgreSQL (postgres.go): Queries pg_class for views/materialized views (relkind IN ('v','m')). Uses pg_get_viewdef() for definitions.
  • MySQL (mysql.go): Queries information_schema.VIEWS. Uses SHOW CREATE VIEW for definitions.
  • SQLite (sqlite.go): Queries sqlite_master WHERE type='view'. Retrieves the sql column for definitions.
  • Oracle (oracle.go): Queries ALL_VIEWS filtered by owner/schema. Retrieves the TEXT column for definitions.
  • SQL Server (mssql.go): Queries sys.views joined with sys.schemas. Uses OBJECT_DEFINITION() for view DDL. Also adds schema handling that was previously missing.

TUI (pkg/bubbletui/)

  • New selectViewMsg — message type for view selection events in the sidebar.
  • New MetadataPanel interface with TablePanel and TextPanel implementations — allows the result set to display either tabular data or plain text (for view definitions).
  • Updated ResultSet — dynamically switches between table-mode tabs (Data, Columns, Indexes, Constraints) and view-mode tabs (Definition, Columns) depending on selection.
  • View emoji indicator in the sidebar to distinguish views from tables.

Supported Databases

Database List Views View Definition View Content
PostgreSQL Yes Yes Yes
MySQL Yes Yes Yes
SQLite Yes Yes Yes
Oracle Yes Yes Yes
SQL Server Yes Yes Yes

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Locally, against containers running the Pagila, Sakila and Chinook databases.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

@danvergara danvergara changed the title Show views Add Full Support for Views Listing and Definitions Jun 7, 2026
@danvergara danvergara marked this pull request as ready for review June 7, 2026 18:38
@danvergara danvergara added the kind/enhancement New feature or request label Jun 9, 2026
@danvergara danvergara self-assigned this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant