[go: up one dir, main page]

0% found this document useful (0 votes)
88 views1 page

d2 Cheat Sheet

Diagram Language Sheet

Uploaded by

Gina Raharja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views1 page

d2 Cheat Sheet

Diagram Language Sheet

Uploaded by

Gina Raharja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DECLARATIVE DIAGRAMMING (D2) CHEAT SHEET

Getting started Advanced

# introduction # special shapes


hello -> world
## classes
D2 AST Parser: {

shape: class

# labels on nodes
+prevRune: rune

hello: hi prevColumn: int

+eatSpace(eatNewlines bool): (rune, error)

# labels on connections unreadRune()

Classes have special syntax

+ for public visibility

hello -> world: bye \#scanKey(r rune): (k Key, _ error)

- for private

}
# for protected

## tables
# chained connections
board: {

a -> b -> c shape: sql_table

id: int {constraint: primary_key}

frame: int {constraint: foreign_key}

diagram: int {constraint: foreign_key}

# containers. there 2 ways of making containers board_objects: jsonb

last_updated: timestamp with time zone

last_thumbgen: timestamp with time zone

## 1st: add “.” anywhere


dsl: text

(quick and easy method)


}
aws.server
pro tip: You can define relationships between tables by:

## 2nd: create a map


diagram: {

(more structured method)


shape: sql_table

aws: {
id: int {constraint: primary_key}

server
}

}
board.diagram -> diagrams.id

pro tip: make sure you reference the


container to target a child

aws: {
# markdown and code
server

points This will create - Usually, when you give shapes a value, they’re treated as labels, e.g. `a: b`

to this a new shape - However, you can also give it a Markdown-style block syntax, or define a

labeled “server” language tag


aws.server
outside of “aws”
server
## markdown
a: |`

# Header

# reserved keywords list - This text

- Will be Markdown

myNode: {shape: circle} `|

pro tip: some keywords are reserved, for D2 renders this as Markdown text with no border.
example “label” and “shape.” You can
choose from any of these shapes:
## code
hexagon: {shape: hexagon}

queue: {shape: queue}


a: |`go

package: {shape: package}


func() {

cylinder: {shape: cylinder}


fmt.Printf("hello")

page: {shape: page}


}()

cloud: {shape: cloud} `|

etc. choose any shape in the shapes panel D2 renders this as a code block

# comments # full language specifications


# to do short one line comments https://d2-lang.com

© 2022 Terrastruct, Inc. Updated for D2 v0.12+

You might also like