Skip to content
Back to search

sql_to_ER

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

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

Its scripts were only partly scanned.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/ystemsrx/sql-to-ER with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/ystemsrx/sql-to-ER'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/ystemsrx--sql-to-er/badge.svg)](/listings/ystemsrx--sql-to-er)

HTML

<a href="/listings/ystemsrx--sql-to-er"><img src="/api/listings/ystemsrx--sql-to-er/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 211 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. <div align="center">
  2. # 🗂️ 最好的 SQL 转 ER 图生成器
  3. **优雅的在线 SQL / DBML 转 ER 图工具**
  4. [English](README.en.md) · **简体中文**
  5. [![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg?style=flat-square)](./LICENSE)
  6. [![GitHub Stars](https://img.shields.io/github/stars/ystemsrx/sql-to-ER?style=flat-square&color=gold)](https://github.com/ystemsrx/sql-to-ER/stargazers)
  7. [![GitHub Forks](https://img.shields.io/github/forks/ystemsrx/sql-to-ER?style=flat-square&color=blue)](https://github.com/ystemsrx/sql-to-ER/network/members)
  8. [![GitHub Issues](https://img.shields.io/github/issues/ystemsrx/sql-to-ER?style=flat-square&color=red)](https://github.com/ystemsrx/sql-to-ER/issues)
  9. [![Last Commit](https://img.shields.io/github/last-commit/ystemsrx/sql-to-ER?style=flat-square&color=green)](https://github.com/ystemsrx/sql-to-ER/commits)
  10. [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=flat-square&logo=typescript&logoColor=white)](#)
  11. [![React](https://img.shields.io/badge/React-19-61DAFB?style=flat-square&logo=react&logoColor=black)](#)
  12. [![Vite](https://img.shields.io/badge/Vite-8-646CFF?style=flat-square&logo=vite&logoColor=white)](#)
  13. [![G6](https://img.shields.io/badge/AntV%20G6-4.8-1890FF?style=flat-square)](#)
  14. [![Vitest](https://img.shields.io/badge/Vitest-4-6E9F18?style=flat-square&logo=vitest&logoColor=white)](#)
  15. [![pnpm](https://img.shields.io/badge/pnpm-F69220?style=flat-square&logo=pnpm&logoColor=white)](#)
  16. ### 🌐 [**在线体验 · Live Demo**](https://ystemsrx.github.io/sql-to-ER/sql2er.html)
  17. </div>
  18. ---
  19. ## 🤖 作为 Skill 安装
  20. 通过一条命令安装 sql2er Agent Skill:
  21. ```bash
  22. npx skills add ystemsrx/sql-to-ER
  23. ```
  24. ---
  25. ## ✨ 项目简介
  26. 一个基于网页的**纯前端**工具,用于从 SQL `CREATE TABLE` 语句和 DBML 代码生成 **Chen 模型 ER 图**。无需登录,无需付费,完全免费开源。
  27. > [!NOTE]
  28. > 为什么做这个?市面上绝大多数 DBML/SQL 转 ER 图的在线工具都需要登录甚至收费,且样式奇丑无比,体验令人失望。于是直接开源一个免费替代品。
  29. > [!TIP]
  30. > 如果你需要绘制的是**逻辑模型**(而非 Chen 模型),推荐使用 [dbdiagram.io](https://dbdiagram.io/),同样免费。
  31. ---
  32. ## 🚀 快速使用
  33. 直接访问在线版本即可使用,**无需安装**:
  34. 🔗 **[ER Diagram Generator](https://ystemsrx.github.io/sql-to-ER/sql2er.html)**
  35. 或者克隆到本地开发运行:
  36. 本项目使用 [pnpm](https://pnpm.io/) 作为包管理器(已通过 `packageManager` 字段锁定版本,建议先 `corepack enable` 让其自动安装)。
  37. ```bash
  38. git clone https://github.com/ystemsrx/sql-to-ER.git
  39. cd sql-to-ER
  40. corepack enable # 一次性,启用 Corepack 自动管理 pnpm 版本
  41. pnpm install
  42. pnpm dev
  43. ```
  44. > [!WARNING]
  45. > **请勿直接双击打开 `sql2er.html`。** 本项目使用 Vite + TypeScript,源码中的 `.ts/.tsx` 和前端依赖需要 Vite 编译与模块解析。开发时请使用:
  46. >
  47. > ```bash
  48. > pnpm dev
  49. > ```
  50. >
  51. > 然后在浏览器访问 Vite 输出的地址,例如 `http://localhost:5173/sql2er.html`。如果要用静态服务器,请先执行 `pnpm build`,再服务 `dist/` 目录。
  52. ---
  53. ## 📖 使用步骤
  54. 1. 通过 `pnpm dev` 打开 `sql2er.html`(参见上方快速使用,或直接访问在线版)
  55. 2. 在输入区粘贴 **SQL `CREATE TABLE`** 语句或 **DBML** 代码
  56. 3. 点击 **「生成 ER 图」** 按钮
  57. 4. 若对节点位置不满意,可**拖拽节点**调整布局;**双击节点**修改内容
  58. 5. 在画布上使用**滚轮**可平滑缩放,按住 **Ctrl + 滚轮**可围绕图形中心平滑旋转(节点形状与文字方向保持不变)
  59. 6. 若图形较复杂,只需将每个矩形(实体)拖到大致位置,再点击 **「智能优化」**,即可自动整理布局
  60. ---
  61. ## 🧩 支持格式
  62. <details open>
  63. <summary><b>📘 SQL 示例</b></summary>
  64. ```sql
  65. CREATE TABLE users (
  66. id INT PRIMARY KEY,
  67. username VARCHAR(255) NOT NULL,
  68. email VARCHAR(255) UNIQUE
  69. );
  70. CREATE TABLE posts (
  71. id INT PRIMARY KEY,
  72. author_id INT,
  73. title VARCHAR(255),
  74. FOREIGN KEY (author_id) REFERENCES users(id)
  75. );
  76. ```
  77. </details>
  78. <details open>
  79. <summary><b>📗 DBML 示例</b></summary>
  80. ```dbml
  81. Table users {
  82. id INT [pk]
  83. username VARCHAR(255) [not null]
  84. email VARCHAR(255) [unique]
  85. }
  86. Table posts {
  87. id INT [pk]
  88. author_id INT
  89. title VARCHAR(255)
  90. }
  91. Ref: posts.author_id > users.id
  92. ```
  93. </details>
  94. ---
  95. ## 🎨 Chen 模型元素
  96. | 图形 | 含义 | 对应数据库概念 |
  97. | :-----------: | :------- | :------------- |
  98. | 🟦 **矩形** | 实体 | 表 |
  99. | 🔶 **菱形** | 关系 | 外键 |
  100. | ⚪ **椭圆** | 属性 | 列 |
  101. | <u>下划线</u> | 主键标识 | 主键属性 |
  102. ---
  103. ## ⚖️ 与标准 Chen 模型的差异
  104. > [!IMPORTANT]
  105. > 本工具为简化使用,在以下方面对标准 Chen 模型做了妥协。如需严格符合学术规范,请参考下方说明手动调整。
  106. - **关系命名**:标准 Chen 模型要求菱形使用语义化名称(如 _属于_、_拥有_),本工具默认显示外键字段名。
  107. - **实体与属性命名**:标准建议使用业务术语,本工具默认直接使用表名与列名。
  108. - **自定义修改**:
  109. - ✏️ **双击** 图形元素可直接编辑显示内容
  110. - 🔁 或在源代码(SQL / DBML)中修改后重新生成
  111. ---
  112. ## 🖼️ 效果展示
  113. ![示例 1](./assets/eg1.png)
  114. > [!TIP]
  115. > 结构较复杂时,直接生成的图可能不够整齐。此时:
  116. >
  117. > 1. 点击 **「智能调整」** 自动整理——通常此时已足够整齐,仅需微调。
  118. > 2. 若仍不理想,点击 **「快速布局」** 再配合「智能调整」通常可得到理想效果。
  119. > 3. 极少数情况下,可先**手动**将矩形(实体)拖到合适位置(其他元素无需调整),再点击「智能调整」即可。
  120. > 4. **实体 / 关系特别多时**,可先点击画布左上角的 **「隐藏属性」**,先把矩形(实体)和菱形(关系)骨架摆到理想位置,再点一次切换回「显示属性」——属性会自动根据当前矩形的位置围绕其均匀分布,避免一上来就被属性干扰拖动。
  121. <table>
  122. <tr>
  123. <td width="50%" align="center">
  124. <h4>🔧 直接生成</h4>
  125. <img src="./assets/eg2.png" alt="Direct Generation"/>
  126. </td>
  127. <td width="50%" align="center">
  128. <h4>✨ 先快速布局 + 智能调整</h4>
  129. <img src="./assets/eg2_opt.png" alt="Optimized Layout"/>
  130. </td>
  131. </tr>
  132. </table>
  133. ---
  134. ## 🕘 生成历史
  135. 每次生成 ER 图时都会自动保存一份**快照**(含缩略图、节点位置、当前显示设置),整理过的布局不会因为重新生成而丢失。
  136. ![生成历史](./assets/eg-history.png)
  137. - **打开**:点击画布左上角的 **🕘 时钟图标**打开历史页面。
  138. - **浏览**:直接 **拖拽** 卡片,或在面板上 **滚轮** 翻动;最近的快照在最前面。
  139. - **恢复**:拖拽任意卡片先把它吸附到中央,再次点击「恢复」即可按当时的节点位置 / 标签重建图(不会重新布局)。
  140. - **删除**:单张快照右下角的 **🗑** 按钮可单独移除该条记录。
  141. - **持久化**:所有数据都存在浏览器本地的 **IndexedDB** 中(首次生成非示例 ER 图后才会出现条目)。
  142. - **会话恢复**:刷新或重新打开页面时仅自动恢复 6 小时内编辑的图(含布局);超过 6 小时会显示初始示例,原有生成历史不会删除。输入框文本另有 localStorage 草稿兜底。
  143. > [!TIP]
  144. > 想撤回上一次手动调整?面板里的「恢复」是按输入文本归档的版本切换,单步撤销 / 重做请用 **Ctrl + Z / Ctrl + Y**。
  145. ---
  146. ## 🤝 贡献
  147. 欢迎提交 Issue 和 Pull Request!如果这个项目对你有帮助,请点一个 ⭐ Star 支持一下。
  148. ---
  149. ## 📄 开源协议
  150. 本项目基于 [GNU AGPL v3.0](./LICENSE) 开源。

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.