/
memo.go
288 lines (264 loc) · 9.51 KB
/
memo.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/isutare412/web-memo/api/internal/core/ent/memo"
"github.com/isutare412/web-memo/api/internal/core/ent/user"
)
// Memo is the model entity for the Memo schema.
type Memo struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// OwnerID holds the value of the "owner_id" field.
OwnerID uuid.UUID `json:"owner_id,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
// Content holds the value of the "content" field.
Content string `json:"content,omitempty"`
// IsPublished holds the value of the "is_published" field.
IsPublished bool `json:"is_published,omitempty"`
// Version holds the value of the "version" field.
Version int `json:"version,omitempty"`
// CreateTime holds the value of the "create_time" field.
CreateTime time.Time `json:"create_time,omitempty"`
// UpdateTime holds the value of the "update_time" field.
UpdateTime time.Time `json:"update_time,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the MemoQuery when eager-loading is set.
Edges MemoEdges `json:"edges"`
selectValues sql.SelectValues
}
// MemoEdges holds the relations/edges for other nodes in the graph.
type MemoEdges struct {
// Owner holds the value of the owner edge.
Owner *User `json:"owner,omitempty"`
// Tags holds the value of the tags edge.
Tags []*Tag `json:"tags,omitempty"`
// Subscribers holds the value of the subscribers edge.
Subscribers []*User `json:"subscribers,omitempty"`
// Collaborators holds the value of the collaborators edge.
Collaborators []*User `json:"collaborators,omitempty"`
// Subscriptions holds the value of the subscriptions edge.
Subscriptions []*Subscription `json:"subscriptions,omitempty"`
// Collaborations holds the value of the collaborations edge.
Collaborations []*Collaboration `json:"collaborations,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [6]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e MemoEdges) OwnerOrErr() (*User, error) {
if e.loadedTypes[0] {
if e.Owner == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
return e.Owner, nil
}
return nil, &NotLoadedError{edge: "owner"}
}
// TagsOrErr returns the Tags value or an error if the edge
// was not loaded in eager-loading.
func (e MemoEdges) TagsOrErr() ([]*Tag, error) {
if e.loadedTypes[1] {
return e.Tags, nil
}
return nil, &NotLoadedError{edge: "tags"}
}
// SubscribersOrErr returns the Subscribers value or an error if the edge
// was not loaded in eager-loading.
func (e MemoEdges) SubscribersOrErr() ([]*User, error) {
if e.loadedTypes[2] {
return e.Subscribers, nil
}
return nil, &NotLoadedError{edge: "subscribers"}
}
// CollaboratorsOrErr returns the Collaborators value or an error if the edge
// was not loaded in eager-loading.
func (e MemoEdges) CollaboratorsOrErr() ([]*User, error) {
if e.loadedTypes[3] {
return e.Collaborators, nil
}
return nil, &NotLoadedError{edge: "collaborators"}
}
// SubscriptionsOrErr returns the Subscriptions value or an error if the edge
// was not loaded in eager-loading.
func (e MemoEdges) SubscriptionsOrErr() ([]*Subscription, error) {
if e.loadedTypes[4] {
return e.Subscriptions, nil
}
return nil, &NotLoadedError{edge: "subscriptions"}
}
// CollaborationsOrErr returns the Collaborations value or an error if the edge
// was not loaded in eager-loading.
func (e MemoEdges) CollaborationsOrErr() ([]*Collaboration, error) {
if e.loadedTypes[5] {
return e.Collaborations, nil
}
return nil, &NotLoadedError{edge: "collaborations"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Memo) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case memo.FieldIsPublished:
values[i] = new(sql.NullBool)
case memo.FieldVersion:
values[i] = new(sql.NullInt64)
case memo.FieldTitle, memo.FieldContent:
values[i] = new(sql.NullString)
case memo.FieldCreateTime, memo.FieldUpdateTime:
values[i] = new(sql.NullTime)
case memo.FieldID, memo.FieldOwnerID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Memo fields.
func (m *Memo) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case memo.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
m.ID = *value
}
case memo.FieldOwnerID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field owner_id", values[i])
} else if value != nil {
m.OwnerID = *value
}
case memo.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
} else if value.Valid {
m.Title = value.String
}
case memo.FieldContent:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field content", values[i])
} else if value.Valid {
m.Content = value.String
}
case memo.FieldIsPublished:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_published", values[i])
} else if value.Valid {
m.IsPublished = value.Bool
}
case memo.FieldVersion:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field version", values[i])
} else if value.Valid {
m.Version = int(value.Int64)
}
case memo.FieldCreateTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field create_time", values[i])
} else if value.Valid {
m.CreateTime = value.Time
}
case memo.FieldUpdateTime:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field update_time", values[i])
} else if value.Valid {
m.UpdateTime = value.Time
}
default:
m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Memo.
// This includes values selected through modifiers, order, etc.
func (m *Memo) Value(name string) (ent.Value, error) {
return m.selectValues.Get(name)
}
// QueryOwner queries the "owner" edge of the Memo entity.
func (m *Memo) QueryOwner() *UserQuery {
return NewMemoClient(m.config).QueryOwner(m)
}
// QueryTags queries the "tags" edge of the Memo entity.
func (m *Memo) QueryTags() *TagQuery {
return NewMemoClient(m.config).QueryTags(m)
}
// QuerySubscribers queries the "subscribers" edge of the Memo entity.
func (m *Memo) QuerySubscribers() *UserQuery {
return NewMemoClient(m.config).QuerySubscribers(m)
}
// QueryCollaborators queries the "collaborators" edge of the Memo entity.
func (m *Memo) QueryCollaborators() *UserQuery {
return NewMemoClient(m.config).QueryCollaborators(m)
}
// QuerySubscriptions queries the "subscriptions" edge of the Memo entity.
func (m *Memo) QuerySubscriptions() *SubscriptionQuery {
return NewMemoClient(m.config).QuerySubscriptions(m)
}
// QueryCollaborations queries the "collaborations" edge of the Memo entity.
func (m *Memo) QueryCollaborations() *CollaborationQuery {
return NewMemoClient(m.config).QueryCollaborations(m)
}
// Update returns a builder for updating this Memo.
// Note that you need to call Memo.Unwrap() before calling this method if this Memo
// was returned from a transaction, and the transaction was committed or rolled back.
func (m *Memo) Update() *MemoUpdateOne {
return NewMemoClient(m.config).UpdateOne(m)
}
// Unwrap unwraps the Memo entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (m *Memo) Unwrap() *Memo {
_tx, ok := m.config.driver.(*txDriver)
if !ok {
panic("ent: Memo is not a transactional entity")
}
m.config.driver = _tx.drv
return m
}
// String implements the fmt.Stringer.
func (m *Memo) String() string {
var builder strings.Builder
builder.WriteString("Memo(")
builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
builder.WriteString("owner_id=")
builder.WriteString(fmt.Sprintf("%v", m.OwnerID))
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(m.Title)
builder.WriteString(", ")
builder.WriteString("content=")
builder.WriteString(m.Content)
builder.WriteString(", ")
builder.WriteString("is_published=")
builder.WriteString(fmt.Sprintf("%v", m.IsPublished))
builder.WriteString(", ")
builder.WriteString("version=")
builder.WriteString(fmt.Sprintf("%v", m.Version))
builder.WriteString(", ")
builder.WriteString("create_time=")
builder.WriteString(m.CreateTime.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("update_time=")
builder.WriteString(m.UpdateTime.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Memos is a parsable slice of Memo.
type Memos []*Memo