### Install ANTLR4 Tools using pip (Bash) Source: https://github.com/holistics/dbml/blob/master/packages/dbml-core/src/parse/ANTLR/README.md Installs the ANTLR4 tools package using pip, the Python package installer. This is the first step in setting up the ANTLR4 environment. The comment suggests running `antlr4` after installation to verify and get help. ```bash pip install antlr4-tools # Run antlr4 to check the version and help ``` -------------------------------- ### Example: Running Tests for @dbml/cli Source: https://github.com/holistics/dbml/blob/master/CONTRIBUTING.md An example demonstrating how to run tests specifically for the @dbml/cli package using Lerna, including the command and its typical output. ```Shell lerna run test --scope @dbml/cli info cli using local version of lerna lerna notice cli v3.16.4 lerna info filter [ '@dbml/cli' ] lerna info Executing command in 1 package: "yarn run test" lerna info run Ran npm script 'test' in '@dbml/cli' in 82.1s: yarn run v1.17.3 $ jest Done in 81.28s. lerna success run Ran npm script 'test' in 1 package in 82.1s: lerna success - @dbml/cli ``` -------------------------------- ### Installing @dbml/core Source: https://github.com/holistics/dbml/blob/master/packages/dbml-core/README.md Instructions for installing the @dbml/core library using npm or yarn package managers. ```bash npm install @dbml/core ``` ```bash yarn add @dbml/core ``` -------------------------------- ### Example DBML Syntax Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md A basic example demonstrating table definitions for 'users' and 'posts' with columns, settings (primary key, note), and a many-to-one relationship defined using 'Ref'. ```text 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 ``` -------------------------------- ### Install @dbml/cli Source: https://github.com/holistics/dbml/blob/master/packages/dbml-cli/README.md These commands demonstrate different methods to install or run the @dbml/cli tool globally using npm or yarn, or directly execute it using npx. ```shell npm install -g @dbml/cli ``` ```shell yarn global add @dbml/cli ``` ```shell npx -p @dbml/cli dbml2sql schema.dbml -o schema.sql ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/README.md Installs the necessary project dependencies using the Yarn package manager. This command should be run after cloning the repository. ```Shell yarn ``` -------------------------------- ### Full DBML TablePartial Example Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md A comprehensive example demonstrating the definition of multiple TablePartials and their injection into a table definition. ```text TablePartial base_template [headerColor: #ff0000] { id int [pk, not null] created_at timestamp [default: `now()`] updated_at timestamp [default: `now()`] } TablePartial soft_delete_template { delete_status boolean [not null] deleted_at timestamp [default: `now()`] } TablePartial email_index { email varchar [unique] indexes { email [unique] } } Table users { ~base_template ~email_index name varchar ~soft_delete_template } ``` -------------------------------- ### Navigate to Parser Directory (Bash) Source: https://github.com/holistics/dbml/blob/master/packages/dbml-core/src/parse/ANTLR/README.md Changes the current directory to the specific location where the new ANTLR parser files for PostgreSQL are intended to be placed within the project structure. This is a prerequisite for running the ANTLR4 commands in the next step. ```bash cd packages/dbml-core/src/parse/ANTLR/parsers/postgresql ``` -------------------------------- ### Start Local Development Server with Yarn Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/README.md Starts a local development server for the Docusaurus website. It automatically opens a browser window and reflects most changes live without requiring a server restart. ```Shell yarn dev ``` -------------------------------- ### Installing @dbml/connector (bash) Source: https://github.com/holistics/dbml/blob/master/packages/dbml-connector/README.md Commands to install the @dbml/connector package using either npm or yarn package managers. ```bash npm install @dbml/connector # or if you're using yarn yarn add @dbml/connector ``` -------------------------------- ### Install DBML CLI via npm Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Installs the DBML Command Line Interface globally using npm. This makes the `dbml2sql`, `sql2dbml`, and `db2dbml` commands available in your terminal. ```bash npm install -g @dbml/cli ``` -------------------------------- ### Installing Yarn and Lerna (Global) Source: https://github.com/holistics/dbml/blob/master/CONTRIBUTING.md Instructions to install Yarn and Lerna globally on your system using either npm or yarn's global command. ```Shell npm install -g yarn lerna ``` ```Shell yarn global add lerna ``` -------------------------------- ### Install @dbml/core with npm Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This command installs the @dbml/core package using the npm package manager, making its functionalities available for use in your project. ```bash npm install @dbml/core ``` -------------------------------- ### Generate JavaScript Parser Files (Bash) Source: https://github.com/holistics/dbml/blob/master/packages/dbml-core/src/parse/ANTLR/README.md Runs the ANTLR4 tool to generate parser and lexer files from the specified grammar files (`` and ``). The `-Dlanguage=JavaScript` flag specifies the target language for the generated code, `-no-listener` disables listener generation, and `-visitor` enables visitor generation, which is required for writing the AST visitor. ```bash antlr4 -Dlanguage=JavaScript -no-listener -visitor antlr4 -Dlanguage=JavaScript -no-listener -visitor ``` -------------------------------- ### Cloning and Building DBML Source: https://github.com/holistics/dbml/blob/master/CONTRIBUTING.md Steps to clone the DBML repository from GitHub, navigate into the project directory, install dependencies using yarn, and build the project. ```Shell git clone cd dbml yarn install yarn build ``` -------------------------------- ### Installing @dbml/connector package - Bash Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/connector.md Installs the @dbml/connector package using npm, making it available for use in your project. Requires Node.js 18.0.0 or higher. ```bash npm install @dbml/connector ``` -------------------------------- ### Generate DBML from Database (PostgreSQL) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Connects directly to a database using a connection string and generates DBML based on its schema. This example connects to a PostgreSQL database and prints the output to the console. ```bash $ db2dbml postgres 'postgresql://dbml_user:dbml_pass@localhost:5432/dbname?schemas=public' Table "staff" { "id" int4 [pk, not null] "name" varchar "age" int4 "email" varchar } ... ``` -------------------------------- ### Defining Sticky Notes in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Examples of defining standalone sticky notes on the diagram canvas, including single-line and multi-line formats. ```text Table jobs { ... } Note single_line_note { 'This is a single line note' } Note multiple_lines_note { ''' This is a multiple lines note This string can spans over multiple lines. ''' } ``` -------------------------------- ### Generate DBML from PostgreSQL SQL using importer.import Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This example demonstrates how to read a PostgreSQL SQL file and use the `importer.import` method to convert its content into the DBML format. It requires the 'fs' module to read the file. ```javascript const fs = require('fs'); const { importer } = require('@dbml/core'); // read PostgreSQL file script const postgreSQL = fs.readFileSync('./schema.sql', 'utf-8'); // generate DBML from PostgreSQL script const dbml = importer.import(postgreSQL, 'postgres'); ``` -------------------------------- ### DBML TablePartial Injection Result Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows the resulting table definition after injecting the TablePartials from the previous example, illustrating how partials are merged. ```text Table users [headerColor: #ff0000] { id int [pk, not null] created_at timestamp [default: `now()`] updated_at timestamp [default: `now()`] email varchar [unique] name varchar delete_status boolean [not null] deleted_at timestamp [default: `now()`] indexes { email [unique] } } ``` -------------------------------- ### Defining TableGroup in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Provides the basic syntax and an example for grouping related tables using the TableGroup keyword. ```text TableGroup tablegroup_name { // tablegroup is case-insensitive. table1 table2 table3 } // example TableGroup e_commerce1 { merchants countries } ``` -------------------------------- ### Convert DBML to SQL (Output to File) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Converts a DBML file to SQL and saves the output to a specified file using the `-o` or `--out-file` option. This example saves the PostgreSQL output to `schema.sql`. ```bash $ dbml2sql schema.dbml -o schema.sql ✔ Generated SQL dump file (PostgreSQL): schema.sql ``` -------------------------------- ### Parse DBML to Database object using parser.parse Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This example reads a DBML file and uses the `parser.parse` method to convert the DBML content into a structured `Database` object, which can then be further processed or exported. ```javascript const fs = require('fs'); const { Parser } = require('@dbml/core'); const parser = new Parser(); // get DBML file content const dbml = fs.readFileSync('./schema.dbml', 'utf-8'); // parse DBML to Database object const database = parser.parse(dbml, 'dbml'); ``` -------------------------------- ### Export DBML to MySQL SQL using exporter.export Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This example demonstrates reading a DBML file and using the `exporter.export` method to convert its content into a MySQL SQL script. It requires the 'fs' module to read the file. ```javascript const fs = require('fs'); const { exporter } = require('@dbml/core'); // get DBML file content const dbml = fs.readFileSync('./schema.dbml', 'utf-8'); // generate MySQL from DBML const mysql = exporter.export(dbml, 'mysql'); ``` -------------------------------- ### Setting Default Values for DBML Table Columns Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates the syntax for setting default values for columns in DBML, showing examples for number, string (using single quotes), expression (using backticks), and boolean/null values. ```text Table users { id integer [primary key] username varchar(255) [not null, unique] full_name varchar(255) [not null] gender varchar(1) [not null] source varchar(255) [default: 'direct'] created_at timestamp [default: `now()`] rating integer [default: 10] } ``` -------------------------------- ### DBML Multi-line String Output Example Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows the resulting string value after parsing a multi-line string defined with triple single quotes ('''). The parser automatically removes the minimum number of leading spaces among all lines from the final output. ```DBML This is a block string This string can spans over multiple lines. ``` -------------------------------- ### Preview Local Build with Yarn Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/README.md Serves the static content generated by the build command locally. This allows previewing the production version of the site before deployment. Ensure 'yarn build' is run first. ```Shell yarn serve ``` -------------------------------- ### db2dbml Command Syntax Manual Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Provides the general command-line syntax for the `db2dbml` tool, showing the required database type and connection string arguments, and the optional flag for specifying the output file. ```bash $ db2dbml postgres|mysql|mssql|snowflake|bigquery [-o|--out-file ] ``` -------------------------------- ### sql2dbml Command Syntax Manual Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Provides the general command-line syntax for the `sql2dbml` tool, showing required arguments (input file) and optional flags for specifying the input SQL dialect and output file. ```bash $ sql2dbml [--mysql|--postgres|--mssql|--postgres-legacy|--mysql-legacy|--mssql-legacy|--snowflake] [-o|--out-file ] ``` -------------------------------- ### dbml2sql Command Syntax Manual Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Provides the general command-line syntax for the `dbml2sql` tool, showing required arguments (input file) and optional flags for specifying the output dialect and output file. ```bash $ dbml2sql [--mysql|--postgres|--mssql|--oracle] [-o|--out-file ] ``` -------------------------------- ### Build Static Website with Yarn Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/README.md Generates the static content for the website into the 'build' directory. The output can then be served using any static content hosting service. ```Shell yarn build ``` -------------------------------- ### Format Code with Yarn Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/README.md Runs a command to automatically format the project's code, ensuring consistent style before committing changes. ```Shell yarn format ``` -------------------------------- ### Recommended DBML File Structure Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/home.md This snippet illustrates the recommended file structure for including a `database.dbml` file within a project's root repository. It suggests placing the DBML schema definition alongside other configuration and boilerplate files like `README.md` for easy access and consistency. ```text . |_ ... |_ database.dbml |_ README.md ``` -------------------------------- ### Generate DBML from Database (Output to File) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Connects to a database using a connection string and generates DBML, saving the output to a specified file using the `-o` option. ```bash $ db2dbml postgres 'postgresql://dbml_user:dbml_pass@localhost:5432/dbname?schemas=public' -o schema.dbml ✔ Generated DBML file from database's connection: schema.dbml ``` -------------------------------- ### Running Tests for All Packages Source: https://github.com/holistics/dbml/blob/master/CONTRIBUTING.md Command to execute the test script defined in the package.json for all packages within the monorepo using Lerna. ```Shell lerna run test ``` -------------------------------- ### Defining a DBML Project Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Syntax for defining a project in DBML, including specifying the database type and adding a project-level note. ```text Project project_name { database_type: 'PostgreSQL' Note: 'Description of the project' } ``` -------------------------------- ### Applying Settings to a DBML Table Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to add settings to a table definition using square brackets, such as changing the header color or applying column-level settings like 'primary key', 'not null', and 'unique'. ```text Table users [headercolor: #3498DB] { id integer [primary key] username varchar(255) [not null, unique] } ``` -------------------------------- ### Running Tests for a Specific Package Source: https://github.com/holistics/dbml/blob/master/CONTRIBUTING.md Command to execute the test script for a single, specified package within the monorepo using Lerna's --scope option. ```Shell lerna run test --scope ``` -------------------------------- ### Adding TableGroup Settings in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Demonstrates how to apply settings like color to a TableGroup definition using square brackets. ```text TableGroup e_commerce [color: #345] { merchants countries } ``` -------------------------------- ### Defining Project Note in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Demonstrates how to add a multi-line note to a DBML project definition, providing a general description and benefits. ```text Project DBML { Note: ''' # DBML - Database Markup Language DBML (database markup language) is a simple, readable DSL language designed to define database structures. ## Benefits * It is simple, flexible and highly human-readable * It is database agnostic, focusing on the essential database structure definition without worrying about the detailed syntaxes of each database * Comes with a free, simple database visualiser at [dbdiagram.io](http://dbdiagram.io) ''' } ``` -------------------------------- ### Defining a Schema and Table in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to define a table within a specific schema by prefixing the table name with the schema name. ```text Table core.user { ... } ``` -------------------------------- ### Convert SQL to DBML (Output to File) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Converts a SQL file to DBML format for a specified dialect (MySQL in this case) and saves the output to a file using the `-o` option. ```bash $ sql2dbml --mysql dump.sql -o mydatabase.dbml ✔ Generated DBML file from SQL file (MySQL): mydatabase.dbml ``` -------------------------------- ### Adding Settings to DBML Relationships Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Explains how to apply settings like referential actions (`delete`, `update`) and visual properties (`color`) to relationships defined using the short or long `Ref` syntax. Settings are enclosed in square brackets after the relationship definition. ```text // short form Ref: products.merchant_id > merchants.id [delete: cascade, update: no action, color: #79AD51] // long form Ref { products.merchant_id > merchants.id [delete: cascade, update: no action, color: #79AD51] } ``` -------------------------------- ### Defining DBML Table Columns with Settings Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Demonstrates how to apply optional settings such as unique, not null, primary key (pk), default values, and notes to columns within a DBML table definition using square brackets. ```text Table buildings { ... address varchar(255) [unique, not null, note: 'to include unit number'] id integer [ pk, unique, default: 123, note: 'Number' ] } ``` -------------------------------- ### Convert SQL to DBML (PostgreSQL Default) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Converts a SQL dump file into DBML format. The `--postgres` flag specifies the input SQL dialect. The resulting DBML is printed to the console. ```bash $ sql2dbml dump.sql --postgres Table staff { id int [pk] name varchar age int email varchar } ... ``` -------------------------------- ### DBML TablePartial Usage Syntax Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates how to inject a defined TablePartial into a table definition using the `~` prefix. ```text Table table_name { ~partial_name field_name field_type ~another_partial } ``` -------------------------------- ### Import and instantiate Parser from @dbml/core Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This snippet imports the `Parser` class from @dbml/core and creates a new instance, which is used to parse various schema formats into a `Database` object representation. ```javascript const { Parser } = require('@dbml/core'); const parser = new Parser(); ``` -------------------------------- ### Defining Database Schema with DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/home.md This DBML snippet demonstrates how to define database tables, enums, and relationships. It includes definitions for 'users' and 'posts' tables with various column types and constraints, an 'post_status' enum, and a many-to-one reference between 'posts.user_id' and 'users.id'. This declarative syntax simplifies schema documentation and understanding. ```DBML 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 status post_status created_at timestamp } Enum post_status { draft published private [note: 'visible via URL only'] } Ref: posts.user_id > users.id // many-to-one ``` -------------------------------- ### Defining Database Schema with DBML Source: https://github.com/holistics/dbml/blob/master/README.md This snippet demonstrates how to define a database schema using DBML. It includes the creation of two tables, 'users' and 'posts', specifying their columns, data types, and constraints (like primary key). It also illustrates how to define a many-to-one relationship between the 'posts' table (user_id) and the 'users' table (id). ```DBML 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 ``` -------------------------------- ### Convert DBML to SQL (Specify Dialect) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Converts a DBML file into SQL statements for a specific database dialect, such as MySQL, using the `--mysql` flag. The output is printed to the console. ```bash $ dbml2sql schema.dbml --mysql CREATE TABLE `staff` ( `id` INT PRIMARY KEY, `name` VARCHAR(255), `age` INT, `email` VARCHAR(255) ); ... ``` -------------------------------- ### DBML TablePartial Definition Syntax Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows the syntax for defining a reusable TablePartial, including fields, settings, and indexes. ```text TablePartial partial_name [table_settings] { field_name field_type [field_settings] indexes { (column_name) [index_settings] } } ``` -------------------------------- ### Aliasing Tables in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Demonstrates how to assign an alias to a table using the 'as' keyword, which can then be used in relationship definitions. ```text Table very_long_user_table as U { ... } Ref: U.id < posts.user_id ``` -------------------------------- ### Convert DBML to SQL (PostgreSQL Default) Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Converts a DBML file into SQL statements. By default, it generates SQL compatible with PostgreSQL and prints the output to the console. ```bash $ dbml2sql schema.dbml CREATE TABLE "staff" ( "id" INT PRIMARY KEY, "name" VARCHAR, "age" INT, "email" VARCHAR ); ... ``` -------------------------------- ### Defining Composite Foreign Keys in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to define a relationship based on multiple columns (composite foreign key) using the short form `Ref` syntax, listing the columns within parentheses. ```text Ref: merchant_periods.(merchant_id, country_code) > merchants.(id, country_code) ``` -------------------------------- ### Basic DBML Table Definition Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Syntax for defining tables, both in the default 'public' schema and within a specified schema, including column definitions with types and optional settings. ```text // table belonged to default "public" schema Table table_name { column_name column_type [column_settings] } // table belonged to a schema Table schema_name.table_name { column_name column_type [column_settings] } ``` -------------------------------- ### Defining Cross-Schema Relationships in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates how to define relationships between tables residing in different schemas by prefixing table names with their schema name (e.g., `schema.table`). Both inline and short `Ref` syntaxes are shown. ```text Table core.users { id integer [pk] } Table blogging.posts { id integer [pk] user_id integer [ref: > core.users.id] } // or this Ref: blogging.posts.user_id > core.users.id ``` -------------------------------- ### Generate DBML from DatabaseSchema object using importer.generateDbml Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This snippet shows how to use the `importer.generateDbml` method to create a DBML string from a `DatabaseSchema` object, typically obtained using the @dbml/connector package. ```javascript const { importer } = require('@dbml/core'); const { connector } = require('@dbml/connector'); // Use the dbml connector to get the DatabaseSchema object const connection = 'postgresql://dbml_user:dbml_pass@localhost:5432/dbname?schemas=public'; const databaseType = 'postgres'; const schemaJson = await connector.fetchSchemaJson(connection, databaseType); // Generate DBML from the DatabaseSchema object const dbml = importer.generateDbml(schemaJson); ``` -------------------------------- ### Adding Notes to a DBML Table Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Syntax for including a descriptive note directly within a table definition, providing context for the table's purpose. ```text Table users { id integer status varchar [note: 'status'] Note: 'Stores user data' } ``` -------------------------------- ### Defining Indexes in DBML Tables Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to define various types of indexes within the 'indexes' block of a DBML table definition, including single-column, composite, and expression-based indexes, along with specifying index settings like primary key (pk), name, unique, and type. ```text Table bookings { id integer country varchar booking_date date created_at timestamp indexes { (id, country) [pk] // composite primary key created_at [name: 'created_at_index', note: 'Date'] booking_date (country, booking_date) [unique] booking_date [type: hash] (`id*2`) (`id*3`,`getdate()`) (`id*3`,id) } } ``` -------------------------------- ### Importing connector module - JavaScript Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/connector.md Imports the 'connector' object from the '@dbml/connector' package using the Node.js require syntax. This object provides methods for interacting with databases. ```javascript const { connector } = require('@dbml/connector'); ``` -------------------------------- ### Fetching database schema JSON - JavaScript Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/connector.md Uses the 'connector.fetchSchemaJson' method to connect to a specified database and retrieve its schema information as a DatabaseSchema object. Requires a connection string and database type. ```javascript const { connector } = require('@dbml/connector'); const connection = 'postgresql://dbml_user:dbml_pass@localhost:5432/dbname?schemas=public'; const databaseType = 'postgres'; const schemaJson = await connector.fetchSchemaJson(connection, databaseType); ``` -------------------------------- ### BigQuery JSON Credential File Format Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/cli.md Specifies the required JSON format for the credential file used when generating DBML from a Google BigQuery database via the `db2dbml` command. ```json { "project_id": "your-project-id", "client_email": "your-client-email", "private_key": "your-private-key", "datasets": ["dataset_1", "dataset_2", ...] } ``` -------------------------------- ### Export Database object to PostgreSQL SQL using ModelExporter.export Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This snippet demonstrates how to use the static `ModelExporter.export` method to convert a `Database` object (obtained from parsing) into a PostgreSQL SQL string. It shows both exporting the raw object and a normalized version. ```javascript const { ModelExporter, Parser } = require('@dbml/core'); // get DBML file content const dbml = fs.readFileSync('./schema.dbml', 'utf-8'); // parse DBML to Database object const parser = new Parser(); const database = parser.parse(dbml, 'dbml'); // Export Database object to PostgreSQL const postgreSQL = ModelExporter.export(database, 'postgres', false); // or const postgreSQL = ModelExporter.export(database.normalize(), 'postgres'); ``` -------------------------------- ### Import importer from @dbml/core Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This line imports the `importer` object from the @dbml/core package, which is used for generating DBML from various input formats like SQL or a DatabaseSchema object. ```javascript const { importer } = require('@dbml/core'); ``` -------------------------------- ### Defining Inline One-to-One Relationship in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Demonstrates the inline syntax for defining a one-to-one relationship (`-`) where the column with the `ref` definition (`user_id` in `user_infos`) is treated as the foreign key. ```text Table user_infos { user_id integer [ref: - users.id] } ``` -------------------------------- ### Adding Single-Line Table Note in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to add a single-line note directly within a table definition to describe its purpose. ```text Table users { id int [pk] name varchar Note: 'Stores user data' } ``` -------------------------------- ### Adding Notes to DBML Elements Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Explains how to add descriptive notes to DBML elements like tables using either a short form with a colon or a long form with curly braces. Notes are string values. ```text Table users { id int [pk] name varchar Note: 'This is a note of this table' // or Note { 'This is a note of this table' } } ``` -------------------------------- ### Adding Multi-Line Column Note in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates adding a multi-line note to a column definition, useful for enumerating possible values or detailed descriptions. ```text Table orders { status varchar [ note: ''' 💸 1 = processing, ✔️ 2 = shipped, ❌ 3 = cancelled, 😔 4 = refunded '''] } ``` -------------------------------- ### Adding TableGroup Note in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to add a note to a TableGroup definition, either inline using the note setting or using the Note keyword within the group block. ```text TableGroup e_commerce [note: 'Contains tables that are related to e-commerce system'] { merchants countries // or Note: 'Contains tables that are related to e-commerce system' } ``` -------------------------------- ### Import exporter from @dbml/core Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/js-module/core.md This line imports the `exporter` object from the @dbml/core package, which is used for converting DBML content into various SQL dialects. ```javascript const { exporter } = require('@dbml/core'); ``` -------------------------------- ### Defining Zero-to Relationships in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how zero-to-one or zero-to-many relationships are implicitly defined by combining the relationship symbol (`>`) with the column's nullable constraint (`null` or `not null`). ```text Table follows { following_user_id int [ref: > users.id] // many-to-zero followed_user_id int [ref: > users.id, null] // many-to-zero } Table posts { id int [pk] user_id int [ref: > users.id, not null] // many-to-one } ``` -------------------------------- ### Defining Inline Relationships in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates how to define many-to-one and one-to-many relationships directly within table column definitions using the `ref` keyword and relationship symbols (`>`, `<`). Multiple relationships can be defined on a single column. ```text Table posts { id integer [primary key] user_id integer [ref: > users.id] // many-to-one } // or this Table users { id integer [ref: < posts.user_id, ref: < reviews.user_id] // one to many } // The space after '<' is optional ``` -------------------------------- ### Defining DBML Multi-line String Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Demonstrates how to define a multi-line string value in DBML using triple single quotes ('''). The content between the quotes can span multiple lines, and leading indentation is handled automatically by the parser. ```DBML Note: ''' This is a block string This string can spans over multiple lines. ''' ``` -------------------------------- ### DBML Relationship Definition Syntaxes Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Presents the three main syntaxes for defining relationships in DBML: the verbose long form using curly braces, the concise short form using a colon, and the inline form within a table column definition. ```text // Long form Ref name_optional { schema1.table1.column1 < schema2.table2.column2 } // Short form Ref name_optional: schema1.table1.column1 < schema2.table2.column2 // Inline form Table schema2.table2 { id integer column2 integer [ref: > schema1.table1.column1] } ``` -------------------------------- ### DBML Single-line Comment Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates how to add a single-line comment in DBML using double forward slashes (//). Comments are used for code documentation and review, and they extend to the end of the line. ```DBML // order_items refer to items from that order ``` -------------------------------- ### Defining Enums in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to define custom enum types with a list of allowed values. Enums can belong to the default schema or a specified schema and can include notes for individual values. Tables can then use these enums as column types. ```text // enum belonged to default "public" schema enum job_status { created [note: 'Waiting to be processed'] running done failure } // enum belonged to a schema enum v2.job_status { ... } Table jobs { id integer status job_status status_v2 v2.job_status } ``` -------------------------------- ### DBML Column Note Syntax Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Provides the basic syntax for adding a note to a column definition in DBML. ```text column_name column_type [note: 'replace text here'] ``` -------------------------------- ### DBML Multi-line Comment Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Shows how to define a multi-line comment block in DBML by enclosing the comment text within /* and */. This is useful for longer explanations or temporarily disabling blocks of code across multiple lines. ```DBML /* This is a Multi-lines comment */ ``` -------------------------------- ### Defining Enums with Special Characters in DBML Source: https://github.com/holistics/dbml/blob/master/dbml-homepage/docs/docs.md Illustrates how to define enum values that contain spaces or other special characters by enclosing the values in double quotes. ```text enum grade { "A+" "A" "A-" "Not Yet Set" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.