eventparticipant_update.go•15.9 kB
// 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/event"
"github.com/Southclaws/storyden/internal/ent/eventparticipant"
"github.com/Southclaws/storyden/internal/ent/predicate"
"github.com/rs/xid"
)
// EventParticipantUpdate is the builder for updating EventParticipant entities.
type EventParticipantUpdate struct {
config
hooks []Hook
mutation *EventParticipantMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the EventParticipantUpdate builder.
func (_u *EventParticipantUpdate) Where(ps ...predicate.EventParticipant) *EventParticipantUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetRole sets the "role" field.
func (_u *EventParticipantUpdate) SetRole(v string) *EventParticipantUpdate {
_u.mutation.SetRole(v)
return _u
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_u *EventParticipantUpdate) SetNillableRole(v *string) *EventParticipantUpdate {
if v != nil {
_u.SetRole(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *EventParticipantUpdate) SetStatus(v string) *EventParticipantUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *EventParticipantUpdate) SetNillableStatus(v *string) *EventParticipantUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetAccountID sets the "account_id" field.
func (_u *EventParticipantUpdate) SetAccountID(v xid.ID) *EventParticipantUpdate {
_u.mutation.SetAccountID(v)
return _u
}
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (_u *EventParticipantUpdate) SetNillableAccountID(v *xid.ID) *EventParticipantUpdate {
if v != nil {
_u.SetAccountID(*v)
}
return _u
}
// SetEventID sets the "event_id" field.
func (_u *EventParticipantUpdate) SetEventID(v xid.ID) *EventParticipantUpdate {
_u.mutation.SetEventID(v)
return _u
}
// SetNillableEventID sets the "event_id" field if the given value is not nil.
func (_u *EventParticipantUpdate) SetNillableEventID(v *xid.ID) *EventParticipantUpdate {
if v != nil {
_u.SetEventID(*v)
}
return _u
}
// SetAccount sets the "account" edge to the Account entity.
func (_u *EventParticipantUpdate) SetAccount(v *Account) *EventParticipantUpdate {
return _u.SetAccountID(v.ID)
}
// SetEvent sets the "event" edge to the Event entity.
func (_u *EventParticipantUpdate) SetEvent(v *Event) *EventParticipantUpdate {
return _u.SetEventID(v.ID)
}
// Mutation returns the EventParticipantMutation object of the builder.
func (_u *EventParticipantUpdate) Mutation() *EventParticipantMutation {
return _u.mutation
}
// ClearAccount clears the "account" edge to the Account entity.
func (_u *EventParticipantUpdate) ClearAccount() *EventParticipantUpdate {
_u.mutation.ClearAccount()
return _u
}
// ClearEvent clears the "event" edge to the Event entity.
func (_u *EventParticipantUpdate) ClearEvent() *EventParticipantUpdate {
_u.mutation.ClearEvent()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *EventParticipantUpdate) 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 *EventParticipantUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *EventParticipantUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *EventParticipantUpdate) 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 *EventParticipantUpdate) check() error {
if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "EventParticipant.account"`)
}
if _u.mutation.EventCleared() && len(_u.mutation.EventIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "EventParticipant.event"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *EventParticipantUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *EventParticipantUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *EventParticipantUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(eventparticipant.Table, eventparticipant.Columns, sqlgraph.NewFieldSpec(eventparticipant.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.Role(); ok {
_spec.SetField(eventparticipant.FieldRole, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(eventparticipant.FieldStatus, field.TypeString, value)
}
if _u.mutation.AccountCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.AccountTable,
Columns: []string{eventparticipant.AccountColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.AccountTable,
Columns: []string{eventparticipant.AccountColumn},
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)
}
if _u.mutation.EventCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.EventTable,
Columns: []string{eventparticipant.EventColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(event.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.EventIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.EventTable,
Columns: []string{eventparticipant.EventColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(event.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{eventparticipant.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// EventParticipantUpdateOne is the builder for updating a single EventParticipant entity.
type EventParticipantUpdateOne struct {
config
fields []string
hooks []Hook
mutation *EventParticipantMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetRole sets the "role" field.
func (_u *EventParticipantUpdateOne) SetRole(v string) *EventParticipantUpdateOne {
_u.mutation.SetRole(v)
return _u
}
// SetNillableRole sets the "role" field if the given value is not nil.
func (_u *EventParticipantUpdateOne) SetNillableRole(v *string) *EventParticipantUpdateOne {
if v != nil {
_u.SetRole(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *EventParticipantUpdateOne) SetStatus(v string) *EventParticipantUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *EventParticipantUpdateOne) SetNillableStatus(v *string) *EventParticipantUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetAccountID sets the "account_id" field.
func (_u *EventParticipantUpdateOne) SetAccountID(v xid.ID) *EventParticipantUpdateOne {
_u.mutation.SetAccountID(v)
return _u
}
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (_u *EventParticipantUpdateOne) SetNillableAccountID(v *xid.ID) *EventParticipantUpdateOne {
if v != nil {
_u.SetAccountID(*v)
}
return _u
}
// SetEventID sets the "event_id" field.
func (_u *EventParticipantUpdateOne) SetEventID(v xid.ID) *EventParticipantUpdateOne {
_u.mutation.SetEventID(v)
return _u
}
// SetNillableEventID sets the "event_id" field if the given value is not nil.
func (_u *EventParticipantUpdateOne) SetNillableEventID(v *xid.ID) *EventParticipantUpdateOne {
if v != nil {
_u.SetEventID(*v)
}
return _u
}
// SetAccount sets the "account" edge to the Account entity.
func (_u *EventParticipantUpdateOne) SetAccount(v *Account) *EventParticipantUpdateOne {
return _u.SetAccountID(v.ID)
}
// SetEvent sets the "event" edge to the Event entity.
func (_u *EventParticipantUpdateOne) SetEvent(v *Event) *EventParticipantUpdateOne {
return _u.SetEventID(v.ID)
}
// Mutation returns the EventParticipantMutation object of the builder.
func (_u *EventParticipantUpdateOne) Mutation() *EventParticipantMutation {
return _u.mutation
}
// ClearAccount clears the "account" edge to the Account entity.
func (_u *EventParticipantUpdateOne) ClearAccount() *EventParticipantUpdateOne {
_u.mutation.ClearAccount()
return _u
}
// ClearEvent clears the "event" edge to the Event entity.
func (_u *EventParticipantUpdateOne) ClearEvent() *EventParticipantUpdateOne {
_u.mutation.ClearEvent()
return _u
}
// Where appends a list predicates to the EventParticipantUpdate builder.
func (_u *EventParticipantUpdateOne) Where(ps ...predicate.EventParticipant) *EventParticipantUpdateOne {
_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 *EventParticipantUpdateOne) Select(field string, fields ...string) *EventParticipantUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated EventParticipant entity.
func (_u *EventParticipantUpdateOne) Save(ctx context.Context) (*EventParticipant, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *EventParticipantUpdateOne) SaveX(ctx context.Context) *EventParticipant {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *EventParticipantUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *EventParticipantUpdateOne) 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 *EventParticipantUpdateOne) check() error {
if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "EventParticipant.account"`)
}
if _u.mutation.EventCleared() && len(_u.mutation.EventIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "EventParticipant.event"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *EventParticipantUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *EventParticipantUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *EventParticipantUpdateOne) sqlSave(ctx context.Context) (_node *EventParticipant, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(eventparticipant.Table, eventparticipant.Columns, sqlgraph.NewFieldSpec(eventparticipant.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "EventParticipant.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, eventparticipant.FieldID)
for _, f := range fields {
if !eventparticipant.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != eventparticipant.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.Role(); ok {
_spec.SetField(eventparticipant.FieldRole, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(eventparticipant.FieldStatus, field.TypeString, value)
}
if _u.mutation.AccountCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.AccountTable,
Columns: []string{eventparticipant.AccountColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.AccountTable,
Columns: []string{eventparticipant.AccountColumn},
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)
}
if _u.mutation.EventCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.EventTable,
Columns: []string{eventparticipant.EventColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(event.FieldID, field.TypeString),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.EventIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: eventparticipant.EventTable,
Columns: []string{eventparticipant.EventColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(event.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 = &EventParticipant{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{eventparticipant.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}