What SQL Dialects Are Supported for Export in drawDB?
drawDB supports export to six SQL dialects: MySQL, PostgreSQL, SQLite, MariaDB, Microsoft SQL Server, and Oracle SQL, plus generic helper utilities for basic SQL generation.
drawDB is an open-source database design tool that converts visual entity-relationship diagrams into executable SQL scripts. The export system routes your diagram to a dialect-specific code generator based on the database property selected for your project.
How drawDB Routes Exports to SQL Dialects
The core dispatch logic lives in src/utils/exportSQL/index.js. This module inspects diagram.database—a constant from src/data/constants.js—and delegates to the appropriate exporter implementation.
The DB enum in constants.js defines the supported targets:
// From src/data/constants.js
export const DB = Object.freeze({
MYSQL: 'mysql',
POSTGRES: 'postgres',
SQLITE: 'sqlite',
MARIADB: 'mariadb',
MSSQL: 'mssql',
ORACLE: 'oracle'
});
When you call exportSQL(diagram), the dispatcher matches diagram.database against these values and loads the corresponding module.
MySQL Export
src/utils/exportSQL/mysql.js generates MySQL-compatible CREATE TABLE statements with full support for:
AUTO_INCREMENTfor primary keysUNSIGNEDnumeric modifiers- Backtick-quoted identifiers
- MySQL-specific data type mappings
import { exportSQL } from "./src/utils/exportSQL";
import { DB } from "./src/data/constants";
const mysqlDiagram = { /* tables, fields, relationships */, database: DB.MYSQL };
const mysqlSQL = exportSQL(mysqlDiagram);
// Returns: "CREATE TABLE `users` (`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, ...);"
PostgreSQL Export
src/utils/exportSQL/postgres.js produces PostgreSQL syntax featuring:
GENERATED BY DEFAULT AS IDENTITYfor auto-incrementing keysCHECKconstraints- Double-quoted identifiers for case sensitivity
- Native PostgreSQL type mappings (e.g.,
SERIAL,TIMESTAMPTZ)
const pgDiagram = { /* diagram data */, database: DB.POSTGRES };
const pgSQL = exportSQL(pgDiagram);
// Returns: 'CREATE TABLE "users" ("id" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, ...);'
SQLite Export
src/utils/exportSQL/sqlite.js handles SQLite's unique requirements:
AUTOINCREMENT(SQLite's specific spelling, no underscore)- Double-quoted identifiers per SQLite's flexible quoting rules
- Simplified type system mapping
const sqliteDiagram = { /* diagram data */, database: DB.SQLITE };
const sqliteSQL = exportSQL(sqliteDiagram);
// Returns: 'CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, ...);'
MariaDB Export
src/utils/exportSQL/mariadb.js extends MySQL syntax with MariaDB-specific adaptations. While structurally similar to the MySQL exporter, this module accounts for MariaDB's divergent features and defaults, ensuring compatibility with both community and enterprise MariaDB releases.
Microsoft SQL Server Export
src/utils/exportSQL/mssql.js generates T-SQL code with:
- Bracketed identifiers
[like_this] IDENTITY(1,1)for auto-incrementing columns- SQL Server-specific type mappings (e.g.,
NVARCHAR,DATETIME2)
const mssqlDiagram = { /* diagram data */, database: DB.MSSQL };
const mssqlSQL = exportSQL(mssqlDiagram);
// Returns: "CREATE TABLE [users] ([id] INT IDENTITY(1,1) PRIMARY KEY, ...);"
Oracle SQL Export
src/utils/exportSQL/oraclesql.js handles Oracle's distinct SQL dialect including:
- Oracle-specific data types (
NUMBER,VARCHAR2) - Sequence and trigger patterns for auto-increment behavior
- Oracle's naming conventions and constraint syntax
Generic SQL Helpers
src/utils/exportSQL/generic.js provides shared utilities when no specific dialect is selected. This module contains base functions for:
- Type conversion and mapping
- Identifier quoting fallbacks
- Generic constraint generation
If diagram.database doesn't match any DB enum value, the dispatcher falls back to these helper functions for basic SQL output.
Complete Export Code Example
Here's a practical pattern for programmatic export across dialects:
import { exportSQL } from "./src/utils/exportSQL";
import { DB } from "./src/data/constants";
const diagram = {
tables: [/* table definitions */],
relationships: [/* foreign key definitions */],
// database: DB.MYSQL | DB.POSTGRES | DB.SQLITE | DB.MARIADB | DB.MSSQL | DB.ORACLE
};
function exportToDialect(diagram, dialect) {
const exportable = { ...diagram, database: dialect };
return exportSQL(exportable);
}
// Example usage
const outputs = {
mysql: exportToDialect(diagram, DB.MYSQL),
postgres: exportToDialect(diagram, DB.POSTGRES),
sqlite: exportToDialect(diagram, DB.SQLITE)
};
Summary
- Six dialects supported: MySQL, PostgreSQL, SQLite, MariaDB, Microsoft SQL Server, and Oracle SQL via dedicated exporter modules in
src/utils/exportSQL/ - Dispatch architecture: Central router in
index.jsselects exporter based ondiagram.databasematching theDBenum - Dialect-specific features: Each exporter handles native syntax for identifiers, auto-increment, types, and constraints
- Fallback option: Generic helper functions in
generic.jsprovide basic SQL generation for unsupported cases
Frequently Asked Questions
Does drawDB support NoSQL database exports?
No. According to the drawDB source code, export is limited to relational SQL dialects. The DB enum in src/data/constants.js contains only SQL-based targets, and all exporter modules in src/utils/exportSQL/ generate CREATE TABLE syntax.
Can I export the same diagram to multiple SQL dialects?
Yes. The exportSQL function accepts any valid diagram object with a database property. You can clone your diagram, change only the database field to a different DB value, and re-export to generate dialect-specific scripts.
How does drawDB handle auto-incrementing primary keys across dialects?
Each exporter implements the native syntax: AUTO_INCREMENT for MySQL/MariaDB, GENERATED BY DEFAULT AS IDENTITY for PostgreSQL, AUTOINCREMENT for SQLite, IDENTITY(1,1) for MSSQL, and sequences/triggers for Oracle.
What happens if I select an unsupported database type?
The dispatcher in src/utils/exportSQL/index.js falls back to the generic helper functions from generic.js. You'll receive basic SQL without dialect-specific optimizations, which may require manual adjustment to run on your target database.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →