Skip to main content

Diagram views

A large schema is easier to read in parts. A DiagramView names a subset of it — some tables, sticky notes, table groups or whole schemas — right in the DBML file, so dbdiagram.io, the relvista editor and every diagram in your docs show the same views.

Declaring a view​

DiagramView billing {
Tables {
customers
invoices
payments
}
Notes {
billing_note
}
}

A view can list four kinds of things. Each list is optional; { * } means "all of them".

BlockContains
TablesTables by name (orders, or core.audit_events in a schema)
NotesSticky notes by name
TableGroupsEvery table of these groups
SchemasEvery table of these schemas

Refs are shown when both of their tables are in the view. A view with no blocks is empty. A file can declare as many views as you like.

Opening a diagram in a view​

The schema below declares two views, billing and catalog. With a fence, add view="billing" to its meta string:

```dbml view="billing" title="Billing" id="billing-fence"
Table customers { ... }
...
DiagramView billing {
Tables {
customers
invoices
payments
}
Notes {
billing_note
}
}
```
Billing
Billingbilling_noteInvoices are issued when anorder ships.public.customers.id < public.invoices.customer_idpublic.invoices.id < public.payments.invoice_idcustomerscustomersid integer · primary keyidintegeremail varchar · uniqueemailUvarcharinvoicesinvoicesid integer · primary keyidintegercustomer_id integer · foreign keycustomer_idintegertotal decimal(10,2)totaldecimal(10,2)paymentspaymentsid integer · primary keyidintegerinvoice_id integer · foreign keyinvoice_idintegeramount decimal(10,2)amountdecimal(10,2)

With the component, pass view:

<DbmlDiagram value={shop} view="billing" title="Billing" />
Billing view
Billing viewbilling_noteInvoices are issued when anorder ships.public.customers.id < public.invoices.customer_idpublic.invoices.id < public.payments.invoice_idcustomerscustomersid integer · primary keyidintegeremail varchar · uniqueemailUvarcharname varcharnamevarcharinvoicesinvoicesid integer · primary keyidintegercustomer_id integer · foreign keycustomer_idintegerissued_at timestampissued_attimestamptotal decimal(10,2)totaldecimal(10,2)paymentspaymentsid integer · primary keyidintegerinvoice_id integer · foreign keyinvoice_idintegeramount decimal(10,2)amountdecimal(10,2)

The toolbar's view menu switches between the views; All tables is the whole schema. A view the DBML does not declare falls back to every table.

A layout per view​

Every view has its own table positions in the layout file: views["*"] is the whole diagram, views.billing the billing view. A table placed in "*" but not in a view keeps its "*" position there, so you only store what differs. In the editor, moving a table while a view is open saves it for that view.

shop.dbml.layout.json
{
"version": 1,
"views": {
"*": { "nodes": { "public.customers": { "x": 0, "y": 140 }, "...": {} } },
"billing": {
"nodes": {
"public.customers": { "x": 0, "y": 0 },
"public.invoices": { "x": 0, "y": 200 },
"public.payments": { "x": 300, "y": 200 },
"note:billing_note": { "x": 300, "y": 20 }
}
}
}
}

The same schema with that layout: the whole diagram first, then the billing view, each with its own arrangement. Switch the view in the toolbar of either one to compare.

All tables
All tablesbilling_noteInvoices are issued when anorder ships.public.customers.id < public.invoices.customer_idpublic.invoices.id < public.payments.invoice_idpublic.customers.id < public.orders.customer_idpublic.orders.id < public.order_items.order_idpublic.products.id < public.order_items.product_idcustomerscustomersid integer · primary keyidintegeremail varchar · uniqueemailUvarcharname varcharnamevarcharinvoicesinvoicesid integer · primary keyidintegercustomer_id integer · foreign keycustomer_idintegerissued_at timestampissued_attimestamptotal decimal(10,2)totaldecimal(10,2)paymentspaymentsid integer · primary keyidintegerinvoice_id integer · foreign keyinvoice_idintegeramount decimal(10,2)amountdecimal(10,2)productsproductsid integer · primary keyidintegername varcharnamevarcharprice decimal(10,2)pricedecimal(10,2)ordersordersid integer · primary keyidintegercustomer_id integer · foreign keycustomer_idintegercreated_at timestampcreated_attimestamporder_itemsorder_itemsorder_id integer · foreign keyorder_idintegerproduct_id integer · foreign keyproduct_idintegerquantity integerquantityinteger
Billing, own layout
Billing, own layoutbilling_noteInvoices are issued when anorder ships.public.customers.id < public.invoices.customer_idpublic.invoices.id < public.payments.invoice_idcustomerscustomersid integer · primary keyidintegeremail varchar · uniqueemailUvarcharname varcharnamevarcharinvoicesinvoicesid integer · primary keyidintegercustomer_id integer · foreign keycustomer_idintegerissued_at timestampissued_attimestamptotal decimal(10,2)totaldecimal(10,2)paymentspaymentsid integer · primary keyidintegerinvoice_id integer · foreign keyinvoice_idintegeramount decimal(10,2)amountdecimal(10,2)

Linking to a view​

A link can open a diagram in a view: add &view=<name> after the diagram's anchor, for example

#shop-all&view=catalog

. See deep links for everything a link can carry.

Managing views in the editor​

The editor's view menu lists every view (with a filter field once there are more than seven) and creates, edits and deletes them: New view from selection, Edit view… (tables by schema, groups, notes, schemas, or "All tables"), Delete view…. The table menu has Add to view and Remove from view. Every change is written into the DiagramView block of your DBML, leaving the rest of the file untouched. See the editor.