优雅的在线 SQL / DBML 转 ER 图工具
$ npx -y skills add ystemsrx/sql_to_ER --agent claude-code
Run the curl in your terminal, the rest in Claude Code.
Repo: ystemsrx/sql_to_ER
What's inside
优雅的在线 SQL / DBML 转 ER 图工具
English · 简体中文
通过一条命令安装 sql2er Agent Skill:
npx skills add ystemsrx/sql_to_er
一个基于网页的纯前端工具,用于从 SQL CREATE TABLE 语句和 DBML 代码生成 Chen 模型 ER 图。无需登录,无需付费,完全免费开源。
[!NOTE] 为什么做这个?市面上绝大多数 DBML/SQL 转 ER 图的在线工具都需要登录甚至收费,且样式奇丑无比,体验令人失望。于是直接开源一个免费替代品。
[!TIP] 如果你需要绘制的是逻辑模型(而非 Chen 模型),推荐使用 dbdiagram.io,同样免费。
直接访问在线版本即可使用,无需安装:
或者克隆到本地开发运行:
本项目使用 pnpm 作为包管理器(已通过 packageManager 字段锁定版本,建议先 corepack enable 让其自动安装)。
git clone https://github.com/ystemsrx/sql_to_ER.git
cd sql_to_ER
corepack enable # 一次性,启用 Corepack 自动管理 pnpm 版本
pnpm install
pnpm dev
[!WARNING] 请勿直接双击打开
sql2er.html。 本项目使用 Vite + TypeScript,源码中的.ts/.tsx和前端依赖需要 Vite 编译与模块解析。开发时请使用:pnpm dev然后在浏览器访问 Vite 输出的地址,例如
http://localhost:5173/sql2er.html。如果要用静态服务器,请先执行pnpm build,再服务dist/目录。
pnpm dev 打开 sql2er.html(参见上方快速使用,或直接访问在线版)CREATE TABLE 语句或 DBML 代码CREATE TABLE users (
id INT PRIMARY KEY,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE
);
CREATE TABLE posts (
id INT PRIMARY KEY,
author_id INT,
title VARCHAR(255),
FOREIGN KEY (author_id) REFERENCES users(id)
);
Table users {
id INT [pk]
username VARCHAR(255) [not null]
email VARCHAR(255) [unique]
}
Table posts {
id INT [pk]
author_id INT
title VARCHAR(255)
}
Ref: posts.author_id > users.id
| 图形 | 含义 | 对应数据库概念 |
|---|---|---|
| 🟦 矩形 | 实体 | 表 |
| 🔶 菱形 | 关系 | 外键 |
| ⚪ 椭圆 | 属性 | 列 |
| 下划线 | 主键标识 | 主键属性 |
[!IMPORTANT] 本工具为简化使用,在以下方面对标准 Chen 模型做了妥协。如需严格符合学术规范,请参考下方说明手动调整。

[!TIP] 结构较复杂时,直接生成的图可能不够整齐。此时:
- 点击 「智能调整」 自动整理——通常此时已足够整齐,仅需微调。
- 若仍不理想,点击 「快速布局」 再配合「智能调整」通常可得到理想效果。
- 极少数情况下,可先手动将矩形(实体)拖到合适位置(其他元素无需调整),再点击「智能调整」即可。
- 实体 / 关系特别多时,可先点击画布左上角的 「隐藏属性」,先把矩形(实体)和菱形(关系)骨架摆到理想位置,再点一次切换回「显示属性」——属性会自动根据当前矩形的位置围绕其均匀分布,避免一上来就被属性干扰拖动。
每次生成 ER 图时都会自动保存一份快照(含缩略图、节点位置、当前显示设置),整理过的布局不会因为重新生成而丢失。

[!TIP] 想撤回上一次手动调整?面板里的「恢复」是按输入文本归档的版本切换,单步撤销 / 重做请用 Ctrl + Z / Ctrl + Y。
欢迎提交 Issue 和 Pull Request!如果这个项目对你有帮助,请点一个 ⭐ Star 支持一下。
本项目基于 GNU AGPL v3.0 开源。
.gitattributes
.github/
dependabot.yml
workflows/
ci.yml
pages.yml
.gitignore
.npmrc
.prettierignore
.prettierrc.json
assets/
base.css
eg-history.png
eg1.png
eg2_opt.png
eg2.png
fonts/
dm-sans-latin-300-normal.woff2
dm-sans-latin-400-normal.woff2
dm-sans-latin-500-normal.woff2
dm-sans-latin-700-normal.woff2
dm-serif-display-latin-400-italic.woff2
dm-serif-display-latin-400-normal.woff2
dm-serif-text-latin-400-italic.woff2
dm-serif-text-latin-400-normal.woff2
fonts.css
jetbrains-mono-latin-400-normal.woff2
lora-latin-400-italic.woff2
lora-latin-400-normal.woff2
lora-latin-500-italic.woff2
lora-latin-500-normal.woff2
lora-latin-600-italic.woff2
lora-latin-600-normal.woff2
lora-latin-700-italic.woff2
lora-latin-700-normal.woff2
poppins-latin-300-normal.woff2
poppins-latin-400-italic.woff2
poppins-latin-400-normal.woff2
poppins-latin-500-normal.woff2
poppins-latin-600-normal.woff2
poppins-latin-700-italic.woff2
poppins-latin-700-normal.woff2
css/
landing.css
style.css
index.html
LICENSE
package.json
pnpm-lock.yaml
pnpm-workspace.yaml
README.en.md
README.md
skills/
sql2er/
agents/
openai.yaml
references/
commands.md
data-model.md
scripts/
build.mjs
engine/
adapter.ts
cli.ts
describe.ts
exporters.ts
ops.ts
shims.ts
skeleton.ts
tsconfig.json
sql2er-agent.mjs
SKILL.md
sql2er.html
src/
App.tsx
attributeLayout.ts
builder.ts
codeEditor.tsx
components/
icons.tsx
SwitchControl.tsx
editor.tsx
embedded.tsx
EmbeddedApp.tsx
exporter.ts
graph/
attachEntityDragSync.ts
autoAvoid.ts
createERGraph.ts
entityMoveSync.ts
forceLoop.ts
sizeAwareGeometry.ts
updateGraphStyles.ts
history.ts
HistoryOverlay.tsx
hooks/
useEmbeddedGraph.ts
useExportButton.ts
useGraph.ts
useSnapshotPersistence.ts
useUndoRedoShortcuts.ts
useWheelZoomRotate.ts
i18n.ts
landing/
hero.ts
language.ts
layout/
animation.ts
arrangeLayout.ts
attributeRings.ts
componentSpread.ts
geometry.ts
index.ts
initialLayout.ts
skeletonLayout.ts
spatialGrid.ts
utils.ts
legendPlacement.ts
main.tsx
parser/
dbml.ts
sql.ts
snapshots.ts
test/
animation.test.ts
attachEntityDragSync.test.ts
autoAvoid.test.ts
builder.test.ts
createERGraph.test.ts
diagnostic-overlays.test.ts
editor-dblclick.test.ts
entityMoveSync.test.ts
exporter-xml.test.ts
forceLoop.test.ts
i18n.test.ts
legendPlacement.test.ts
parser-dbml-edge.test.ts
parser-dbml-fixes.test.ts
parser-dbml.test.ts
parser-sql-dialects.test.ts
parser-sql-edge.test.ts
parser-sql-fixes.test.ts
parser-sql-issues.test.ts
parser-sql.test.ts
perf-layout.test.ts
session-restore.test.ts
sizeAwareGeometry.test.ts
skeletonLayout.test.ts
snapshot-persistence.test.ts
snapshots.test.ts
sql2er-agent-cli.test.ts
wheelZoomRotate.test.ts
types.ts
vite-env.d.ts
tsconfig.json
vite.config.tsFAQ
sql-to-er is a Claude Code plugin with 1 hand-picked skill for documentation work, indexed on Flowy. Install it with the command on its page. It includes sql2er. Its skills do not fire on their own yet. Request auto-invocation to have Flowy route them as you prompt. Free and open source.