@schemat/parser-dbml
v0.2.1
Published
DBML parser for Schemat (DBML schema -> IR).
Maintainers
Readme
@schemat/parser-dbml
DBML parser for Schemat: turns a DBML schema (the format used by dbdiagram.io) into the canonical Schemat IR.
Install
npm i @schemat/parser-dbmlUsage
import { dbmlParser } from "@schemat/parser-dbml";
// Detect + parse a project's DBML file into an IRSchema:
const ir = await dbmlParser.parse({ projectPath: "." });
// Or point at a specific file:
const ir2 = await dbmlParser.parse({ projectPath: ".", files: ["docs/schema.dbml"] });dbmlParser implements the SchemaParser interface (detect + parse) from
@schemat/core and returns an
IRSchema.
Detection
The parser looks for a DBML file at (in order): schema.dbml, database.dbml,
dbml/schema.dbml, docs/schema.dbml, db/schema.dbml, or any *.dbml file in
the project root.
What it maps
- Tables → tables (with table
Noteas the comment) - Fields → columns (type,
pk,unique,not null, defaults, fieldnote) - Composite
pkindexes → primary-key columns - Enums → enums
- Refs (inline
[ref: > ...]and standaloneRef:) → relations, with cardinality inferred from the DBML relation symbols (>/<= one-to-many,-= one-to-one,<>= many-to-many)
Limitations (v1)
TablePartialis not supported. The parser runs@dbml/corein itsdbmlmode, which rejects the newerTablePartialblock and the~partialinjection syntax outright — a schema using them fails to parse rather than losing a few fields. Inline the shared columns into each table until upstream support lands.- Composite uniques are not represented. A composite
pkindex promotes its columns to primary keys, but a compositeuniqueindex is dropped: marking each column individually unique would be a stronger claim than the schema makes. - Refs with unsupported endpoints are skipped, with a warning naming the ref and its schema, rather than emitted as a guessed edge.
- Table groups, project blocks, and sticky notes carry no IR meaning and are
ignored. Table and field
Notes are kept, as comments.
License
MIT © Ali Reza Hamid
