Files
MonkeyCode/backend/db/notifysendlog_update.go

451 lines
14 KiB
Go

// Code generated by ent, DO NOT EDIT.
package db
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/chaitin/MonkeyCode/backend/consts"
"github.com/chaitin/MonkeyCode/backend/db/notifysendlog"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/google/uuid"
)
// NotifySendLogUpdate is the builder for updating NotifySendLog entities.
type NotifySendLogUpdate struct {
config
hooks []Hook
mutation *NotifySendLogMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the NotifySendLogUpdate builder.
func (_u *NotifySendLogUpdate) Where(ps ...predicate.NotifySendLog) *NotifySendLogUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetSubscriptionID sets the "subscription_id" field.
func (_u *NotifySendLogUpdate) SetSubscriptionID(v uuid.UUID) *NotifySendLogUpdate {
_u.mutation.SetSubscriptionID(v)
return _u
}
// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableSubscriptionID(v *uuid.UUID) *NotifySendLogUpdate {
if v != nil {
_u.SetSubscriptionID(*v)
}
return _u
}
// SetChannelID sets the "channel_id" field.
func (_u *NotifySendLogUpdate) SetChannelID(v uuid.UUID) *NotifySendLogUpdate {
_u.mutation.SetChannelID(v)
return _u
}
// SetNillableChannelID sets the "channel_id" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableChannelID(v *uuid.UUID) *NotifySendLogUpdate {
if v != nil {
_u.SetChannelID(*v)
}
return _u
}
// SetEventType sets the "event_type" field.
func (_u *NotifySendLogUpdate) SetEventType(v consts.NotifyEventType) *NotifySendLogUpdate {
_u.mutation.SetEventType(v)
return _u
}
// SetNillableEventType sets the "event_type" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableEventType(v *consts.NotifyEventType) *NotifySendLogUpdate {
if v != nil {
_u.SetEventType(*v)
}
return _u
}
// SetEventRefID sets the "event_ref_id" field.
func (_u *NotifySendLogUpdate) SetEventRefID(v string) *NotifySendLogUpdate {
_u.mutation.SetEventRefID(v)
return _u
}
// SetNillableEventRefID sets the "event_ref_id" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableEventRefID(v *string) *NotifySendLogUpdate {
if v != nil {
_u.SetEventRefID(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *NotifySendLogUpdate) SetStatus(v consts.NotifySendStatus) *NotifySendLogUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableStatus(v *consts.NotifySendStatus) *NotifySendLogUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetError sets the "error" field.
func (_u *NotifySendLogUpdate) SetError(v string) *NotifySendLogUpdate {
_u.mutation.SetError(v)
return _u
}
// SetNillableError sets the "error" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableError(v *string) *NotifySendLogUpdate {
if v != nil {
_u.SetError(*v)
}
return _u
}
// ClearError clears the value of the "error" field.
func (_u *NotifySendLogUpdate) ClearError() *NotifySendLogUpdate {
_u.mutation.ClearError()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *NotifySendLogUpdate) SetCreatedAt(v time.Time) *NotifySendLogUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *NotifySendLogUpdate) SetNillableCreatedAt(v *time.Time) *NotifySendLogUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// Mutation returns the NotifySendLogMutation object of the builder.
func (_u *NotifySendLogUpdate) Mutation() *NotifySendLogMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *NotifySendLogUpdate) 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 *NotifySendLogUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *NotifySendLogUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *NotifySendLogUpdate) 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 *NotifySendLogUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *NotifySendLogUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *NotifySendLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(notifysendlog.Table, notifysendlog.Columns, sqlgraph.NewFieldSpec(notifysendlog.FieldID, field.TypeUUID))
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.SubscriptionID(); ok {
_spec.SetField(notifysendlog.FieldSubscriptionID, field.TypeUUID, value)
}
if value, ok := _u.mutation.ChannelID(); ok {
_spec.SetField(notifysendlog.FieldChannelID, field.TypeUUID, value)
}
if value, ok := _u.mutation.EventType(); ok {
_spec.SetField(notifysendlog.FieldEventType, field.TypeString, value)
}
if value, ok := _u.mutation.EventRefID(); ok {
_spec.SetField(notifysendlog.FieldEventRefID, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(notifysendlog.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Error(); ok {
_spec.SetField(notifysendlog.FieldError, field.TypeString, value)
}
if _u.mutation.ErrorCleared() {
_spec.ClearField(notifysendlog.FieldError, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(notifysendlog.FieldCreatedAt, field.TypeTime, value)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{notifysendlog.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// NotifySendLogUpdateOne is the builder for updating a single NotifySendLog entity.
type NotifySendLogUpdateOne struct {
config
fields []string
hooks []Hook
mutation *NotifySendLogMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetSubscriptionID sets the "subscription_id" field.
func (_u *NotifySendLogUpdateOne) SetSubscriptionID(v uuid.UUID) *NotifySendLogUpdateOne {
_u.mutation.SetSubscriptionID(v)
return _u
}
// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableSubscriptionID(v *uuid.UUID) *NotifySendLogUpdateOne {
if v != nil {
_u.SetSubscriptionID(*v)
}
return _u
}
// SetChannelID sets the "channel_id" field.
func (_u *NotifySendLogUpdateOne) SetChannelID(v uuid.UUID) *NotifySendLogUpdateOne {
_u.mutation.SetChannelID(v)
return _u
}
// SetNillableChannelID sets the "channel_id" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableChannelID(v *uuid.UUID) *NotifySendLogUpdateOne {
if v != nil {
_u.SetChannelID(*v)
}
return _u
}
// SetEventType sets the "event_type" field.
func (_u *NotifySendLogUpdateOne) SetEventType(v consts.NotifyEventType) *NotifySendLogUpdateOne {
_u.mutation.SetEventType(v)
return _u
}
// SetNillableEventType sets the "event_type" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableEventType(v *consts.NotifyEventType) *NotifySendLogUpdateOne {
if v != nil {
_u.SetEventType(*v)
}
return _u
}
// SetEventRefID sets the "event_ref_id" field.
func (_u *NotifySendLogUpdateOne) SetEventRefID(v string) *NotifySendLogUpdateOne {
_u.mutation.SetEventRefID(v)
return _u
}
// SetNillableEventRefID sets the "event_ref_id" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableEventRefID(v *string) *NotifySendLogUpdateOne {
if v != nil {
_u.SetEventRefID(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *NotifySendLogUpdateOne) SetStatus(v consts.NotifySendStatus) *NotifySendLogUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableStatus(v *consts.NotifySendStatus) *NotifySendLogUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetError sets the "error" field.
func (_u *NotifySendLogUpdateOne) SetError(v string) *NotifySendLogUpdateOne {
_u.mutation.SetError(v)
return _u
}
// SetNillableError sets the "error" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableError(v *string) *NotifySendLogUpdateOne {
if v != nil {
_u.SetError(*v)
}
return _u
}
// ClearError clears the value of the "error" field.
func (_u *NotifySendLogUpdateOne) ClearError() *NotifySendLogUpdateOne {
_u.mutation.ClearError()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *NotifySendLogUpdateOne) SetCreatedAt(v time.Time) *NotifySendLogUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *NotifySendLogUpdateOne) SetNillableCreatedAt(v *time.Time) *NotifySendLogUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// Mutation returns the NotifySendLogMutation object of the builder.
func (_u *NotifySendLogUpdateOne) Mutation() *NotifySendLogMutation {
return _u.mutation
}
// Where appends a list predicates to the NotifySendLogUpdate builder.
func (_u *NotifySendLogUpdateOne) Where(ps ...predicate.NotifySendLog) *NotifySendLogUpdateOne {
_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 *NotifySendLogUpdateOne) Select(field string, fields ...string) *NotifySendLogUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated NotifySendLog entity.
func (_u *NotifySendLogUpdateOne) Save(ctx context.Context) (*NotifySendLog, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *NotifySendLogUpdateOne) SaveX(ctx context.Context) *NotifySendLog {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *NotifySendLogUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *NotifySendLogUpdateOne) 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 *NotifySendLogUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *NotifySendLogUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *NotifySendLogUpdateOne) sqlSave(ctx context.Context) (_node *NotifySendLog, err error) {
_spec := sqlgraph.NewUpdateSpec(notifysendlog.Table, notifysendlog.Columns, sqlgraph.NewFieldSpec(notifysendlog.FieldID, field.TypeUUID))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "NotifySendLog.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, notifysendlog.FieldID)
for _, f := range fields {
if !notifysendlog.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
}
if f != notifysendlog.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.SubscriptionID(); ok {
_spec.SetField(notifysendlog.FieldSubscriptionID, field.TypeUUID, value)
}
if value, ok := _u.mutation.ChannelID(); ok {
_spec.SetField(notifysendlog.FieldChannelID, field.TypeUUID, value)
}
if value, ok := _u.mutation.EventType(); ok {
_spec.SetField(notifysendlog.FieldEventType, field.TypeString, value)
}
if value, ok := _u.mutation.EventRefID(); ok {
_spec.SetField(notifysendlog.FieldEventRefID, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(notifysendlog.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Error(); ok {
_spec.SetField(notifysendlog.FieldError, field.TypeString, value)
}
if _u.mutation.ErrorCleared() {
_spec.ClearField(notifysendlog.FieldError, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(notifysendlog.FieldCreatedAt, field.TypeTime, value)
}
_spec.AddModifiers(_u.modifiers...)
_node = &NotifySendLog{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{notifysendlog.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}