MySQL exporter documentation
Overview
MySQLExporter Convert the JSON Schema generated by schema-dsl into MySQL DDL statements, including CREATE TABLE and index creation statements.
Core functions
- ✅ Generate
CREATE TABLEDDL statement - ✅ Automatic type mapping (JSON Schema → MySQL)
- ✅Support NOT NULL, DEFAULT, COMMENT
- ✅ Automatically detect primary keys
- ✅ Generate index DDL
- ✅ Configurable storage engine and character set
quick start
Output:
API reference
Constructor
Parameters:
method
export(tableName, jsonSchema)
Generate a MySQL CREATE TABLE statement.
Parameters:
tableName(string): table namejsonSchema(Object): JSON Schema object (must be of object type)
Return Value:
string: MySQL DDL statement
generateIndex(tableName, columnName, options)
Generate index creation statements.
Parameters:
tableName(string): table namecolumnName(string): column nameoptions.name(string): index name (optional, defaultidx_table_column)options.unique(boolean): Whether the index is unique (default false)
MySQLExporter.export(tableName, jsonSchema) (static method)
Fast export without instantiation.
Configuration options
storage engine
Character set configuration
Complete example
User table DDL generation
Output:
type mapping
constraint mapping
Primary key detection
The exporter automatically detects the following fields as primary keys:
- Field named
id - Field named
_id
If these fields exist, PRIMARY KEY constraints are automatically added.
Export restrictions
⚠️ IMPORTANT: MySQL has limited support for constraints.
Features not supported by MySQL:
- ❌ Regular expression constraints (
pattern) - ❌ Numerical range constraints (
minimum/maximum) - ❌ Enumeration CHECK constraints (exported as normal
VARCHAR) - ❌ Minimum string length (
minLength) - ❌ Conditional validation logic (
s.match(),s.if())
Detailed instructions: Please read Export restrictions document
Related documents
Corresponding sample file
Example entry: mysql-exporter.ts
Description: Overrides export() generation of DDL, primary key detection, and generateIndex() generation of normal/unique indexes.