-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsom.go
141 lines (115 loc) · 3.13 KB
/
som.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
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
141
package som
import (
"github.com/go-surreal/sdbc"
"time"
)
type ID = sdbc.ID
// type Record = Node // TODO: should we use this to clarify whether a model has edges (node) or not (record)?
type Node struct {
id *ID
}
func NewNode(id *ID) Node {
return Node{
id: id,
}
}
func (n Node) ID() *ID {
return n.id
}
// Edge describes an edge between two Node elements.
// It may have its own fields.
type Edge struct {
id *ID
}
func NewEdge(id *ID) Edge {
return Edge{
id: id,
}
}
func (e Edge) ID() *ID {
return e.id
}
type Timestamps struct {
createdAt time.Time
updatedAt time.Time
}
func NewTimestamps(createdAt *sdbc.DateTime, updatedAt *sdbc.DateTime) Timestamps {
var ts Timestamps
if createdAt != nil {
ts.createdAt = createdAt.Time
}
if updatedAt != nil {
ts.updatedAt = updatedAt.Time
}
return ts
}
func (t Timestamps) CreatedAt() time.Time {
return t.createdAt
}
func (t Timestamps) UpdatedAt() time.Time {
return t.updatedAt
}
// TODO: implement soft delete feature
// type SoftDelete struct {
// deletedAt time.Time
// }
//
// func NewSoftDelete(deletedAt time.Time) SoftDelete {
// return SoftDelete{
// deletedAt: deletedAt,
// }
// }
//
// func (t SoftDelete) DeletedAt() time.Time {
// return t.deletedAt
// }
// Enum describes a database type with a fixed set of allowed values.
type Enum string
// Email describes a string field that should contain an email address.
type Email string
// Password describes a string field that should contain a password.
type Password string
// SemVer describes a string field that should contain a semantic version.
type SemVer string
// Password describes a special string field.
// Regarding the generated database query operations, it can only be matched, but never read.
// In a query result, the Password field will always be empty.
// TODO: implement!
// type Password string
// Meta describes a model that is not related to any Node or Edge.
// Instead, it is used to hold metadata that was queried from a Node or Edge.
//
// Applying this struct to a type within your model package will ensure
// that this type is never considered for the generated layer.
// type Meta struct{}
// Info holds information about a single database operation.
// It is used as target to hold said information when building
// an operation using the WithInfo() method. The generated
// builder for each model provides this capability.
//
// Example:
// Take a model named "Model" for which the som code is generated.
// Accessing the database operation happens as usual for example via
// client.Model().Create() or client.Model().Query(). Extracting the
// Info out of those operations is as simple as:
//
// var info *som.Info
// client.Model().WithInfo(info).Create()
// client.Model().WithInfo(info).Query()
//
// Please note: When using the same base for multiple operations, the Info
// struct will only ever hold the information of the last operation.
// TODO: implement!
// type Info struct {
// Time time.Time
// Status string
// Message string
// }
// TODO: below needed?
// type Entity interface {
// entity()
// }
// TODO: implement external types
// type External struct {
// ID string
// }