// 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/Southclaws/storyden/internal/ent/account"
"github.com/Southclaws/storyden/internal/ent/auditlog"
"github.com/Southclaws/storyden/internal/ent/predicate"
"github.com/rs/xid"
)
// AuditLogUpdate is the builder for updating AuditLog entities.
type AuditLogUpdate struct {
config
hooks []Hook
mutation *AuditLogMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the AuditLogUpdate builder.
func (_u *AuditLogUpdate) Where(ps ...predicate.AuditLog) *AuditLogUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetEnactedByID sets the "enacted_by_id" field.
func (_u *AuditLogUpdate) SetEnactedByID(v xid.ID) *AuditLogUpdate {
_u.mutation.SetEnactedByID(v)
return _u
}
// SetNillableEnactedByID sets the "enacted_by_id" field if the given value is not nil.
func (_u *AuditLogUpdate) SetNillableEnactedByID(v *xid.ID) *AuditLogUpdate {
if v != nil {
_u.SetEnactedByID(*v)
}
return _u
}
// ClearEnactedByID clears the value of the "enacted_by_id" field.
func (_u *AuditLogUpdate) ClearEnactedByID() *AuditLogUpdate {
_u.mutation.ClearEnactedByID()
return _u
}
// SetTargetID sets the "target_id" field.
func (_u *AuditLogUpdate) SetTargetID(v xid.ID) *AuditLogUpdate {
_u.mutation.SetTargetID(v)
return _u
}
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
func (_u *AuditLogUpdate) SetNillableTargetID(v *xid.ID) *AuditLogUpdate {
if v != nil {
_u.SetTargetID(*v)
}
return _u
}
// ClearTargetID clears the value of the "target_id" field.
func (_u *AuditLogUpdate) ClearTargetID() *AuditLogUpdate {
_u.mutation.ClearTargetID()
return _u
}
// SetTargetKind sets the "target_kind" field.
func (_u *AuditLogUpdate) SetTargetKind(v string) *AuditLogUpdate {
_u.mutation.SetTargetKind(v)
return _u
}
// SetNillableTargetKind sets the "target_kind" field if the given value is not nil.
func (_u *AuditLogUpdate) SetNillableTargetKind(v *string) *AuditLogUpdate {
if v != nil {
_u.SetTargetKind(*v)
}
return _u
}
// ClearTargetKind clears the value of the "target_kind" field.
func (_u *AuditLogUpdate) ClearTargetKind() *AuditLogUpdate {
_u.mutation.ClearTargetKind()
return _u
}
// SetType sets the "type" field.
func (_u *AuditLogUpdate) SetType(v string) *AuditLogUpdate {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *AuditLogUpdate) SetNillableType(v *string) *AuditLogUpdate {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetError sets the "error" field.
func (_u *AuditLogUpdate) SetError(v string) *AuditLogUpdate {
_u.mutation.SetError(v)
return _u
}
// SetNillableError sets the "error" field if the given value is not nil.
func (_u *AuditLogUpdate) SetNillableError(v *string) *AuditLogUpdate {
if v != nil {
_u.SetError(*v)
}
return _u
}
// ClearError clears the value of the "error" field.
func (_u *AuditLogUpdate) ClearError() *AuditLogUpdate {
_u.mutation.ClearError()
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *AuditLogUpdate) SetMetadata(v map[string]interface{}) *AuditLogUpdate {
_u.mutation.SetMetadata(v)
return _u
}
// ClearMetadata clears the value of the "metadata" field.
func (_u *AuditLogUpdate) ClearMetadata() *AuditLogUpdate {
_u.mutation.ClearMetadata()
return _u
}
// SetEnactedBy sets the "enacted_by" edge to the Account entity.
func (_u *AuditLogUpdate) SetEnactedBy(v *Account) *AuditLogUpdate {
return _u.SetEnactedByID(v.ID)
}
// Mutation returns the AuditLogMutation object of the builder.
func (_u *AuditLogUpdate) Mutation() *AuditLogMutation {
return _u.mutation
}
// ClearEnactedBy clears the "enacted_by" edge to the Account entity.
func (_u *AuditLogUpdate) ClearEnactedBy() *AuditLogUpdate {
_u.mutation.ClearEnactedBy()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *AuditLogUpdate) 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 *AuditLogUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *AuditLogUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *AuditLogUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *AuditLogUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AuditLogUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *AuditLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(auditlog.Table, auditlog.Columns, sqlgraph.NewFieldSpec(auditlog.FieldID, field.TypeString))
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.TargetID(); ok {
_spec.SetField(auditlog.FieldTargetID, field.TypeString, value)
}
if _u.mutation.TargetIDCleared() {
_spec.ClearField(auditlog.FieldTargetID, field.TypeString)
}
if value, ok := _u.mutation.TargetKind(); ok {
_spec.SetField(auditlog.FieldTargetKind, field.TypeString, value)
}
if _u.mutation.TargetKindCleared() {
_spec.ClearField(auditlog.FieldTargetKind, field.TypeString)
}
if value, ok := _u.mutation.GetType(); ok {
_spec.SetField(auditlog.FieldType, field.TypeString, value)
}
if value, ok := _u.mutation.Error(); ok {
_spec.SetField(auditlog.FieldError, field.TypeString, value)
}
if _u.mutation.ErrorCleared() {
_spec.ClearField(auditlog.FieldError, field.TypeString)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(auditlog.FieldMetadata, field.TypeJSON, value)
}
if _u.mutation.MetadataCleared() {
_spec.ClearField(auditlog.FieldMetadata, field.TypeJSON)
}
if _u.mutation.EnactedByCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: auditlog.EnactedByTable,
Columns: []string{auditlog.EnactedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.EnactedByIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: auditlog.EnactedByTable,
Columns: []string{auditlog.EnactedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{auditlog.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// AuditLogUpdateOne is the builder for updating a single AuditLog entity.
type AuditLogUpdateOne struct {
config
fields []string
hooks []Hook
mutation *AuditLogMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetEnactedByID sets the "enacted_by_id" field.
func (_u *AuditLogUpdateOne) SetEnactedByID(v xid.ID) *AuditLogUpdateOne {
_u.mutation.SetEnactedByID(v)
return _u
}
// SetNillableEnactedByID sets the "enacted_by_id" field if the given value is not nil.
func (_u *AuditLogUpdateOne) SetNillableEnactedByID(v *xid.ID) *AuditLogUpdateOne {
if v != nil {
_u.SetEnactedByID(*v)
}
return _u
}
// ClearEnactedByID clears the value of the "enacted_by_id" field.
func (_u *AuditLogUpdateOne) ClearEnactedByID() *AuditLogUpdateOne {
_u.mutation.ClearEnactedByID()
return _u
}
// SetTargetID sets the "target_id" field.
func (_u *AuditLogUpdateOne) SetTargetID(v xid.ID) *AuditLogUpdateOne {
_u.mutation.SetTargetID(v)
return _u
}
// SetNillableTargetID sets the "target_id" field if the given value is not nil.
func (_u *AuditLogUpdateOne) SetNillableTargetID(v *xid.ID) *AuditLogUpdateOne {
if v != nil {
_u.SetTargetID(*v)
}
return _u
}
// ClearTargetID clears the value of the "target_id" field.
func (_u *AuditLogUpdateOne) ClearTargetID() *AuditLogUpdateOne {
_u.mutation.ClearTargetID()
return _u
}
// SetTargetKind sets the "target_kind" field.
func (_u *AuditLogUpdateOne) SetTargetKind(v string) *AuditLogUpdateOne {
_u.mutation.SetTargetKind(v)
return _u
}
// SetNillableTargetKind sets the "target_kind" field if the given value is not nil.
func (_u *AuditLogUpdateOne) SetNillableTargetKind(v *string) *AuditLogUpdateOne {
if v != nil {
_u.SetTargetKind(*v)
}
return _u
}
// ClearTargetKind clears the value of the "target_kind" field.
func (_u *AuditLogUpdateOne) ClearTargetKind() *AuditLogUpdateOne {
_u.mutation.ClearTargetKind()
return _u
}
// SetType sets the "type" field.
func (_u *AuditLogUpdateOne) SetType(v string) *AuditLogUpdateOne {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *AuditLogUpdateOne) SetNillableType(v *string) *AuditLogUpdateOne {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetError sets the "error" field.
func (_u *AuditLogUpdateOne) SetError(v string) *AuditLogUpdateOne {
_u.mutation.SetError(v)
return _u
}
// SetNillableError sets the "error" field if the given value is not nil.
func (_u *AuditLogUpdateOne) SetNillableError(v *string) *AuditLogUpdateOne {
if v != nil {
_u.SetError(*v)
}
return _u
}
// ClearError clears the value of the "error" field.
func (_u *AuditLogUpdateOne) ClearError() *AuditLogUpdateOne {
_u.mutation.ClearError()
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *AuditLogUpdateOne) SetMetadata(v map[string]interface{}) *AuditLogUpdateOne {
_u.mutation.SetMetadata(v)
return _u
}
// ClearMetadata clears the value of the "metadata" field.
func (_u *AuditLogUpdateOne) ClearMetadata() *AuditLogUpdateOne {
_u.mutation.ClearMetadata()
return _u
}
// SetEnactedBy sets the "enacted_by" edge to the Account entity.
func (_u *AuditLogUpdateOne) SetEnactedBy(v *Account) *AuditLogUpdateOne {
return _u.SetEnactedByID(v.ID)
}
// Mutation returns the AuditLogMutation object of the builder.
func (_u *AuditLogUpdateOne) Mutation() *AuditLogMutation {
return _u.mutation
}
// ClearEnactedBy clears the "enacted_by" edge to the Account entity.
func (_u *AuditLogUpdateOne) ClearEnactedBy() *AuditLogUpdateOne {
_u.mutation.ClearEnactedBy()
return _u
}
// Where appends a list predicates to the AuditLogUpdate builder.
func (_u *AuditLogUpdateOne) Where(ps ...predicate.AuditLog) *AuditLogUpdateOne {
_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 *AuditLogUpdateOne) Select(field string, fields ...string) *AuditLogUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated AuditLog entity.
func (_u *AuditLogUpdateOne) Save(ctx context.Context) (*AuditLog, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *AuditLogUpdateOne) SaveX(ctx context.Context) *AuditLog {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *AuditLogUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *AuditLogUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *AuditLogUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AuditLogUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *AuditLogUpdateOne) sqlSave(ctx context.Context) (_node *AuditLog, err error) {
_spec := sqlgraph.NewUpdateSpec(auditlog.Table, auditlog.Columns, sqlgraph.NewFieldSpec(auditlog.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuditLog.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, auditlog.FieldID)
for _, f := range fields {
if !auditlog.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != auditlog.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.TargetID(); ok {
_spec.SetField(auditlog.FieldTargetID, field.TypeString, value)
}
if _u.mutation.TargetIDCleared() {
_spec.ClearField(auditlog.FieldTargetID, field.TypeString)
}
if value, ok := _u.mutation.TargetKind(); ok {
_spec.SetField(auditlog.FieldTargetKind, field.TypeString, value)
}
if _u.mutation.TargetKindCleared() {
_spec.ClearField(auditlog.FieldTargetKind, field.TypeString)
}
if value, ok := _u.mutation.GetType(); ok {
_spec.SetField(auditlog.FieldType, field.TypeString, value)
}
if value, ok := _u.mutation.Error(); ok {
_spec.SetField(auditlog.FieldError, field.TypeString, value)
}
if _u.mutation.ErrorCleared() {
_spec.ClearField(auditlog.FieldError, field.TypeString)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(auditlog.FieldMetadata, field.TypeJSON, value)
}
if _u.mutation.MetadataCleared() {
_spec.ClearField(auditlog.FieldMetadata, field.TypeJSON)
}
if _u.mutation.EnactedByCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: auditlog.EnactedByTable,
Columns: []string{auditlog.EnactedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.EnactedByIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: auditlog.EnactedByTable,
Columns: []string{auditlog.EnactedByColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_spec.AddModifiers(_u.modifiers...)
_node = &AuditLog{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{auditlog.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}