Use when needing to visualize database schema, generate ERD diagrams from Drizzle ORM schemas, or understand table relationships
Generate Mermaid ERD diagrams from Drizzle ORM schema files.
schema.ts or tables.ts).references() calls and relations definitionserDiagram
TABLE_NAME {
type column_name PK "Primary Key"
type column_name FK "Foreign Key"
type column_name UK "Unique"
type column_name "nullable"
}
TABLE_A ||--o{ TABLE_B : "has many"
TABLE_A ||--|| TABLE_C : "has one"
TABLE_A }o--|| TABLE_D : "belongs to"
| Symbol | Meaning |
|---|---|
|| | Exactly one |
o| | Zero or one |
}o | Zero or many |
}| | One or many |
| Drizzle | Mermaid |
|---|---|
text() | string |
integer() | int |
real() | float |
blob() | blob |
boolean mode | boolean |
erDiagram
%% Master Tables
%% Transaction Tables
%% Snapshot Tables
%% Relations
From Drizzle:
export const users = sqliteTable("users", {
id: integer("id").primaryKey(),
name: text("name").notNull(),
email: text("email").unique(),
});
export const posts = sqliteTable("posts", {
id: integer("id").primaryKey(),
userId: integer("user_id").references(() => users.id),
title: text("title").notNull(),
});
To Mermaid:
erDiagram
users {
int id PK
string name
string email UK
}
posts {
int id PK
int user_id FK
string title
}
users ||--o{ posts : "has many"
PK - primaryKey()FK - .references()UK - .unique()Group related tables with Mermaid comments:
%% === Master Tables ===
%% === Transaction Tables ===