Skip to content
freddyhcodePublic

About

DSL for defining database schemas.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

26 Commits

Folders and files

Repository files navigation

Boldodsl

English | Español

Status TypeScript Node npm License

A declarative DSL for describing database schemas.

What is Boldodsl?

Boldodsl is a domain-specific language, close to SQL, for describing tables, columns, constraints, and relationships.

Status

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.

Usage

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.

Syntax

The formal grammar is available in docs/grammar.md.

Example

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
}

Database

Every schema starts with the database keyword, a name, and a block between braces.

Tables and columns

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.

Reserved words

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.

Types

Type Description
int Integer number
string Text string
decimal Decimal number
boolean True or false
date Date
datetime Date and time

Constraints

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

Relationships

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

Comments

# Single-line comment

Development

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

Documentation

License

MIT

About

DSL for defining database schemas.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages