Files
ersteller/schema/ent/event_update.go
T
2025-11-16 19:54:42 +01:00

282 lines
7.6 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/schema/field"
"git.gorlug.de/code/ersteller/schema/ent/event"
"git.gorlug.de/code/ersteller/schema/ent/predicate"
)
// EventUpdate is the builder for updating Event entities.
type EventUpdate struct {
config
hooks []Hook
mutation *EventMutation
}
// Where appends a list predicates to the EventUpdate builder.
func (_u *EventUpdate) Where(ps ...predicate.Event) *EventUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetName sets the "name" field.
func (_u *EventUpdate) SetName(v string) *EventUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *EventUpdate) SetNillableName(v *string) *EventUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetData sets the "data" field.
func (_u *EventUpdate) SetData(v map[string]interface{}) *EventUpdate {
_u.mutation.SetData(v)
return _u
}
// SetUserID sets the "user_id" field.
func (_u *EventUpdate) SetUserID(v int) *EventUpdate {
_u.mutation.ResetUserID()
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *EventUpdate) SetNillableUserID(v *int) *EventUpdate {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// AddUserID adds value to the "user_id" field.
func (_u *EventUpdate) AddUserID(v int) *EventUpdate {
_u.mutation.AddUserID(v)
return _u
}
// Mutation returns the EventMutation object of the builder.
func (_u *EventUpdate) Mutation() *EventMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *EventUpdate) 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 *EventUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *EventUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *EventUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *EventUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(event.Table, event.Columns, sqlgraph.NewFieldSpec(event.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.Name(); ok {
_spec.SetField(event.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Data(); ok {
_spec.SetField(event.FieldData, field.TypeJSON, value)
}
if value, ok := _u.mutation.UserID(); ok {
_spec.SetField(event.FieldUserID, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedUserID(); ok {
_spec.AddField(event.FieldUserID, field.TypeInt, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{event.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// EventUpdateOne is the builder for updating a single Event entity.
type EventUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EventMutation
}
// SetName sets the "name" field.
func (_u *EventUpdateOne) SetName(v string) *EventUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *EventUpdateOne) SetNillableName(v *string) *EventUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetData sets the "data" field.
func (_u *EventUpdateOne) SetData(v map[string]interface{}) *EventUpdateOne {
_u.mutation.SetData(v)
return _u
}
// SetUserID sets the "user_id" field.
func (_u *EventUpdateOne) SetUserID(v int) *EventUpdateOne {
_u.mutation.ResetUserID()
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *EventUpdateOne) SetNillableUserID(v *int) *EventUpdateOne {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// AddUserID adds value to the "user_id" field.
func (_u *EventUpdateOne) AddUserID(v int) *EventUpdateOne {
_u.mutation.AddUserID(v)
return _u
}
// Mutation returns the EventMutation object of the builder.
func (_u *EventUpdateOne) Mutation() *EventMutation {
return _u.mutation
}
// Where appends a list predicates to the EventUpdate builder.
func (_u *EventUpdateOne) Where(ps ...predicate.Event) *EventUpdateOne {
_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 *EventUpdateOne) Select(field string, fields ...string) *EventUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Event entity.
func (_u *EventUpdateOne) Save(ctx context.Context) (*Event, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *EventUpdateOne) SaveX(ctx context.Context) *Event {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *EventUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *EventUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *EventUpdateOne) sqlSave(ctx context.Context) (_node *Event, err error) {
_spec := sqlgraph.NewUpdateSpec(event.Table, event.Columns, sqlgraph.NewFieldSpec(event.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Event.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, event.FieldID)
for _, f := range fields {
if !event.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != event.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.Name(); ok {
_spec.SetField(event.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Data(); ok {
_spec.SetField(event.FieldData, field.TypeJSON, value)
}
if value, ok := _u.mutation.UserID(); ok {
_spec.SetField(event.FieldUserID, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedUserID(); ok {
_spec.AddField(event.FieldUserID, field.TypeInt, value)
}
_node = &Event{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{event.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}