348 lines
10 KiB
Go
348 lines
10 KiB
Go
// 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/examples/triggers/ent/predicate"
|
|
"entgo.io/ent/examples/triggers/ent/userauditlog"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// UserAuditLogUpdate is the builder for updating UserAuditLog entities.
|
|
type UserAuditLogUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *UserAuditLogMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the UserAuditLogUpdate builder.
|
|
func (_u *UserAuditLogUpdate) Where(ps ...predicate.UserAuditLog) *UserAuditLogUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetOperationType sets the "operation_type" field.
|
|
func (_u *UserAuditLogUpdate) SetOperationType(v string) *UserAuditLogUpdate {
|
|
_u.mutation.SetOperationType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperationType sets the "operation_type" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdate) SetNillableOperationType(v *string) *UserAuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetOperationType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperationTime sets the "operation_time" field.
|
|
func (_u *UserAuditLogUpdate) SetOperationTime(v string) *UserAuditLogUpdate {
|
|
_u.mutation.SetOperationTime(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperationTime sets the "operation_time" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdate) SetNillableOperationTime(v *string) *UserAuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetOperationTime(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOldValue sets the "old_value" field.
|
|
func (_u *UserAuditLogUpdate) SetOldValue(v string) *UserAuditLogUpdate {
|
|
_u.mutation.SetOldValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOldValue sets the "old_value" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdate) SetNillableOldValue(v *string) *UserAuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetOldValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearOldValue clears the value of the "old_value" field.
|
|
func (_u *UserAuditLogUpdate) ClearOldValue() *UserAuditLogUpdate {
|
|
_u.mutation.ClearOldValue()
|
|
return _u
|
|
}
|
|
|
|
// SetNewValue sets the "new_value" field.
|
|
func (_u *UserAuditLogUpdate) SetNewValue(v string) *UserAuditLogUpdate {
|
|
_u.mutation.SetNewValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNewValue sets the "new_value" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdate) SetNillableNewValue(v *string) *UserAuditLogUpdate {
|
|
if v != nil {
|
|
_u.SetNewValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearNewValue clears the value of the "new_value" field.
|
|
func (_u *UserAuditLogUpdate) ClearNewValue() *UserAuditLogUpdate {
|
|
_u.mutation.ClearNewValue()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the UserAuditLogMutation object of the builder.
|
|
func (_u *UserAuditLogUpdate) Mutation() *UserAuditLogMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *UserAuditLogUpdate) 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 *UserAuditLogUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *UserAuditLogUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *UserAuditLogUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (_u *UserAuditLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(userauditlog.Table, userauditlog.Columns, sqlgraph.NewFieldSpec(userauditlog.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.OperationType(); ok {
|
|
_spec.SetField(userauditlog.FieldOperationType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OperationTime(); ok {
|
|
_spec.SetField(userauditlog.FieldOperationTime, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OldValue(); ok {
|
|
_spec.SetField(userauditlog.FieldOldValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.OldValueCleared() {
|
|
_spec.ClearField(userauditlog.FieldOldValue, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NewValue(); ok {
|
|
_spec.SetField(userauditlog.FieldNewValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.NewValueCleared() {
|
|
_spec.ClearField(userauditlog.FieldNewValue, field.TypeString)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{userauditlog.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// UserAuditLogUpdateOne is the builder for updating a single UserAuditLog entity.
|
|
type UserAuditLogUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *UserAuditLogMutation
|
|
}
|
|
|
|
// SetOperationType sets the "operation_type" field.
|
|
func (_u *UserAuditLogUpdateOne) SetOperationType(v string) *UserAuditLogUpdateOne {
|
|
_u.mutation.SetOperationType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperationType sets the "operation_type" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdateOne) SetNillableOperationType(v *string) *UserAuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetOperationType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperationTime sets the "operation_time" field.
|
|
func (_u *UserAuditLogUpdateOne) SetOperationTime(v string) *UserAuditLogUpdateOne {
|
|
_u.mutation.SetOperationTime(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperationTime sets the "operation_time" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdateOne) SetNillableOperationTime(v *string) *UserAuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetOperationTime(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOldValue sets the "old_value" field.
|
|
func (_u *UserAuditLogUpdateOne) SetOldValue(v string) *UserAuditLogUpdateOne {
|
|
_u.mutation.SetOldValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOldValue sets the "old_value" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdateOne) SetNillableOldValue(v *string) *UserAuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetOldValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearOldValue clears the value of the "old_value" field.
|
|
func (_u *UserAuditLogUpdateOne) ClearOldValue() *UserAuditLogUpdateOne {
|
|
_u.mutation.ClearOldValue()
|
|
return _u
|
|
}
|
|
|
|
// SetNewValue sets the "new_value" field.
|
|
func (_u *UserAuditLogUpdateOne) SetNewValue(v string) *UserAuditLogUpdateOne {
|
|
_u.mutation.SetNewValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableNewValue sets the "new_value" field if the given value is not nil.
|
|
func (_u *UserAuditLogUpdateOne) SetNillableNewValue(v *string) *UserAuditLogUpdateOne {
|
|
if v != nil {
|
|
_u.SetNewValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearNewValue clears the value of the "new_value" field.
|
|
func (_u *UserAuditLogUpdateOne) ClearNewValue() *UserAuditLogUpdateOne {
|
|
_u.mutation.ClearNewValue()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the UserAuditLogMutation object of the builder.
|
|
func (_u *UserAuditLogUpdateOne) Mutation() *UserAuditLogMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the UserAuditLogUpdate builder.
|
|
func (_u *UserAuditLogUpdateOne) Where(ps ...predicate.UserAuditLog) *UserAuditLogUpdateOne {
|
|
_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 *UserAuditLogUpdateOne) Select(field string, fields ...string) *UserAuditLogUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated UserAuditLog entity.
|
|
func (_u *UserAuditLogUpdateOne) Save(ctx context.Context) (*UserAuditLog, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *UserAuditLogUpdateOne) SaveX(ctx context.Context) *UserAuditLog {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *UserAuditLogUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *UserAuditLogUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (_u *UserAuditLogUpdateOne) sqlSave(ctx context.Context) (_node *UserAuditLog, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(userauditlog.Table, userauditlog.Columns, sqlgraph.NewFieldSpec(userauditlog.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserAuditLog.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, userauditlog.FieldID)
|
|
for _, f := range fields {
|
|
if !userauditlog.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != userauditlog.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.OperationType(); ok {
|
|
_spec.SetField(userauditlog.FieldOperationType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OperationTime(); ok {
|
|
_spec.SetField(userauditlog.FieldOperationTime, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OldValue(); ok {
|
|
_spec.SetField(userauditlog.FieldOldValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.OldValueCleared() {
|
|
_spec.ClearField(userauditlog.FieldOldValue, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.NewValue(); ok {
|
|
_spec.SetField(userauditlog.FieldNewValue, field.TypeString, value)
|
|
}
|
|
if _u.mutation.NewValueCleared() {
|
|
_spec.ClearField(userauditlog.FieldNewValue, field.TypeString)
|
|
}
|
|
_node = &UserAuditLog{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{userauditlog.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|