Skip to content

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'

On this page
  1. The tables of a shop
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

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.id orders.customer_id points to customers.id
  • order_items.order_id → orders.id order_items.order_id points to orders.id
  • order_items.product_id → products.id order_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 column and row so 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

EntityDiagramTypeDefault
entitiesrequired Entity[]
labelrequired string
columns number 3
EntityDiagramSkeletonTypeDefault
columns number 3
tables number 3
  1. The tables of a shop
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms