English | Español
A declarative DSL for describing database schemas.
Boldodsl is a domain-specific language, close to SQL, for describing tables, columns, constraints, and relationships.
The lexer, parser, and AST are implemented. Semantic validation and SQL generation are not implemented yet.
The lexer does not throw. Invalid characters become NOT_SUPPORTED tokens, and
the parser reports syntax errors as ParseError with the offending line and
column.
import { BoldoDSL } from "boldodsl";
const source = `
database ecommerce {
table users {
id: int primary key increment
}
}
`;
const tokens = BoldoDSL.lexer(source);
const ast = BoldoDSL.parser(source);Lexer and Parser are also exported if you need the classes directly.
The formal grammar is available in docs/grammar.md.
database ecommerce {
# Users table
table users {
id: int primary key increment
username: string not null
email: string unique
}
# Orders table
table orders {
id: int primary key increment
user_id: int not null
total: decimal
}
ref orders.user_id -> users.id many:one
}
Every schema starts with the database keyword, a name, and a block between
braces.
Each table is declared with table and a block. Each column is written as
name: type, followed by its constraints. Identifiers are normalized to
lowercase.
Keywords and type names are reserved and cannot be used as identifiers. The
reserved words are database, table, ref, primary, key, unique,
not, null, increment, one, many, int, string, decimal,
boolean, date, and datetime.
| Type | Description |
|---|---|
int |
Integer number |
string |
Text string |
decimal |
Decimal number |
boolean |
True or false |
date |
Date |
datetime |
Date and time |
| Constraint | Description |
|---|---|
primary key |
Primary key of the table |
unique |
The value cannot be repeated |
not null |
The value is required |
increment |
The value is incremented automatically |
ref orders.user_id -> users.id many:one
Cardinality is read from left to right: first the left side of the arrow.
| Cardinality | Meaning |
|---|---|
one:one |
One to one |
one:many |
One to many |
many:one |
Many to one |
many:many |
Many to many |
# Single-line comment
npm run test:run # single test run
npm run debug:lexer # token debug playground
npm run debug:parser # AST debug playground
npm run build # build dist with tsup- Formal grammar: English · Español
- Spanish README: README.es.md
MIT