sql_to_ER

作者 ystemsrx已验证

【在线免费使用】 简单快速将SQL或DBML转换为美观的ER图(支持 Agent Skill)/ The best SQL to ER Diagram converter (Support Agent Skill).

182
Stars
25
Forks
JavaScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/ystemsrx/sql_to_ER

快速入门

使用 sql_to_ER 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

🗂️ 最好的 SQL 转 ER 图生成器

优雅的在线 SQL / DBML 转 ER 图工具

English · 简体中文

License: AGPL v3 GitHub Stars GitHub Forks GitHub Issues Last Commit TypeScript React Vite G6 Vitest pnpm

🌐 在线体验 · Live Demo

🤖 作为 Skill 安装

通过一条命令安装 sql2er Agent Skill:

npx skills add ystemsrx/sql_to_er

✨ 项目简介

一个基于网页的纯前端工具,用于从 SQL CREATE TABLE 语句和 DBML 代码生成 Chen 模型 ER 图。无需登录,无需付费,完全免费开源。

[!NOTE] 为什么做这个?市面上绝大多数 DBML/SQL 转 ER 图的在线工具都需要登录甚至收费,且样式奇丑无比,体验令人失望。于是直接开源一个免费替代品。

[!TIP] 如果你需要绘制的是逻辑模型(而非 Chen 模型),推荐使用 dbdiagram.io,同样免费。

🚀 快速使用

直接访问在线版本即可使用,无需安装

🔗 ER Diagram Generator

或者克隆到本地开发运行:

本项目使用 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(参见上方快速使用,或直接访问在线版)

  • 在输入区粘贴 SQL CREATE TABLE 语句或 DBML 代码

  • 点击 「生成 ER 图」 按钮

  • 若对节点位置不满意,可拖拽节点调整布局;双击节点修改内容

  • 在画布上使用滚轮可平滑缩放,按住 Ctrl + 滚轮可围绕图形中心平滑旋转(节点形状与文字方向保持不变)

  • 若图形较复杂,只需将每个矩形(实体)拖到大致位置,再点击 「智能优化」,即可自动整理布局

🧩 支持格式

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

🎨 Chen 模型元素

图形 含义 对应数据库概念

🟦 矩形 实体 表

🔶 菱形 关系 外键

椭圆 属性 列

下划线 主键标识 主键属性

⚖️ 与标准 Chen 模型的差异

[!IMPORTANT] 本工具为简化使用,在以下方面对标准 Chen 模型做了妥协。如需严格符合学术规范,请参考下方说明手动调整。

  • 关系命名:标准 Chen 模型要求菱形使用语义化名称(如 属于拥有),本工具默认显示外键字段名。

  • 实体与属性命名:标准建议使用业务术语,本工具默认直接使用表名与列名。

  • 自定义修改

  • ✏️ 双击 图形元素可直接编辑显示内容

  • 🔁 或在源代码(SQL / DBML)中修改后重新生成

🖼️ 效果展示

示例 1

[!TIP] 结构较复杂时,直接生成的图可能不够整齐。此时:

  • 点击 「智能调整」 自动整理——通常此时已足够整齐,仅需微调。

  • 若仍不理想,点击 「快速布局」 再配合「智能调整」通常可得到理想效果。

  • 极少数情况下,可先手动将矩形(实体)拖到合适位置(其他元素无需调整),再点击「智能调整」即可。

  • 实体 / 关系特别多时,可先点击画布左上角的 「隐藏属性」,先把矩形(实体)和菱形(关系)骨架摆到理想位置,再点一次切换回「显示属性」——属性会自动根据当前矩形的位置围绕其均匀分布,避免一上来就被属性干扰拖动。

🕘 生成历史

每次生成 ER 图时都会自动保存一份快照(含缩略图、节点位置、当前显示设置),整理过的布局不会因为重新生成而丢失。

生成历史

  • 打开:点击画布左上角的 🕘 时钟图标打开历史页面。

  • 浏览:直接 拖拽 卡片,或在面板上 滚轮 翻动;最近的快照在最前面。

  • 恢复:拖拽任意卡片先把它吸附到中央,再次点击「恢复」即可按当时的节点位置 / 标签重建图(不会重新布局)。

  • 删除:单张快照右下角的 🗑 按钮可单独移除该条记录。

  • 持久化:所有数据都存在浏览器本地的 IndexedDB 中(首次生成非示例 ER 图后才会出现条目)。

  • 会话恢复:刷新或重新打开页面时仅自动恢复 6 小时内编辑的图(含布局);超过 6 小时会显示初始示例,原有生成历史不会删除。输入框文本另有 localStorage 草稿兜底。

[!TIP] 想撤回上一次手动调整?面板里的「恢复」是按输入文本归档的版本切换,单步撤销 / 重做请用 Ctrl + Z / Ctrl + Y

🤝 贡献

欢迎提交 Issue 和 Pull Request!如果这个项目对你有帮助,请点一个 ⭐ Star 支持一下。

📄 开源协议

本项目基于 GNU AGPL v3.0 开源。

常见问题

What is sql_to_ER?

sql_to_ER is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by ystemsrx. 【在线免费使用】 简单快速将SQL或DBML转换为美观的ER图(支持 Agent Skill)/ The best SQL to ER Diagram converter (Support Agent Skill). It has 182 GitHub stars.

Is sql_to_ER safe to use?

Yes. sql_to_ER passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install sql_to_ER?

Clone the repository with "git clone https://github.com/ystemsrx/sql_to_ER" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is sql_to_ER written in?

sql_to_ER is primarily written in JavaScript. It is open-source under ystemsrx on GitHub, so you can review or fork the full source.

Are there alternatives to sql_to_ER?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh sql_to_ER against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情