EntityDiagram
Tables and how they point to each other: each table a box with its columns and types, keys marked, and a line from each column that points to another table's key.
import { EntityDiagram, EntityDiagramSkeleton } from '@sypnia/ui/react'
The tables of a shop
customers
- PKiduuid
- emailtext
- nametext?
- created_
attimestamptz
orders
- PKidbigint
- customer_
iduuid - totalnumeric
- statetext
order_items
- PKidbigint
- order_
idbigint - product_
idbigint - quantityint
products
- PKidbigint
- nametext
- pricenumeric
orders.customer_id→customers.idorders.customer_id points to customers.idorder_items.order_id→orders.idorder_items.order_id points to orders.idorder_items.product_id→products.idorder_items.product_id points to products.id
Code
import { EntityDiagram } from '@sypnia/ui/react';
// Each table with its columns; a line from every column that points to another table's key. On phones the boxes
// stack and the relations are listed under them.
export default function Shop() {
return (
<EntityDiagram label="Tables of the shop" columns={3} entities={[
{ name: 'customers', column: 1, row: 1, columns: [{ name: 'id', type: 'uuid', primaryKey: true }, { name: 'email', type: 'text' }, { name: 'name', type: 'text', nullable: true }, { name: 'created_at', type: 'timestamptz' }] },
{ name: 'orders', column: 2, row: 1, columns: [{ name: 'id', type: 'bigint', primaryKey: true }, { name: 'customer_id', type: 'uuid', references: 'customers.id' }, { name: 'total', type: 'numeric' }, { name: 'state', type: 'text' }] },
{ name: 'order_items', column: 3, row: 1, columns: [{ name: 'id', type: 'bigint', primaryKey: true }, { name: 'order_id', type: 'bigint', references: 'orders.id' }, { name: 'product_id', type: 'bigint', references: 'products.id' }, { name: 'quantity', type: 'int' }] },
{ name: 'products', column: 2, row: 2, columns: [{ name: 'id', type: 'bigint', primaryKey: true }, { name: 'name', type: 'text' }, { name: 'price', type: 'numeric' }] },
]} />
);
} Skeleton
Code
import { EntityDiagramSkeleton } from '@sypnia/ui/react';
// The tables while they load.
export default function Skeleton() {
return <EntityDiagramSkeleton tables={3} />;
} When to use it
Use it when
- The schema of a database, in the console or the docs.
- Place tables with
columnandrowso lines do not cross.
Do not use it when
- One table's columns in detail: use SchemaViewer.
For everyone
- Each table is a region named with its column count; keys are said in words.
- The relations are listed under the boxes, so phones and screen readers get them without the lines.
Props
| EntityDiagram | Type | Default |
|---|---|---|
entitiesrequired | Entity[] | |
labelrequired | string | |
columns | number | 3 |
| EntityDiagramSkeleton | Type | Default |
|---|---|---|
columns | number | 3 |
tables | number | 3 |