SQL → TS / Zod / Go
解析 PostgreSQL、MySQL、SQLite 的 CREATE TABLE 语句,生成 TypeScript 接口、Zod 架构、Go 结构体、Prisma 模型和 Pydantic 类,并提供 camelCase 与 null 写法选项。
完全在浏览器中运行 — 粘贴的内容不会被上传。
只读取 CREATE TABLE;ALTER TABLE、索引和 INSERT 语句会被忽略。
export interface User {
id: number;
email: string;
display_name: string | null;
plan: string;
created_at: string;
}
export interface Order {
id: number;
user_id: number;
total: number;
metadata: unknown;
placed_at: string;
}在 Prisma 之外,外键保持为普通列;Prisma 需要关系字段。
SQL DDL 到模型参考
快速参考- CREATE TABLE users (…);
- 本工具唯一读取的语句。列名、类型、NOT NULL、DEFAULT 和键约束都会翻译成目标模型。
- serial / bigserial
- PostgreSQL 自增。在 Prisma 中变成 @default(autoincrement()),在 TypeScript 中只是 number,因为值由数据库提供。
- timestamptz
- 带时区的时间戳。在 TypeScript 和 Zod 中是 ISO 8601 字符串,Prisma 中是 DateTime,Pydantic 中是 datetime。
- numeric(12, 2)
- 带精度和小数位数的精确小数。Prisma 与 Pydantic 用 Decimal,Go 用 float64,其余用 number。SQL 里金额绝不要用浮点数。
- REFERENCES users(id)
- 外键。TypeScript 和 Go 保留为普通列;Prisma 需要两个模型都有关系字段,因此生成的 Prisma 模型保持扁平。
- PRIMARY KEY (a, b)
- 复合主键。Prisma 用 @@id([a, b]),而不是给单个字段加 @id。
常见问题
答案在工具下方能读哪些 SQL 方言?
PostgreSQL、MySQL、SQLite 的 CREATE TABLE 语句,包括 serial 和 uuid 主键、varchar 长度、numeric 精度、数组和默认值。
可空列在 TypeScript 里为什么是联合类型?
TypeScript 需要 string | null,Prisma 用 ? 表示。nullable 选项可以在 null 联合和可选键之间切换。
会生成外键关系吗?
会报告引用并保留该列,但 Prisma 关系需要两边都有字段,所以生成的 Prisma 模型保持扁平。
SQL 相关语法指南
全部 SQL 指南Postgres permission denied for sequence: GRANT USAGE and nextval
Sequences carry their own ACL, so table grants never cover nextval. The USAGE grant, default privileges, and why identity columns behave differently.
SQLPostgres RLS 42P17: infinite recursion detected in policy
A policy on members that reads members re-enters itself. One security definer function with a pinned search_path ends the recursion and leaves the rest of the policy intact.
SQLPostgres: could not serialize access due to concurrent update
At REPEATABLE READ and SERIALIZABLE a conflicting write aborts with SQLSTATE 40001. Retry the whole transaction with backoff, then remove the conflict instead of retrying it.
SQLPostgres: cached plan must not change result type
A prepared statement or PL/pgSQL plan outlived a schema change. Disable statement caching, force custom plans, discard plans, and order the deploy so no connection straddles DDL.