mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-24 13:18:53 +08:00
820 lines
25 KiB
Go
820 lines
25 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/notifychannel"
|
|
"github.com/chaitin/MonkeyCode/backend/db/notifysubscription"
|
|
"github.com/chaitin/MonkeyCode/backend/db/predicate"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// NotifyChannelUpdate is the builder for updating NotifyChannel entities.
|
|
type NotifyChannelUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *NotifyChannelMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the NotifyChannelUpdate builder.
|
|
func (_u *NotifyChannelUpdate) Where(ps ...predicate.NotifyChannel) *NotifyChannelUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_u *NotifyChannelUpdate) SetDeletedAt(v time.Time) *NotifyChannelUpdate {
|
|
_u.mutation.SetDeletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableDeletedAt(v *time.Time) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetDeletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (_u *NotifyChannelUpdate) ClearDeletedAt() *NotifyChannelUpdate {
|
|
_u.mutation.ClearDeletedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerID sets the "owner_id" field.
|
|
func (_u *NotifyChannelUpdate) SetOwnerID(v uuid.UUID) *NotifyChannelUpdate {
|
|
_u.mutation.SetOwnerID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableOwnerID(v *uuid.UUID) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetOwnerID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerType sets the "owner_type" field.
|
|
func (_u *NotifyChannelUpdate) SetOwnerType(v consts.NotifyOwnerType) *NotifyChannelUpdate {
|
|
_u.mutation.SetOwnerType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerType sets the "owner_type" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableOwnerType(v *consts.NotifyOwnerType) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetOwnerType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *NotifyChannelUpdate) SetName(v string) *NotifyChannelUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableName(v *string) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetKind sets the "kind" field.
|
|
func (_u *NotifyChannelUpdate) SetKind(v consts.NotifyChannelKind) *NotifyChannelUpdate {
|
|
_u.mutation.SetKind(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableKind sets the "kind" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableKind(v *consts.NotifyChannelKind) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetKind(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWebhookURL sets the "webhook_url" field.
|
|
func (_u *NotifyChannelUpdate) SetWebhookURL(v string) *NotifyChannelUpdate {
|
|
_u.mutation.SetWebhookURL(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWebhookURL sets the "webhook_url" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableWebhookURL(v *string) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetWebhookURL(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSecret sets the "secret" field.
|
|
func (_u *NotifyChannelUpdate) SetSecret(v string) *NotifyChannelUpdate {
|
|
_u.mutation.SetSecret(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSecret sets the "secret" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableSecret(v *string) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetSecret(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearSecret clears the value of the "secret" field.
|
|
func (_u *NotifyChannelUpdate) ClearSecret() *NotifyChannelUpdate {
|
|
_u.mutation.ClearSecret()
|
|
return _u
|
|
}
|
|
|
|
// SetHeaders sets the "headers" field.
|
|
func (_u *NotifyChannelUpdate) SetHeaders(v map[string]string) *NotifyChannelUpdate {
|
|
_u.mutation.SetHeaders(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearHeaders clears the value of the "headers" field.
|
|
func (_u *NotifyChannelUpdate) ClearHeaders() *NotifyChannelUpdate {
|
|
_u.mutation.ClearHeaders()
|
|
return _u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_u *NotifyChannelUpdate) SetEnabled(v bool) *NotifyChannelUpdate {
|
|
_u.mutation.SetEnabled(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableEnabled(v *bool) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetEnabled(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *NotifyChannelUpdate) SetCreatedAt(v time.Time) *NotifyChannelUpdate {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdate) SetNillableCreatedAt(v *time.Time) *NotifyChannelUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *NotifyChannelUpdate) SetUpdatedAt(v time.Time) *NotifyChannelUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// AddSubscriptionIDs adds the "subscriptions" edge to the NotifySubscription entity by IDs.
|
|
func (_u *NotifyChannelUpdate) AddSubscriptionIDs(ids ...uuid.UUID) *NotifyChannelUpdate {
|
|
_u.mutation.AddSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddSubscriptions adds the "subscriptions" edges to the NotifySubscription entity.
|
|
func (_u *NotifyChannelUpdate) AddSubscriptions(v ...*NotifySubscription) *NotifyChannelUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the NotifyChannelMutation object of the builder.
|
|
func (_u *NotifyChannelUpdate) Mutation() *NotifyChannelMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearSubscriptions clears all "subscriptions" edges to the NotifySubscription entity.
|
|
func (_u *NotifyChannelUpdate) ClearSubscriptions() *NotifyChannelUpdate {
|
|
_u.mutation.ClearSubscriptions()
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptionIDs removes the "subscriptions" edge to NotifySubscription entities by IDs.
|
|
func (_u *NotifyChannelUpdate) RemoveSubscriptionIDs(ids ...uuid.UUID) *NotifyChannelUpdate {
|
|
_u.mutation.RemoveSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptions removes "subscriptions" edges to NotifySubscription entities.
|
|
func (_u *NotifyChannelUpdate) RemoveSubscriptions(v ...*NotifySubscription) *NotifyChannelUpdate {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *NotifyChannelUpdate) Save(ctx context.Context) (int, error) {
|
|
if err := _u.defaults(); err != nil {
|
|
return 0, err
|
|
}
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *NotifyChannelUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *NotifyChannelUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *NotifyChannelUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *NotifyChannelUpdate) defaults() error {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
if notifychannel.UpdateDefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized notifychannel.UpdateDefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := notifychannel.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *NotifyChannelUpdate) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := notifychannel.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "NotifyChannel.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.WebhookURL(); ok {
|
|
if err := notifychannel.WebhookURLValidator(v); err != nil {
|
|
return &ValidationError{Name: "webhook_url", err: fmt.Errorf(`db: validator failed for field "NotifyChannel.webhook_url": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *NotifyChannelUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *NotifyChannelUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *NotifyChannelUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(notifychannel.Table, notifychannel.Columns, sqlgraph.NewFieldSpec(notifychannel.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.DeletedAt(); ok {
|
|
_spec.SetField(notifychannel.FieldDeletedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DeletedAtCleared() {
|
|
_spec.ClearField(notifychannel.FieldDeletedAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.OwnerID(); ok {
|
|
_spec.SetField(notifychannel.FieldOwnerID, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.OwnerType(); ok {
|
|
_spec.SetField(notifychannel.FieldOwnerType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(notifychannel.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Kind(); ok {
|
|
_spec.SetField(notifychannel.FieldKind, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WebhookURL(); ok {
|
|
_spec.SetField(notifychannel.FieldWebhookURL, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Secret(); ok {
|
|
_spec.SetField(notifychannel.FieldSecret, field.TypeString, value)
|
|
}
|
|
if _u.mutation.SecretCleared() {
|
|
_spec.ClearField(notifychannel.FieldSecret, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Headers(); ok {
|
|
_spec.SetField(notifychannel.FieldHeaders, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.HeadersCleared() {
|
|
_spec.ClearField(notifychannel.FieldHeaders, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(notifychannel.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(notifychannel.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(notifychannel.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: notifychannel.SubscriptionsTable,
|
|
Columns: []string{notifychannel.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: notifychannel.SubscriptionsTable,
|
|
Columns: []string{notifychannel.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.SubscriptionsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: notifychannel.SubscriptionsTable,
|
|
Columns: []string{notifychannel.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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{notifychannel.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// NotifyChannelUpdateOne is the builder for updating a single NotifyChannel entity.
|
|
type NotifyChannelUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *NotifyChannelMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_u *NotifyChannelUpdateOne) SetDeletedAt(v time.Time) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetDeletedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableDeletedAt(v *time.Time) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetDeletedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (_u *NotifyChannelUpdateOne) ClearDeletedAt() *NotifyChannelUpdateOne {
|
|
_u.mutation.ClearDeletedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerID sets the "owner_id" field.
|
|
func (_u *NotifyChannelUpdateOne) SetOwnerID(v uuid.UUID) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetOwnerID(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableOwnerID(v *uuid.UUID) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetOwnerID(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOwnerType sets the "owner_type" field.
|
|
func (_u *NotifyChannelUpdateOne) SetOwnerType(v consts.NotifyOwnerType) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetOwnerType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOwnerType sets the "owner_type" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableOwnerType(v *consts.NotifyOwnerType) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetOwnerType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *NotifyChannelUpdateOne) SetName(v string) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableName(v *string) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetKind sets the "kind" field.
|
|
func (_u *NotifyChannelUpdateOne) SetKind(v consts.NotifyChannelKind) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetKind(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableKind sets the "kind" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableKind(v *consts.NotifyChannelKind) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetKind(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWebhookURL sets the "webhook_url" field.
|
|
func (_u *NotifyChannelUpdateOne) SetWebhookURL(v string) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetWebhookURL(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWebhookURL sets the "webhook_url" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableWebhookURL(v *string) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetWebhookURL(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSecret sets the "secret" field.
|
|
func (_u *NotifyChannelUpdateOne) SetSecret(v string) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetSecret(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSecret sets the "secret" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableSecret(v *string) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetSecret(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearSecret clears the value of the "secret" field.
|
|
func (_u *NotifyChannelUpdateOne) ClearSecret() *NotifyChannelUpdateOne {
|
|
_u.mutation.ClearSecret()
|
|
return _u
|
|
}
|
|
|
|
// SetHeaders sets the "headers" field.
|
|
func (_u *NotifyChannelUpdateOne) SetHeaders(v map[string]string) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetHeaders(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearHeaders clears the value of the "headers" field.
|
|
func (_u *NotifyChannelUpdateOne) ClearHeaders() *NotifyChannelUpdateOne {
|
|
_u.mutation.ClearHeaders()
|
|
return _u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_u *NotifyChannelUpdateOne) SetEnabled(v bool) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetEnabled(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableEnabled(v *bool) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetEnabled(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *NotifyChannelUpdateOne) SetCreatedAt(v time.Time) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *NotifyChannelUpdateOne) SetNillableCreatedAt(v *time.Time) *NotifyChannelUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *NotifyChannelUpdateOne) SetUpdatedAt(v time.Time) *NotifyChannelUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// AddSubscriptionIDs adds the "subscriptions" edge to the NotifySubscription entity by IDs.
|
|
func (_u *NotifyChannelUpdateOne) AddSubscriptionIDs(ids ...uuid.UUID) *NotifyChannelUpdateOne {
|
|
_u.mutation.AddSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// AddSubscriptions adds the "subscriptions" edges to the NotifySubscription entity.
|
|
func (_u *NotifyChannelUpdateOne) AddSubscriptions(v ...*NotifySubscription) *NotifyChannelUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.AddSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the NotifyChannelMutation object of the builder.
|
|
func (_u *NotifyChannelUpdateOne) Mutation() *NotifyChannelMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// ClearSubscriptions clears all "subscriptions" edges to the NotifySubscription entity.
|
|
func (_u *NotifyChannelUpdateOne) ClearSubscriptions() *NotifyChannelUpdateOne {
|
|
_u.mutation.ClearSubscriptions()
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptionIDs removes the "subscriptions" edge to NotifySubscription entities by IDs.
|
|
func (_u *NotifyChannelUpdateOne) RemoveSubscriptionIDs(ids ...uuid.UUID) *NotifyChannelUpdateOne {
|
|
_u.mutation.RemoveSubscriptionIDs(ids...)
|
|
return _u
|
|
}
|
|
|
|
// RemoveSubscriptions removes "subscriptions" edges to NotifySubscription entities.
|
|
func (_u *NotifyChannelUpdateOne) RemoveSubscriptions(v ...*NotifySubscription) *NotifyChannelUpdateOne {
|
|
ids := make([]uuid.UUID, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _u.RemoveSubscriptionIDs(ids...)
|
|
}
|
|
|
|
// Where appends a list predicates to the NotifyChannelUpdate builder.
|
|
func (_u *NotifyChannelUpdateOne) Where(ps ...predicate.NotifyChannel) *NotifyChannelUpdateOne {
|
|
_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 *NotifyChannelUpdateOne) Select(field string, fields ...string) *NotifyChannelUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated NotifyChannel entity.
|
|
func (_u *NotifyChannelUpdateOne) Save(ctx context.Context) (*NotifyChannel, error) {
|
|
if err := _u.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *NotifyChannelUpdateOne) SaveX(ctx context.Context) *NotifyChannel {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *NotifyChannelUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *NotifyChannelUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_u *NotifyChannelUpdateOne) defaults() error {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
if notifychannel.UpdateDefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized notifychannel.UpdateDefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := notifychannel.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *NotifyChannelUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := notifychannel.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`db: validator failed for field "NotifyChannel.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.WebhookURL(); ok {
|
|
if err := notifychannel.WebhookURLValidator(v); err != nil {
|
|
return &ValidationError{Name: "webhook_url", err: fmt.Errorf(`db: validator failed for field "NotifyChannel.webhook_url": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *NotifyChannelUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *NotifyChannelUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *NotifyChannelUpdateOne) sqlSave(ctx context.Context) (_node *NotifyChannel, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(notifychannel.Table, notifychannel.Columns, sqlgraph.NewFieldSpec(notifychannel.FieldID, field.TypeUUID))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "NotifyChannel.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, notifychannel.FieldID)
|
|
for _, f := range fields {
|
|
if !notifychannel.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)}
|
|
}
|
|
if f != notifychannel.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.DeletedAt(); ok {
|
|
_spec.SetField(notifychannel.FieldDeletedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DeletedAtCleared() {
|
|
_spec.ClearField(notifychannel.FieldDeletedAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.OwnerID(); ok {
|
|
_spec.SetField(notifychannel.FieldOwnerID, field.TypeUUID, value)
|
|
}
|
|
if value, ok := _u.mutation.OwnerType(); ok {
|
|
_spec.SetField(notifychannel.FieldOwnerType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(notifychannel.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Kind(); ok {
|
|
_spec.SetField(notifychannel.FieldKind, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WebhookURL(); ok {
|
|
_spec.SetField(notifychannel.FieldWebhookURL, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Secret(); ok {
|
|
_spec.SetField(notifychannel.FieldSecret, field.TypeString, value)
|
|
}
|
|
if _u.mutation.SecretCleared() {
|
|
_spec.ClearField(notifychannel.FieldSecret, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Headers(); ok {
|
|
_spec.SetField(notifychannel.FieldHeaders, field.TypeJSON, value)
|
|
}
|
|
if _u.mutation.HeadersCleared() {
|
|
_spec.ClearField(notifychannel.FieldHeaders, field.TypeJSON)
|
|
}
|
|
if value, ok := _u.mutation.Enabled(); ok {
|
|
_spec.SetField(notifychannel.FieldEnabled, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(notifychannel.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(notifychannel.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: notifychannel.SubscriptionsTable,
|
|
Columns: []string{notifychannel.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.RemovedSubscriptionsIDs(); len(nodes) > 0 && !_u.mutation.SubscriptionsCleared() {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: notifychannel.SubscriptionsTable,
|
|
Columns: []string{notifychannel.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
}
|
|
if nodes := _u.mutation.SubscriptionsIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: false,
|
|
Table: notifychannel.SubscriptionsTable,
|
|
Columns: []string{notifychannel.SubscriptionsColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
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 = &NotifyChannel{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{notifychannel.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|