plc.directory mirror
1// Code generated by ent, DO NOT EDIT.
2
3package ent
4
5import (
6 "context"
7 "errors"
8 "fmt"
9 "time"
10
11 "entgo.io/ent/dialect/sql"
12 "entgo.io/ent/dialect/sql/sqlgraph"
13 "entgo.io/ent/schema/field"
14 "tangled.sh/seiso.moe/aletheia.directory/ent/predicate"
15 "tangled.sh/seiso.moe/aletheia.directory/ent/syncstatus"
16)
17
18// SyncStatusUpdate is the builder for updating SyncStatus entities.
19type SyncStatusUpdate struct {
20 config
21 hooks []Hook
22 mutation *SyncStatusMutation
23}
24
25// Where appends a list predicates to the SyncStatusUpdate builder.
26func (ssu *SyncStatusUpdate) Where(ps ...predicate.SyncStatus) *SyncStatusUpdate {
27 ssu.mutation.Where(ps...)
28 return ssu
29}
30
31// SetKey sets the "key" field.
32func (ssu *SyncStatusUpdate) SetKey(s string) *SyncStatusUpdate {
33 ssu.mutation.SetKey(s)
34 return ssu
35}
36
37// SetNillableKey sets the "key" field if the given value is not nil.
38func (ssu *SyncStatusUpdate) SetNillableKey(s *string) *SyncStatusUpdate {
39 if s != nil {
40 ssu.SetKey(*s)
41 }
42 return ssu
43}
44
45// SetLastOperationTime sets the "last_operation_time" field.
46func (ssu *SyncStatusUpdate) SetLastOperationTime(t time.Time) *SyncStatusUpdate {
47 ssu.mutation.SetLastOperationTime(t)
48 return ssu
49}
50
51// SetNillableLastOperationTime sets the "last_operation_time" field if the given value is not nil.
52func (ssu *SyncStatusUpdate) SetNillableLastOperationTime(t *time.Time) *SyncStatusUpdate {
53 if t != nil {
54 ssu.SetLastOperationTime(*t)
55 }
56 return ssu
57}
58
59// SetLastSyncTime sets the "last_sync_time" field.
60func (ssu *SyncStatusUpdate) SetLastSyncTime(t time.Time) *SyncStatusUpdate {
61 ssu.mutation.SetLastSyncTime(t)
62 return ssu
63}
64
65// SetNillableLastSyncTime sets the "last_sync_time" field if the given value is not nil.
66func (ssu *SyncStatusUpdate) SetNillableLastSyncTime(t *time.Time) *SyncStatusUpdate {
67 if t != nil {
68 ssu.SetLastSyncTime(*t)
69 }
70 return ssu
71}
72
73// Mutation returns the SyncStatusMutation object of the builder.
74func (ssu *SyncStatusUpdate) Mutation() *SyncStatusMutation {
75 return ssu.mutation
76}
77
78// Save executes the query and returns the number of nodes affected by the update operation.
79func (ssu *SyncStatusUpdate) Save(ctx context.Context) (int, error) {
80 return withHooks(ctx, ssu.sqlSave, ssu.mutation, ssu.hooks)
81}
82
83// SaveX is like Save, but panics if an error occurs.
84func (ssu *SyncStatusUpdate) SaveX(ctx context.Context) int {
85 affected, err := ssu.Save(ctx)
86 if err != nil {
87 panic(err)
88 }
89 return affected
90}
91
92// Exec executes the query.
93func (ssu *SyncStatusUpdate) Exec(ctx context.Context) error {
94 _, err := ssu.Save(ctx)
95 return err
96}
97
98// ExecX is like Exec, but panics if an error occurs.
99func (ssu *SyncStatusUpdate) ExecX(ctx context.Context) {
100 if err := ssu.Exec(ctx); err != nil {
101 panic(err)
102 }
103}
104
105func (ssu *SyncStatusUpdate) sqlSave(ctx context.Context) (n int, err error) {
106 _spec := sqlgraph.NewUpdateSpec(syncstatus.Table, syncstatus.Columns, sqlgraph.NewFieldSpec(syncstatus.FieldID, field.TypeInt))
107 if ps := ssu.mutation.predicates; len(ps) > 0 {
108 _spec.Predicate = func(selector *sql.Selector) {
109 for i := range ps {
110 ps[i](selector)
111 }
112 }
113 }
114 if value, ok := ssu.mutation.Key(); ok {
115 _spec.SetField(syncstatus.FieldKey, field.TypeString, value)
116 }
117 if value, ok := ssu.mutation.LastOperationTime(); ok {
118 _spec.SetField(syncstatus.FieldLastOperationTime, field.TypeTime, value)
119 }
120 if value, ok := ssu.mutation.LastSyncTime(); ok {
121 _spec.SetField(syncstatus.FieldLastSyncTime, field.TypeTime, value)
122 }
123 if n, err = sqlgraph.UpdateNodes(ctx, ssu.driver, _spec); err != nil {
124 if _, ok := err.(*sqlgraph.NotFoundError); ok {
125 err = &NotFoundError{syncstatus.Label}
126 } else if sqlgraph.IsConstraintError(err) {
127 err = &ConstraintError{msg: err.Error(), wrap: err}
128 }
129 return 0, err
130 }
131 ssu.mutation.done = true
132 return n, nil
133}
134
135// SyncStatusUpdateOne is the builder for updating a single SyncStatus entity.
136type SyncStatusUpdateOne struct {
137 config
138 fields []string
139 hooks []Hook
140 mutation *SyncStatusMutation
141}
142
143// SetKey sets the "key" field.
144func (ssuo *SyncStatusUpdateOne) SetKey(s string) *SyncStatusUpdateOne {
145 ssuo.mutation.SetKey(s)
146 return ssuo
147}
148
149// SetNillableKey sets the "key" field if the given value is not nil.
150func (ssuo *SyncStatusUpdateOne) SetNillableKey(s *string) *SyncStatusUpdateOne {
151 if s != nil {
152 ssuo.SetKey(*s)
153 }
154 return ssuo
155}
156
157// SetLastOperationTime sets the "last_operation_time" field.
158func (ssuo *SyncStatusUpdateOne) SetLastOperationTime(t time.Time) *SyncStatusUpdateOne {
159 ssuo.mutation.SetLastOperationTime(t)
160 return ssuo
161}
162
163// SetNillableLastOperationTime sets the "last_operation_time" field if the given value is not nil.
164func (ssuo *SyncStatusUpdateOne) SetNillableLastOperationTime(t *time.Time) *SyncStatusUpdateOne {
165 if t != nil {
166 ssuo.SetLastOperationTime(*t)
167 }
168 return ssuo
169}
170
171// SetLastSyncTime sets the "last_sync_time" field.
172func (ssuo *SyncStatusUpdateOne) SetLastSyncTime(t time.Time) *SyncStatusUpdateOne {
173 ssuo.mutation.SetLastSyncTime(t)
174 return ssuo
175}
176
177// SetNillableLastSyncTime sets the "last_sync_time" field if the given value is not nil.
178func (ssuo *SyncStatusUpdateOne) SetNillableLastSyncTime(t *time.Time) *SyncStatusUpdateOne {
179 if t != nil {
180 ssuo.SetLastSyncTime(*t)
181 }
182 return ssuo
183}
184
185// Mutation returns the SyncStatusMutation object of the builder.
186func (ssuo *SyncStatusUpdateOne) Mutation() *SyncStatusMutation {
187 return ssuo.mutation
188}
189
190// Where appends a list predicates to the SyncStatusUpdate builder.
191func (ssuo *SyncStatusUpdateOne) Where(ps ...predicate.SyncStatus) *SyncStatusUpdateOne {
192 ssuo.mutation.Where(ps...)
193 return ssuo
194}
195
196// Select allows selecting one or more fields (columns) of the returned entity.
197// The default is selecting all fields defined in the entity schema.
198func (ssuo *SyncStatusUpdateOne) Select(field string, fields ...string) *SyncStatusUpdateOne {
199 ssuo.fields = append([]string{field}, fields...)
200 return ssuo
201}
202
203// Save executes the query and returns the updated SyncStatus entity.
204func (ssuo *SyncStatusUpdateOne) Save(ctx context.Context) (*SyncStatus, error) {
205 return withHooks(ctx, ssuo.sqlSave, ssuo.mutation, ssuo.hooks)
206}
207
208// SaveX is like Save, but panics if an error occurs.
209func (ssuo *SyncStatusUpdateOne) SaveX(ctx context.Context) *SyncStatus {
210 node, err := ssuo.Save(ctx)
211 if err != nil {
212 panic(err)
213 }
214 return node
215}
216
217// Exec executes the query on the entity.
218func (ssuo *SyncStatusUpdateOne) Exec(ctx context.Context) error {
219 _, err := ssuo.Save(ctx)
220 return err
221}
222
223// ExecX is like Exec, but panics if an error occurs.
224func (ssuo *SyncStatusUpdateOne) ExecX(ctx context.Context) {
225 if err := ssuo.Exec(ctx); err != nil {
226 panic(err)
227 }
228}
229
230func (ssuo *SyncStatusUpdateOne) sqlSave(ctx context.Context) (_node *SyncStatus, err error) {
231 _spec := sqlgraph.NewUpdateSpec(syncstatus.Table, syncstatus.Columns, sqlgraph.NewFieldSpec(syncstatus.FieldID, field.TypeInt))
232 id, ok := ssuo.mutation.ID()
233 if !ok {
234 return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SyncStatus.id" for update`)}
235 }
236 _spec.Node.ID.Value = id
237 if fields := ssuo.fields; len(fields) > 0 {
238 _spec.Node.Columns = make([]string, 0, len(fields))
239 _spec.Node.Columns = append(_spec.Node.Columns, syncstatus.FieldID)
240 for _, f := range fields {
241 if !syncstatus.ValidColumn(f) {
242 return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
243 }
244 if f != syncstatus.FieldID {
245 _spec.Node.Columns = append(_spec.Node.Columns, f)
246 }
247 }
248 }
249 if ps := ssuo.mutation.predicates; len(ps) > 0 {
250 _spec.Predicate = func(selector *sql.Selector) {
251 for i := range ps {
252 ps[i](selector)
253 }
254 }
255 }
256 if value, ok := ssuo.mutation.Key(); ok {
257 _spec.SetField(syncstatus.FieldKey, field.TypeString, value)
258 }
259 if value, ok := ssuo.mutation.LastOperationTime(); ok {
260 _spec.SetField(syncstatus.FieldLastOperationTime, field.TypeTime, value)
261 }
262 if value, ok := ssuo.mutation.LastSyncTime(); ok {
263 _spec.SetField(syncstatus.FieldLastSyncTime, field.TypeTime, value)
264 }
265 _node = &SyncStatus{config: ssuo.config}
266 _spec.Assign = _node.assignValues
267 _spec.ScanValues = _node.scanValues
268 if err = sqlgraph.UpdateNode(ctx, ssuo.driver, _spec); err != nil {
269 if _, ok := err.(*sqlgraph.NotFoundError); ok {
270 err = &NotFoundError{syncstatus.Label}
271 } else if sqlgraph.IsConstraintError(err) {
272 err = &ConstraintError{msg: err.Error(), wrap: err}
273 }
274 return nil, err
275 }
276 ssuo.mutation.done = true
277 return _node, nil
278}