forked from goadesign/gorma
/
models.go
97 lines (92 loc) · 2.69 KB
/
models.go
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
package design
import (
"github.com/goadesign/gorma"
. "github.com/goadesign/gorma/dsl"
)
var _ = StorageGroup("CongoStorageGroup", func() {
Description("This is the global storage group")
Store("postgres", gorma.Postgres, func() {
Description("This is the Postgres relational store")
Model("User", func() {
BuildsFrom(func() {
Payload("user", "create")
Payload("user", "update")
})
RendersTo(User)
Description("User Model Description")
HasMany("Reviews", "Review")
HasMany("Proposals", "Proposal")
Field("id", gorma.Integer, func() {
PrimaryKey()
Description("This is the User Model PK field")
})
Field("created_at", gorma.Timestamp, func() {})
Field("updated_at", gorma.Timestamp, func() {})
Field("deleted_at", gorma.NullableTimestamp, func() {})
})
Model("Proposal", func() {
BuildsFrom(func() {
Payload("proposal", "create")
Payload("proposal", "update")
})
RendersTo(Proposal)
Description("Proposal Model")
BelongsTo("User")
HasMany("Reviews", "Review")
Field("id", gorma.Integer, func() {
PrimaryKey()
Description("This is the Payload Model PK field")
})
Field("title", func() {
Alias("proposal_title")
})
Field("created_at", gorma.Timestamp, func() {})
Field("updated_at", gorma.Timestamp, func() {})
Field("deleted_at", gorma.NullableTimestamp, func() {})
})
Model("Review", func() {
BuildsFrom(func() {
Payload("review", "create")
Payload("review", "update")
})
RendersTo(Review)
Description("Review Model")
BelongsTo("User")
BelongsTo("Proposal")
Field("id", gorma.Integer, func() {
PrimaryKey()
Description("This is the Review Model PK field")
})
Field("created_at", gorma.Timestamp, func() {})
Field("updated_at", gorma.Timestamp, func() {})
Field("deleted_at", gorma.NullableTimestamp, func() {})
})
Model("Test", func() {
Description("Test Model")
NoAutomaticIDFields()
Field("created_at", gorma.Timestamp, func() {})
Field("updated_at", gorma.Timestamp, func() {})
Field("deleted_at", gorma.NullableTimestamp, func() {})
})
Model("TestToo", func() {
Description("TestToo Model")
NoAutomaticIDFields()
Field("idone", gorma.Integer, func() {
PrimaryKey()
Description("This is one of the TestToo Model PK fields")
})
Field("idtwo", gorma.Integer, func() {
PrimaryKey()
Description("This is one of the TestToo Model PK fields")
})
BuildsFrom(func() {
Payload("user", "create")
Payload("user", "update")
})
RendersTo(User)
Field("created_at", gorma.Timestamp, func() {})
Field("updated_at", gorma.Timestamp, func() {})
Field("deleted_at", gorma.NullableTimestamp, func() {})
})
})
})