### DBML Index Definitions and PostgreSQL Examples Source: https://docs.dbdiagram.io/release-notes/page/8 Shows how to define indexes in DBML, including single-field, composite, and expression-based indexes, with corresponding PostgreSQL SQL syntax examples. ```SQL CREATE INDEX Date on users (created_at) ``` ```SQL CREATE INDEX on users (created_at, country) ``` ```SQL CREATE INDEX ON users (lower(name)) ``` ```SQL CREATE INDEX ON users ( country, (lower(name)) ) ``` ```DBML Indexes { created_at [name: "Date"] (created_at, country) `lower(name)` (country,`lower(name)`) (country) [unique] booking_date [type: btree] } ``` -------------------------------- ### Example Table Group - access_control - dbdiagram Source: https://docs.dbdiagram.io/release-notes/2020-03-table-group Provides a practical example of using the Table Group syntax to create an 'access_control' group containing 'users', 'groups', and 'user_group_mapping' tables. ```dbdiagram tablegroup access_control { users groups user_group_mapping } ``` -------------------------------- ### dbdiagram: Table Group Example Source: https://docs.dbdiagram.io/release-notes/page/7 Demonstrates the practical application of table groups by creating a group named 'access_control' that includes 'users', 'groups', and 'user_group_mapping' tables. ```dbdiagram tablegroup access_control { users groups user_group_mapping } ``` -------------------------------- ### dbdiagram Composite Foreign Key Example Source: https://docs.dbdiagram.io/release-notes/2020-06-composite-foreign-key Illustrates the practical application of composite foreign keys in dbdiagram.io. It shows how to define tables and establish a relationship between them using multiple columns. ```dbdiagram Table user { id int country_code int } Table account { user_id int country_code int } Ref: user.(id, country_code) - account.(user_id, country_code) ``` -------------------------------- ### Generate DBML and Create DBdocs Project using db2dbml CLI Source: https://docs.dbdiagram.io/release-notes/2024-08-generate-dbml-from-db This snippet demonstrates how to use the `db2dbml` CLI command, part of the dbdocs CLI, to generate DBML code from a database connection and subsequently create a database documentation project within dbdocs. Ensure the dbdocs CLI is installed. ```bash db2dbml --host --port --user --password --database --output ``` -------------------------------- ### DBML TablePartial Syntax Example Source: https://docs.dbdiagram.io/release-notes/2025-04-dbml-tablepartial Demonstrates the basic usage of TablePartial in DBML to define and reuse a set of fields. This example shows how to define a 'Timestamps' partial with 'created_at' and 'updated_at' fields and then apply it to a 'Users' table. ```dbml table Users { id int [pk] name varchar ~Timestamps } ref { field [Users.id] references [Posts.user_id] } partial Timestamps { created_at timestamp updated_at timestamp } ``` -------------------------------- ### Sample DBML Diagram Structure Source: https://docs.dbdiagram.io/api/v1 This snippet shows a sample DBML (Database Markup Language) structure used to define database tables, relationships, and attributes. It includes examples of table definitions, primary keys, notes, and foreign key constraints. ```dbml // Use DBML to define your database structure // Docs: https://dbml.dbdiagram.io/docs Table follows { following_user_id integer followed_user_id integer created_at timestamp } Table users [headercolor: #79AD51] { id integer [primary key] username varchar role varchar created_at timestamp } Table posts [headercolor: #DE65C3] { id integer [primary key] title varchar body text [note: 'Content of the post'] user_id integer status varchar created_at timestamp } Ref: posts.user_id > users.id // many-to-one Ref: users.id < follows.following_user_id Ref: users.id < follows.followed_user_id ``` -------------------------------- ### Generate DBML from Database using db2dbml CLI Source: https://docs.dbdiagram.io/release-notes This snippet demonstrates the basic usage of the `db2dbml` command-line interface to generate DBML code from a database. It assumes the `dbdocs` CLI is installed, which includes `db2dbml`. The command connects to a specified database, extracts its schema, and outputs DBML code. ```bash db2dbml --db-type --host --port --user --password --database --output ``` -------------------------------- ### DBML Table with Multi-Column and Unique Indexes Source: https://docs.dbdiagram.io/release-notes/page/8 Illustrates defining a DBML table with multi-column indexes and unique constraints, showcasing a practical example. ```DBML Table products { id int [pk] name varchar merchant_id int [not null] price int status varchar created_at datetime [default: `now()`] Indexes { (merchant_id, status) [name:"product_status"] id [unique] } } ``` -------------------------------- ### Cross-Schema Relationships and Enum Usage Source: https://docs.dbdiagram.io/release-notes/2022-04-multiple-schemas This example shows how to define relationships between tables in different schemas and reference enums from other schemas. It highlights the flexibility of dbdiagram.io for complex database documentation. ```dbml Table orders { id int [pk, ref: < ecommerce.order_items.order_id] status core.order_status ... } Enum core.order_status { ... } ``` -------------------------------- ### GET /diagrams Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 Retrieves a list of all diagrams associated with your account. This endpoint is useful for fetching an overview of your diagrams. ```APIDOC ## GET /diagrams ### Description Retrieve a list of diagrams ### Method GET ### Endpoint /diagrams ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```shell curl --location 'https://api.dbdiagram.io/v1/diagrams' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` ### Response #### Success Response (200) Returns an array of Diagram objects. #### Response Example ```json [ { "id": "string", "title": "string", "url": "string", "created_at": "string", "updated_at": "string", "public": true, "owner_id": "string" } ] ``` ``` -------------------------------- ### Enum Usage Example in Table Source: https://docs.dbdiagram.io/release-notes/2019-06-enum-syntax Demonstrates how to define an Enum for order statuses and then use it as a data type for a 'status' field within the 'orders' table. This enhances data integrity and provides visual cues. ```dbdiagram Enum orders_status { created running done failure } Table orders { id int [pk] user_id int [not null, unique] status orders_status created_at varchar [note: "When order created"] } ``` -------------------------------- ### DBML Syntax for Default Column Values Source: https://docs.dbdiagram.io/release-notes/page/8 Provides examples of DBML syntax for setting default values for columns, including numeric, string, expression, and boolean types. ```DBML Table users { id integer [primary key] username varchar(255) [not null, unique] full_name varchar(255) [not null] gender varchar(1) [default: 'm'] created_at timestamp [default: `now()`] rating integer [default: 10] } ``` ```DBML Enum job_status { created running done failure } Table jobs { id integer status job_status [note: 'Status of a job', default: 'created'] } ``` -------------------------------- ### DBML Table with Composite Index and Unique Index Source: https://docs.dbdiagram.io/release-notes/2019-07-index-for-table An example of a DBML table definition that includes a composite index with a specified name and a unique index on the 'id' column. ```dbml Table products { id int [pk] name varchar merchant_id int [not null] price int status varchar created_at datetime [default: `now()`] Indexes { (merchant_id, status) [name:"product_status"] id [unique] } } ``` -------------------------------- ### Table Group Notes in DBML (Single and Multi-line) Source: https://docs.dbdiagram.io/release-notes This example shows how to add notes to table groups in DBML, supporting both single-line and multi-line Markdown content. These notes provide additional context and details about the table group's purpose. ```dbml TableGroup "User Wishlist System" [note: 'Manages the user wishlist functionality'] { ... // or use multi-line string to define Markdown content Note: ''' This group manages the user wishlist functionality. - wishlists: Stores user-specific wishlists. - wishlist_items: Contains items added to each wishlist. ''' } ``` -------------------------------- ### Retrieve Embed Link by Diagram ID (Shell) Source: https://docs.dbdiagram.io/api/v1 This command shows how to fetch an embed link for a specific diagram using its ID. It makes a GET request to the dbdiagram.io API and requires an API token for authentication. ```shell curl --location 'https://api.dbdiagram.io/v1/embed_link/:diagramId' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` -------------------------------- ### PostgreSQL Index Creation Syntax Source: https://docs.dbdiagram.io/release-notes/2019-07-index-for-table Demonstrates the SQL syntax for creating indexes in PostgreSQL, including single-field, composite, and expression-based indexes. ```sql CREATE INDEX Date on users (created_at) ``` ```sql CREATE INDEX on users (created_at, country) ``` ```sql CREATE INDEX ON users (lower(name)) ``` ```sql CREATE INDEX ON users ( country, (lower(name)) ) ``` -------------------------------- ### Create a Table Group with Color and Notes Source: https://docs.dbdiagram.io/table-groups Defines a table group named 'User Wishlist System' with a specific color and includes multi-line notes explaining its purpose and the tables it contains. This syntax is used within dbdiagram.io for project organization. ```dbdiagram TableGroup "User Wishlist System" [color: #1E69FD] { wishlists wishlist_items Note: ''' This group manages the user wishlist functionality. - wishlists: Stores user-specific wishlists. - wishlist_items: Contains items added to each wishlist. ''' } ``` -------------------------------- ### GET /embed_link/{diagramId} Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 Retrieve a specific embed link by providing the diagram ID. ```APIDOC ## GET /embed_link/{diagramId} ### Description Retrieve a specific embed link by diagramId. ### Method GET ### Endpoint /embed_link/{diagramId} ### Parameters #### Path Parameters - **diagramId** (string) - Required - The ID of the diagram to retrieve the embed link for. ### Request Example ```shell curl --location 'https://api.dbdiagram.io/v1/embed_link/:diagramId' --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` ### Response #### Success Response (200) - **EmbedLink** (object) - An object containing the embed link details. #### Response Example ```json { "embedLink": "https://dbdiagram.io/embed/your_embed_link_id" } ``` ``` -------------------------------- ### GET /v1/diagrams/{diagramId} Source: https://docs.dbdiagram.io/api/v1 Retrieves a specific diagram by its unique ID. Requires an API token for authorization. ```APIDOC ## GET /v1/diagrams/{diagramId} ### Description Retrieves a specific diagram by its unique ID. This endpoint is protected and requires an API token for authorization. ### Method GET ### Endpoint https://api.dbdiagram.io/v1/diagrams/{diagramId} ### Parameters #### Path Parameters - **diagramId** (string) - Required - The unique identifier (ObjectId) of the diagram to retrieve. Example: 664d69b5f994a43a6264b553 #### Query Parameters None #### Request Body None ### Request Example ``` curl --location 'https://api.dbdiagram.io/v1/diagrams/:diagramId' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` ### Response #### Success Response (200) - **_id** (string) - The unique identifier of the diagram. - **name** (string) - The name of the diagram. - **content** (string) - The DBML content of the diagram. - **detailLevel** (string) - The detail level of the diagram content. - **userid** (string) - The ID of the user who created the diagram. - **createdAt** (string) - The timestamp when the diagram was created. - **updatedAt** (string) - The timestamp when the diagram was last updated. #### Response Example ```json { "_id": "664447d8dc6e320126b7679f", "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: 'Content of the post']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n", "detailLevel": "All", "userid": "661601d0a5223d95b7f4aa53", "createdAt": "2022-02-01T07:00:00.000Z", "updatedAt": "2022-02-01T07:00:00.000Z" } ``` ``` -------------------------------- ### GET /v1/embed_link/{diagramId} Source: https://docs.dbdiagram.io/api/v1 Retrieves a specific embed link for a diagram by its unique ID. Requires API token authorization. ```APIDOC ## GET /v1/embed_link/{diagramId} ### Description Retrieves a specific embed link for a diagram by its unique ID. Requires API token authorization. ### Method GET ### Endpoint /v1/embed_link/{diagramId} ### Parameters #### Path Parameters - **diagramId** (string) - Required - ID of the diagram ### Request Example ```shell curl --location 'https://api.dbdiagram.io/v1/embed_link/:diagramId' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` ### Response #### Success Response (200) - **embed_link** (string) - The embed link for the specified diagram. #### Response Example ```json { "embed_link": "https://dbdiagram.io/embed/YOUR_DIAGRAM_ID" } ``` ``` -------------------------------- ### GET /diagrams/{diagramId} Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 Retrieves a specific diagram by its unique ID. This endpoint allows you to fetch the details of a saved diagram. ```APIDOC ## GET /diagrams/{diagramId} ### Description Retrieve a specific diagram by ID. ### Method GET ### Endpoint /diagrams/{diagramId} ### Parameters #### Path Parameters - **diagramId** (string) - Required - The ID of the diagram to retrieve. ### Request Example ```shell curl --location 'https://api.dbdiagram.io/v1/diagrams/:diagramId' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` ### Response #### Success Response (200) - **Diagram** (object) - Contains the details of the diagram, including its name, content, and associated metadata. #### Response Example ```json { "id": "d1", "name": "Sample Diagram", "content": "\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: 'Content of the post']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n", "detailLevel": "All", "diagram_guid": "661601d0a5223d95b7f4aa53", "workspaceId": "6646cc0af8d989b3142b7f32", "createdAt": "2022-02-01T07:00:00.000Z", "updatedAt": "2022-02-01T07:00:00.000Z" } ``` ``` -------------------------------- ### Create New Diagram using Shell Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 This snippet demonstrates how to create a new database diagram using a cURL command. It sends a POST request to the dbdiagram.io API with the diagram's name and content in DBML format. Ensure you replace 'YOUR_API_TOKEN' with your actual API token. ```Shell curl --location --request POST 'https://api.dbdiagram.io/v1/diagrams' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "name": "Sample Diagram", "content": "// Use DBML to define your database structure // Docs: https://dbml.dbdiagram.io/docs Table follows { following_user_id integer followed_user_id integer created_at timestamp } Table users [headercolor: #79AD51] { id integer [primary key] username varchar role varchar created_at timestamp } Table posts [headercolor: #DE65C3] { id integer [primary key] title varchar body text [note: '\'Content of the post\''] user_id integer status varchar created_at timestamp } Ref: posts.user_id > users.id // many-to-one Ref: users.id < follows.following_user_id Ref: users.id < follows.followed_user_id " }' ``` -------------------------------- ### Navigate Diagram Elements from Code Source: https://docs.dbdiagram.io/release-notes/2023-04-improvements-in-code-editor This snippet explains how to navigate and focus on specific elements within a diagram directly from the code editor interface. It uses keyboard commands to link code references to their visual representations in the diagram. ```General To zoom in on a table/table group/relationship, use `Cmd/Ctrl + Click` or `Cmd/Ctrl + F12`. ``` -------------------------------- ### DBML Index Definition Syntax Source: https://docs.dbdiagram.io/release-notes/2019-07-index-for-table Shows the DBML syntax for defining various types of indexes, including named, composite, expression-based, unique, and type-specific indexes. ```dbml Indexes { created_at [name: "Date"] (created_at, country) `lower(name)` (country,`lower(name)`) (country) [unique] booking_date [type: btree] } ``` -------------------------------- ### POST /v1/diagrams Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 Creates a new database diagram. You can provide a name and the database content in DBML format. ```APIDOC ## POST /v1/diagrams ### Description Creates a new database diagram. You can provide a name and the database content in DBML format. ### Method POST ### Endpoint /v1/diagrams ### Parameters #### Request Body - **name** (string) - Optional - The name of the diagram. - **content** (string) - Required - The database structure content in DBML format. ### Request Example ```json { "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: '\'Content of the post\'']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n" } ``` ### Response #### Success Response (200) - **_id** (string) - The unique identifier for the diagram. - **name** (string) - The name of the diagram. - **content** (string) - The DBML content of the diagram. - **detailLevel** (string) - The detail level of the diagram (e.g., 'All'). - **userid** (string) - The ID of the user who created the diagram. - **createdAt** (string) - The timestamp when the diagram was created. - **updatedAt** (string) - The timestamp when the diagram was last updated. - **workspaceId** (string) - Optional - The ID of the workspace if the diagram belongs to a team workspace. #### Response Example (Personal Workspace) ```json { "_id": "664447d8dc6e320126b7679f", "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: '\'Content of the post\'']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n", "detailLevel": "All", "userid": "661601d0a5223d95b7f4aa53", "createdAt": "2022-02-01T07:00:00.000Z", "updatedAt": "2022-02-01T07:00:00.000Z" } ``` #### Response Example (Team Workspace) ```json { "_id": "664447d8dc6e320126b7679f", "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n", "detailLevel": "All", "userid": "661601d0a5223d95b7f4aa53", "workspaceId": "664447d8dc6e320126b7679f", "createdAt": "2022-02-01T07:00:00.000Z", "updatedAt": "2022-02-01T07:00:00.000Z" } ``` ``` -------------------------------- ### Sample Diagram JSON Response Source: https://docs.dbdiagram.io/api/v1 This JSON object represents a sample response from the dbdiagram.io API, detailing a database diagram. It includes metadata like '_id', 'name', and 'content' (which is in DBML format), along with visualization data such as 'tables', 'tableGroups', 'stickyNoteLayouts', and 'referencePaths'. ```json { "_id": "664447d8dc6e320126b7679f", "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: 'Content of the post']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n", "detailLevel": "All", "userid": "661601d0a5223d95b7f4aa53", "workspaceId": "6646cc0af8d989b3142b7f32", "diagram": { "tables": [ { "name": "follows", "schemaName": "public", "x": -394, "y": -385 }, { "name": "users", "schemaName": "public", "x": -394, "y": -136 }, { "name": "posts", "schemaName": "public", "x": 439.80029296875, "y": -440 }, { "name": "test", "schemaName": "public", "x": -419, "y": 193 } ] }, "tableGroups": [ { "name": "people", "isCollapsed": false } ], "stickyNoteLayouts": [ { "name": "sticky_notes", "x": 249.8002929687508, "y": 193, "width": 399.5151367187492, "height": 160 } ], "referencePaths": [ { "firstFieldNames": [ "user_id" ], "firstTableName": "posts", "firstSchemaName": "public", "firstRelation": "*", "secondFieldNames": [ "id" ], "secondTableName": "users", "secondSchemaName": "public", "secondRelation": "1", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] }, { "firstFieldNames": [ "id" ], "firstTableName": "users", "firstSchemaName": "public", "firstRelation": "1", "secondFieldNames": [ "following_user_id" ], "secondTableName": "follows", "secondSchemaName": "public", "secondRelation": "*", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] }, { "firstFieldNames": [ "id" ], "firstTableName": "users", "firstSchemaName": "public", "firstRelation": "1", "secondFieldNames": [ "followed_user_id" ], "secondTableName": "follows", "secondSchemaName": "public", "secondRelation": "*", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] }, { "firstFieldNames": [ "id" ], "firstTableName": "users", "firstSchemaName": "public", "firstRelation": "1", "secondFieldNames": [ "user_id" ], "secondTableName": "test", "secondSchemaName": "public", "secondRelation": "*", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] } ], "lastPublishedDbdocsProject": {}, "createdAt": "2019-08-24T14:15:22Z", "updatedAt": "2019-08-24T14:15:22Z" } ``` -------------------------------- ### Create a new diagram Source: https://docs.dbdiagram.io/api/v1 Allows users to create a new database diagram by providing a name and the DBML content. Authentication is required via an API token. ```APIDOC ## POST /v1/diagrams ### Description Creates a new database diagram using DBML content. ### Method POST ### Endpoint https://api.dbdiagram.io/v1/diagrams ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - Required - The diagram's name - **content** (string) - Required - The DBML content of the diagram ### Request Example ```json { "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: 'Content of the post']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n" } ``` ### Response #### Success Response (200) Diagram created successfully. #### Response Example ```json { "_id": "664447d8dc6e320126b7679f", "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: 'Content of the post']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n", "detailLevel": "All", "userid": "661601d0a5223d95b7f4aa53", "workspaceId": "6646cc0af8d989b3142b7f32", "diagram": { "tables": [ { "name": "follows", "schemaName": "public", "x": -394, "y": -385 }, { "name": "users", "schemaName": "public", "x": -394, "y": -136 }, { "name": "posts", "schemaName": "public", "x": 439.80029296875, "y": -440 }, { "name": "test", "schemaName": "public", "x": -419, "y": 193 } ], "tableGroups": [ { "name": "people", "isCollapsed": false } ], "stickyNoteLayouts": [ { "name": "sticky_notes", "x": 249.8002929687508, "y": 193, "width": 399.5151367187492, "height": 160 } ], "referencePaths": [ { "firstFieldNames": [ "user_id" ], "firstTableName": "posts", "firstSchemaName": "public", "firstRelation": "*", "secondFieldNames": [ "id" ], "secondTableName": "users", "secondSchemaName": "public", "secondRelation": "1", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] }, { "firstFieldNames": [ "id" ], "firstTableName": "users", "firstSchemaName": "public", "firstRelation": "1", "secondFieldNames": [ "following_user_id" ], "secondTableName": "follows", "secondSchemaName": "public", "secondRelation": "*", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] }, { "firstFieldNames": [ "id" ], "firstTableName": "users", "firstSchemaName": "public", "firstRelation": "1", "secondFieldNames": [ "followed_user_id" ], "secondTableName": "follows", "secondSchemaName": "public", "secondRelation": "*", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] }, { "firstFieldNames": [ "id" ], "firstTableName": "users", "firstSchemaName": "public", "firstRelation": "1", "secondFieldNames": [ "user_id" ], "secondTableName": "test", "secondSchemaName": "public", "secondRelation": "*", "firstEndpointSide": null, "secondEndpointSide": null, "checkPoints": [] } ] }, "lastPublishedDbdocsProject": {}, "createdAt": "2019-08-24T14:15:22Z", "updatedAt": "2019-08-24T14:15:22Z" } ``` ``` -------------------------------- ### Access Monaco Editor Command Palette (F1) Source: https://docs.dbdiagram.io/release-notes/page/4 This snippet demonstrates how to access the command palette in the dbdiagram code editor, which is powered by Monaco Editor. It allows users to explore available shortcuts for improved productivity. ```text Press `F1` to see the command palette and explore familiar shortcuts! ``` -------------------------------- ### Create Sticky Note via DBML Code Source: https://docs.dbdiagram.io/sticky-notes This code snippet demonstrates how to create a sticky note using DBML syntax. It allows for multi-line comments within the note, facilitating detailed annotations and task assignments. ```dbml Note todoNote { '''TODO 1: David Bui to add rating to product table TODO 2: Tea Nguyen to add price to product table''' } ``` -------------------------------- ### Retrieve a list of diagrams (Shell) Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 This code snippet demonstrates how to fetch a list of diagrams using the dbdiagram Public API via a cURL command. It requires an API token for authentication and specifies the API endpoint. ```Shell curl --location 'https://api.dbdiagram.io/v1/diagrams' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' ``` -------------------------------- ### Monaco Editor Shortcuts for Code Editing Source: https://docs.dbdiagram.io/release-notes/2023-04-improvements-in-code-editor This snippet highlights common keyboard shortcuts available in the Monaco Editor, used to enhance productivity within the dbdiagram code editor. These include commands for duplicating lines, multi-selection, and accessing the command palette. ```General Press `F1` to see the command palette and explore familiar shortcuts! Enjoy shortcuts such as: * `Shift + Alt/Option + Up` to copy a line up * `Ctrl/Cmd + D` to add selection to next match ``` -------------------------------- ### DBML Auto-Increment and SQL Server/PostgreSQL/MySQL Syntax Source: https://docs.dbdiagram.io/release-notes/page/8 Demonstrates the DBML syntax for auto-increment columns and provides equivalent SQL code for PostgreSQL and MySQL. ```DBML Table users { id integer [pk, increment] name varchar [not null] } ``` ```SQL CREATE TABLE "users" ( "id" SERIAL PRIMARY KEY, "name" varchar NOT NULL ) ``` ```SQL CREATE TABLE `users` ( `id` integer PRIMARY KEY AUTO_INCREMENT, `name` varchar(255) NOT NULL ) ``` -------------------------------- ### Name Relationships in DBML Source: https://docs.dbdiagram.io/release-notes/2025-03-zero-to-many-relationship-relationship-color Illustrates the DBML syntax for naming relationships, which will appear as hover-text in the dbdiagram.io interface, aiding in the identification of connections between tables. ```dbml Ref user_posts: posts.user_id > users.id ``` -------------------------------- ### Define Enum Syntax in dbdiagram.io Source: https://docs.dbdiagram.io/release-notes/page/9 Demonstrates the syntax for defining and using enumerations (enums) within dbdiagram.io. Enums allow for predefined constants in database fields. ```dbdiagram Enum header_column { predefined_1 predefined_2 : } Table orders { id int [pk] user_id int [not null, unique] status orders_status created_at varchar [note: "When order created"] } Enum orders_status { created running done failure } ``` -------------------------------- ### Enum Syntax Definition Source: https://docs.dbdiagram.io/release-notes/2019-06-enum-syntax Defines the basic structure for creating an Enum type in dbdiagram.io. This syntax allows you to list predefined constant values for a variable. ```dbdiagram Enum header_column { predefined_1 predefined_2 : } ``` -------------------------------- ### JSON Response Sample for a Diagram Source: https://docs.dbdiagram.io/api/v1 This JSON object represents a sample successful response when retrieving a diagram. It includes the diagram's ID, name, content (defined in DBML), detail level, user ID, and timestamps for creation and updates. The 'content' field contains the database schema definition. ```json { "_id": "664447d8dc6e320126b7679f", "name": "Sample Diagram", "content": "// Use DBML to define your database structure\n// Docs: https://dbml.dbdiagram.io/docs\n\nTable follows {\n following_user_id integer\n followed_user_id integer\n created_at timestamp\n}\n\nTable users [headercolor: #79AD51] {\n id integer [primary key]\n username varchar\n role varchar\n created_at timestamp\n}\n\nTable posts [headercolor: #DE65C3] {\n id integer [primary key]\n title varchar\n body text [note: 'Content of the post']\n user_id integer\n status varchar\n created_at timestamp\n}\n\nRef: posts.user_id > users.id // many-to-one\n\nRef: users.id < follows.following_user_id\n\nRef: users.id < follows.followed_user_id\n", "detailLevel": "All", "userid": "661601d0a5223d95b7f4aa53", "createdAt": "2022-02-01T07:00:00.000Z", "updatedAt": "2022-02-01T07:00:00.000Z" } ``` -------------------------------- ### Create Embed Link - JSON Response Sample Source: https://docs.dbdiagram.io/api/v1 This JSON sample represents a successful response after creating an embed link. It includes the unique ID of the embed link, the associated diagram ID, the embed URL, and various configuration options. ```json { "_id": "664d89ff25ea4653266055f5", "diagramId": "664447d8dc6e320126b7679f", "url": "https://dbdiagram.io/e/:diagramId/:embedLinkId", "darkMode": false, "highlight": false, "detailLevel": "All", "enabled": false, "lastView": "2019-08-24T14:15:22Z", "createdAt": "2019-08-24T14:15:22Z", "updatedAt": "2019-08-24T14:15:22Z" } ``` -------------------------------- ### Create Embed Link by Diagram ID (Shell) Source: https://docs.dbdiagram.io/redocusaurus/public-api-v1 Creates a new embed link for a given diagram ID, with options for detail level, dark mode, highlighting, and enabled status. Requires an API token and JSON payload for customization. ```Shell curl --location --request POST \ 'https://api.dbdiagram.io/v1/embed_link/:diagramId' \ --header 'dbdiagram-access-token: YOUR_API_TOKEN' \ --header 'Content-Type: application/json' \ --data '{ "detailLevel": "All", "darkMode": "false", "highlight": "false", "enabled": "true" }' ``` -------------------------------- ### Monaco Editor Shortcuts for Line Manipulation Source: https://docs.dbdiagram.io/release-notes/page/4 This snippet outlines specific keyboard shortcuts available in the dbdiagram code editor (powered by Monaco Editor) for efficient line manipulation, such as copying lines up and adding selections to next matches. ```text `Shift + Alt/Option + Up` to copy a line up `Ctrl/Cmd + D` to add selection to next match ``` -------------------------------- ### Define Custom Folding Region in DBML Source: https://docs.dbdiagram.io/basic-editing-experience Demonstrates how to manually define a custom folding region within DBML code using // #region and // #endregion comments. This allows users to hide or show specific blocks of code for better focus. ```dbml // #region ... // #endregion ``` -------------------------------- ### Markdown Formatting for Table/Field Notes Source: https://docs.dbdiagram.io/release-notes/page/4 This snippet illustrates the capability to use Markdown syntax within dbdiagram's table and field notes. This allows for richer descriptions, including code blocks, sample data tables, and related URLs, improving readability and information presentation. ```text To enrich your table/field descriptions, you can now use Markdown syntax to present code blocks, sample data tables, related URLs, and so on. ``` -------------------------------- ### Define Constraints (Primary Key, Unique, Nullable) in dbdiagram.io Source: https://docs.dbdiagram.io/release-notes/page/9 Shows the syntax for specifying column constraints such as primary key, unique, null, and not null in dbdiagram.io. ```dbdiagram Table users { id integer [primary key] username varchar [not null, unique] full_name type [not null] ..... } ``` -------------------------------- ### Define Table with Schema Name Source: https://docs.dbdiagram.io/release-notes/2022-04-multiple-schemas This code snippet demonstrates how to define a table within a specific schema using dbdiagram.io syntax. It specifies the schema name followed by the table name. ```dbml Table ecommerce.order_items { ... } ``` -------------------------------- ### Add Table Group Notes (dbdiagram syntax) Source: https://docs.dbdiagram.io/release-notes/2024-09-table-group-notes-and-color This snippet shows how to add descriptive notes to a table group using the dbdiagram syntax. Notes can be single-line or multi-line Markdown content, providing context and details about the group's purpose and contents. ```dbdiagram TableGroup "User Wishlist System" [note: 'Manages the user wishlist functionality'] { // or use multi-line string to define Markdown content Note: ''' This group manages the user wishlist functionality. - wishlists: Stores user-specific wishlists. - wishlist_items: Contains items added to each wishlist. ''' } ``` -------------------------------- ### dbdiagram: Table Group Syntax Source: https://docs.dbdiagram.io/release-notes/page/7 Illustrates the syntax for creating table groups in dbdiagram, a feature for categorizing related tables. This helps in organizing complex database diagrams. ```dbdiagram tablegroup group_name { table_name1 table_name2 ... } ``` -------------------------------- ### Toggle Code Editor and Resize Shortcut Source: https://docs.dbdiagram.io/release-notes/page/4 This snippet details the keyboard shortcut to toggle the code editor's visibility and control its width, allowing it to expand up to 50% of the screen. The editor's size preference is remembered across sessions. ```text Easily toggle your code editor with the `Cmd + \` shortcut, and enable the editor to increase up to 50% of your screen width. ``` -------------------------------- ### Toggle and Resize Code Editor Source: https://docs.dbdiagram.io/release-notes/2023-04-improvements-in-code-editor This entry describes a keyboard shortcut to toggle the visibility or size of the code editor interface, allowing users to maximize screen real estate for their diagrams. The preferred editor size is persisted across sessions. ```General Easily toggle your code editor with the `Cmd + \` shortcut, and enable the editor to increase up to 50% of your screen width. Your preferred editor size will be remembered as well the next time you come back to work on your diagrams. ```