Schema Viewer

Database table schema inspector displaying columns, types, nullability, defaults, key badges, and clickable foreign key links.

@drift-ui/schema-viewerRegistry JSONOpen in v0
public.orders7 columns

Customer purchase orders and fulfillment totals.

ColumnTypeNullableDefaultConstraints
id
uuidNOT NULLgen_random_uuid()
PK
user_id
uuidNOT NULL—
order_number
textNOT NULL—
UQ
total
numeric(10,2)NOT NULL0
—
status
order_statusNOT NULL'pending'
IDX
notes
textNULL—
—
created_at
timestamptzNOT NULLnow()
—
On this page

Installation

The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.

Usage

schema-viewer-usage.tsx
"use client"

import { SchemaViewer } from "@/components/ui/schema-viewer"

export function OrdersSchema() {
  return (
    <SchemaViewer
      table={{
        name: "orders",
        columns: [
          { name: "id", type: "uuid", primaryKey: true },
          { name: "user_id", type: "uuid", nullable: false, references: "users.id" },
          { name: "total", type: "numeric(10,2)", nullable: false, default: "0" },
        ],
      }}
      onReferenceClick={(ref) => console.log("Open", ref)}
    />
  )
}

Examples

Navigating foreign keys

Follow foreign key reference links across related tables with onReferenceClick.

orders3 columns
ColumnTypeNullableDefaultConstraints
id
uuidNOT NULL—
PK
user_id
uuidNOT NULL—
total
numeric(10,2)NOT NULL0
—

Constraints and descriptions

Display primary keys, unique constraints, indexes, and column descriptions without the filter bar.

billing.invoices5 columns

Issued monthly subscription invoices.

ColumnTypeNullableDefaultConstraints
idMonotonic surrogate key
bigintNOT NULL—
PK
external_idProvider invoice identifier
textNOT NULL—
UQIDX
account_id
uuidNOT NULL—
amount_cents
integerNOT NULL0
—
paid_at
timestamptzNULL—
—

API reference

SchemaViewer

Renders a database table schema in a semantic HTML table with column name, type, nullability, default value, constraint badges (PK, FK, UQ, IDX), clickable foreign key links, and a column filter input.

Prop
tableRequiredSchemaTableTable definition including name, optional schema, optional description, and columns array.
onReferenceClick(ref: string, column: SchemaColumn) => voidCalled when a foreign key reference link is activated.
filterstringControlled column-name filter query.
defaultFilterstringDefault""Initial column-name filter query when uncontrolled.
onFilterChange(filter: string) => voidCalled when the filter query changes.
searchablebooleanDefaulttrueWhether to render the column filter input and apply filtering (filter and defaultFilter are ignored when false).

Other props go to the <div>.

parseReference, getColumnBadges, isColumnNullable, filterColumns, formatTableName, summarizeColumns

parseReference(ref: string): SchemaForeignKeyRef | null; getColumnBadges(column: SchemaColumn): SchemaBadgeKind[]; isColumnNullable(column: SchemaColumn): boolean; filterColumns(columns: SchemaColumn[], query: string): SchemaColumn[]; formatTableName(table: Pick<SchemaTable, 'name' | 'schema'>): string; summarizeColumns(columns: SchemaColumn[]): { total: number; primaryKeys: number; foreignKeys: number; unique: number; indexed: number }

Pure schema helpers for parsing foreign key references, computing constraint badges, resolving SQL nullability, filtering columns, formatting table names, and summarizing counts. Import from @/lib/schema-viewer-utils.

Source

components/ui/schema-viewer.tsx