forked from duythinht/dbml-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.dbml
97 lines (79 loc) · 1.94 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
//// -- 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
Note: 'khong hieu duoc'
}
Table merchants {
id int [pk]
merchant_name varchar [note: '@gopointer(true)']
country_code varchar [not null]
updated_at varchar [note:'@gotype(time:Time)']
'created at' varchar
admin_id int [ref: > U.id] // inline relationship (many-to-one)
}
Table countries {
code int [pk]
name varchar
continent_name varchar
}
// 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]
}
}
Ref: products.merchant_id > merchants.id // many-to-one
TableGroup hello_world {
just_test
just_a_test
}