DBML to SQL & ERD Online
Convert DBML (dbdiagram.io syntax) to PostgreSQL, MySQL, SQL Server or SQLite DDL, SQL DDL back to DBML, and draw an ERD as SVG or PNG.
Result
Press “Run” to see the result.
DBML is the readable schema language of dbdiagram.io. Send dbml and get CREATE statements for to=postgres (default), mysql, mssql or sqlite: tables with schemas, column types, primary keys (also composite), increment (IDENTITY / AUTO_INCREMENT / AUTOINCREMENT), unique, not null, defaults (strings, numbers, booleans, expressions), enums (CREATE TYPE in PostgreSQL, ENUM in MySQL, CHECK constraints elsewhere), indexes (composite, expression, unique, named, type: hash), notes as COMMENT ON / COMMENT / extended properties, and foreign keys from inline or block refs (>, <, -, composite, delete: cascade). Many-to-many refs (<>) create a junction table.
The reverse works too: send sql (CREATE TABLE, CREATE INDEX, CREATE TYPE … AS ENUM, ALTER TABLE ADD FOREIGN KEY / PRIMARY KEY, COMMENT ON, MySQL inline KEY / ENUM / COMMENT, SQL Server [brackets] and IDENTITY) and get DBML, the JSON model (to=json) or the DDL of another database, e.g. MySQL dump to PostgreSQL.
to=svg or to=png draws an entity-relationship diagram: tables placed in layers (referenced tables to the left of the tables that point to them), primary keys highlighted, foreign keys marked, crow's-foot ends for "many", header colours from headercolor, theme=dark. The parser is APIBox's own (no @dbml/core); TablePartial, records and DBML 3 sticky notes are not supported, and expression indexes are written as given for every database.
Use this in your code
curl -X POST "https://apibox.io.vn/v1/dbml" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"dbml":"Table users {\n id int [pk, increment]\n email varchar(255) [unique, not null]\n}\n\nTable posts {\n id int [pk]\n user_id int [ref: > users.id]\n title varchar\n}","to":"postgres"}'const res = await fetch('https://apibox.io.vn/v1/dbml', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"dbml": "Table users {\n id int [pk, increment]\n email varchar(255) [unique, not null]\n}\n\nTable posts {\n id int [pk]\n user_id int [ref: > users.id]\n title varchar\n}",
"to": "postgres"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/dbml",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"dbml": "Table users {\n id int [pk, increment]\n email varchar(255) [unique, not null]\n}\n\nTable posts {\n id int [pk]\n user_id int [ref: > users.id]\n title varchar\n}", "to": "postgres"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/dbml');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"dbml":"Table users {\\n id int [pk, increment]\\n email varchar(255) [unique, not null]\\n}\\n\\nTable posts {\\n id int [pk]\\n user_id int [ref: > users.id]\\n title varchar\\n}","to":"postgres"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));API documentation → Get a free API key
FAQ
Is it compatible with dbdiagram.io?
It follows the DBML syntax: Project, Table (alias, settings, indexes, notes), Ref (inline, short, long, composite, actions), Enum, TableGroup and Note. TablePartial and records are not supported yet.
How are relationships turned into foreign keys?
For a > b the foreign key goes on a (many side); for a < b on b; a - b puts it on a; a <> b creates a junction table a_b with two foreign keys.
Can I get a PNG?
Yes, to=png renders the diagram (scale up to 3). SVG stays sharp at any size and is better for documents.