AI-Ready Data Modeling Language - Independent AIR-DML parser with zero dependencies
npm install air-dmlArea
bash
npm install air-dml
`
Quick Start
`typescript
import { parseAirDML, exportToAirDML } from 'air-dml';
// Parse AIR-DML text
const airDmlText =
;
const diagram = parseAirDML(airDmlText);
console.log(diagram);
// Export back to AIR-DML
const output = exportToAirDML(diagram);
console.log(output);
`
AIR-DML Syntax
$3
`dbml
Table table_name [alias: "論理名", pos_x: 100, pos_y: 200, color: "#1976D2"] {
column_name data_type [constraints, alias: "カラム論理名"]
Note: "テーブルの説明"
}
`
$3
| Constraint | Description | Example |
|------------|-------------|---------|
| pk | Primary Key | id serial [pk] |
| fk | Foreign Key (use with Ref) | user_id integer [fk] |
| unique | Unique constraint | email varchar [unique] |
| not null | NOT NULL constraint | name varchar [not null] |
| increment | Auto increment | id integer [pk, increment] |
| alias: "name" | Logical name | [alias: "ユーザーID"] |
| note: "desc" | Column description | [note: "説明"] |
$3
`dbml
Ref: table_a.column > table_b.column // Many-to-One (A → B)
Ref: table_a.column < table_b.column // One-to-Many (A ← B)
Ref: table_a.column - table_b.column // One-to-One
Ref: table_a.column >< table_b.column // Many-to-Many
Ref: table_a.column ~ table_b.column // AI-inferred (undetermined)
`
$3
`dbml
Area "Area Name" [
pos_x: 50,
pos_y: 50,
width: 600,
height: 300,
color: "#1976D2"
] {
table1
table2
database_type: "PostgreSQL"
CommonColumns: [
created_at timestamp [not null, alias: "作成日時"]
updated_at timestamp [not null, alias: "更新日時"]
]
Note: "Area description"
}
`
AI Generation Guidelines
When using AI to generate AIR-DML, follow these rules:
Required:
- Use double quotes for alias values: alias: "論理名" ✅
- Do NOT use single quotes: alias: '論理名' ❌
- Mark foreign key columns with [fk]
- Define relationships separately with Ref:
- Do NOT add inline comments after column definitions
Example Output:
`dbml
// 定期購入機能
Table subscriptions [alias: "定期購入"] {
id serial [pk, alias: "定期購入ID"]
user_id integer [fk, not null, alias: "ユーザーID"]
product_id integer [fk, not null, alias: "商品ID"]
status text [not null, alias: "ステータス"]
created_at timestamp [not null, alias: "作成日時"]
}
Ref: subscriptions.user_id > users.id
Ref: subscriptions.product_id > products.id
`
For complete AI generation guidelines, see SPECIFICATION.md Section 5.
API Reference
$3
Parse AIR-DML text into a Diagram object.
Parameters:
- airDmlText - AIR-DML formatted text
- diagramId - Optional diagram ID
Returns: Diagram object
$3
Export a Diagram object to AIR-DML text.
Parameters:
- diagram - Diagram object
Returns: AIR-DML formatted text
Type Definitions
`typescript
interface Diagram {
id: string;
name: string;
project?: string;
database?: string;
tables: Table[];
references: Reference[];
areas?: Area[];
createdAt?: string;
updatedAt?: string;
note?: string;
}
interface Table {
id: string;
name: string;
logicalName?: string; // alias
columns: Column[];
color?: string;
pos?: Position;
areaIds?: string[];
note?: string;
leadingComments?: string[]; // v1.2.0+
}
interface Column {
name: string;
logicalName?: string; // alias
type: DataType;
typeParams?: string;
pk?: boolean;
fk?: boolean;
unique?: boolean;
notNull?: boolean;
increment?: boolean;
note?: string;
leadingComments?: string[]; // v1.2.0+
}
interface Reference {
id: string;
fromTable: string;
fromColumn: string;
toTable: string;
toColumn: string;
type: RelationshipType;
swapEdge?: boolean;
leadingComments?: string[]; // v1.2.0+
}
interface Area {
id: string;
name: string;
tables: string[];
color?: string;
pos?: Position;
width?: number;
height?: number;
labelHorizontal?: 'left' | 'center' | 'right';
labelVertical?: 'top' | 'center' | 'bottom';
databaseType?: string;
commonColumns?: Column[];
note?: string;
leadingComments?: string[]; // v1.2.0+
}
`
Comparison: DBML vs AIR-DML
| Feature | DBML | AIR-DML |
|---------|------|---------|
| Focus | Database schema | AI-ready + Business context |
| Logical names | ❌ | ✅ alias attribute |
| Area management | TableGroup (basic) | Area (extended: CommonColumns, database_type) |
| Visual info | ❌ | ✅ Coordinates, colors, sizes |
| Multi-DB | Project-level | Area-level (polyglot persistence) |
| AI optimization | ❌ | ✅ LLM-friendly design |
| Comment preservation | ❌ | ✅ Leading comments (v1.2.0+) |
Changelog
$3
- Breaking: Removed default column constraint from syntax
- Simplified parser by removing inconsistent quote handling for default values
$3
- Major: Replaced @dbml/core dependency with custom hand-written recursive descent parser
- Full AIR-DML syntax support without external dependencies
- Improved error messages in Japanese
- Better handling of Japanese identifiers and comments
$3
- Bug fixes for Area parsing with Japanese names
- Improved comment preservation
- Added AI generation guidelines to specification
$3
- Added leading comment preservation for Tables, References, and Areas
- Added leadingComments field to type definitions
- Export comments back to AIR-DML format
$3
- Added labelHorizontal and labelVertical attributes for Areas
- Added swapEdge` attribute for References