plc.directory mirror
1// Code generated by ent, DO NOT EDIT.
2
3package ent
4
5import (
6 "context"
7 "errors"
8 "fmt"
9 "sync"
10 "time"
11
12 "entgo.io/ent"
13 "entgo.io/ent/dialect/sql"
14 "tangled.sh/seiso.moe/aletheia.directory/ent/operation"
15 "tangled.sh/seiso.moe/aletheia.directory/ent/predicate"
16 "tangled.sh/seiso.moe/aletheia.directory/ent/syncstatus"
17 "tangled.sh/seiso.moe/aletheia.directory/pkg/plc"
18)
19
20const (
21 // Operation types.
22 OpCreate = ent.OpCreate
23 OpDelete = ent.OpDelete
24 OpDeleteOne = ent.OpDeleteOne
25 OpUpdate = ent.OpUpdate
26 OpUpdateOne = ent.OpUpdateOne
27
28 // Node types.
29 TypeOperation = "Operation"
30 TypeSyncStatus = "SyncStatus"
31)
32
33// OperationMutation represents an operation that mutates the Operation nodes in the graph.
34type OperationMutation struct {
35 config
36 op Op
37 typ string
38 id *int
39 did *string
40 operation *plc.PLCOperation
41 cid *string
42 nullified *bool
43 created_at *time.Time
44 clearedFields map[string]struct{}
45 done bool
46 oldValue func(context.Context) (*Operation, error)
47 predicates []predicate.Operation
48}
49
50var _ ent.Mutation = (*OperationMutation)(nil)
51
52// operationOption allows management of the mutation configuration using functional options.
53type operationOption func(*OperationMutation)
54
55// newOperationMutation creates new mutation for the Operation entity.
56func newOperationMutation(c config, op Op, opts ...operationOption) *OperationMutation {
57 m := &OperationMutation{
58 config: c,
59 op: op,
60 typ: TypeOperation,
61 clearedFields: make(map[string]struct{}),
62 }
63 for _, opt := range opts {
64 opt(m)
65 }
66 return m
67}
68
69// withOperationID sets the ID field of the mutation.
70func withOperationID(id int) operationOption {
71 return func(m *OperationMutation) {
72 var (
73 err error
74 once sync.Once
75 value *Operation
76 )
77 m.oldValue = func(ctx context.Context) (*Operation, error) {
78 once.Do(func() {
79 if m.done {
80 err = errors.New("querying old values post mutation is not allowed")
81 } else {
82 value, err = m.Client().Operation.Get(ctx, id)
83 }
84 })
85 return value, err
86 }
87 m.id = &id
88 }
89}
90
91// withOperation sets the old Operation of the mutation.
92func withOperation(node *Operation) operationOption {
93 return func(m *OperationMutation) {
94 m.oldValue = func(context.Context) (*Operation, error) {
95 return node, nil
96 }
97 m.id = &node.ID
98 }
99}
100
101// Client returns a new `ent.Client` from the mutation. If the mutation was
102// executed in a transaction (ent.Tx), a transactional client is returned.
103func (m OperationMutation) Client() *Client {
104 client := &Client{config: m.config}
105 client.init()
106 return client
107}
108
109// Tx returns an `ent.Tx` for mutations that were executed in transactions;
110// it returns an error otherwise.
111func (m OperationMutation) Tx() (*Tx, error) {
112 if _, ok := m.driver.(*txDriver); !ok {
113 return nil, errors.New("ent: mutation is not running in a transaction")
114 }
115 tx := &Tx{config: m.config}
116 tx.init()
117 return tx, nil
118}
119
120// ID returns the ID value in the mutation. Note that the ID is only available
121// if it was provided to the builder or after it was returned from the database.
122func (m *OperationMutation) ID() (id int, exists bool) {
123 if m.id == nil {
124 return
125 }
126 return *m.id, true
127}
128
129// IDs queries the database and returns the entity ids that match the mutation's predicate.
130// That means, if the mutation is applied within a transaction with an isolation level such
131// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
132// or updated by the mutation.
133func (m *OperationMutation) IDs(ctx context.Context) ([]int, error) {
134 switch {
135 case m.op.Is(OpUpdateOne | OpDeleteOne):
136 id, exists := m.ID()
137 if exists {
138 return []int{id}, nil
139 }
140 fallthrough
141 case m.op.Is(OpUpdate | OpDelete):
142 return m.Client().Operation.Query().Where(m.predicates...).IDs(ctx)
143 default:
144 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
145 }
146}
147
148// SetDid sets the "did" field.
149func (m *OperationMutation) SetDid(s string) {
150 m.did = &s
151}
152
153// Did returns the value of the "did" field in the mutation.
154func (m *OperationMutation) Did() (r string, exists bool) {
155 v := m.did
156 if v == nil {
157 return
158 }
159 return *v, true
160}
161
162// OldDid returns the old "did" field's value of the Operation entity.
163// If the Operation object wasn't provided to the builder, the object is fetched from the database.
164// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
165func (m *OperationMutation) OldDid(ctx context.Context) (v string, err error) {
166 if !m.op.Is(OpUpdateOne) {
167 return v, errors.New("OldDid is only allowed on UpdateOne operations")
168 }
169 if m.id == nil || m.oldValue == nil {
170 return v, errors.New("OldDid requires an ID field in the mutation")
171 }
172 oldValue, err := m.oldValue(ctx)
173 if err != nil {
174 return v, fmt.Errorf("querying old value for OldDid: %w", err)
175 }
176 return oldValue.Did, nil
177}
178
179// ResetDid resets all changes to the "did" field.
180func (m *OperationMutation) ResetDid() {
181 m.did = nil
182}
183
184// SetOperation sets the "operation" field.
185func (m *OperationMutation) SetOperation(po plc.PLCOperation) {
186 m.operation = &po
187}
188
189// Operation returns the value of the "operation" field in the mutation.
190func (m *OperationMutation) Operation() (r plc.PLCOperation, exists bool) {
191 v := m.operation
192 if v == nil {
193 return
194 }
195 return *v, true
196}
197
198// OldOperation returns the old "operation" field's value of the Operation entity.
199// If the Operation object wasn't provided to the builder, the object is fetched from the database.
200// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
201func (m *OperationMutation) OldOperation(ctx context.Context) (v plc.PLCOperation, err error) {
202 if !m.op.Is(OpUpdateOne) {
203 return v, errors.New("OldOperation is only allowed on UpdateOne operations")
204 }
205 if m.id == nil || m.oldValue == nil {
206 return v, errors.New("OldOperation requires an ID field in the mutation")
207 }
208 oldValue, err := m.oldValue(ctx)
209 if err != nil {
210 return v, fmt.Errorf("querying old value for OldOperation: %w", err)
211 }
212 return oldValue.Operation, nil
213}
214
215// ResetOperation resets all changes to the "operation" field.
216func (m *OperationMutation) ResetOperation() {
217 m.operation = nil
218}
219
220// SetCid sets the "cid" field.
221func (m *OperationMutation) SetCid(s string) {
222 m.cid = &s
223}
224
225// Cid returns the value of the "cid" field in the mutation.
226func (m *OperationMutation) Cid() (r string, exists bool) {
227 v := m.cid
228 if v == nil {
229 return
230 }
231 return *v, true
232}
233
234// OldCid returns the old "cid" field's value of the Operation entity.
235// If the Operation object wasn't provided to the builder, the object is fetched from the database.
236// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
237func (m *OperationMutation) OldCid(ctx context.Context) (v string, err error) {
238 if !m.op.Is(OpUpdateOne) {
239 return v, errors.New("OldCid is only allowed on UpdateOne operations")
240 }
241 if m.id == nil || m.oldValue == nil {
242 return v, errors.New("OldCid requires an ID field in the mutation")
243 }
244 oldValue, err := m.oldValue(ctx)
245 if err != nil {
246 return v, fmt.Errorf("querying old value for OldCid: %w", err)
247 }
248 return oldValue.Cid, nil
249}
250
251// ResetCid resets all changes to the "cid" field.
252func (m *OperationMutation) ResetCid() {
253 m.cid = nil
254}
255
256// SetNullified sets the "nullified" field.
257func (m *OperationMutation) SetNullified(b bool) {
258 m.nullified = &b
259}
260
261// Nullified returns the value of the "nullified" field in the mutation.
262func (m *OperationMutation) Nullified() (r bool, exists bool) {
263 v := m.nullified
264 if v == nil {
265 return
266 }
267 return *v, true
268}
269
270// OldNullified returns the old "nullified" field's value of the Operation entity.
271// If the Operation object wasn't provided to the builder, the object is fetched from the database.
272// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
273func (m *OperationMutation) OldNullified(ctx context.Context) (v bool, err error) {
274 if !m.op.Is(OpUpdateOne) {
275 return v, errors.New("OldNullified is only allowed on UpdateOne operations")
276 }
277 if m.id == nil || m.oldValue == nil {
278 return v, errors.New("OldNullified requires an ID field in the mutation")
279 }
280 oldValue, err := m.oldValue(ctx)
281 if err != nil {
282 return v, fmt.Errorf("querying old value for OldNullified: %w", err)
283 }
284 return oldValue.Nullified, nil
285}
286
287// ResetNullified resets all changes to the "nullified" field.
288func (m *OperationMutation) ResetNullified() {
289 m.nullified = nil
290}
291
292// SetCreatedAt sets the "created_at" field.
293func (m *OperationMutation) SetCreatedAt(t time.Time) {
294 m.created_at = &t
295}
296
297// CreatedAt returns the value of the "created_at" field in the mutation.
298func (m *OperationMutation) CreatedAt() (r time.Time, exists bool) {
299 v := m.created_at
300 if v == nil {
301 return
302 }
303 return *v, true
304}
305
306// OldCreatedAt returns the old "created_at" field's value of the Operation entity.
307// If the Operation object wasn't provided to the builder, the object is fetched from the database.
308// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
309func (m *OperationMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
310 if !m.op.Is(OpUpdateOne) {
311 return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
312 }
313 if m.id == nil || m.oldValue == nil {
314 return v, errors.New("OldCreatedAt requires an ID field in the mutation")
315 }
316 oldValue, err := m.oldValue(ctx)
317 if err != nil {
318 return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
319 }
320 return oldValue.CreatedAt, nil
321}
322
323// ResetCreatedAt resets all changes to the "created_at" field.
324func (m *OperationMutation) ResetCreatedAt() {
325 m.created_at = nil
326}
327
328// Where appends a list predicates to the OperationMutation builder.
329func (m *OperationMutation) Where(ps ...predicate.Operation) {
330 m.predicates = append(m.predicates, ps...)
331}
332
333// WhereP appends storage-level predicates to the OperationMutation builder. Using this method,
334// users can use type-assertion to append predicates that do not depend on any generated package.
335func (m *OperationMutation) WhereP(ps ...func(*sql.Selector)) {
336 p := make([]predicate.Operation, len(ps))
337 for i := range ps {
338 p[i] = ps[i]
339 }
340 m.Where(p...)
341}
342
343// Op returns the operation name.
344func (m *OperationMutation) Op() Op {
345 return m.op
346}
347
348// SetOp allows setting the mutation operation.
349func (m *OperationMutation) SetOp(op Op) {
350 m.op = op
351}
352
353// Type returns the node type of this mutation (Operation).
354func (m *OperationMutation) Type() string {
355 return m.typ
356}
357
358// Fields returns all fields that were changed during this mutation. Note that in
359// order to get all numeric fields that were incremented/decremented, call
360// AddedFields().
361func (m *OperationMutation) Fields() []string {
362 fields := make([]string, 0, 5)
363 if m.did != nil {
364 fields = append(fields, operation.FieldDid)
365 }
366 if m.operation != nil {
367 fields = append(fields, operation.FieldOperation)
368 }
369 if m.cid != nil {
370 fields = append(fields, operation.FieldCid)
371 }
372 if m.nullified != nil {
373 fields = append(fields, operation.FieldNullified)
374 }
375 if m.created_at != nil {
376 fields = append(fields, operation.FieldCreatedAt)
377 }
378 return fields
379}
380
381// Field returns the value of a field with the given name. The second boolean
382// return value indicates that this field was not set, or was not defined in the
383// schema.
384func (m *OperationMutation) Field(name string) (ent.Value, bool) {
385 switch name {
386 case operation.FieldDid:
387 return m.Did()
388 case operation.FieldOperation:
389 return m.Operation()
390 case operation.FieldCid:
391 return m.Cid()
392 case operation.FieldNullified:
393 return m.Nullified()
394 case operation.FieldCreatedAt:
395 return m.CreatedAt()
396 }
397 return nil, false
398}
399
400// OldField returns the old value of the field from the database. An error is
401// returned if the mutation operation is not UpdateOne, or the query to the
402// database failed.
403func (m *OperationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
404 switch name {
405 case operation.FieldDid:
406 return m.OldDid(ctx)
407 case operation.FieldOperation:
408 return m.OldOperation(ctx)
409 case operation.FieldCid:
410 return m.OldCid(ctx)
411 case operation.FieldNullified:
412 return m.OldNullified(ctx)
413 case operation.FieldCreatedAt:
414 return m.OldCreatedAt(ctx)
415 }
416 return nil, fmt.Errorf("unknown Operation field %s", name)
417}
418
419// SetField sets the value of a field with the given name. It returns an error if
420// the field is not defined in the schema, or if the type mismatched the field
421// type.
422func (m *OperationMutation) SetField(name string, value ent.Value) error {
423 switch name {
424 case operation.FieldDid:
425 v, ok := value.(string)
426 if !ok {
427 return fmt.Errorf("unexpected type %T for field %s", value, name)
428 }
429 m.SetDid(v)
430 return nil
431 case operation.FieldOperation:
432 v, ok := value.(plc.PLCOperation)
433 if !ok {
434 return fmt.Errorf("unexpected type %T for field %s", value, name)
435 }
436 m.SetOperation(v)
437 return nil
438 case operation.FieldCid:
439 v, ok := value.(string)
440 if !ok {
441 return fmt.Errorf("unexpected type %T for field %s", value, name)
442 }
443 m.SetCid(v)
444 return nil
445 case operation.FieldNullified:
446 v, ok := value.(bool)
447 if !ok {
448 return fmt.Errorf("unexpected type %T for field %s", value, name)
449 }
450 m.SetNullified(v)
451 return nil
452 case operation.FieldCreatedAt:
453 v, ok := value.(time.Time)
454 if !ok {
455 return fmt.Errorf("unexpected type %T for field %s", value, name)
456 }
457 m.SetCreatedAt(v)
458 return nil
459 }
460 return fmt.Errorf("unknown Operation field %s", name)
461}
462
463// AddedFields returns all numeric fields that were incremented/decremented during
464// this mutation.
465func (m *OperationMutation) AddedFields() []string {
466 return nil
467}
468
469// AddedField returns the numeric value that was incremented/decremented on a field
470// with the given name. The second boolean return value indicates that this field
471// was not set, or was not defined in the schema.
472func (m *OperationMutation) AddedField(name string) (ent.Value, bool) {
473 return nil, false
474}
475
476// AddField adds the value to the field with the given name. It returns an error if
477// the field is not defined in the schema, or if the type mismatched the field
478// type.
479func (m *OperationMutation) AddField(name string, value ent.Value) error {
480 switch name {
481 }
482 return fmt.Errorf("unknown Operation numeric field %s", name)
483}
484
485// ClearedFields returns all nullable fields that were cleared during this
486// mutation.
487func (m *OperationMutation) ClearedFields() []string {
488 return nil
489}
490
491// FieldCleared returns a boolean indicating if a field with the given name was
492// cleared in this mutation.
493func (m *OperationMutation) FieldCleared(name string) bool {
494 _, ok := m.clearedFields[name]
495 return ok
496}
497
498// ClearField clears the value of the field with the given name. It returns an
499// error if the field is not defined in the schema.
500func (m *OperationMutation) ClearField(name string) error {
501 return fmt.Errorf("unknown Operation nullable field %s", name)
502}
503
504// ResetField resets all changes in the mutation for the field with the given name.
505// It returns an error if the field is not defined in the schema.
506func (m *OperationMutation) ResetField(name string) error {
507 switch name {
508 case operation.FieldDid:
509 m.ResetDid()
510 return nil
511 case operation.FieldOperation:
512 m.ResetOperation()
513 return nil
514 case operation.FieldCid:
515 m.ResetCid()
516 return nil
517 case operation.FieldNullified:
518 m.ResetNullified()
519 return nil
520 case operation.FieldCreatedAt:
521 m.ResetCreatedAt()
522 return nil
523 }
524 return fmt.Errorf("unknown Operation field %s", name)
525}
526
527// AddedEdges returns all edge names that were set/added in this mutation.
528func (m *OperationMutation) AddedEdges() []string {
529 edges := make([]string, 0, 0)
530 return edges
531}
532
533// AddedIDs returns all IDs (to other nodes) that were added for the given edge
534// name in this mutation.
535func (m *OperationMutation) AddedIDs(name string) []ent.Value {
536 return nil
537}
538
539// RemovedEdges returns all edge names that were removed in this mutation.
540func (m *OperationMutation) RemovedEdges() []string {
541 edges := make([]string, 0, 0)
542 return edges
543}
544
545// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
546// the given name in this mutation.
547func (m *OperationMutation) RemovedIDs(name string) []ent.Value {
548 return nil
549}
550
551// ClearedEdges returns all edge names that were cleared in this mutation.
552func (m *OperationMutation) ClearedEdges() []string {
553 edges := make([]string, 0, 0)
554 return edges
555}
556
557// EdgeCleared returns a boolean which indicates if the edge with the given name
558// was cleared in this mutation.
559func (m *OperationMutation) EdgeCleared(name string) bool {
560 return false
561}
562
563// ClearEdge clears the value of the edge with the given name. It returns an error
564// if that edge is not defined in the schema.
565func (m *OperationMutation) ClearEdge(name string) error {
566 return fmt.Errorf("unknown Operation unique edge %s", name)
567}
568
569// ResetEdge resets all changes to the edge with the given name in this mutation.
570// It returns an error if the edge is not defined in the schema.
571func (m *OperationMutation) ResetEdge(name string) error {
572 return fmt.Errorf("unknown Operation edge %s", name)
573}
574
575// SyncStatusMutation represents an operation that mutates the SyncStatus nodes in the graph.
576type SyncStatusMutation struct {
577 config
578 op Op
579 typ string
580 id *int
581 key *string
582 last_operation_time *time.Time
583 last_sync_time *time.Time
584 clearedFields map[string]struct{}
585 done bool
586 oldValue func(context.Context) (*SyncStatus, error)
587 predicates []predicate.SyncStatus
588}
589
590var _ ent.Mutation = (*SyncStatusMutation)(nil)
591
592// syncstatusOption allows management of the mutation configuration using functional options.
593type syncstatusOption func(*SyncStatusMutation)
594
595// newSyncStatusMutation creates new mutation for the SyncStatus entity.
596func newSyncStatusMutation(c config, op Op, opts ...syncstatusOption) *SyncStatusMutation {
597 m := &SyncStatusMutation{
598 config: c,
599 op: op,
600 typ: TypeSyncStatus,
601 clearedFields: make(map[string]struct{}),
602 }
603 for _, opt := range opts {
604 opt(m)
605 }
606 return m
607}
608
609// withSyncStatusID sets the ID field of the mutation.
610func withSyncStatusID(id int) syncstatusOption {
611 return func(m *SyncStatusMutation) {
612 var (
613 err error
614 once sync.Once
615 value *SyncStatus
616 )
617 m.oldValue = func(ctx context.Context) (*SyncStatus, error) {
618 once.Do(func() {
619 if m.done {
620 err = errors.New("querying old values post mutation is not allowed")
621 } else {
622 value, err = m.Client().SyncStatus.Get(ctx, id)
623 }
624 })
625 return value, err
626 }
627 m.id = &id
628 }
629}
630
631// withSyncStatus sets the old SyncStatus of the mutation.
632func withSyncStatus(node *SyncStatus) syncstatusOption {
633 return func(m *SyncStatusMutation) {
634 m.oldValue = func(context.Context) (*SyncStatus, error) {
635 return node, nil
636 }
637 m.id = &node.ID
638 }
639}
640
641// Client returns a new `ent.Client` from the mutation. If the mutation was
642// executed in a transaction (ent.Tx), a transactional client is returned.
643func (m SyncStatusMutation) Client() *Client {
644 client := &Client{config: m.config}
645 client.init()
646 return client
647}
648
649// Tx returns an `ent.Tx` for mutations that were executed in transactions;
650// it returns an error otherwise.
651func (m SyncStatusMutation) Tx() (*Tx, error) {
652 if _, ok := m.driver.(*txDriver); !ok {
653 return nil, errors.New("ent: mutation is not running in a transaction")
654 }
655 tx := &Tx{config: m.config}
656 tx.init()
657 return tx, nil
658}
659
660// ID returns the ID value in the mutation. Note that the ID is only available
661// if it was provided to the builder or after it was returned from the database.
662func (m *SyncStatusMutation) ID() (id int, exists bool) {
663 if m.id == nil {
664 return
665 }
666 return *m.id, true
667}
668
669// IDs queries the database and returns the entity ids that match the mutation's predicate.
670// That means, if the mutation is applied within a transaction with an isolation level such
671// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
672// or updated by the mutation.
673func (m *SyncStatusMutation) IDs(ctx context.Context) ([]int, error) {
674 switch {
675 case m.op.Is(OpUpdateOne | OpDeleteOne):
676 id, exists := m.ID()
677 if exists {
678 return []int{id}, nil
679 }
680 fallthrough
681 case m.op.Is(OpUpdate | OpDelete):
682 return m.Client().SyncStatus.Query().Where(m.predicates...).IDs(ctx)
683 default:
684 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
685 }
686}
687
688// SetKey sets the "key" field.
689func (m *SyncStatusMutation) SetKey(s string) {
690 m.key = &s
691}
692
693// Key returns the value of the "key" field in the mutation.
694func (m *SyncStatusMutation) Key() (r string, exists bool) {
695 v := m.key
696 if v == nil {
697 return
698 }
699 return *v, true
700}
701
702// OldKey returns the old "key" field's value of the SyncStatus entity.
703// If the SyncStatus object wasn't provided to the builder, the object is fetched from the database.
704// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
705func (m *SyncStatusMutation) OldKey(ctx context.Context) (v string, err error) {
706 if !m.op.Is(OpUpdateOne) {
707 return v, errors.New("OldKey is only allowed on UpdateOne operations")
708 }
709 if m.id == nil || m.oldValue == nil {
710 return v, errors.New("OldKey requires an ID field in the mutation")
711 }
712 oldValue, err := m.oldValue(ctx)
713 if err != nil {
714 return v, fmt.Errorf("querying old value for OldKey: %w", err)
715 }
716 return oldValue.Key, nil
717}
718
719// ResetKey resets all changes to the "key" field.
720func (m *SyncStatusMutation) ResetKey() {
721 m.key = nil
722}
723
724// SetLastOperationTime sets the "last_operation_time" field.
725func (m *SyncStatusMutation) SetLastOperationTime(t time.Time) {
726 m.last_operation_time = &t
727}
728
729// LastOperationTime returns the value of the "last_operation_time" field in the mutation.
730func (m *SyncStatusMutation) LastOperationTime() (r time.Time, exists bool) {
731 v := m.last_operation_time
732 if v == nil {
733 return
734 }
735 return *v, true
736}
737
738// OldLastOperationTime returns the old "last_operation_time" field's value of the SyncStatus entity.
739// If the SyncStatus object wasn't provided to the builder, the object is fetched from the database.
740// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
741func (m *SyncStatusMutation) OldLastOperationTime(ctx context.Context) (v time.Time, err error) {
742 if !m.op.Is(OpUpdateOne) {
743 return v, errors.New("OldLastOperationTime is only allowed on UpdateOne operations")
744 }
745 if m.id == nil || m.oldValue == nil {
746 return v, errors.New("OldLastOperationTime requires an ID field in the mutation")
747 }
748 oldValue, err := m.oldValue(ctx)
749 if err != nil {
750 return v, fmt.Errorf("querying old value for OldLastOperationTime: %w", err)
751 }
752 return oldValue.LastOperationTime, nil
753}
754
755// ResetLastOperationTime resets all changes to the "last_operation_time" field.
756func (m *SyncStatusMutation) ResetLastOperationTime() {
757 m.last_operation_time = nil
758}
759
760// SetLastSyncTime sets the "last_sync_time" field.
761func (m *SyncStatusMutation) SetLastSyncTime(t time.Time) {
762 m.last_sync_time = &t
763}
764
765// LastSyncTime returns the value of the "last_sync_time" field in the mutation.
766func (m *SyncStatusMutation) LastSyncTime() (r time.Time, exists bool) {
767 v := m.last_sync_time
768 if v == nil {
769 return
770 }
771 return *v, true
772}
773
774// OldLastSyncTime returns the old "last_sync_time" field's value of the SyncStatus entity.
775// If the SyncStatus object wasn't provided to the builder, the object is fetched from the database.
776// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
777func (m *SyncStatusMutation) OldLastSyncTime(ctx context.Context) (v time.Time, err error) {
778 if !m.op.Is(OpUpdateOne) {
779 return v, errors.New("OldLastSyncTime is only allowed on UpdateOne operations")
780 }
781 if m.id == nil || m.oldValue == nil {
782 return v, errors.New("OldLastSyncTime requires an ID field in the mutation")
783 }
784 oldValue, err := m.oldValue(ctx)
785 if err != nil {
786 return v, fmt.Errorf("querying old value for OldLastSyncTime: %w", err)
787 }
788 return oldValue.LastSyncTime, nil
789}
790
791// ResetLastSyncTime resets all changes to the "last_sync_time" field.
792func (m *SyncStatusMutation) ResetLastSyncTime() {
793 m.last_sync_time = nil
794}
795
796// Where appends a list predicates to the SyncStatusMutation builder.
797func (m *SyncStatusMutation) Where(ps ...predicate.SyncStatus) {
798 m.predicates = append(m.predicates, ps...)
799}
800
801// WhereP appends storage-level predicates to the SyncStatusMutation builder. Using this method,
802// users can use type-assertion to append predicates that do not depend on any generated package.
803func (m *SyncStatusMutation) WhereP(ps ...func(*sql.Selector)) {
804 p := make([]predicate.SyncStatus, len(ps))
805 for i := range ps {
806 p[i] = ps[i]
807 }
808 m.Where(p...)
809}
810
811// Op returns the operation name.
812func (m *SyncStatusMutation) Op() Op {
813 return m.op
814}
815
816// SetOp allows setting the mutation operation.
817func (m *SyncStatusMutation) SetOp(op Op) {
818 m.op = op
819}
820
821// Type returns the node type of this mutation (SyncStatus).
822func (m *SyncStatusMutation) Type() string {
823 return m.typ
824}
825
826// Fields returns all fields that were changed during this mutation. Note that in
827// order to get all numeric fields that were incremented/decremented, call
828// AddedFields().
829func (m *SyncStatusMutation) Fields() []string {
830 fields := make([]string, 0, 3)
831 if m.key != nil {
832 fields = append(fields, syncstatus.FieldKey)
833 }
834 if m.last_operation_time != nil {
835 fields = append(fields, syncstatus.FieldLastOperationTime)
836 }
837 if m.last_sync_time != nil {
838 fields = append(fields, syncstatus.FieldLastSyncTime)
839 }
840 return fields
841}
842
843// Field returns the value of a field with the given name. The second boolean
844// return value indicates that this field was not set, or was not defined in the
845// schema.
846func (m *SyncStatusMutation) Field(name string) (ent.Value, bool) {
847 switch name {
848 case syncstatus.FieldKey:
849 return m.Key()
850 case syncstatus.FieldLastOperationTime:
851 return m.LastOperationTime()
852 case syncstatus.FieldLastSyncTime:
853 return m.LastSyncTime()
854 }
855 return nil, false
856}
857
858// OldField returns the old value of the field from the database. An error is
859// returned if the mutation operation is not UpdateOne, or the query to the
860// database failed.
861func (m *SyncStatusMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
862 switch name {
863 case syncstatus.FieldKey:
864 return m.OldKey(ctx)
865 case syncstatus.FieldLastOperationTime:
866 return m.OldLastOperationTime(ctx)
867 case syncstatus.FieldLastSyncTime:
868 return m.OldLastSyncTime(ctx)
869 }
870 return nil, fmt.Errorf("unknown SyncStatus field %s", name)
871}
872
873// SetField sets the value of a field with the given name. It returns an error if
874// the field is not defined in the schema, or if the type mismatched the field
875// type.
876func (m *SyncStatusMutation) SetField(name string, value ent.Value) error {
877 switch name {
878 case syncstatus.FieldKey:
879 v, ok := value.(string)
880 if !ok {
881 return fmt.Errorf("unexpected type %T for field %s", value, name)
882 }
883 m.SetKey(v)
884 return nil
885 case syncstatus.FieldLastOperationTime:
886 v, ok := value.(time.Time)
887 if !ok {
888 return fmt.Errorf("unexpected type %T for field %s", value, name)
889 }
890 m.SetLastOperationTime(v)
891 return nil
892 case syncstatus.FieldLastSyncTime:
893 v, ok := value.(time.Time)
894 if !ok {
895 return fmt.Errorf("unexpected type %T for field %s", value, name)
896 }
897 m.SetLastSyncTime(v)
898 return nil
899 }
900 return fmt.Errorf("unknown SyncStatus field %s", name)
901}
902
903// AddedFields returns all numeric fields that were incremented/decremented during
904// this mutation.
905func (m *SyncStatusMutation) AddedFields() []string {
906 return nil
907}
908
909// AddedField returns the numeric value that was incremented/decremented on a field
910// with the given name. The second boolean return value indicates that this field
911// was not set, or was not defined in the schema.
912func (m *SyncStatusMutation) AddedField(name string) (ent.Value, bool) {
913 return nil, false
914}
915
916// AddField adds the value to the field with the given name. It returns an error if
917// the field is not defined in the schema, or if the type mismatched the field
918// type.
919func (m *SyncStatusMutation) AddField(name string, value ent.Value) error {
920 switch name {
921 }
922 return fmt.Errorf("unknown SyncStatus numeric field %s", name)
923}
924
925// ClearedFields returns all nullable fields that were cleared during this
926// mutation.
927func (m *SyncStatusMutation) ClearedFields() []string {
928 return nil
929}
930
931// FieldCleared returns a boolean indicating if a field with the given name was
932// cleared in this mutation.
933func (m *SyncStatusMutation) FieldCleared(name string) bool {
934 _, ok := m.clearedFields[name]
935 return ok
936}
937
938// ClearField clears the value of the field with the given name. It returns an
939// error if the field is not defined in the schema.
940func (m *SyncStatusMutation) ClearField(name string) error {
941 return fmt.Errorf("unknown SyncStatus nullable field %s", name)
942}
943
944// ResetField resets all changes in the mutation for the field with the given name.
945// It returns an error if the field is not defined in the schema.
946func (m *SyncStatusMutation) ResetField(name string) error {
947 switch name {
948 case syncstatus.FieldKey:
949 m.ResetKey()
950 return nil
951 case syncstatus.FieldLastOperationTime:
952 m.ResetLastOperationTime()
953 return nil
954 case syncstatus.FieldLastSyncTime:
955 m.ResetLastSyncTime()
956 return nil
957 }
958 return fmt.Errorf("unknown SyncStatus field %s", name)
959}
960
961// AddedEdges returns all edge names that were set/added in this mutation.
962func (m *SyncStatusMutation) AddedEdges() []string {
963 edges := make([]string, 0, 0)
964 return edges
965}
966
967// AddedIDs returns all IDs (to other nodes) that were added for the given edge
968// name in this mutation.
969func (m *SyncStatusMutation) AddedIDs(name string) []ent.Value {
970 return nil
971}
972
973// RemovedEdges returns all edge names that were removed in this mutation.
974func (m *SyncStatusMutation) RemovedEdges() []string {
975 edges := make([]string, 0, 0)
976 return edges
977}
978
979// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
980// the given name in this mutation.
981func (m *SyncStatusMutation) RemovedIDs(name string) []ent.Value {
982 return nil
983}
984
985// ClearedEdges returns all edge names that were cleared in this mutation.
986func (m *SyncStatusMutation) ClearedEdges() []string {
987 edges := make([]string, 0, 0)
988 return edges
989}
990
991// EdgeCleared returns a boolean which indicates if the edge with the given name
992// was cleared in this mutation.
993func (m *SyncStatusMutation) EdgeCleared(name string) bool {
994 return false
995}
996
997// ClearEdge clears the value of the edge with the given name. It returns an error
998// if that edge is not defined in the schema.
999func (m *SyncStatusMutation) ClearEdge(name string) error {
1000 return fmt.Errorf("unknown SyncStatus unique edge %s", name)
1001}
1002
1003// ResetEdge resets all changes to the edge with the given name in this mutation.
1004// It returns an error if the edge is not defined in the schema.
1005func (m *SyncStatusMutation) ResetEdge(name string) error {
1006 return fmt.Errorf("unknown SyncStatus edge %s", name)
1007}