🎉 init
This commit is contained in:
680
common/ent/scaauthpermissionrule_update.go
Normal file
680
common/ent/scaauthpermissionrule_update.go
Normal file
@@ -0,0 +1,680 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"schisandra-album-cloud-microservices/common/ent/predicate"
|
||||
"schisandra-album-cloud-microservices/common/ent/scaauthpermissionrule"
|
||||
"schisandra-album-cloud-microservices/common/ent/scaauthrole"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ScaAuthPermissionRuleUpdate is the builder for updating ScaAuthPermissionRule entities.
|
||||
type ScaAuthPermissionRuleUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ScaAuthPermissionRuleMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ScaAuthPermissionRuleUpdate builder.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) Where(ps ...predicate.ScaAuthPermissionRule) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.Where(ps...)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetPtype sets the "ptype" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetPtype(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetPtype(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillablePtype sets the "ptype" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillablePtype(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetPtype(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetV0 sets the "v0" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetV0(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetV0(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableV0 sets the "v0" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableV0(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetV0(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetV1 sets the "v1" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetV1(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetV1(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableV1 sets the "v1" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableV1(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetV1(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetV2 sets the "v2" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetV2(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetV2(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableV2 sets the "v2" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableV2(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetV2(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// ClearV2 clears the value of the "v2" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) ClearV2() *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.ClearV2()
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetV3 sets the "v3" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetV3(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetV3(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableV3 sets the "v3" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableV3(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetV3(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// ClearV3 clears the value of the "v3" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) ClearV3() *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.ClearV3()
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetV4 sets the "v4" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetV4(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetV4(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableV4 sets the "v4" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableV4(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetV4(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// ClearV4 clears the value of the "v4" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) ClearV4() *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.ClearV4()
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetV5 sets the "v5" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetV5(s string) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetV5(s)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableV5 sets the "v5" field if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableV5(s *string) *ScaAuthPermissionRuleUpdate {
|
||||
if s != nil {
|
||||
sapru.SetV5(*s)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// ClearV5 clears the value of the "v5" field.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) ClearV5() *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.ClearV5()
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetScaAuthRoleID sets the "sca_auth_role" edge to the ScaAuthRole entity by ID.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetScaAuthRoleID(id int64) *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.SetScaAuthRoleID(id)
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetNillableScaAuthRoleID sets the "sca_auth_role" edge to the ScaAuthRole entity by ID if the given value is not nil.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetNillableScaAuthRoleID(id *int64) *ScaAuthPermissionRuleUpdate {
|
||||
if id != nil {
|
||||
sapru = sapru.SetScaAuthRoleID(*id)
|
||||
}
|
||||
return sapru
|
||||
}
|
||||
|
||||
// SetScaAuthRole sets the "sca_auth_role" edge to the ScaAuthRole entity.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SetScaAuthRole(s *ScaAuthRole) *ScaAuthPermissionRuleUpdate {
|
||||
return sapru.SetScaAuthRoleID(s.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ScaAuthPermissionRuleMutation object of the builder.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) Mutation() *ScaAuthPermissionRuleMutation {
|
||||
return sapru.mutation
|
||||
}
|
||||
|
||||
// ClearScaAuthRole clears the "sca_auth_role" edge to the ScaAuthRole entity.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) ClearScaAuthRole() *ScaAuthPermissionRuleUpdate {
|
||||
sapru.mutation.ClearScaAuthRole()
|
||||
return sapru
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, sapru.sqlSave, sapru.mutation, sapru.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := sapru.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) Exec(ctx context.Context) error {
|
||||
_, err := sapru.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) ExecX(ctx context.Context) {
|
||||
if err := sapru.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) check() error {
|
||||
if v, ok := sapru.mutation.Ptype(); ok {
|
||||
if err := scaauthpermissionrule.PtypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ptype", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.ptype": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapru.mutation.V0(); ok {
|
||||
if err := scaauthpermissionrule.V0Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v0", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v0": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapru.mutation.V1(); ok {
|
||||
if err := scaauthpermissionrule.V1Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v1", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v1": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapru.mutation.V2(); ok {
|
||||
if err := scaauthpermissionrule.V2Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v2", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v2": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapru.mutation.V3(); ok {
|
||||
if err := scaauthpermissionrule.V3Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v3", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v3": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapru.mutation.V4(); ok {
|
||||
if err := scaauthpermissionrule.V4Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v4", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v4": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapru.mutation.V5(); ok {
|
||||
if err := scaauthpermissionrule.V5Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v5", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v5": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sapru *ScaAuthPermissionRuleUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := sapru.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(scaauthpermissionrule.Table, scaauthpermissionrule.Columns, sqlgraph.NewFieldSpec(scaauthpermissionrule.FieldID, field.TypeInt64))
|
||||
if ps := sapru.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := sapru.mutation.Ptype(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldPtype, field.TypeString, value)
|
||||
}
|
||||
if value, ok := sapru.mutation.V0(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV0, field.TypeString, value)
|
||||
}
|
||||
if value, ok := sapru.mutation.V1(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV1, field.TypeString, value)
|
||||
}
|
||||
if value, ok := sapru.mutation.V2(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV2, field.TypeString, value)
|
||||
}
|
||||
if sapru.mutation.V2Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV2, field.TypeString)
|
||||
}
|
||||
if value, ok := sapru.mutation.V3(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV3, field.TypeString, value)
|
||||
}
|
||||
if sapru.mutation.V3Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV3, field.TypeString)
|
||||
}
|
||||
if value, ok := sapru.mutation.V4(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV4, field.TypeString, value)
|
||||
}
|
||||
if sapru.mutation.V4Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV4, field.TypeString)
|
||||
}
|
||||
if value, ok := sapru.mutation.V5(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV5, field.TypeString, value)
|
||||
}
|
||||
if sapru.mutation.V5Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV5, field.TypeString)
|
||||
}
|
||||
if sapru.mutation.ScaAuthRoleCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: scaauthpermissionrule.ScaAuthRoleTable,
|
||||
Columns: []string{scaauthpermissionrule.ScaAuthRoleColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(scaauthrole.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := sapru.mutation.ScaAuthRoleIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: scaauthpermissionrule.ScaAuthRoleTable,
|
||||
Columns: []string{scaauthpermissionrule.ScaAuthRoleColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(scaauthrole.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, sapru.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{scaauthpermissionrule.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
sapru.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// ScaAuthPermissionRuleUpdateOne is the builder for updating a single ScaAuthPermissionRule entity.
|
||||
type ScaAuthPermissionRuleUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ScaAuthPermissionRuleMutation
|
||||
}
|
||||
|
||||
// SetPtype sets the "ptype" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetPtype(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetPtype(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillablePtype sets the "ptype" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillablePtype(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetPtype(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetV0 sets the "v0" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetV0(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetV0(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableV0 sets the "v0" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableV0(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetV0(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetV1 sets the "v1" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetV1(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetV1(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableV1 sets the "v1" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableV1(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetV1(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetV2 sets the "v2" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetV2(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetV2(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableV2 sets the "v2" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableV2(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetV2(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// ClearV2 clears the value of the "v2" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) ClearV2() *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.ClearV2()
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetV3 sets the "v3" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetV3(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetV3(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableV3 sets the "v3" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableV3(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetV3(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// ClearV3 clears the value of the "v3" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) ClearV3() *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.ClearV3()
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetV4 sets the "v4" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetV4(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetV4(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableV4 sets the "v4" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableV4(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetV4(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// ClearV4 clears the value of the "v4" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) ClearV4() *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.ClearV4()
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetV5 sets the "v5" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetV5(s string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetV5(s)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableV5 sets the "v5" field if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableV5(s *string) *ScaAuthPermissionRuleUpdateOne {
|
||||
if s != nil {
|
||||
sapruo.SetV5(*s)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// ClearV5 clears the value of the "v5" field.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) ClearV5() *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.ClearV5()
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetScaAuthRoleID sets the "sca_auth_role" edge to the ScaAuthRole entity by ID.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetScaAuthRoleID(id int64) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.SetScaAuthRoleID(id)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetNillableScaAuthRoleID sets the "sca_auth_role" edge to the ScaAuthRole entity by ID if the given value is not nil.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetNillableScaAuthRoleID(id *int64) *ScaAuthPermissionRuleUpdateOne {
|
||||
if id != nil {
|
||||
sapruo = sapruo.SetScaAuthRoleID(*id)
|
||||
}
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// SetScaAuthRole sets the "sca_auth_role" edge to the ScaAuthRole entity.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SetScaAuthRole(s *ScaAuthRole) *ScaAuthPermissionRuleUpdateOne {
|
||||
return sapruo.SetScaAuthRoleID(s.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the ScaAuthPermissionRuleMutation object of the builder.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) Mutation() *ScaAuthPermissionRuleMutation {
|
||||
return sapruo.mutation
|
||||
}
|
||||
|
||||
// ClearScaAuthRole clears the "sca_auth_role" edge to the ScaAuthRole entity.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) ClearScaAuthRole() *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.ClearScaAuthRole()
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ScaAuthPermissionRuleUpdate builder.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) Where(ps ...predicate.ScaAuthPermissionRule) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.mutation.Where(ps...)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) Select(field string, fields ...string) *ScaAuthPermissionRuleUpdateOne {
|
||||
sapruo.fields = append([]string{field}, fields...)
|
||||
return sapruo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated ScaAuthPermissionRule entity.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) Save(ctx context.Context) (*ScaAuthPermissionRule, error) {
|
||||
return withHooks(ctx, sapruo.sqlSave, sapruo.mutation, sapruo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) SaveX(ctx context.Context) *ScaAuthPermissionRule {
|
||||
node, err := sapruo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := sapruo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := sapruo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) check() error {
|
||||
if v, ok := sapruo.mutation.Ptype(); ok {
|
||||
if err := scaauthpermissionrule.PtypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ptype", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.ptype": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapruo.mutation.V0(); ok {
|
||||
if err := scaauthpermissionrule.V0Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v0", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v0": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapruo.mutation.V1(); ok {
|
||||
if err := scaauthpermissionrule.V1Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v1", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v1": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapruo.mutation.V2(); ok {
|
||||
if err := scaauthpermissionrule.V2Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v2", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v2": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapruo.mutation.V3(); ok {
|
||||
if err := scaauthpermissionrule.V3Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v3", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v3": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapruo.mutation.V4(); ok {
|
||||
if err := scaauthpermissionrule.V4Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v4", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v4": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := sapruo.mutation.V5(); ok {
|
||||
if err := scaauthpermissionrule.V5Validator(v); err != nil {
|
||||
return &ValidationError{Name: "v5", err: fmt.Errorf(`ent: validator failed for field "ScaAuthPermissionRule.v5": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sapruo *ScaAuthPermissionRuleUpdateOne) sqlSave(ctx context.Context) (_node *ScaAuthPermissionRule, err error) {
|
||||
if err := sapruo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(scaauthpermissionrule.Table, scaauthpermissionrule.Columns, sqlgraph.NewFieldSpec(scaauthpermissionrule.FieldID, field.TypeInt64))
|
||||
id, ok := sapruo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ScaAuthPermissionRule.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := sapruo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, scaauthpermissionrule.FieldID)
|
||||
for _, f := range fields {
|
||||
if !scaauthpermissionrule.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != scaauthpermissionrule.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := sapruo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := sapruo.mutation.Ptype(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldPtype, field.TypeString, value)
|
||||
}
|
||||
if value, ok := sapruo.mutation.V0(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV0, field.TypeString, value)
|
||||
}
|
||||
if value, ok := sapruo.mutation.V1(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV1, field.TypeString, value)
|
||||
}
|
||||
if value, ok := sapruo.mutation.V2(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV2, field.TypeString, value)
|
||||
}
|
||||
if sapruo.mutation.V2Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV2, field.TypeString)
|
||||
}
|
||||
if value, ok := sapruo.mutation.V3(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV3, field.TypeString, value)
|
||||
}
|
||||
if sapruo.mutation.V3Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV3, field.TypeString)
|
||||
}
|
||||
if value, ok := sapruo.mutation.V4(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV4, field.TypeString, value)
|
||||
}
|
||||
if sapruo.mutation.V4Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV4, field.TypeString)
|
||||
}
|
||||
if value, ok := sapruo.mutation.V5(); ok {
|
||||
_spec.SetField(scaauthpermissionrule.FieldV5, field.TypeString, value)
|
||||
}
|
||||
if sapruo.mutation.V5Cleared() {
|
||||
_spec.ClearField(scaauthpermissionrule.FieldV5, field.TypeString)
|
||||
}
|
||||
if sapruo.mutation.ScaAuthRoleCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: scaauthpermissionrule.ScaAuthRoleTable,
|
||||
Columns: []string{scaauthpermissionrule.ScaAuthRoleColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(scaauthrole.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := sapruo.mutation.ScaAuthRoleIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: scaauthpermissionrule.ScaAuthRoleTable,
|
||||
Columns: []string{scaauthpermissionrule.ScaAuthRoleColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(scaauthrole.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &ScaAuthPermissionRule{config: sapruo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, sapruo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{scaauthpermissionrule.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
sapruo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
Reference in New Issue
Block a user