544 lines
16 KiB
Go
544 lines
16 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/permission"
|
|
"bj_power_mes/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// PermissionUpdate is the builder for updating Permission entities.
|
|
type PermissionUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *PermissionMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the PermissionUpdate builder.
|
|
func (_u *PermissionUpdate) Where(ps ...predicate.Permission) *PermissionUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_u *PermissionUpdate) SetCode(v string) *PermissionUpdate {
|
|
_u.mutation.SetCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCode sets the "code" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillableCode(v *string) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *PermissionUpdate) SetName(v string) *PermissionUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillableName(v *string) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *PermissionUpdate) SetType(v string) *PermissionUpdate {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillableType(v *string) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (_u *PermissionUpdate) SetPath(v string) *PermissionUpdate {
|
|
_u.mutation.SetPath(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillablePath(v *string) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetPath(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetIcon sets the "icon" field.
|
|
func (_u *PermissionUpdate) SetIcon(v string) *PermissionUpdate {
|
|
_u.mutation.SetIcon(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIcon sets the "icon" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillableIcon(v *string) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetIcon(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSort sets the "sort" field.
|
|
func (_u *PermissionUpdate) SetSort(v int) *PermissionUpdate {
|
|
_u.mutation.ResetSort()
|
|
_u.mutation.SetSort(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSort sets the "sort" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillableSort(v *int) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetSort(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSort adds value to the "sort" field.
|
|
func (_u *PermissionUpdate) AddSort(v int) *PermissionUpdate {
|
|
_u.mutation.AddSort(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearSort clears the value of the "sort" field.
|
|
func (_u *PermissionUpdate) ClearSort() *PermissionUpdate {
|
|
_u.mutation.ClearSort()
|
|
return _u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_u *PermissionUpdate) SetRemark(v string) *PermissionUpdate {
|
|
_u.mutation.SetRemark(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_u *PermissionUpdate) SetNillableRemark(v *string) *PermissionUpdate {
|
|
if v != nil {
|
|
_u.SetRemark(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the PermissionMutation object of the builder.
|
|
func (_u *PermissionUpdate) Mutation() *PermissionMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *PermissionUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *PermissionUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *PermissionUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *PermissionUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *PermissionUpdate) check() error {
|
|
if v, ok := _u.mutation.Code(); ok {
|
|
if err := permission.CodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Permission.code": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := permission.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Permission.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := permission.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Permission.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Path(); ok {
|
|
if err := permission.PathValidator(v); err != nil {
|
|
return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Permission.path": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Icon(); ok {
|
|
if err := permission.IconValidator(v); err != nil {
|
|
return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Permission.icon": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Remark(); ok {
|
|
if err := permission.RemarkValidator(v); err != nil {
|
|
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Permission.remark": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *PermissionUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *PermissionUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *PermissionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(permission.Table, permission.Columns, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt))
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.Code(); ok {
|
|
_spec.SetField(permission.FieldCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(permission.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(permission.FieldType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Path(); ok {
|
|
_spec.SetField(permission.FieldPath, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Icon(); ok {
|
|
_spec.SetField(permission.FieldIcon, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Sort(); ok {
|
|
_spec.SetField(permission.FieldSort, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSort(); ok {
|
|
_spec.AddField(permission.FieldSort, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.SortCleared() {
|
|
_spec.ClearField(permission.FieldSort, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Remark(); ok {
|
|
_spec.SetField(permission.FieldRemark, field.TypeString, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{permission.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// PermissionUpdateOne is the builder for updating a single Permission entity.
|
|
type PermissionUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *PermissionMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_u *PermissionUpdateOne) SetCode(v string) *PermissionUpdateOne {
|
|
_u.mutation.SetCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCode sets the "code" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillableCode(v *string) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *PermissionUpdateOne) SetName(v string) *PermissionUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillableName(v *string) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetType sets the "type" field.
|
|
func (_u *PermissionUpdateOne) SetType(v string) *PermissionUpdateOne {
|
|
_u.mutation.SetType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableType sets the "type" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillableType(v *string) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetPath sets the "path" field.
|
|
func (_u *PermissionUpdateOne) SetPath(v string) *PermissionUpdateOne {
|
|
_u.mutation.SetPath(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillablePath sets the "path" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillablePath(v *string) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetPath(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetIcon sets the "icon" field.
|
|
func (_u *PermissionUpdateOne) SetIcon(v string) *PermissionUpdateOne {
|
|
_u.mutation.SetIcon(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIcon sets the "icon" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillableIcon(v *string) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetIcon(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSort sets the "sort" field.
|
|
func (_u *PermissionUpdateOne) SetSort(v int) *PermissionUpdateOne {
|
|
_u.mutation.ResetSort()
|
|
_u.mutation.SetSort(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSort sets the "sort" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillableSort(v *int) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetSort(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSort adds value to the "sort" field.
|
|
func (_u *PermissionUpdateOne) AddSort(v int) *PermissionUpdateOne {
|
|
_u.mutation.AddSort(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearSort clears the value of the "sort" field.
|
|
func (_u *PermissionUpdateOne) ClearSort() *PermissionUpdateOne {
|
|
_u.mutation.ClearSort()
|
|
return _u
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_u *PermissionUpdateOne) SetRemark(v string) *PermissionUpdateOne {
|
|
_u.mutation.SetRemark(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_u *PermissionUpdateOne) SetNillableRemark(v *string) *PermissionUpdateOne {
|
|
if v != nil {
|
|
_u.SetRemark(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the PermissionMutation object of the builder.
|
|
func (_u *PermissionUpdateOne) Mutation() *PermissionMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the PermissionUpdate builder.
|
|
func (_u *PermissionUpdateOne) Where(ps ...predicate.Permission) *PermissionUpdateOne {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (_u *PermissionUpdateOne) Select(field string, fields ...string) *PermissionUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Permission entity.
|
|
func (_u *PermissionUpdateOne) Save(ctx context.Context) (*Permission, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *PermissionUpdateOne) SaveX(ctx context.Context) *Permission {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *PermissionUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *PermissionUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *PermissionUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Code(); ok {
|
|
if err := permission.CodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Permission.code": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := permission.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Permission.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.GetType(); ok {
|
|
if err := permission.TypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Permission.type": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Path(); ok {
|
|
if err := permission.PathValidator(v); err != nil {
|
|
return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Permission.path": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Icon(); ok {
|
|
if err := permission.IconValidator(v); err != nil {
|
|
return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Permission.icon": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Remark(); ok {
|
|
if err := permission.RemarkValidator(v); err != nil {
|
|
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "Permission.remark": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *PermissionUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *PermissionUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *PermissionUpdateOne) sqlSave(ctx context.Context) (_node *Permission, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(permission.Table, permission.Columns, sqlgraph.NewFieldSpec(permission.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Permission.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := _u.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, permission.FieldID)
|
|
for _, f := range fields {
|
|
if !permission.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != permission.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := _u.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := _u.mutation.Code(); ok {
|
|
_spec.SetField(permission.FieldCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(permission.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.GetType(); ok {
|
|
_spec.SetField(permission.FieldType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Path(); ok {
|
|
_spec.SetField(permission.FieldPath, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Icon(); ok {
|
|
_spec.SetField(permission.FieldIcon, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Sort(); ok {
|
|
_spec.SetField(permission.FieldSort, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSort(); ok {
|
|
_spec.AddField(permission.FieldSort, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.SortCleared() {
|
|
_spec.ClearField(permission.FieldSort, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Remark(); ok {
|
|
_spec.SetField(permission.FieldRemark, field.TypeString, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &Permission{config: _u.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{permission.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|