oceanbase
645 строк · 19.2 Кб
1// Code generated by entc, DO NOT EDIT.
2
3package ent4
5import (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
18const (19// Operation types.20OpCreate = ent.OpCreate21OpDelete = ent.OpDelete22OpDeleteOne = ent.OpDeleteOne23OpUpdate = ent.OpUpdate24OpUpdateOne = ent.OpUpdateOne25
26// Node types.27TypeObCluster = "ObCluster"28)
29
30// ObClusterMutation represents an operation that mutates the ObCluster nodes in the graph.
31type ObClusterMutation struct {32config
33op Op
34typ string35id *int36create_time *time.Time37update_time *time.Time38name *string39ob_cluster_id *int6440addob_cluster_id *int6441_type *string42rootservice_json *string43clearedFields map[string]struct{}44done bool45oldValue func(context.Context) (*ObCluster, error)46predicates []predicate.ObCluster47}
48
49var _ ent.Mutation = (*ObClusterMutation)(nil)50
51// obclusterOption allows management of the mutation configuration using functional options.
52type obclusterOption func(*ObClusterMutation)53
54// newObClusterMutation creates new mutation for the ObCluster entity.
55func newObClusterMutation(c config, op Op, opts ...obclusterOption) *ObClusterMutation {56m := &ObClusterMutation{57config: c,58op: op,59typ: TypeObCluster,60clearedFields: make(map[string]struct{}),61}62for _, opt := range opts {63opt(m)64}65return m66}
67
68// withObClusterID sets the ID field of the mutation.
69func withObClusterID(id int) obclusterOption {70return func(m *ObClusterMutation) {71var (72err error73once sync.Once74value *ObCluster75)76m.oldValue = func(ctx context.Context) (*ObCluster, error) {77once.Do(func() {78if m.done {79err = errors.New("querying old values post mutation is not allowed")80} else {81value, err = m.Client().ObCluster.Get(ctx, id)82}83})84return value, err85}86m.id = &id87}88}
89
90// withObCluster sets the old ObCluster of the mutation.
91func withObCluster(node *ObCluster) obclusterOption {92return func(m *ObClusterMutation) {93m.oldValue = func(context.Context) (*ObCluster, error) {94return node, nil95}96m.id = &node.ID97}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.
102func (m ObClusterMutation) Client() *Client {103client := &Client{config: m.config}104client.init()105return client106}
107
108// Tx returns an `ent.Tx` for mutations that were executed in transactions;
109// it returns an error otherwise.
110func (m ObClusterMutation) Tx() (*Tx, error) {111if _, ok := m.driver.(*txDriver); !ok {112return nil, errors.New("ent: mutation is not running in a transaction")113}114tx := &Tx{config: m.config}115tx.init()116return tx, nil117}
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.
121func (m *ObClusterMutation) ID() (id int, exists bool) {122if m.id == nil {123return124}125return *m.id, true126}
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.
132func (m *ObClusterMutation) IDs(ctx context.Context) ([]int, error) {133switch {134case m.op.Is(OpUpdateOne | OpDeleteOne):135id, exists := m.ID()136if exists {137return []int{id}, nil138}139fallthrough140case m.op.Is(OpUpdate | OpDelete):141return m.Client().ObCluster.Query().Where(m.predicates...).IDs(ctx)142default:143return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)144}145}
146
147// SetCreateTime sets the "create_time" field.
148func (m *ObClusterMutation) SetCreateTime(t time.Time) {149m.create_time = &t150}
151
152// CreateTime returns the value of the "create_time" field in the mutation.
153func (m *ObClusterMutation) CreateTime() (r time.Time, exists bool) {154v := m.create_time155if v == nil {156return157}158return *v, true159}
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.
164func (m *ObClusterMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) {165if !m.op.Is(OpUpdateOne) {166return v, errors.New("OldCreateTime is only allowed on UpdateOne operations")167}168if m.id == nil || m.oldValue == nil {169return v, errors.New("OldCreateTime requires an ID field in the mutation")170}171oldValue, err := m.oldValue(ctx)172if err != nil {173return v, fmt.Errorf("querying old value for OldCreateTime: %w", err)174}175return oldValue.CreateTime, nil176}
177
178// ResetCreateTime resets all changes to the "create_time" field.
179func (m *ObClusterMutation) ResetCreateTime() {180m.create_time = nil181}
182
183// SetUpdateTime sets the "update_time" field.
184func (m *ObClusterMutation) SetUpdateTime(t time.Time) {185m.update_time = &t186}
187
188// UpdateTime returns the value of the "update_time" field in the mutation.
189func (m *ObClusterMutation) UpdateTime() (r time.Time, exists bool) {190v := m.update_time191if v == nil {192return193}194return *v, true195}
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.
200func (m *ObClusterMutation) OldUpdateTime(ctx context.Context) (v time.Time, err error) {201if !m.op.Is(OpUpdateOne) {202return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations")203}204if m.id == nil || m.oldValue == nil {205return v, errors.New("OldUpdateTime requires an ID field in the mutation")206}207oldValue, err := m.oldValue(ctx)208if err != nil {209return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err)210}211return oldValue.UpdateTime, nil212}
213
214// ResetUpdateTime resets all changes to the "update_time" field.
215func (m *ObClusterMutation) ResetUpdateTime() {216m.update_time = nil217}
218
219// SetName sets the "name" field.
220func (m *ObClusterMutation) SetName(s string) {221m.name = &s222}
223
224// Name returns the value of the "name" field in the mutation.
225func (m *ObClusterMutation) Name() (r string, exists bool) {226v := m.name227if v == nil {228return229}230return *v, true231}
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.
236func (m *ObClusterMutation) OldName(ctx context.Context) (v string, err error) {237if !m.op.Is(OpUpdateOne) {238return v, errors.New("OldName is only allowed on UpdateOne operations")239}240if m.id == nil || m.oldValue == nil {241return v, errors.New("OldName requires an ID field in the mutation")242}243oldValue, err := m.oldValue(ctx)244if err != nil {245return v, fmt.Errorf("querying old value for OldName: %w", err)246}247return oldValue.Name, nil248}
249
250// ResetName resets all changes to the "name" field.
251func (m *ObClusterMutation) ResetName() {252m.name = nil253}
254
255// SetObClusterID sets the "ob_cluster_id" field.
256func (m *ObClusterMutation) SetObClusterID(i int64) {257m.ob_cluster_id = &i258m.addob_cluster_id = nil259}
260
261// ObClusterID returns the value of the "ob_cluster_id" field in the mutation.
262func (m *ObClusterMutation) ObClusterID() (r int64, exists bool) {263v := m.ob_cluster_id264if v == nil {265return266}267return *v, true268}
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.
273func (m *ObClusterMutation) OldObClusterID(ctx context.Context) (v int64, err error) {274if !m.op.Is(OpUpdateOne) {275return v, errors.New("OldObClusterID is only allowed on UpdateOne operations")276}277if m.id == nil || m.oldValue == nil {278return v, errors.New("OldObClusterID requires an ID field in the mutation")279}280oldValue, err := m.oldValue(ctx)281if err != nil {282return v, fmt.Errorf("querying old value for OldObClusterID: %w", err)283}284return oldValue.ObClusterID, nil285}
286
287// AddObClusterID adds i to the "ob_cluster_id" field.
288func (m *ObClusterMutation) AddObClusterID(i int64) {289if m.addob_cluster_id != nil {290*m.addob_cluster_id += i291} else {292m.addob_cluster_id = &i293}294}
295
296// AddedObClusterID returns the value that was added to the "ob_cluster_id" field in this mutation.
297func (m *ObClusterMutation) AddedObClusterID() (r int64, exists bool) {298v := m.addob_cluster_id299if v == nil {300return301}302return *v, true303}
304
305// ResetObClusterID resets all changes to the "ob_cluster_id" field.
306func (m *ObClusterMutation) ResetObClusterID() {307m.ob_cluster_id = nil308m.addob_cluster_id = nil309}
310
311// SetType sets the "type" field.
312func (m *ObClusterMutation) SetType(s string) {313m._type = &s314}
315
316// GetType returns the value of the "type" field in the mutation.
317func (m *ObClusterMutation) GetType() (r string, exists bool) {318v := m._type319if v == nil {320return321}322return *v, true323}
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.
328func (m *ObClusterMutation) OldType(ctx context.Context) (v string, err error) {329if !m.op.Is(OpUpdateOne) {330return v, errors.New("OldType is only allowed on UpdateOne operations")331}332if m.id == nil || m.oldValue == nil {333return v, errors.New("OldType requires an ID field in the mutation")334}335oldValue, err := m.oldValue(ctx)336if err != nil {337return v, fmt.Errorf("querying old value for OldType: %w", err)338}339return oldValue.Type, nil340}
341
342// ResetType resets all changes to the "type" field.
343func (m *ObClusterMutation) ResetType() {344m._type = nil345}
346
347// SetRootserviceJSON sets the "rootservice_json" field.
348func (m *ObClusterMutation) SetRootserviceJSON(s string) {349m.rootservice_json = &s350}
351
352// RootserviceJSON returns the value of the "rootservice_json" field in the mutation.
353func (m *ObClusterMutation) RootserviceJSON() (r string, exists bool) {354v := m.rootservice_json355if v == nil {356return357}358return *v, true359}
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.
364func (m *ObClusterMutation) OldRootserviceJSON(ctx context.Context) (v string, err error) {365if !m.op.Is(OpUpdateOne) {366return v, errors.New("OldRootserviceJSON is only allowed on UpdateOne operations")367}368if m.id == nil || m.oldValue == nil {369return v, errors.New("OldRootserviceJSON requires an ID field in the mutation")370}371oldValue, err := m.oldValue(ctx)372if err != nil {373return v, fmt.Errorf("querying old value for OldRootserviceJSON: %w", err)374}375return oldValue.RootserviceJSON, nil376}
377
378// ResetRootserviceJSON resets all changes to the "rootservice_json" field.
379func (m *ObClusterMutation) ResetRootserviceJSON() {380m.rootservice_json = nil381}
382
383// Where appends a list predicates to the ObClusterMutation builder.
384func (m *ObClusterMutation) Where(ps ...predicate.ObCluster) {385m.predicates = append(m.predicates, ps...)386}
387
388// Op returns the operation name.
389func (m *ObClusterMutation) Op() Op {390return m.op391}
392
393// Type returns the node type of this mutation (ObCluster).
394func (m *ObClusterMutation) Type() string {395return m.typ396}
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().
401func (m *ObClusterMutation) Fields() []string {402fields := make([]string, 0, 6)403if m.create_time != nil {404fields = append(fields, obcluster.FieldCreateTime)405}406if m.update_time != nil {407fields = append(fields, obcluster.FieldUpdateTime)408}409if m.name != nil {410fields = append(fields, obcluster.FieldName)411}412if m.ob_cluster_id != nil {413fields = append(fields, obcluster.FieldObClusterID)414}415if m._type != nil {416fields = append(fields, obcluster.FieldType)417}418if m.rootservice_json != nil {419fields = append(fields, obcluster.FieldRootserviceJSON)420}421return fields422}
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.
427func (m *ObClusterMutation) Field(name string) (ent.Value, bool) {428switch name {429case obcluster.FieldCreateTime:430return m.CreateTime()431case obcluster.FieldUpdateTime:432return m.UpdateTime()433case obcluster.FieldName:434return m.Name()435case obcluster.FieldObClusterID:436return m.ObClusterID()437case obcluster.FieldType:438return m.GetType()439case obcluster.FieldRootserviceJSON:440return m.RootserviceJSON()441}442return nil, false443}
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.
448func (m *ObClusterMutation) OldField(ctx context.Context, name string) (ent.Value, error) {449switch name {450case obcluster.FieldCreateTime:451return m.OldCreateTime(ctx)452case obcluster.FieldUpdateTime:453return m.OldUpdateTime(ctx)454case obcluster.FieldName:455return m.OldName(ctx)456case obcluster.FieldObClusterID:457return m.OldObClusterID(ctx)458case obcluster.FieldType:459return m.OldType(ctx)460case obcluster.FieldRootserviceJSON:461return m.OldRootserviceJSON(ctx)462}463return 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.
469func (m *ObClusterMutation) SetField(name string, value ent.Value) error {470switch name {471case obcluster.FieldCreateTime:472v, ok := value.(time.Time)473if !ok {474return fmt.Errorf("unexpected type %T for field %s", value, name)475}476m.SetCreateTime(v)477return nil478case obcluster.FieldUpdateTime:479v, ok := value.(time.Time)480if !ok {481return fmt.Errorf("unexpected type %T for field %s", value, name)482}483m.SetUpdateTime(v)484return nil485case obcluster.FieldName:486v, ok := value.(string)487if !ok {488return fmt.Errorf("unexpected type %T for field %s", value, name)489}490m.SetName(v)491return nil492case obcluster.FieldObClusterID:493v, ok := value.(int64)494if !ok {495return fmt.Errorf("unexpected type %T for field %s", value, name)496}497m.SetObClusterID(v)498return nil499case obcluster.FieldType:500v, ok := value.(string)501if !ok {502return fmt.Errorf("unexpected type %T for field %s", value, name)503}504m.SetType(v)505return nil506case obcluster.FieldRootserviceJSON:507v, ok := value.(string)508if !ok {509return fmt.Errorf("unexpected type %T for field %s", value, name)510}511m.SetRootserviceJSON(v)512return nil513}514return fmt.Errorf("unknown ObCluster field %s", name)515}
516
517// AddedFields returns all numeric fields that were incremented/decremented during
518// this mutation.
519func (m *ObClusterMutation) AddedFields() []string {520var fields []string521if m.addob_cluster_id != nil {522fields = append(fields, obcluster.FieldObClusterID)523}524return fields525}
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.
530func (m *ObClusterMutation) AddedField(name string) (ent.Value, bool) {531switch name {532case obcluster.FieldObClusterID:533return m.AddedObClusterID()534}535return nil, false536}
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.
541func (m *ObClusterMutation) AddField(name string, value ent.Value) error {542switch name {543case obcluster.FieldObClusterID:544v, ok := value.(int64)545if !ok {546return fmt.Errorf("unexpected type %T for field %s", value, name)547}548m.AddObClusterID(v)549return nil550}551return fmt.Errorf("unknown ObCluster numeric field %s", name)552}
553
554// ClearedFields returns all nullable fields that were cleared during this
555// mutation.
556func (m *ObClusterMutation) ClearedFields() []string {557return nil558}
559
560// FieldCleared returns a boolean indicating if a field with the given name was
561// cleared in this mutation.
562func (m *ObClusterMutation) FieldCleared(name string) bool {563_, ok := m.clearedFields[name]564return ok565}
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.
569func (m *ObClusterMutation) ClearField(name string) error {570return 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.
575func (m *ObClusterMutation) ResetField(name string) error {576switch name {577case obcluster.FieldCreateTime:578m.ResetCreateTime()579return nil580case obcluster.FieldUpdateTime:581m.ResetUpdateTime()582return nil583case obcluster.FieldName:584m.ResetName()585return nil586case obcluster.FieldObClusterID:587m.ResetObClusterID()588return nil589case obcluster.FieldType:590m.ResetType()591return nil592case obcluster.FieldRootserviceJSON:593m.ResetRootserviceJSON()594return nil595}596return fmt.Errorf("unknown ObCluster field %s", name)597}
598
599// AddedEdges returns all edge names that were set/added in this mutation.
600func (m *ObClusterMutation) AddedEdges() []string {601edges := make([]string, 0, 0)602return edges603}
604
605// AddedIDs returns all IDs (to other nodes) that were added for the given edge
606// name in this mutation.
607func (m *ObClusterMutation) AddedIDs(name string) []ent.Value {608return nil609}
610
611// RemovedEdges returns all edge names that were removed in this mutation.
612func (m *ObClusterMutation) RemovedEdges() []string {613edges := make([]string, 0, 0)614return edges615}
616
617// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
618// the given name in this mutation.
619func (m *ObClusterMutation) RemovedIDs(name string) []ent.Value {620return nil621}
622
623// ClearedEdges returns all edge names that were cleared in this mutation.
624func (m *ObClusterMutation) ClearedEdges() []string {625edges := make([]string, 0, 0)626return edges627}
628
629// EdgeCleared returns a boolean which indicates if the edge with the given name
630// was cleared in this mutation.
631func (m *ObClusterMutation) EdgeCleared(name string) bool {632return false633}
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.
637func (m *ObClusterMutation) ClearEdge(name string) error {638return 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.
643func (m *ObClusterMutation) ResetEdge(name string) error {644return fmt.Errorf("unknown ObCluster edge %s", name)645}
646