// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/FrankenBotDev/FrankenAPI/ent/authorizables" "github.com/FrankenBotDev/FrankenAPI/ent/predicate" ) // AuthorizablesUpdate is the builder for updating Authorizables entities. type AuthorizablesUpdate struct { config hooks []Hook mutation *AuthorizablesMutation } // Where appends a list predicates to the AuthorizablesUpdate builder. func (au *AuthorizablesUpdate) Where(ps ...predicate.Authorizables) *AuthorizablesUpdate { au.mutation.Where(ps...) return au } // SetUsername sets the "username" field. func (au *AuthorizablesUpdate) SetUsername(s string) *AuthorizablesUpdate { au.mutation.SetUsername(s) return au } // SetPassword sets the "password" field. func (au *AuthorizablesUpdate) SetPassword(s string) *AuthorizablesUpdate { au.mutation.SetPassword(s) return au } // SetServerid sets the "serverid" field. func (au *AuthorizablesUpdate) SetServerid(s string) *AuthorizablesUpdate { au.mutation.SetServerid(s) return au } // SetUserid sets the "userid" field. func (au *AuthorizablesUpdate) SetUserid(s string) *AuthorizablesUpdate { au.mutation.SetUserid(s) return au } // Mutation returns the AuthorizablesMutation object of the builder. func (au *AuthorizablesUpdate) Mutation() *AuthorizablesMutation { return au.mutation } // Save executes the query and returns the number of nodes affected by the update operation. func (au *AuthorizablesUpdate) Save(ctx context.Context) (int, error) { var ( err error affected int ) if len(au.hooks) == 0 { affected, err = au.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*AuthorizablesMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } au.mutation = mutation affected, err = au.sqlSave(ctx) mutation.done = true return affected, err }) for i := len(au.hooks) - 1; i >= 0; i-- { if au.hooks[i] == nil { return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = au.hooks[i](mut) } if _, err := mut.Mutate(ctx, au.mutation); err != nil { return 0, err } } return affected, err } // SaveX is like Save, but panics if an error occurs. func (au *AuthorizablesUpdate) SaveX(ctx context.Context) int { affected, err := au.Save(ctx) if err != nil { panic(err) } return affected } // Exec executes the query. func (au *AuthorizablesUpdate) Exec(ctx context.Context) error { _, err := au.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (au *AuthorizablesUpdate) ExecX(ctx context.Context) { if err := au.Exec(ctx); err != nil { panic(err) } } func (au *AuthorizablesUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: authorizables.Table, Columns: authorizables.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: authorizables.FieldID, }, }, } if ps := au.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := au.mutation.Username(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldUsername, }) } if value, ok := au.mutation.Password(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldPassword, }) } if value, ok := au.mutation.Serverid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldServerid, }) } if value, ok := au.mutation.Userid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldUserid, }) } if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{authorizables.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return 0, err } return n, nil } // AuthorizablesUpdateOne is the builder for updating a single Authorizables entity. type AuthorizablesUpdateOne struct { config fields []string hooks []Hook mutation *AuthorizablesMutation } // SetUsername sets the "username" field. func (auo *AuthorizablesUpdateOne) SetUsername(s string) *AuthorizablesUpdateOne { auo.mutation.SetUsername(s) return auo } // SetPassword sets the "password" field. func (auo *AuthorizablesUpdateOne) SetPassword(s string) *AuthorizablesUpdateOne { auo.mutation.SetPassword(s) return auo } // SetServerid sets the "serverid" field. func (auo *AuthorizablesUpdateOne) SetServerid(s string) *AuthorizablesUpdateOne { auo.mutation.SetServerid(s) return auo } // SetUserid sets the "userid" field. func (auo *AuthorizablesUpdateOne) SetUserid(s string) *AuthorizablesUpdateOne { auo.mutation.SetUserid(s) return auo } // Mutation returns the AuthorizablesMutation object of the builder. func (auo *AuthorizablesUpdateOne) Mutation() *AuthorizablesMutation { return auo.mutation } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (auo *AuthorizablesUpdateOne) Select(field string, fields ...string) *AuthorizablesUpdateOne { auo.fields = append([]string{field}, fields...) return auo } // Save executes the query and returns the updated Authorizables entity. func (auo *AuthorizablesUpdateOne) Save(ctx context.Context) (*Authorizables, error) { var ( err error node *Authorizables ) if len(auo.hooks) == 0 { node, err = auo.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*AuthorizablesMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } auo.mutation = mutation node, err = auo.sqlSave(ctx) mutation.done = true return node, err }) for i := len(auo.hooks) - 1; i >= 0; i-- { if auo.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } mut = auo.hooks[i](mut) } v, err := mut.Mutate(ctx, auo.mutation) if err != nil { return nil, err } nv, ok := v.(*Authorizables) if !ok { return nil, fmt.Errorf("unexpected node type %T returned from AuthorizablesMutation", v) } node = nv } return node, err } // SaveX is like Save, but panics if an error occurs. func (auo *AuthorizablesUpdateOne) SaveX(ctx context.Context) *Authorizables { node, err := auo.Save(ctx) if err != nil { panic(err) } return node } // Exec executes the query on the entity. func (auo *AuthorizablesUpdateOne) Exec(ctx context.Context) error { _, err := auo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (auo *AuthorizablesUpdateOne) ExecX(ctx context.Context) { if err := auo.Exec(ctx); err != nil { panic(err) } } func (auo *AuthorizablesUpdateOne) sqlSave(ctx context.Context) (_node *Authorizables, err error) { _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ Table: authorizables.Table, Columns: authorizables.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, Column: authorizables.FieldID, }, }, } id, ok := auo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Authorizables.id" for update`)} } _spec.Node.ID.Value = id if fields := auo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) _spec.Node.Columns = append(_spec.Node.Columns, authorizables.FieldID) for _, f := range fields { if !authorizables.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } if f != authorizables.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } if ps := auo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } if value, ok := auo.mutation.Username(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldUsername, }) } if value, ok := auo.mutation.Password(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldPassword, }) } if value, ok := auo.mutation.Serverid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldServerid, }) } if value, ok := auo.mutation.Userid(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, Value: value, Column: authorizables.FieldUserid, }) } _node = &Authorizables{config: auo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{authorizables.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } return nil, err } return _node, nil }