oceanbase

Форк
0
645 строк · 19.2 Кб
1
// Code generated by entc, DO NOT EDIT.
2

3
package ent
4

5
import (
6
	"context"
7
	"errors"
8
	"fmt"
9
	"sync"
10
	"time"
11

12
	"github.com/oceanbase/configserver/ent/obcluster"
13
	"github.com/oceanbase/configserver/ent/predicate"
14

15
	"entgo.io/ent"
16
)
17

18
const (
19
	// Operation types.
20
	OpCreate    = ent.OpCreate
21
	OpDelete    = ent.OpDelete
22
	OpDeleteOne = ent.OpDeleteOne
23
	OpUpdate    = ent.OpUpdate
24
	OpUpdateOne = ent.OpUpdateOne
25

26
	// Node types.
27
	TypeObCluster = "ObCluster"
28
)
29

30
// ObClusterMutation represents an operation that mutates the ObCluster nodes in the graph.
31
type ObClusterMutation struct {
32
	config
33
	op               Op
34
	typ              string
35
	id               *int
36
	create_time      *time.Time
37
	update_time      *time.Time
38
	name             *string
39
	ob_cluster_id    *int64
40
	addob_cluster_id *int64
41
	_type            *string
42
	rootservice_json *string
43
	clearedFields    map[string]struct{}
44
	done             bool
45
	oldValue         func(context.Context) (*ObCluster, error)
46
	predicates       []predicate.ObCluster
47
}
48

49
var _ ent.Mutation = (*ObClusterMutation)(nil)
50

51
// obclusterOption allows management of the mutation configuration using functional options.
52
type obclusterOption func(*ObClusterMutation)
53

54
// newObClusterMutation creates new mutation for the ObCluster entity.
55
func newObClusterMutation(c config, op Op, opts ...obclusterOption) *ObClusterMutation {
56
	m := &ObClusterMutation{
57
		config:        c,
58
		op:            op,
59
		typ:           TypeObCluster,
60
		clearedFields: make(map[string]struct{}),
61
	}
62
	for _, opt := range opts {
63
		opt(m)
64
	}
65
	return m
66
}
67

68
// withObClusterID sets the ID field of the mutation.
69
func withObClusterID(id int) obclusterOption {
70
	return func(m *ObClusterMutation) {
71
		var (
72
			err   error
73
			once  sync.Once
74
			value *ObCluster
75
		)
76
		m.oldValue = func(ctx context.Context) (*ObCluster, error) {
77
			once.Do(func() {
78
				if m.done {
79
					err = errors.New("querying old values post mutation is not allowed")
80
				} else {
81
					value, err = m.Client().ObCluster.Get(ctx, id)
82
				}
83
			})
84
			return value, err
85
		}
86
		m.id = &id
87
	}
88
}
89

90
// withObCluster sets the old ObCluster of the mutation.
91
func withObCluster(node *ObCluster) obclusterOption {
92
	return func(m *ObClusterMutation) {
93
		m.oldValue = func(context.Context) (*ObCluster, error) {
94
			return node, nil
95
		}
96
		m.id = &node.ID
97
	}
98
}
99

100
// Client returns a new `ent.Client` from the mutation. If the mutation was
101
// executed in a transaction (ent.Tx), a transactional client is returned.
102
func (m ObClusterMutation) Client() *Client {
103
	client := &Client{config: m.config}
104
	client.init()
105
	return client
106
}
107

108
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
109
// it returns an error otherwise.
110
func (m ObClusterMutation) Tx() (*Tx, error) {
111
	if _, ok := m.driver.(*txDriver); !ok {
112
		return nil, errors.New("ent: mutation is not running in a transaction")
113
	}
114
	tx := &Tx{config: m.config}
115
	tx.init()
116
	return tx, nil
117
}
118

119
// ID returns the ID value in the mutation. Note that the ID is only available
120
// if it was provided to the builder or after it was returned from the database.
121
func (m *ObClusterMutation) ID() (id int, exists bool) {
122
	if m.id == nil {
123
		return
124
	}
125
	return *m.id, true
126
}
127

128
// IDs queries the database and returns the entity ids that match the mutation's predicate.
129
// That means, if the mutation is applied within a transaction with an isolation level such
130
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
131
// or updated by the mutation.
132
func (m *ObClusterMutation) IDs(ctx context.Context) ([]int, error) {
133
	switch {
134
	case m.op.Is(OpUpdateOne | OpDeleteOne):
135
		id, exists := m.ID()
136
		if exists {
137
			return []int{id}, nil
138
		}
139
		fallthrough
140
	case m.op.Is(OpUpdate | OpDelete):
141
		return m.Client().ObCluster.Query().Where(m.predicates...).IDs(ctx)
142
	default:
143
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
144
	}
145
}
146

147
// SetCreateTime sets the "create_time" field.
148
func (m *ObClusterMutation) SetCreateTime(t time.Time) {
149
	m.create_time = &t
150
}
151

152
// CreateTime returns the value of the "create_time" field in the mutation.
153
func (m *ObClusterMutation) CreateTime() (r time.Time, exists bool) {
154
	v := m.create_time
155
	if v == nil {
156
		return
157
	}
158
	return *v, true
159
}
160

161
// OldCreateTime returns the old "create_time" field's value of the ObCluster entity.
162
// If the ObCluster object wasn't provided to the builder, the object is fetched from the database.
163
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
164
func (m *ObClusterMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) {
165
	if !m.op.Is(OpUpdateOne) {
166
		return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")
167
	}
168
	if m.id == nil || m.oldValue == nil {
169
		return v, errors.New("OldCreateTime requires an ID field in the mutation")
170
	}
171
	oldValue, err := m.oldValue(ctx)
172
	if err != nil {
173
		return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)
174
	}
175
	return oldValue.CreateTime, nil
176
}
177

178
// ResetCreateTime resets all changes to the "create_time" field.
179
func (m *ObClusterMutation) ResetCreateTime() {
180
	m.create_time = nil
181
}
182

183
// SetUpdateTime sets the "update_time" field.
184
func (m *ObClusterMutation) SetUpdateTime(t time.Time) {
185
	m.update_time = &t
186
}
187

188
// UpdateTime returns the value of the "update_time" field in the mutation.
189
func (m *ObClusterMutation) UpdateTime() (r time.Time, exists bool) {
190
	v := m.update_time
191
	if v == nil {
192
		return
193
	}
194
	return *v, true
195
}
196

197
// OldUpdateTime returns the old "update_time" field's value of the ObCluster entity.
198
// If the ObCluster object wasn't provided to the builder, the object is fetched from the database.
199
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
200
func (m *ObClusterMutation) OldUpdateTime(ctx context.Context) (v time.Time, err error) {
201
	if !m.op.Is(OpUpdateOne) {
202
		return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")
203
	}
204
	if m.id == nil || m.oldValue == nil {
205
		return v, errors.New("OldUpdateTime requires an ID field in the mutation")
206
	}
207
	oldValue, err := m.oldValue(ctx)
208
	if err != nil {
209
		return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)
210
	}
211
	return oldValue.UpdateTime, nil
212
}
213

214
// ResetUpdateTime resets all changes to the "update_time" field.
215
func (m *ObClusterMutation) ResetUpdateTime() {
216
	m.update_time = nil
217
}
218

219
// SetName sets the "name" field.
220
func (m *ObClusterMutation) SetName(s string) {
221
	m.name = &s
222
}
223

224
// Name returns the value of the "name" field in the mutation.
225
func (m *ObClusterMutation) Name() (r string, exists bool) {
226
	v := m.name
227
	if v == nil {
228
		return
229
	}
230
	return *v, true
231
}
232

233
// OldName returns the old "name" field's value of the ObCluster entity.
234
// If the ObCluster object wasn't provided to the builder, the object is fetched from the database.
235
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
236
func (m *ObClusterMutation) OldName(ctx context.Context) (v string, err error) {
237
	if !m.op.Is(OpUpdateOne) {
238
		return v, errors.New("OldName is only allowed on UpdateOne operations")
239
	}
240
	if m.id == nil || m.oldValue == nil {
241
		return v, errors.New("OldName requires an ID field in the mutation")
242
	}
243
	oldValue, err := m.oldValue(ctx)
244
	if err != nil {
245
		return v, fmt.Errorf("querying old value for OldName: %w", err)
246
	}
247
	return oldValue.Name, nil
248
}
249

250
// ResetName resets all changes to the "name" field.
251
func (m *ObClusterMutation) ResetName() {
252
	m.name = nil
253
}
254

255
// SetObClusterID sets the "ob_cluster_id" field.
256
func (m *ObClusterMutation) SetObClusterID(i int64) {
257
	m.ob_cluster_id = &i
258
	m.addob_cluster_id = nil
259
}
260

261
// ObClusterID returns the value of the "ob_cluster_id" field in the mutation.
262
func (m *ObClusterMutation) ObClusterID() (r int64, exists bool) {
263
	v := m.ob_cluster_id
264
	if v == nil {
265
		return
266
	}
267
	return *v, true
268
}
269

270
// OldObClusterID returns the old "ob_cluster_id" field's value of the ObCluster entity.
271
// If the ObCluster 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.
273
func (m *ObClusterMutation) OldObClusterID(ctx context.Context) (v int64, err error) {
274
	if !m.op.Is(OpUpdateOne) {
275
		return v, errors.New("OldObClusterID is only allowed on UpdateOne operations")
276
	}
277
	if m.id == nil || m.oldValue == nil {
278
		return v, errors.New("OldObClusterID 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 OldObClusterID: %w", err)
283
	}
284
	return oldValue.ObClusterID, nil
285
}
286

287
// AddObClusterID adds i to the "ob_cluster_id" field.
288
func (m *ObClusterMutation) AddObClusterID(i int64) {
289
	if m.addob_cluster_id != nil {
290
		*m.addob_cluster_id += i
291
	} else {
292
		m.addob_cluster_id = &i
293
	}
294
}
295

296
// AddedObClusterID returns the value that was added to the "ob_cluster_id" field in this mutation.
297
func (m *ObClusterMutation) AddedObClusterID() (r int64, exists bool) {
298
	v := m.addob_cluster_id
299
	if v == nil {
300
		return
301
	}
302
	return *v, true
303
}
304

305
// ResetObClusterID resets all changes to the "ob_cluster_id" field.
306
func (m *ObClusterMutation) ResetObClusterID() {
307
	m.ob_cluster_id = nil
308
	m.addob_cluster_id = nil
309
}
310

311
// SetType sets the "type" field.
312
func (m *ObClusterMutation) SetType(s string) {
313
	m._type = &s
314
}
315

316
// GetType returns the value of the "type" field in the mutation.
317
func (m *ObClusterMutation) GetType() (r string, exists bool) {
318
	v := m._type
319
	if v == nil {
320
		return
321
	}
322
	return *v, true
323
}
324

325
// OldType returns the old "type" field's value of the ObCluster entity.
326
// If the ObCluster object wasn't provided to the builder, the object is fetched from the database.
327
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
328
func (m *ObClusterMutation) OldType(ctx context.Context) (v string, err error) {
329
	if !m.op.Is(OpUpdateOne) {
330
		return v, errors.New("OldType is only allowed on UpdateOne operations")
331
	}
332
	if m.id == nil || m.oldValue == nil {
333
		return v, errors.New("OldType requires an ID field in the mutation")
334
	}
335
	oldValue, err := m.oldValue(ctx)
336
	if err != nil {
337
		return v, fmt.Errorf("querying old value for OldType: %w", err)
338
	}
339
	return oldValue.Type, nil
340
}
341

342
// ResetType resets all changes to the "type" field.
343
func (m *ObClusterMutation) ResetType() {
344
	m._type = nil
345
}
346

347
// SetRootserviceJSON sets the "rootservice_json" field.
348
func (m *ObClusterMutation) SetRootserviceJSON(s string) {
349
	m.rootservice_json = &s
350
}
351

352
// RootserviceJSON returns the value of the "rootservice_json" field in the mutation.
353
func (m *ObClusterMutation) RootserviceJSON() (r string, exists bool) {
354
	v := m.rootservice_json
355
	if v == nil {
356
		return
357
	}
358
	return *v, true
359
}
360

361
// OldRootserviceJSON returns the old "rootservice_json" field's value of the ObCluster entity.
362
// If the ObCluster object wasn't provided to the builder, the object is fetched from the database.
363
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
364
func (m *ObClusterMutation) OldRootserviceJSON(ctx context.Context) (v string, err error) {
365
	if !m.op.Is(OpUpdateOne) {
366
		return v, errors.New("OldRootserviceJSON is only allowed on UpdateOne operations")
367
	}
368
	if m.id == nil || m.oldValue == nil {
369
		return v, errors.New("OldRootserviceJSON requires an ID field in the mutation")
370
	}
371
	oldValue, err := m.oldValue(ctx)
372
	if err != nil {
373
		return v, fmt.Errorf("querying old value for OldRootserviceJSON: %w", err)
374
	}
375
	return oldValue.RootserviceJSON, nil
376
}
377

378
// ResetRootserviceJSON resets all changes to the "rootservice_json" field.
379
func (m *ObClusterMutation) ResetRootserviceJSON() {
380
	m.rootservice_json = nil
381
}
382

383
// Where appends a list predicates to the ObClusterMutation builder.
384
func (m *ObClusterMutation) Where(ps ...predicate.ObCluster) {
385
	m.predicates = append(m.predicates, ps...)
386
}
387

388
// Op returns the operation name.
389
func (m *ObClusterMutation) Op() Op {
390
	return m.op
391
}
392

393
// Type returns the node type of this mutation (ObCluster).
394
func (m *ObClusterMutation) Type() string {
395
	return m.typ
396
}
397

398
// Fields returns all fields that were changed during this mutation. Note that in
399
// order to get all numeric fields that were incremented/decremented, call
400
// AddedFields().
401
func (m *ObClusterMutation) Fields() []string {
402
	fields := make([]string, 0, 6)
403
	if m.create_time != nil {
404
		fields = append(fields, obcluster.FieldCreateTime)
405
	}
406
	if m.update_time != nil {
407
		fields = append(fields, obcluster.FieldUpdateTime)
408
	}
409
	if m.name != nil {
410
		fields = append(fields, obcluster.FieldName)
411
	}
412
	if m.ob_cluster_id != nil {
413
		fields = append(fields, obcluster.FieldObClusterID)
414
	}
415
	if m._type != nil {
416
		fields = append(fields, obcluster.FieldType)
417
	}
418
	if m.rootservice_json != nil {
419
		fields = append(fields, obcluster.FieldRootserviceJSON)
420
	}
421
	return fields
422
}
423

424
// Field returns the value of a field with the given name. The second boolean
425
// return value indicates that this field was not set, or was not defined in the
426
// schema.
427
func (m *ObClusterMutation) Field(name string) (ent.Value, bool) {
428
	switch name {
429
	case obcluster.FieldCreateTime:
430
		return m.CreateTime()
431
	case obcluster.FieldUpdateTime:
432
		return m.UpdateTime()
433
	case obcluster.FieldName:
434
		return m.Name()
435
	case obcluster.FieldObClusterID:
436
		return m.ObClusterID()
437
	case obcluster.FieldType:
438
		return m.GetType()
439
	case obcluster.FieldRootserviceJSON:
440
		return m.RootserviceJSON()
441
	}
442
	return nil, false
443
}
444

445
// OldField returns the old value of the field from the database. An error is
446
// returned if the mutation operation is not UpdateOne, or the query to the
447
// database failed.
448
func (m *ObClusterMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
449
	switch name {
450
	case obcluster.FieldCreateTime:
451
		return m.OldCreateTime(ctx)
452
	case obcluster.FieldUpdateTime:
453
		return m.OldUpdateTime(ctx)
454
	case obcluster.FieldName:
455
		return m.OldName(ctx)
456
	case obcluster.FieldObClusterID:
457
		return m.OldObClusterID(ctx)
458
	case obcluster.FieldType:
459
		return m.OldType(ctx)
460
	case obcluster.FieldRootserviceJSON:
461
		return m.OldRootserviceJSON(ctx)
462
	}
463
	return nil, fmt.Errorf("unknown ObCluster field %s", name)
464
}
465

466
// SetField sets the value of a field with the given name. It returns an error if
467
// the field is not defined in the schema, or if the type mismatched the field
468
// type.
469
func (m *ObClusterMutation) SetField(name string, value ent.Value) error {
470
	switch name {
471
	case obcluster.FieldCreateTime:
472
		v, ok := value.(time.Time)
473
		if !ok {
474
			return fmt.Errorf("unexpected type %T for field %s", value, name)
475
		}
476
		m.SetCreateTime(v)
477
		return nil
478
	case obcluster.FieldUpdateTime:
479
		v, ok := value.(time.Time)
480
		if !ok {
481
			return fmt.Errorf("unexpected type %T for field %s", value, name)
482
		}
483
		m.SetUpdateTime(v)
484
		return nil
485
	case obcluster.FieldName:
486
		v, ok := value.(string)
487
		if !ok {
488
			return fmt.Errorf("unexpected type %T for field %s", value, name)
489
		}
490
		m.SetName(v)
491
		return nil
492
	case obcluster.FieldObClusterID:
493
		v, ok := value.(int64)
494
		if !ok {
495
			return fmt.Errorf("unexpected type %T for field %s", value, name)
496
		}
497
		m.SetObClusterID(v)
498
		return nil
499
	case obcluster.FieldType:
500
		v, ok := value.(string)
501
		if !ok {
502
			return fmt.Errorf("unexpected type %T for field %s", value, name)
503
		}
504
		m.SetType(v)
505
		return nil
506
	case obcluster.FieldRootserviceJSON:
507
		v, ok := value.(string)
508
		if !ok {
509
			return fmt.Errorf("unexpected type %T for field %s", value, name)
510
		}
511
		m.SetRootserviceJSON(v)
512
		return nil
513
	}
514
	return fmt.Errorf("unknown ObCluster field %s", name)
515
}
516

517
// AddedFields returns all numeric fields that were incremented/decremented during
518
// this mutation.
519
func (m *ObClusterMutation) AddedFields() []string {
520
	var fields []string
521
	if m.addob_cluster_id != nil {
522
		fields = append(fields, obcluster.FieldObClusterID)
523
	}
524
	return fields
525
}
526

527
// AddedField returns the numeric value that was incremented/decremented on a field
528
// with the given name. The second boolean return value indicates that this field
529
// was not set, or was not defined in the schema.
530
func (m *ObClusterMutation) AddedField(name string) (ent.Value, bool) {
531
	switch name {
532
	case obcluster.FieldObClusterID:
533
		return m.AddedObClusterID()
534
	}
535
	return nil, false
536
}
537

538
// AddField adds the value to the field with the given name. It returns an error if
539
// the field is not defined in the schema, or if the type mismatched the field
540
// type.
541
func (m *ObClusterMutation) AddField(name string, value ent.Value) error {
542
	switch name {
543
	case obcluster.FieldObClusterID:
544
		v, ok := value.(int64)
545
		if !ok {
546
			return fmt.Errorf("unexpected type %T for field %s", value, name)
547
		}
548
		m.AddObClusterID(v)
549
		return nil
550
	}
551
	return fmt.Errorf("unknown ObCluster numeric field %s", name)
552
}
553

554
// ClearedFields returns all nullable fields that were cleared during this
555
// mutation.
556
func (m *ObClusterMutation) ClearedFields() []string {
557
	return nil
558
}
559

560
// FieldCleared returns a boolean indicating if a field with the given name was
561
// cleared in this mutation.
562
func (m *ObClusterMutation) FieldCleared(name string) bool {
563
	_, ok := m.clearedFields[name]
564
	return ok
565
}
566

567
// ClearField clears the value of the field with the given name. It returns an
568
// error if the field is not defined in the schema.
569
func (m *ObClusterMutation) ClearField(name string) error {
570
	return fmt.Errorf("unknown ObCluster nullable field %s", name)
571
}
572

573
// ResetField resets all changes in the mutation for the field with the given name.
574
// It returns an error if the field is not defined in the schema.
575
func (m *ObClusterMutation) ResetField(name string) error {
576
	switch name {
577
	case obcluster.FieldCreateTime:
578
		m.ResetCreateTime()
579
		return nil
580
	case obcluster.FieldUpdateTime:
581
		m.ResetUpdateTime()
582
		return nil
583
	case obcluster.FieldName:
584
		m.ResetName()
585
		return nil
586
	case obcluster.FieldObClusterID:
587
		m.ResetObClusterID()
588
		return nil
589
	case obcluster.FieldType:
590
		m.ResetType()
591
		return nil
592
	case obcluster.FieldRootserviceJSON:
593
		m.ResetRootserviceJSON()
594
		return nil
595
	}
596
	return fmt.Errorf("unknown ObCluster field %s", name)
597
}
598

599
// AddedEdges returns all edge names that were set/added in this mutation.
600
func (m *ObClusterMutation) AddedEdges() []string {
601
	edges := make([]string, 0, 0)
602
	return edges
603
}
604

605
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
606
// name in this mutation.
607
func (m *ObClusterMutation) AddedIDs(name string) []ent.Value {
608
	return nil
609
}
610

611
// RemovedEdges returns all edge names that were removed in this mutation.
612
func (m *ObClusterMutation) RemovedEdges() []string {
613
	edges := make([]string, 0, 0)
614
	return edges
615
}
616

617
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
618
// the given name in this mutation.
619
func (m *ObClusterMutation) RemovedIDs(name string) []ent.Value {
620
	return nil
621
}
622

623
// ClearedEdges returns all edge names that were cleared in this mutation.
624
func (m *ObClusterMutation) ClearedEdges() []string {
625
	edges := make([]string, 0, 0)
626
	return edges
627
}
628

629
// EdgeCleared returns a boolean which indicates if the edge with the given name
630
// was cleared in this mutation.
631
func (m *ObClusterMutation) EdgeCleared(name string) bool {
632
	return false
633
}
634

635
// ClearEdge clears the value of the edge with the given name. It returns an error
636
// if that edge is not defined in the schema.
637
func (m *ObClusterMutation) ClearEdge(name string) error {
638
	return fmt.Errorf("unknown ObCluster unique edge %s", name)
639
}
640

641
// ResetEdge resets all changes to the edge with the given name in this mutation.
642
// It returns an error if the edge is not defined in the schema.
643
func (m *ObClusterMutation) ResetEdge(name string) error {
644
	return fmt.Errorf("unknown ObCluster edge %s", name)
645
}
646

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.