forked from ent/contrib
/
validmessage_update.go
341 lines (303 loc) · 9.97 KB
/
validmessage_update.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
"github.com/tilau2328/entcontrib/entproto/internal/entprototest/ent/predicate"
"github.com/tilau2328/entcontrib/entproto/internal/entprototest/ent/validmessage"
)
// ValidMessageUpdate is the builder for updating ValidMessage entities.
type ValidMessageUpdate struct {
config
hooks []Hook
mutation *ValidMessageMutation
}
// Where appends a list predicates to the ValidMessageUpdate builder.
func (vmu *ValidMessageUpdate) Where(ps ...predicate.ValidMessage) *ValidMessageUpdate {
vmu.mutation.Where(ps...)
return vmu
}
// SetName sets the "name" field.
func (vmu *ValidMessageUpdate) SetName(s string) *ValidMessageUpdate {
vmu.mutation.SetName(s)
return vmu
}
// SetTs sets the "ts" field.
func (vmu *ValidMessageUpdate) SetTs(t time.Time) *ValidMessageUpdate {
vmu.mutation.SetTs(t)
return vmu
}
// SetUUID sets the "uuid" field.
func (vmu *ValidMessageUpdate) SetUUID(u uuid.UUID) *ValidMessageUpdate {
vmu.mutation.SetUUID(u)
return vmu
}
// SetU8 sets the "u8" field.
func (vmu *ValidMessageUpdate) SetU8(u uint8) *ValidMessageUpdate {
vmu.mutation.ResetU8()
vmu.mutation.SetU8(u)
return vmu
}
// AddU8 adds u to the "u8" field.
func (vmu *ValidMessageUpdate) AddU8(u int8) *ValidMessageUpdate {
vmu.mutation.AddU8(u)
return vmu
}
// SetOpti8 sets the "opti8" field.
func (vmu *ValidMessageUpdate) SetOpti8(i int8) *ValidMessageUpdate {
vmu.mutation.ResetOpti8()
vmu.mutation.SetOpti8(i)
return vmu
}
// SetNillableOpti8 sets the "opti8" field if the given value is not nil.
func (vmu *ValidMessageUpdate) SetNillableOpti8(i *int8) *ValidMessageUpdate {
if i != nil {
vmu.SetOpti8(*i)
}
return vmu
}
// AddOpti8 adds i to the "opti8" field.
func (vmu *ValidMessageUpdate) AddOpti8(i int8) *ValidMessageUpdate {
vmu.mutation.AddOpti8(i)
return vmu
}
// ClearOpti8 clears the value of the "opti8" field.
func (vmu *ValidMessageUpdate) ClearOpti8() *ValidMessageUpdate {
vmu.mutation.ClearOpti8()
return vmu
}
// Mutation returns the ValidMessageMutation object of the builder.
func (vmu *ValidMessageUpdate) Mutation() *ValidMessageMutation {
return vmu.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (vmu *ValidMessageUpdate) Save(ctx context.Context) (int, error) {
return withHooks[int, ValidMessageMutation](ctx, vmu.sqlSave, vmu.mutation, vmu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (vmu *ValidMessageUpdate) SaveX(ctx context.Context) int {
affected, err := vmu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (vmu *ValidMessageUpdate) Exec(ctx context.Context) error {
_, err := vmu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (vmu *ValidMessageUpdate) ExecX(ctx context.Context) {
if err := vmu.Exec(ctx); err != nil {
panic(err)
}
}
func (vmu *ValidMessageUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(validmessage.Table, validmessage.Columns, sqlgraph.NewFieldSpec(validmessage.FieldID, field.TypeInt))
if ps := vmu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := vmu.mutation.Name(); ok {
_spec.SetField(validmessage.FieldName, field.TypeString, value)
}
if value, ok := vmu.mutation.Ts(); ok {
_spec.SetField(validmessage.FieldTs, field.TypeTime, value)
}
if value, ok := vmu.mutation.UUID(); ok {
_spec.SetField(validmessage.FieldUUID, field.TypeUUID, value)
}
if value, ok := vmu.mutation.U8(); ok {
_spec.SetField(validmessage.FieldU8, field.TypeUint8, value)
}
if value, ok := vmu.mutation.AddedU8(); ok {
_spec.AddField(validmessage.FieldU8, field.TypeUint8, value)
}
if value, ok := vmu.mutation.Opti8(); ok {
_spec.SetField(validmessage.FieldOpti8, field.TypeInt8, value)
}
if value, ok := vmu.mutation.AddedOpti8(); ok {
_spec.AddField(validmessage.FieldOpti8, field.TypeInt8, value)
}
if vmu.mutation.Opti8Cleared() {
_spec.ClearField(validmessage.FieldOpti8, field.TypeInt8)
}
if n, err = sqlgraph.UpdateNodes(ctx, vmu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{validmessage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
vmu.mutation.done = true
return n, nil
}
// ValidMessageUpdateOne is the builder for updating a single ValidMessage entity.
type ValidMessageUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ValidMessageMutation
}
// SetName sets the "name" field.
func (vmuo *ValidMessageUpdateOne) SetName(s string) *ValidMessageUpdateOne {
vmuo.mutation.SetName(s)
return vmuo
}
// SetTs sets the "ts" field.
func (vmuo *ValidMessageUpdateOne) SetTs(t time.Time) *ValidMessageUpdateOne {
vmuo.mutation.SetTs(t)
return vmuo
}
// SetUUID sets the "uuid" field.
func (vmuo *ValidMessageUpdateOne) SetUUID(u uuid.UUID) *ValidMessageUpdateOne {
vmuo.mutation.SetUUID(u)
return vmuo
}
// SetU8 sets the "u8" field.
func (vmuo *ValidMessageUpdateOne) SetU8(u uint8) *ValidMessageUpdateOne {
vmuo.mutation.ResetU8()
vmuo.mutation.SetU8(u)
return vmuo
}
// AddU8 adds u to the "u8" field.
func (vmuo *ValidMessageUpdateOne) AddU8(u int8) *ValidMessageUpdateOne {
vmuo.mutation.AddU8(u)
return vmuo
}
// SetOpti8 sets the "opti8" field.
func (vmuo *ValidMessageUpdateOne) SetOpti8(i int8) *ValidMessageUpdateOne {
vmuo.mutation.ResetOpti8()
vmuo.mutation.SetOpti8(i)
return vmuo
}
// SetNillableOpti8 sets the "opti8" field if the given value is not nil.
func (vmuo *ValidMessageUpdateOne) SetNillableOpti8(i *int8) *ValidMessageUpdateOne {
if i != nil {
vmuo.SetOpti8(*i)
}
return vmuo
}
// AddOpti8 adds i to the "opti8" field.
func (vmuo *ValidMessageUpdateOne) AddOpti8(i int8) *ValidMessageUpdateOne {
vmuo.mutation.AddOpti8(i)
return vmuo
}
// ClearOpti8 clears the value of the "opti8" field.
func (vmuo *ValidMessageUpdateOne) ClearOpti8() *ValidMessageUpdateOne {
vmuo.mutation.ClearOpti8()
return vmuo
}
// Mutation returns the ValidMessageMutation object of the builder.
func (vmuo *ValidMessageUpdateOne) Mutation() *ValidMessageMutation {
return vmuo.mutation
}
// Where appends a list predicates to the ValidMessageUpdate builder.
func (vmuo *ValidMessageUpdateOne) Where(ps ...predicate.ValidMessage) *ValidMessageUpdateOne {
vmuo.mutation.Where(ps...)
return vmuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (vmuo *ValidMessageUpdateOne) Select(field string, fields ...string) *ValidMessageUpdateOne {
vmuo.fields = append([]string{field}, fields...)
return vmuo
}
// Save executes the query and returns the updated ValidMessage entity.
func (vmuo *ValidMessageUpdateOne) Save(ctx context.Context) (*ValidMessage, error) {
return withHooks[*ValidMessage, ValidMessageMutation](ctx, vmuo.sqlSave, vmuo.mutation, vmuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (vmuo *ValidMessageUpdateOne) SaveX(ctx context.Context) *ValidMessage {
node, err := vmuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (vmuo *ValidMessageUpdateOne) Exec(ctx context.Context) error {
_, err := vmuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (vmuo *ValidMessageUpdateOne) ExecX(ctx context.Context) {
if err := vmuo.Exec(ctx); err != nil {
panic(err)
}
}
func (vmuo *ValidMessageUpdateOne) sqlSave(ctx context.Context) (_node *ValidMessage, err error) {
_spec := sqlgraph.NewUpdateSpec(validmessage.Table, validmessage.Columns, sqlgraph.NewFieldSpec(validmessage.FieldID, field.TypeInt))
id, ok := vmuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ValidMessage.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := vmuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, validmessage.FieldID)
for _, f := range fields {
if !validmessage.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != validmessage.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := vmuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := vmuo.mutation.Name(); ok {
_spec.SetField(validmessage.FieldName, field.TypeString, value)
}
if value, ok := vmuo.mutation.Ts(); ok {
_spec.SetField(validmessage.FieldTs, field.TypeTime, value)
}
if value, ok := vmuo.mutation.UUID(); ok {
_spec.SetField(validmessage.FieldUUID, field.TypeUUID, value)
}
if value, ok := vmuo.mutation.U8(); ok {
_spec.SetField(validmessage.FieldU8, field.TypeUint8, value)
}
if value, ok := vmuo.mutation.AddedU8(); ok {
_spec.AddField(validmessage.FieldU8, field.TypeUint8, value)
}
if value, ok := vmuo.mutation.Opti8(); ok {
_spec.SetField(validmessage.FieldOpti8, field.TypeInt8, value)
}
if value, ok := vmuo.mutation.AddedOpti8(); ok {
_spec.AddField(validmessage.FieldOpti8, field.TypeInt8, value)
}
if vmuo.mutation.Opti8Cleared() {
_spec.ClearField(validmessage.FieldOpti8, field.TypeInt8)
}
_node = &ValidMessage{config: vmuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, vmuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{validmessage.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
vmuo.mutation.done = true
return _node, nil
}