Schema Viewer
Database table schema inspector displaying columns, types, nullability, defaults, key badges, and clickable foreign key links.
Customer purchase orders and fulfillment totals.
| Column | Type | Nullable | Default | Constraints |
|---|---|---|---|---|
id | uuid | NOT NULL | gen_random_uuid() | PK |
user_id | uuid | NOT NULL | — | |
order_number | text | NOT NULL | — | UQ |
total | numeric(10,2) | NOT NULL | 0 | — |
status | order_status | NOT NULL | 'pending' | IDX |
notes | text | NULL | — | — |
created_at | timestamptz | NOT NULL | now() | — |
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
"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.
| Column | Type | Nullable | Default | Constraints |
|---|---|---|---|---|
id | uuid | NOT NULL | — | PK |
user_id | uuid | NOT NULL | — | FKusers.id |
total | numeric(10,2) | NOT NULL | 0 | — |
Constraints and descriptions
Display primary keys, unique constraints, indexes, and column descriptions without the filter bar.
Issued monthly subscription invoices.
| Column | Type | Nullable | Default | Constraints |
|---|---|---|---|---|
idMonotonic surrogate key | bigint | NOT NULL | — | PK |
external_idProvider invoice identifier | text | NOT NULL | — | UQIDX |
account_id | uuid | NOT NULL | — | |
amount_cents | integer | NOT NULL | 0 | — |
paid_at | timestamptz | NULL | — | — |
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 | Type | Default |
|---|---|---|
tableRequiredSchemaTableTable definition including name, optional schema, optional description, and columns array. | SchemaTable | |
onReferenceClick(ref: string, column: SchemaColumn) => voidCalled when a foreign key reference link is activated. | (ref: string, column: SchemaColumn) => void | |
filterstringControlled column-name filter query. | string | |
defaultFilterstringDefault""Initial column-name filter query when uncontrolled. | string | "" |
onFilterChange(filter: string) => voidCalled when the filter query changes. | (filter: string) => void | |
searchablebooleanDefaulttrueWhether to render the column filter input and apply filtering (filter and defaultFilter are ignored when false). | boolean | true |
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.