🧠 Second Brain

Search

Search IconIcon to open search

DBML

Last updated Aug 5, 2024

DBML (Database Markup Language) is an open-source DSL language designed to define and document database schemas and structures. It is designed to be simple, consistent, and highly readable.

It also comes with a command-line tool and open-source module to help you convert between DBML and SQL.

# Benefits

# Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Table users {
    id integer
    username varchar
    role varchar
    created_at timestamp
}

Table posts {
    id integer [primary key]
    title varchar
    body text [note: 'Content of the post']
    user_id integer
    created_at timestamp
}

Ref: posts.user_id > users.id // many-to-one

More on GitHub and DBML - Full Syntax Docs | DBML.

See the above dbml doc  visualized on dbdiagram, DBDiagram has a beautiful integration into it.

Used at the Airbyte’s first Hack Days building the ERDs, e.g. dbdocs.io - Database Documentation and Catalog Tool as an example.

# DDL to DBML conversion

Import from Postgres:

# With DbBeaver export

Mark tables and right click -> Tools -> Backup

and then these settings for an equivalent of pg_dump -h <host> -p <port> -d <database_name> -U <username> -s -F p -E UTF-8 -f <output_path>:

Origin: Crafting an Automatic ERD Generator: A Journey from DDL to Diagram | by DevTools Daily | Medium

# Integrations


Origin:
References:
Created 2022-09-22