rano/db/ent/accesscontrol_update.go
2024-11-10 14:52:33 +05:30

451 lines
13 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"gitserver.in/patialtech/rano/db/ent/accesscontrol"
"gitserver.in/patialtech/rano/db/ent/predicate"
)
// AccessControlUpdate is the builder for updating AccessControl entities.
type AccessControlUpdate struct {
config
hooks []Hook
mutation *AccessControlMutation
}
// Where appends a list predicates to the AccessControlUpdate builder.
func (acu *AccessControlUpdate) Where(ps ...predicate.AccessControl) *AccessControlUpdate {
acu.mutation.Where(ps...)
return acu
}
// SetUpdatedAt sets the "updated_at" field.
func (acu *AccessControlUpdate) SetUpdatedAt(t time.Time) *AccessControlUpdate {
acu.mutation.SetUpdatedAt(t)
return acu
}
// SetPtype sets the "ptype" field.
func (acu *AccessControlUpdate) SetPtype(s string) *AccessControlUpdate {
acu.mutation.SetPtype(s)
return acu
}
// SetNillablePtype sets the "ptype" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillablePtype(s *string) *AccessControlUpdate {
if s != nil {
acu.SetPtype(*s)
}
return acu
}
// SetV0 sets the "v0" field.
func (acu *AccessControlUpdate) SetV0(s string) *AccessControlUpdate {
acu.mutation.SetV0(s)
return acu
}
// SetNillableV0 sets the "v0" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillableV0(s *string) *AccessControlUpdate {
if s != nil {
acu.SetV0(*s)
}
return acu
}
// SetV1 sets the "v1" field.
func (acu *AccessControlUpdate) SetV1(s string) *AccessControlUpdate {
acu.mutation.SetV1(s)
return acu
}
// SetNillableV1 sets the "v1" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillableV1(s *string) *AccessControlUpdate {
if s != nil {
acu.SetV1(*s)
}
return acu
}
// SetV2 sets the "v2" field.
func (acu *AccessControlUpdate) SetV2(s string) *AccessControlUpdate {
acu.mutation.SetV2(s)
return acu
}
// SetNillableV2 sets the "v2" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillableV2(s *string) *AccessControlUpdate {
if s != nil {
acu.SetV2(*s)
}
return acu
}
// SetV3 sets the "v3" field.
func (acu *AccessControlUpdate) SetV3(s string) *AccessControlUpdate {
acu.mutation.SetV3(s)
return acu
}
// SetNillableV3 sets the "v3" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillableV3(s *string) *AccessControlUpdate {
if s != nil {
acu.SetV3(*s)
}
return acu
}
// SetV4 sets the "v4" field.
func (acu *AccessControlUpdate) SetV4(s string) *AccessControlUpdate {
acu.mutation.SetV4(s)
return acu
}
// SetNillableV4 sets the "v4" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillableV4(s *string) *AccessControlUpdate {
if s != nil {
acu.SetV4(*s)
}
return acu
}
// SetV5 sets the "v5" field.
func (acu *AccessControlUpdate) SetV5(s string) *AccessControlUpdate {
acu.mutation.SetV5(s)
return acu
}
// SetNillableV5 sets the "v5" field if the given value is not nil.
func (acu *AccessControlUpdate) SetNillableV5(s *string) *AccessControlUpdate {
if s != nil {
acu.SetV5(*s)
}
return acu
}
// Mutation returns the AccessControlMutation object of the builder.
func (acu *AccessControlUpdate) Mutation() *AccessControlMutation {
return acu.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (acu *AccessControlUpdate) Save(ctx context.Context) (int, error) {
acu.defaults()
return withHooks(ctx, acu.sqlSave, acu.mutation, acu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (acu *AccessControlUpdate) SaveX(ctx context.Context) int {
affected, err := acu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (acu *AccessControlUpdate) Exec(ctx context.Context) error {
_, err := acu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (acu *AccessControlUpdate) ExecX(ctx context.Context) {
if err := acu.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (acu *AccessControlUpdate) defaults() {
if _, ok := acu.mutation.UpdatedAt(); !ok {
v := accesscontrol.UpdateDefaultUpdatedAt()
acu.mutation.SetUpdatedAt(v)
}
}
func (acu *AccessControlUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(accesscontrol.Table, accesscontrol.Columns, sqlgraph.NewFieldSpec(accesscontrol.FieldID, field.TypeInt64))
if ps := acu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := acu.mutation.UpdatedAt(); ok {
_spec.SetField(accesscontrol.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := acu.mutation.Ptype(); ok {
_spec.SetField(accesscontrol.FieldPtype, field.TypeString, value)
}
if value, ok := acu.mutation.V0(); ok {
_spec.SetField(accesscontrol.FieldV0, field.TypeString, value)
}
if value, ok := acu.mutation.V1(); ok {
_spec.SetField(accesscontrol.FieldV1, field.TypeString, value)
}
if value, ok := acu.mutation.V2(); ok {
_spec.SetField(accesscontrol.FieldV2, field.TypeString, value)
}
if value, ok := acu.mutation.V3(); ok {
_spec.SetField(accesscontrol.FieldV3, field.TypeString, value)
}
if value, ok := acu.mutation.V4(); ok {
_spec.SetField(accesscontrol.FieldV4, field.TypeString, value)
}
if value, ok := acu.mutation.V5(); ok {
_spec.SetField(accesscontrol.FieldV5, field.TypeString, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, acu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{accesscontrol.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
acu.mutation.done = true
return n, nil
}
// AccessControlUpdateOne is the builder for updating a single AccessControl entity.
type AccessControlUpdateOne struct {
config
fields []string
hooks []Hook
mutation *AccessControlMutation
}
// SetUpdatedAt sets the "updated_at" field.
func (acuo *AccessControlUpdateOne) SetUpdatedAt(t time.Time) *AccessControlUpdateOne {
acuo.mutation.SetUpdatedAt(t)
return acuo
}
// SetPtype sets the "ptype" field.
func (acuo *AccessControlUpdateOne) SetPtype(s string) *AccessControlUpdateOne {
acuo.mutation.SetPtype(s)
return acuo
}
// SetNillablePtype sets the "ptype" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillablePtype(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetPtype(*s)
}
return acuo
}
// SetV0 sets the "v0" field.
func (acuo *AccessControlUpdateOne) SetV0(s string) *AccessControlUpdateOne {
acuo.mutation.SetV0(s)
return acuo
}
// SetNillableV0 sets the "v0" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillableV0(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetV0(*s)
}
return acuo
}
// SetV1 sets the "v1" field.
func (acuo *AccessControlUpdateOne) SetV1(s string) *AccessControlUpdateOne {
acuo.mutation.SetV1(s)
return acuo
}
// SetNillableV1 sets the "v1" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillableV1(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetV1(*s)
}
return acuo
}
// SetV2 sets the "v2" field.
func (acuo *AccessControlUpdateOne) SetV2(s string) *AccessControlUpdateOne {
acuo.mutation.SetV2(s)
return acuo
}
// SetNillableV2 sets the "v2" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillableV2(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetV2(*s)
}
return acuo
}
// SetV3 sets the "v3" field.
func (acuo *AccessControlUpdateOne) SetV3(s string) *AccessControlUpdateOne {
acuo.mutation.SetV3(s)
return acuo
}
// SetNillableV3 sets the "v3" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillableV3(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetV3(*s)
}
return acuo
}
// SetV4 sets the "v4" field.
func (acuo *AccessControlUpdateOne) SetV4(s string) *AccessControlUpdateOne {
acuo.mutation.SetV4(s)
return acuo
}
// SetNillableV4 sets the "v4" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillableV4(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetV4(*s)
}
return acuo
}
// SetV5 sets the "v5" field.
func (acuo *AccessControlUpdateOne) SetV5(s string) *AccessControlUpdateOne {
acuo.mutation.SetV5(s)
return acuo
}
// SetNillableV5 sets the "v5" field if the given value is not nil.
func (acuo *AccessControlUpdateOne) SetNillableV5(s *string) *AccessControlUpdateOne {
if s != nil {
acuo.SetV5(*s)
}
return acuo
}
// Mutation returns the AccessControlMutation object of the builder.
func (acuo *AccessControlUpdateOne) Mutation() *AccessControlMutation {
return acuo.mutation
}
// Where appends a list predicates to the AccessControlUpdate builder.
func (acuo *AccessControlUpdateOne) Where(ps ...predicate.AccessControl) *AccessControlUpdateOne {
acuo.mutation.Where(ps...)
return acuo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (acuo *AccessControlUpdateOne) Select(field string, fields ...string) *AccessControlUpdateOne {
acuo.fields = append([]string{field}, fields...)
return acuo
}
// Save executes the query and returns the updated AccessControl entity.
func (acuo *AccessControlUpdateOne) Save(ctx context.Context) (*AccessControl, error) {
acuo.defaults()
return withHooks(ctx, acuo.sqlSave, acuo.mutation, acuo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (acuo *AccessControlUpdateOne) SaveX(ctx context.Context) *AccessControl {
node, err := acuo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (acuo *AccessControlUpdateOne) Exec(ctx context.Context) error {
_, err := acuo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (acuo *AccessControlUpdateOne) ExecX(ctx context.Context) {
if err := acuo.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (acuo *AccessControlUpdateOne) defaults() {
if _, ok := acuo.mutation.UpdatedAt(); !ok {
v := accesscontrol.UpdateDefaultUpdatedAt()
acuo.mutation.SetUpdatedAt(v)
}
}
func (acuo *AccessControlUpdateOne) sqlSave(ctx context.Context) (_node *AccessControl, err error) {
_spec := sqlgraph.NewUpdateSpec(accesscontrol.Table, accesscontrol.Columns, sqlgraph.NewFieldSpec(accesscontrol.FieldID, field.TypeInt64))
id, ok := acuo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AccessControl.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := acuo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, accesscontrol.FieldID)
for _, f := range fields {
if !accesscontrol.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != accesscontrol.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := acuo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := acuo.mutation.UpdatedAt(); ok {
_spec.SetField(accesscontrol.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := acuo.mutation.Ptype(); ok {
_spec.SetField(accesscontrol.FieldPtype, field.TypeString, value)
}
if value, ok := acuo.mutation.V0(); ok {
_spec.SetField(accesscontrol.FieldV0, field.TypeString, value)
}
if value, ok := acuo.mutation.V1(); ok {
_spec.SetField(accesscontrol.FieldV1, field.TypeString, value)
}
if value, ok := acuo.mutation.V2(); ok {
_spec.SetField(accesscontrol.FieldV2, field.TypeString, value)
}
if value, ok := acuo.mutation.V3(); ok {
_spec.SetField(accesscontrol.FieldV3, field.TypeString, value)
}
if value, ok := acuo.mutation.V4(); ok {
_spec.SetField(accesscontrol.FieldV4, field.TypeString, value)
}
if value, ok := acuo.mutation.V5(); ok {
_spec.SetField(accesscontrol.FieldV5, field.TypeString, value)
}
_node = &AccessControl{config: acuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, acuo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{accesscontrol.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
acuo.mutation.done = true
return _node, nil
}