mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-28 23:58:26 +08:00
921 lines
29 KiB
Go
921 lines
29 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"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/google/uuid"
|
|
)
|
|
|
|
// NotifySubscriptionCreate is the builder for creating a NotifySubscription entity.
|
|
type NotifySubscriptionCreate struct {
|
|
config
|
|
mutation *NotifySubscriptionMutation
|
|
hooks []Hook
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *NotifySubscriptionCreate) SetDeletedAt(v time.Time) *NotifySubscriptionCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *NotifySubscriptionCreate) SetNillableDeletedAt(v *time.Time) *NotifySubscriptionCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetChannelID sets the "channel_id" field.
|
|
func (_c *NotifySubscriptionCreate) SetChannelID(v uuid.UUID) *NotifySubscriptionCreate {
|
|
_c.mutation.SetChannelID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetScope sets the "scope" field.
|
|
func (_c *NotifySubscriptionCreate) SetScope(v string) *NotifySubscriptionCreate {
|
|
_c.mutation.SetScope(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableScope sets the "scope" field if the given value is not nil.
|
|
func (_c *NotifySubscriptionCreate) SetNillableScope(v *string) *NotifySubscriptionCreate {
|
|
if v != nil {
|
|
_c.SetScope(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetEventTypes sets the "event_types" field.
|
|
func (_c *NotifySubscriptionCreate) SetEventTypes(v []consts.NotifyEventType) *NotifySubscriptionCreate {
|
|
_c.mutation.SetEventTypes(v)
|
|
return _c
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (_c *NotifySubscriptionCreate) SetEnabled(v bool) *NotifySubscriptionCreate {
|
|
_c.mutation.SetEnabled(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
|
func (_c *NotifySubscriptionCreate) SetNillableEnabled(v *bool) *NotifySubscriptionCreate {
|
|
if v != nil {
|
|
_c.SetEnabled(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *NotifySubscriptionCreate) SetCreatedAt(v time.Time) *NotifySubscriptionCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *NotifySubscriptionCreate) SetNillableCreatedAt(v *time.Time) *NotifySubscriptionCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *NotifySubscriptionCreate) SetUpdatedAt(v time.Time) *NotifySubscriptionCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *NotifySubscriptionCreate) SetNillableUpdatedAt(v *time.Time) *NotifySubscriptionCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *NotifySubscriptionCreate) SetID(v uuid.UUID) *NotifySubscriptionCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetChannel sets the "channel" edge to the NotifyChannel entity.
|
|
func (_c *NotifySubscriptionCreate) SetChannel(v *NotifyChannel) *NotifySubscriptionCreate {
|
|
return _c.SetChannelID(v.ID)
|
|
}
|
|
|
|
// Mutation returns the NotifySubscriptionMutation object of the builder.
|
|
func (_c *NotifySubscriptionCreate) Mutation() *NotifySubscriptionMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the NotifySubscription in the database.
|
|
func (_c *NotifySubscriptionCreate) Save(ctx context.Context) (*NotifySubscription, error) {
|
|
if err := _c.defaults(); err != nil {
|
|
return nil, err
|
|
}
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *NotifySubscriptionCreate) SaveX(ctx context.Context) *NotifySubscription {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *NotifySubscriptionCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *NotifySubscriptionCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *NotifySubscriptionCreate) defaults() error {
|
|
if _, ok := _c.mutation.Scope(); !ok {
|
|
v := notifysubscription.DefaultScope
|
|
_c.mutation.SetScope(v)
|
|
}
|
|
if _, ok := _c.mutation.Enabled(); !ok {
|
|
v := notifysubscription.DefaultEnabled
|
|
_c.mutation.SetEnabled(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
if notifysubscription.DefaultCreatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized notifysubscription.DefaultCreatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := notifysubscription.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
if notifysubscription.DefaultUpdatedAt == nil {
|
|
return fmt.Errorf("db: uninitialized notifysubscription.DefaultUpdatedAt (forgotten import db/runtime?)")
|
|
}
|
|
v := notifysubscription.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *NotifySubscriptionCreate) check() error {
|
|
if _, ok := _c.mutation.ChannelID(); !ok {
|
|
return &ValidationError{Name: "channel_id", err: errors.New(`db: missing required field "NotifySubscription.channel_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.Scope(); !ok {
|
|
return &ValidationError{Name: "scope", err: errors.New(`db: missing required field "NotifySubscription.scope"`)}
|
|
}
|
|
if _, ok := _c.mutation.EventTypes(); !ok {
|
|
return &ValidationError{Name: "event_types", err: errors.New(`db: missing required field "NotifySubscription.event_types"`)}
|
|
}
|
|
if _, ok := _c.mutation.Enabled(); !ok {
|
|
return &ValidationError{Name: "enabled", err: errors.New(`db: missing required field "NotifySubscription.enabled"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "NotifySubscription.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`db: missing required field "NotifySubscription.updated_at"`)}
|
|
}
|
|
if len(_c.mutation.ChannelIDs()) == 0 {
|
|
return &ValidationError{Name: "channel", err: errors.New(`db: missing required edge "NotifySubscription.channel"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *NotifySubscriptionCreate) sqlSave(ctx context.Context) (*NotifySubscription, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != nil {
|
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
_node.ID = *id
|
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *NotifySubscriptionCreate) createSpec() (*NotifySubscription, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &NotifySubscription{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(notifysubscription.Table, sqlgraph.NewFieldSpec(notifysubscription.FieldID, field.TypeUUID))
|
|
)
|
|
_spec.OnConflict = _c.conflict
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = &id
|
|
}
|
|
if value, ok := _c.mutation.DeletedAt(); ok {
|
|
_spec.SetField(notifysubscription.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Scope(); ok {
|
|
_spec.SetField(notifysubscription.FieldScope, field.TypeString, value)
|
|
_node.Scope = value
|
|
}
|
|
if value, ok := _c.mutation.EventTypes(); ok {
|
|
_spec.SetField(notifysubscription.FieldEventTypes, field.TypeJSON, value)
|
|
_node.EventTypes = value
|
|
}
|
|
if value, ok := _c.mutation.Enabled(); ok {
|
|
_spec.SetField(notifysubscription.FieldEnabled, field.TypeBool, value)
|
|
_node.Enabled = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(notifysubscription.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(notifysubscription.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if nodes := _c.mutation.ChannelIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.M2O,
|
|
Inverse: true,
|
|
Table: notifysubscription.ChannelTable,
|
|
Columns: []string{notifysubscription.ChannelColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(notifychannel.FieldID, field.TypeUUID),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_node.ChannelID = nodes[0]
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// SetDeletedAt(v).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.NotifySubscriptionUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *NotifySubscriptionCreate) OnConflict(opts ...sql.ConflictOption) *NotifySubscriptionUpsertOne {
|
|
_c.conflict = opts
|
|
return &NotifySubscriptionUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *NotifySubscriptionCreate) OnConflictColumns(columns ...string) *NotifySubscriptionUpsertOne {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &NotifySubscriptionUpsertOne{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
type (
|
|
// NotifySubscriptionUpsertOne is the builder for "upsert"-ing
|
|
// one NotifySubscription node.
|
|
NotifySubscriptionUpsertOne struct {
|
|
create *NotifySubscriptionCreate
|
|
}
|
|
|
|
// NotifySubscriptionUpsert is the "OnConflict" setter.
|
|
NotifySubscriptionUpsert struct {
|
|
*sql.UpdateSet
|
|
}
|
|
)
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *NotifySubscriptionUpsert) SetDeletedAt(v time.Time) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldDeletedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateDeletedAt() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *NotifySubscriptionUpsert) ClearDeletedAt() *NotifySubscriptionUpsert {
|
|
u.SetNull(notifysubscription.FieldDeletedAt)
|
|
return u
|
|
}
|
|
|
|
// SetChannelID sets the "channel_id" field.
|
|
func (u *NotifySubscriptionUpsert) SetChannelID(v uuid.UUID) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldChannelID, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateChannelID sets the "channel_id" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateChannelID() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldChannelID)
|
|
return u
|
|
}
|
|
|
|
// SetScope sets the "scope" field.
|
|
func (u *NotifySubscriptionUpsert) SetScope(v string) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldScope, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateScope sets the "scope" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateScope() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldScope)
|
|
return u
|
|
}
|
|
|
|
// SetEventTypes sets the "event_types" field.
|
|
func (u *NotifySubscriptionUpsert) SetEventTypes(v []consts.NotifyEventType) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldEventTypes, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEventTypes sets the "event_types" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateEventTypes() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldEventTypes)
|
|
return u
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *NotifySubscriptionUpsert) SetEnabled(v bool) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldEnabled, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateEnabled() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldEnabled)
|
|
return u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *NotifySubscriptionUpsert) SetCreatedAt(v time.Time) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldCreatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateCreatedAt() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldCreatedAt)
|
|
return u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *NotifySubscriptionUpsert) SetUpdatedAt(v time.Time) *NotifySubscriptionUpsert {
|
|
u.Set(notifysubscription.FieldUpdatedAt, v)
|
|
return u
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsert) UpdateUpdatedAt() *NotifySubscriptionUpsert {
|
|
u.SetExcluded(notifysubscription.FieldUpdatedAt)
|
|
return u
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(notifysubscription.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *NotifySubscriptionUpsertOne) UpdateNewValues() *NotifySubscriptionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
|
if _, exists := u.create.mutation.ID(); exists {
|
|
s.SetIgnore(notifysubscription.FieldID)
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *NotifySubscriptionUpsertOne) Ignore() *NotifySubscriptionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *NotifySubscriptionUpsertOne) DoNothing() *NotifySubscriptionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the NotifySubscriptionCreate.OnConflict
|
|
// documentation for more info.
|
|
func (u *NotifySubscriptionUpsertOne) Update(set func(*NotifySubscriptionUpsert)) *NotifySubscriptionUpsertOne {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&NotifySubscriptionUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetDeletedAt(v time.Time) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateDeletedAt() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *NotifySubscriptionUpsertOne) ClearDeletedAt() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetChannelID sets the "channel_id" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetChannelID(v uuid.UUID) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetChannelID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateChannelID sets the "channel_id" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateChannelID() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateChannelID()
|
|
})
|
|
}
|
|
|
|
// SetScope sets the "scope" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetScope(v string) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetScope(v)
|
|
})
|
|
}
|
|
|
|
// UpdateScope sets the "scope" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateScope() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateScope()
|
|
})
|
|
}
|
|
|
|
// SetEventTypes sets the "event_types" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetEventTypes(v []consts.NotifyEventType) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetEventTypes(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEventTypes sets the "event_types" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateEventTypes() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateEventTypes()
|
|
})
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetEnabled(v bool) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateEnabled() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateEnabled()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetCreatedAt(v time.Time) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateCreatedAt() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *NotifySubscriptionUpsertOne) SetUpdatedAt(v time.Time) *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertOne) UpdateUpdatedAt() *NotifySubscriptionUpsertOne {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *NotifySubscriptionUpsertOne) Exec(ctx context.Context) error {
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for NotifySubscriptionCreate.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *NotifySubscriptionUpsertOne) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// Exec executes the UPSERT query and returns the inserted/updated ID.
|
|
func (u *NotifySubscriptionUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) {
|
|
if u.create.driver.Dialect() == dialect.MySQL {
|
|
// In case of "ON CONFLICT", there is no way to get back non-numeric ID
|
|
// fields from the database since MySQL does not support the RETURNING clause.
|
|
return id, errors.New("db: NotifySubscriptionUpsertOne.ID is not supported by MySQL driver. Use NotifySubscriptionUpsertOne.Exec instead")
|
|
}
|
|
node, err := u.create.Save(ctx)
|
|
if err != nil {
|
|
return id, err
|
|
}
|
|
return node.ID, nil
|
|
}
|
|
|
|
// IDX is like ID, but panics if an error occurs.
|
|
func (u *NotifySubscriptionUpsertOne) IDX(ctx context.Context) uuid.UUID {
|
|
id, err := u.ID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// NotifySubscriptionCreateBulk is the builder for creating many NotifySubscription entities in bulk.
|
|
type NotifySubscriptionCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*NotifySubscriptionCreate
|
|
conflict []sql.ConflictOption
|
|
}
|
|
|
|
// Save creates the NotifySubscription entities in the database.
|
|
func (_c *NotifySubscriptionCreateBulk) Save(ctx context.Context) ([]*NotifySubscription, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*NotifySubscription, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*NotifySubscriptionMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
spec.OnConflict = _c.conflict
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *NotifySubscriptionCreateBulk) SaveX(ctx context.Context) []*NotifySubscription {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *NotifySubscriptionCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *NotifySubscriptionCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
|
|
// of the `INSERT` statement. For example:
|
|
//
|
|
// client.NotifySubscription.CreateBulk(builders...).
|
|
// OnConflict(
|
|
// // Update the row with the new values
|
|
// // the was proposed for insertion.
|
|
// sql.ResolveWithNewValues(),
|
|
// ).
|
|
// // Override some of the fields with custom
|
|
// // update values.
|
|
// Update(func(u *ent.NotifySubscriptionUpsert) {
|
|
// SetDeletedAt(v+v).
|
|
// }).
|
|
// Exec(ctx)
|
|
func (_c *NotifySubscriptionCreateBulk) OnConflict(opts ...sql.ConflictOption) *NotifySubscriptionUpsertBulk {
|
|
_c.conflict = opts
|
|
return &NotifySubscriptionUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// OnConflictColumns calls `OnConflict` and configures the columns
|
|
// as conflict target. Using this option is equivalent to using:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// OnConflict(sql.ConflictColumns(columns...)).
|
|
// Exec(ctx)
|
|
func (_c *NotifySubscriptionCreateBulk) OnConflictColumns(columns ...string) *NotifySubscriptionUpsertBulk {
|
|
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
|
|
return &NotifySubscriptionUpsertBulk{
|
|
create: _c,
|
|
}
|
|
}
|
|
|
|
// NotifySubscriptionUpsertBulk is the builder for "upsert"-ing
|
|
// a bulk of NotifySubscription nodes.
|
|
type NotifySubscriptionUpsertBulk struct {
|
|
create *NotifySubscriptionCreateBulk
|
|
}
|
|
|
|
// UpdateNewValues updates the mutable fields using the new values that
|
|
// were set on create. Using this option is equivalent to using:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// OnConflict(
|
|
// sql.ResolveWithNewValues(),
|
|
// sql.ResolveWith(func(u *sql.UpdateSet) {
|
|
// u.SetIgnore(notifysubscription.FieldID)
|
|
// }),
|
|
// ).
|
|
// Exec(ctx)
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateNewValues() *NotifySubscriptionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
|
|
for _, b := range u.create.builders {
|
|
if _, exists := b.mutation.ID(); exists {
|
|
s.SetIgnore(notifysubscription.FieldID)
|
|
}
|
|
}
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// Ignore sets each column to itself in case of conflict.
|
|
// Using this option is equivalent to using:
|
|
//
|
|
// client.NotifySubscription.Create().
|
|
// OnConflict(sql.ResolveWithIgnore()).
|
|
// Exec(ctx)
|
|
func (u *NotifySubscriptionUpsertBulk) Ignore() *NotifySubscriptionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
|
|
return u
|
|
}
|
|
|
|
// DoNothing configures the conflict_action to `DO NOTHING`.
|
|
// Supported only by SQLite and PostgreSQL.
|
|
func (u *NotifySubscriptionUpsertBulk) DoNothing() *NotifySubscriptionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.DoNothing())
|
|
return u
|
|
}
|
|
|
|
// Update allows overriding fields `UPDATE` values. See the NotifySubscriptionCreateBulk.OnConflict
|
|
// documentation for more info.
|
|
func (u *NotifySubscriptionUpsertBulk) Update(set func(*NotifySubscriptionUpsert)) *NotifySubscriptionUpsertBulk {
|
|
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
|
|
set(&NotifySubscriptionUpsert{UpdateSet: update})
|
|
}))
|
|
return u
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetDeletedAt(v time.Time) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetDeletedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateDeletedAt() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateDeletedAt()
|
|
})
|
|
}
|
|
|
|
// ClearDeletedAt clears the value of the "deleted_at" field.
|
|
func (u *NotifySubscriptionUpsertBulk) ClearDeletedAt() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.ClearDeletedAt()
|
|
})
|
|
}
|
|
|
|
// SetChannelID sets the "channel_id" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetChannelID(v uuid.UUID) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetChannelID(v)
|
|
})
|
|
}
|
|
|
|
// UpdateChannelID sets the "channel_id" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateChannelID() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateChannelID()
|
|
})
|
|
}
|
|
|
|
// SetScope sets the "scope" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetScope(v string) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetScope(v)
|
|
})
|
|
}
|
|
|
|
// UpdateScope sets the "scope" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateScope() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateScope()
|
|
})
|
|
}
|
|
|
|
// SetEventTypes sets the "event_types" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetEventTypes(v []consts.NotifyEventType) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetEventTypes(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEventTypes sets the "event_types" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateEventTypes() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateEventTypes()
|
|
})
|
|
}
|
|
|
|
// SetEnabled sets the "enabled" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetEnabled(v bool) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetEnabled(v)
|
|
})
|
|
}
|
|
|
|
// UpdateEnabled sets the "enabled" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateEnabled() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateEnabled()
|
|
})
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetCreatedAt(v time.Time) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetCreatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateCreatedAt() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateCreatedAt()
|
|
})
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (u *NotifySubscriptionUpsertBulk) SetUpdatedAt(v time.Time) *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.SetUpdatedAt(v)
|
|
})
|
|
}
|
|
|
|
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
|
|
func (u *NotifySubscriptionUpsertBulk) UpdateUpdatedAt() *NotifySubscriptionUpsertBulk {
|
|
return u.Update(func(s *NotifySubscriptionUpsert) {
|
|
s.UpdateUpdatedAt()
|
|
})
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (u *NotifySubscriptionUpsertBulk) Exec(ctx context.Context) error {
|
|
if u.create.err != nil {
|
|
return u.create.err
|
|
}
|
|
for i, b := range u.create.builders {
|
|
if len(b.conflict) != 0 {
|
|
return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the NotifySubscriptionCreateBulk instead", i)
|
|
}
|
|
}
|
|
if len(u.create.conflict) == 0 {
|
|
return errors.New("db: missing options for NotifySubscriptionCreateBulk.OnConflict")
|
|
}
|
|
return u.create.Exec(ctx)
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (u *NotifySubscriptionUpsertBulk) ExecX(ctx context.Context) {
|
|
if err := u.create.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|