How to use ViewDB
Write a database schema in DBML, see it as a diagram, and export it as SQL or ORM code. This page covers the language and every part of the app.
Table users { id integer [pk, increment] email varchar(255) [unique, not null]} Table posts { id integer [pk] author_id integer [ref: > users.id] title varchar(200)}How ViewDB works
Each project is a DBML text plus the positions of its tables on the diagram. You write the schema on the left, and ViewDB draws it on the right as you type.
The text is the source of truth. Moving a table only saves where it sits. Everything else you change on the diagram or in the Schema tab is written back into the DBML, touching only the lines it changes.
When the DBML has an error, the diagram keeps the last version that worked, and the list under the editor says what to fix.
Saving
Changes save a second after you stop typing, and Ctrl/⌘+S saves at once. The status in the toolbar tells you where things stand:
- Saved
- Everything is on the server.
- Saving…
- A save is on its way.
- Unsaved changes
- You typed since the last save. It goes out in a moment.
- Could not save
- The save failed. ViewDB tries again by itself; click the status to try now.
- Changed elsewhere
- The project was saved somewhere else while you had unsaved changes. See below.
A project saves even with DBML errors, so work in progress is never lost. Leaving the page before a save finishes asks you to confirm.
Changes made elsewhere
The editor checks every few seconds for saves made in another tab or by an AI agent. If you have nothing unsaved, it loads them quietly. If you were editing too, it asks which side to keep: Keep my changes or Load the saved project. The side you drop is kept in the version history.
Getting started
- On the projects page, click New project. Start blank or from one of the sample schemas.
- Write or paste DBML in the DBML tab. The diagram follows as you type.
- Drag tables where you want them, or let Arrange lay them out.
- Click Export for SQL, ORM code or an image, and Share to show the diagram to someone.
Bring a schema you already have
Import, on the projects page or in the editor, reads a .dbml file, a .viewdb project, or SQL with CREATE TABLE statements from PostgreSQL, MySQL or SQL Server. Choose a file or paste the text. Files can have up to 900 KB.
In the editor, an import can also replace the current project. ViewDB keeps a “Before import” version first, so you can go back.
Samples in the editor offers the same sample schemas: replace the current code with one, or open it as a new project.
DBML in five minutes
DBML describes tables, columns and the links between them in plain text. These five steps cover most schemas.
A table
Write
Table, a name and the columns between braces. Each column is a name and a type. Any type name works, and ViewDB keeps it as you wrote it.DBMLTable users { id integer email varchar(255) created_at timestamp}Keys and rules
Settings go in square brackets after the type:
pkfor the primary key,increment,unique,not nullanddefault. A default between backticks, like now() here, is an SQL expression.DBMLTable users { id integer [pk, increment] email varchar(255) [unique, not null] created_at timestamp [default: `now()`]}A relationship
ref: > users.idon a column says that many posts point to one user. The diagram draws a line between the two columns.DBMLTable users { id integer [pk, increment] email varchar(255) [unique, not null]} Table posts { id integer [pk, increment] author_id integer [not null, ref: > users.id] title varchar(200) [not null]}A list of values
Enumnames the values a column may hold. Use the enum's name as the column type.DBMLEnum post_status { draft published archived} Table posts { id integer [pk, increment] author_id integer [not null, ref: > users.id] status post_status [default: 'draft']} Table users { id integer [pk, increment]}Groups and notes
TableGroupdraws a frame around related tables. ANoteoutside any table becomes a sticky note on the diagram.DBMLTable users { id integer [pk]} Table posts { id integer [pk] author_id integer [ref: > users.id]} TableGroup blog [color: #0f766e] { users posts} Note publishing { 'Posts are visible once status is published.'}
That is enough for most apps. The reference below has every option.
DBML reference
Everything ViewDB reads, with an example for each part.
Tables and columns
A table can live in a schema (billing.invoices; without one it goes in public), have a short alias with as, a headercolor and a note. Each line inside is a column: its name, its type, then settings in brackets.
Table billing.invoices as I [headercolor: #2563eb, note: 'One per order'] { id uuid [pk, default: `gen_random_uuid()`] number varchar(20) [unique, not null, note: 'Shown to the customer'] total decimal(10,2) [not null, default: 0] paid boolean [default: false] tags text[] currency char(3) [default: 'USD']}pkorprimary key- The primary key. For a key over several columns, use Indexes.
increment- Numbers go up by themselves.
unique- No two rows can share the value.
not null/null- Whether the column can be left empty.
default: …- A number,
'text',trueorfalse, or an SQL expression between backticks. note: '…'- A comment on the column. SQL exports keep it as a comment.
ref: > table.column- A relationship written on the column itself.
Types stay as written, so varchar(255), decimal(10,2), text[] and enum names all work. Exports translate the common ones for each database.
Indexes
An Indexes block at the end of a table lists indexes on one or more columns. Each can be pk (a primary key over several columns), unique, and have a name.
Table order_items { order_id integer product_id integer sku varchar(40) Indexes { (order_id, product_id) [pk] sku [unique, name: 'order_items_sku_key'] }}Relationships
Write a relationship on the column, or on a line of its own starting with Ref, which can also have a name and actions. The symbol says how many rows are on each side:
>- Many to one: many orders, one user.
<is the same, written the other way round. -- One to one.
<>- Many to many. Exports create the junction table for you.
Table users { id integer [pk]} Table profiles { user_id integer [pk, ref: - users.id]} Table orders { id integer [pk] user_id integer} Table products { id integer [pk]} Table tags { id integer [pk]} Ref orders_user: orders.user_id > users.id [delete: cascade, update: no action]Ref: products.id <> tags.iddelete and update take cascade, restrict, set null, set default or no action. Two relationships between the same columns are an error.
For a key over several columns, list them in parentheses on both sides. Relationships like these can only be changed in the code.
Table orders { region varchar(2) number integer Indexes { (region, number) [pk] }} Table shipments { id integer [pk] order_region varchar(2) order_number integer} Ref: shipments.(order_region, order_number) > orders.(region, number)Enums
An enum lists the values a column can hold, one per line. Put quotes around values with spaces. Enums can belong to a schema too: use the full name as the column type.
Enum billing.payment_method { card pix "bank transfer"} Table billing.payments { id integer [pk] method billing.payment_method [not null]}Groups and sticky notes
TableGroup lists the tables to frame together, with an optional color and note. A table belongs to one group at most. A Note with a name, outside any table, becomes a sticky note; color: none leaves it without fill. Three quotes (''') hold text over several lines.
Table customers { id integer [pk]} Table orders { id integer [pk] customer_id integer [ref: > customers.id]} TableGroup sales [color: #c2410c, note: 'Owned by the sales team'] { customers orders} Note release_plan [color: #F4D03F] { ''' Orders ship in v2. Customers already exist. '''}Comments
// turns the rest of the line into a comment, and /* */ a whole block. Ctrl/⌘+/ comments out the selected lines.
// A line comment/* A block comment over two lines */Table audit_log { id bigint [pk] // after a column too payload json}Limits
- A project's DBML can have up to 500,000 characters.
- Project names can have up to 120 characters.
- Names typed in the Schema tab cannot contain double quotes.
Accepted but not drawn
These parts of DBML are read without errors, but they do not show on the diagram or in the exports:
Project- The project's name, database type and note.
Records- Sample rows.
checksandcheck:- Check constraints. They stay in the code as written.
- Index
type - Such as
type: hash. The index itself is kept. - Notes on enum values
- The values are kept, the notes are not.
TablePartial works: its columns are added to each table that uses it with ~name.
Reading an error
When the DBML cannot be read, the toolbar counts the problems and the list under the editor says where they are, as in “Line 3: Expect an identifier”. Click a line to jump to it.
Table users { id integer [pk}] is missing on line 2, and the error points at line 3.Writing in the editor
- Problems
- The pill in the toolbar shows No errors or how many problems there are. Click it to go to the first one.
- Find and edit
- Ctrl/⌘+F finds and replaces, Ctrl/⌘+Z undoes, Ctrl/⌘+/ comments lines and Tab indents. Brackets and quotes close by themselves.
- Code and diagram together
- Moving the cursor into a table, group or note selects it on the diagram. Clicking it on the diagram brings its code or its form into view.
- The panel
- Ctrl/⌘+B hides or shows the editor. Drag the divider to resize it, or focus it and press the arrow keys. Each pane has its own light and dark switch.
- On a phone
- The editor, the diagram and the assistant are separate views. Switch between them with the tabs above.
Working on the diagram
The diagram is drawn from the DBML, and most of what you do on it goes back into the code.
- Move around
- Drag the background to pan, and scroll or pinch to zoom, from 20% to 250%. Click the percentage to return to 100%, or Fit to see everything.
- Select
- Click a table to select it. Shift+click adds tables to the selection, and Shift+drag draws a box around several.
- Add
- Add table, Add group and Add note create items right away; Add group puts the selected tables in the new group. Double-click an empty spot to drop a sticky note there. These buttons wait while the DBML has errors.
- Change
- Drag a table into or out of a group's frame to change its group. Drag its right edge to change its width. Double-click a table, group or relationship to edit it in the Schema tab.
- Connect
- Hover a column and a dot shows on its right. Drag that dot to another column to create a relationship.
- Color
- The color button on a table header, group or note picks a preset or any color you like. It writes
headercolororcolorin the code. - Read the lines
- The legend in the corner shows how a line ends: a bar for one, a fork for many. Hovering a table fades the ones it is not linked to.
Arrange
Arrange lays out all the tables at once. With the menu open, keys 1 to 4 pick an option. A project with no saved positions is arranged the first time you open it.
- Left to right
- Referenced tables on the left, following the relationships.
- Top to bottom
- Referenced tables on top, following the relationships.
- SnowflakePro
- The most connected tables in the middle, related ones around them.
- CompactPro
- Tables packed tightly in rows, ignoring relationships.
Editing without code
The Schema tab, next to DBML, has forms for Tables, Refs, Enums, Groups and Notes. Each change rewrites only the lines it affects, so your formatting and comments stay put.
- Tables
- Name, alias, note, color, group and columns, with type, primary key, not null, unique, auto-increment, default and note. Move or remove columns, or delete the table together with its relationships.
- Refs
- Both ends, the kind and the actions on delete and update. A relationship written on a column becomes a
Refline when you save it. - Enums
- Add, rename and remove values, and see which columns use the enum.
- Groups and Notes
- Name, color, note and member tables of each group; text and color of each sticky note.
While the DBML has errors, the forms show the last valid version and cannot be changed. Fix the code first.
Exporting
Export turns the current schema into code or a picture. Copy the code, or Download it as a file.
- PostgreSQL, MySQL, SQLite
CREATE TABLEscripts with keys, indexes, enums and comments.- Prisma
- A
schema.prismafor PostgreSQL, MySQL or SQLite. - Drizzle
- A
schema.tsfor PostgreSQL, MySQL or SQLite. - DBML
- The code exactly as written, errors included.
- ViewDB
- A
.viewdbfile with the name, the DBML and the diagram positions. Import opens it again.
Code exports need DBML without errors.
Images
PNG and SVG save the diagram as it looks now, at twice the screen resolution.
- PNG
- On Starter, a PNG has a small ViewDB logo in the corner.
- PNGPro
- PNG without the logo.
- SVGPro
- A vector file that stays sharp at any size.
Version historyPro
History lists earlier states of the project. Preview any of them, compare it with now, and bring it back.
- Kept for you
- While you edit, ViewDB keeps a version every 10 minutes at most. It also keeps one before an import, a sample, a restore, an agent edit or an assistant change.
- Named versions
- Save version keeps the current state under a name. Named versions are never removed automatically; of the others, the latest 100 stay.
- Preview and compare
- Open a version to see its diagram and how its DBML differs from the current one or from the version before it. The editor is read only while you look.
- Restore
- Restore brings the version back. The state you leave is kept first, and Undo in the message reverts the restore.
- More
- Rename or delete a version, Duplicate as project, or download it as
.viewdb.
On Starter, versions are still recorded, and they show up once you move to Pro.
AI assistantPro
Assistant opens a chat about the project you are in. It reads the current DBML and only talks about this schema.
- Ask
- Ask what a table is for, how to model something, or what is wrong. The suggestions are a start: “Explain this schema”, “Suggest improvements to this model”, “Fix the DBML errors”.
- Review changes
- Ask for a change and the reply comes as a proposal. Show changes lists the differences, and Apply writes them into the editor. A version is kept first, and Ctrl/⌘+Z undoes it.
- Messages
- The assistant that comes with ViewDB answers 20 messages a month during the trial and 200 on Pro.
- Your own key
- In Account → AI assistant, add a Google Gemini, OpenAI or Anthropic key and pick the model. Your own key has no monthly limit; the provider bills you for its use.
- The conversation
- It lasts while the editor is open. New conversation starts over.
Connecting AI agentsPro
Agents such as Claude and Cursor can read and edit your projects through MCP. You approve each connection, and every change they make is kept in the version history as “Before agent edit”.
Apps that connect
- Claude (web and desktop)
- Add ViewDB as a custom connector.
- Claude Code
- Add it with one terminal command.
- Cursor
- Add it to
mcp.json. - Claude Desktop with a key
- Install the
.mcpbfile and paste an API key instead of signing in.
What an agent can do
- List your projects and read their DBML and versions.
- Export a schema as SQL or ORM code.
- Create and rename projects, and change their schema.
- Show the diagram inside the chat.
API keys can read only, or read and edit. Revoke a key or disconnect an app on the same page.
Account and plans
- Profile
- Your name. The photo comes from GitHub or Google.
- Preferences
- The language of the app and of emails. It is also in the account menu.
- Security
- Password, sign-in with GitHub and Google, and where you are signed in.
- Plan and billing
- Your plan, the renewal date, and the Stripe portal for invoices and plan changes.
- Delete account
- Deletes the account and its projects, and cancels the subscription at once.
The sun and moon button in the header switches between light and dark.
Plans
Every account can start with 3 days of Pro, free, with one project. After that, choose Starter or Pro.
- Trial
- Everything in Pro, with one project and 20 assistant messages.
- Starter
- Up to 10 projects, every code export, PNG with the logo, two layouts and sharing.
- Pro
- Unlimited projects, PNG without the logo and SVG, every layout, version history, the assistant, agents, and link passwords and expiry dates.
- Read only
- When the trial or subscription ends, you can still open your projects, download their DBML and
.viewdb, and delete them. Shared links keep working.
Keyboard shortcuts
| Keys | What it does |
|---|---|
| Ctrl/⌘+S | Save now |
| Ctrl/⌘+B | Hide or show the editor |
| Ctrl/⌘+F | Find and replace in the code |
| Ctrl/⌘+Z Ctrl/⌘+Shift+Z | Undo and redo |
| Ctrl/⌘+/ | Comment out lines |
| 1–4 | Pick a layout, with the Arrange menu open |
| Shift+click | Add a table to the selection |
| Shift+drag | Select tables with a box |
| Double-click | On the background, add a sticky note |
| Esc | Stop editing a note, or undo a name being typed |
| ← → | Resize the panels, with the divider focused |
| Enter Shift+Enter | Send a message to the assistant, or add a line |