forked from duythinht/dbml-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.dbml
140 lines (117 loc) · 2.69 KB
/
test.dbml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//// -- LEVEL 1
//// -- Tables and References
Project test {
database_type: 'PostgreSQL'
Note: 'Description of the project'
}
// Creating tables
Table users as U {
id int [pk, unique, increment] // auto-increment
full_name varchar [not null, unique, default: 1]
created_at timestamp
country_code int
type int
note int
Note: 'khong hieu duoc'
}
Table merchants {
id int [pk]
merchant_name varchar
country_code int [not null]
'created at' varchar
admin_id int [ref: > U.id] // inline relationship (many-to-one)
}
Table countries {
code int [pk]
name varchar
continent_name varchar
}
Table Action {
id int
act varchar(20)
}
// Creating references
// You can also define relaionship separately
// > many-to-one; < one-to-many; - one-to-one
Ref{
U.country_code > countries.code
merchants.country_code > countries.code
}
//----------------------------------------------//
//// -- LEVEL 2
//// -- Adding column settings
Table order_items {
order_id int [ref: > orders.id]
product_id int
quantity int [default: 1] // default value
}
Ref: order_items.product_id > products.id
Table orders {
id int [pk] // primary key
user_id int [not null, unique]
status varchar
created_at varchar [note: '''When order created'''] // add column note
}
Table int {
id int
}
//----------------------------------------------//
//// -- Level 3
//// -- Enum, Indexes
// Enum for 'products' table below
Enum products_status {
out_of_stock
in_stock
running_low [note: 'less than 20'] // add column note
}
// Indexes: You can define a single or multi-column index
Table products {
id int [pk]
name varchar
merchant_id int [not null]
price int
status products_status
created_at datetime [default: `now()`]
Indexes {
(merchant_id, status) [name:'product_status', type: hash]
id [unique]
}
}
enum keywords_as_enum {
key
default
type
}
Ref: products.merchant_id > merchants.id // many-to-one
TableGroup hello_world {
just_test
just_a_test
}
// Index: have a column names 'key' as part of an index
Table items1 {
key int [pk] // primary key
user_id int [not null, unique]
status varchar
Indexes {
(key) [unique]
}
}
Table items2 {
key int [pk] // primary key
order_id int [not null, unique]
status varchar
Indexes {
(key, order_id) [name: 'some_name', unique]
}
}
// Index: have a keywords - Action, Type, Section, Project, Default - fields as part of an index
Table action1 {
action int [pk] // primary key
order_id int [not null, unique]
status varchar
type varchar
Indexes {
(action, order_id) [name: 'some_name', unique]
(type, section, project, default) [name: 'keywords_as_index', unique]
}
}