You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

924 lines
27 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionary"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/dictionarydetail"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
)
// DictionaryCreate is the builder for creating a Dictionary entity.
type DictionaryCreate struct {
config
mutation *DictionaryMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (dc *DictionaryCreate) SetCreatedAt(t time.Time) *DictionaryCreate {
dc.mutation.SetCreatedAt(t)
return dc
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (dc *DictionaryCreate) SetNillableCreatedAt(t *time.Time) *DictionaryCreate {
if t != nil {
dc.SetCreatedAt(*t)
}
return dc
}
// SetUpdatedAt sets the "updated_at" field.
func (dc *DictionaryCreate) SetUpdatedAt(t time.Time) *DictionaryCreate {
dc.mutation.SetUpdatedAt(t)
return dc
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (dc *DictionaryCreate) SetNillableUpdatedAt(t *time.Time) *DictionaryCreate {
if t != nil {
dc.SetUpdatedAt(*t)
}
return dc
}
// SetStatus sets the "status" field.
func (dc *DictionaryCreate) SetStatus(t types.Status) *DictionaryCreate {
dc.mutation.SetStatus(t)
return dc
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (dc *DictionaryCreate) SetNillableStatus(t *types.Status) *DictionaryCreate {
if t != nil {
dc.SetStatus(*t)
}
return dc
}
// SetVersion sets the "version" field.
func (dc *DictionaryCreate) SetVersion(i int64) *DictionaryCreate {
dc.mutation.SetVersion(i)
return dc
}
// SetNillableVersion sets the "version" field if the given value is not nil.
func (dc *DictionaryCreate) SetNillableVersion(i *int64) *DictionaryCreate {
if i != nil {
dc.SetVersion(*i)
}
return dc
}
// SetTitle sets the "title" field.
func (dc *DictionaryCreate) SetTitle(s string) *DictionaryCreate {
dc.mutation.SetTitle(s)
return dc
}
// SetName sets the "name" field.
func (dc *DictionaryCreate) SetName(s string) *DictionaryCreate {
dc.mutation.SetName(s)
return dc
}
// SetDescription sets the "description" field.
func (dc *DictionaryCreate) SetDescription(s string) *DictionaryCreate {
dc.mutation.SetDescription(s)
return dc
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (dc *DictionaryCreate) SetNillableDescription(s *string) *DictionaryCreate {
if s != nil {
dc.SetDescription(*s)
}
return dc
}
// SetID sets the "id" field.
func (dc *DictionaryCreate) SetID(i int64) *DictionaryCreate {
dc.mutation.SetID(i)
return dc
}
// SetNillableID sets the "id" field if the given value is not nil.
func (dc *DictionaryCreate) SetNillableID(i *int64) *DictionaryCreate {
if i != nil {
dc.SetID(*i)
}
return dc
}
// AddDetailIDs adds the "details" edge to the DictionaryDetail entity by IDs.
func (dc *DictionaryCreate) AddDetailIDs(ids ...int64) *DictionaryCreate {
dc.mutation.AddDetailIDs(ids...)
return dc
}
// AddDetails adds the "details" edges to the DictionaryDetail entity.
func (dc *DictionaryCreate) AddDetails(d ...*DictionaryDetail) *DictionaryCreate {
ids := make([]int64, len(d))
for i := range d {
ids[i] = d[i].ID
}
return dc.AddDetailIDs(ids...)
}
// Mutation returns the DictionaryMutation object of the builder.
func (dc *DictionaryCreate) Mutation() *DictionaryMutation {
return dc.mutation
}
// Save creates the Dictionary in the database.
func (dc *DictionaryCreate) Save(ctx context.Context) (*Dictionary, error) {
if err := dc.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, dc.sqlSave, dc.mutation, dc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (dc *DictionaryCreate) SaveX(ctx context.Context) *Dictionary {
v, err := dc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dc *DictionaryCreate) Exec(ctx context.Context) error {
_, err := dc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dc *DictionaryCreate) ExecX(ctx context.Context) {
if err := dc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (dc *DictionaryCreate) defaults() error {
if _, ok := dc.mutation.CreatedAt(); !ok {
if dictionary.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized dictionary.DefaultCreatedAt (forgotten import ent/runtime?)")
}
v := dictionary.DefaultCreatedAt()
dc.mutation.SetCreatedAt(v)
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
if dictionary.DefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized dictionary.DefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := dictionary.DefaultUpdatedAt()
dc.mutation.SetUpdatedAt(v)
}
if _, ok := dc.mutation.Status(); !ok {
v := dictionary.DefaultStatus
dc.mutation.SetStatus(v)
}
if _, ok := dc.mutation.Version(); !ok {
v := dictionary.DefaultVersion
dc.mutation.SetVersion(v)
}
if _, ok := dc.mutation.ID(); !ok {
if dictionary.DefaultID == nil {
return fmt.Errorf("ent: uninitialized dictionary.DefaultID (forgotten import ent/runtime?)")
}
v := dictionary.DefaultID()
dc.mutation.SetID(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (dc *DictionaryCreate) check() error {
if _, ok := dc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Dictionary.created_at"`)}
}
if _, ok := dc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Dictionary.updated_at"`)}
}
if _, ok := dc.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Dictionary.status"`)}
}
if v, ok := dc.mutation.Status(); ok {
if err := dictionary.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Dictionary.status": %w`, err)}
}
}
if _, ok := dc.mutation.Version(); !ok {
return &ValidationError{Name: "version", err: errors.New(`ent: missing required field "Dictionary.version"`)}
}
if _, ok := dc.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Dictionary.title"`)}
}
if _, ok := dc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Dictionary.name"`)}
}
return nil
}
func (dc *DictionaryCreate) sqlSave(ctx context.Context) (*Dictionary, error) {
if err := dc.check(); err != nil {
return nil, err
}
_node, _spec := dc.createSpec()
if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
dc.mutation.id = &_node.ID
dc.mutation.done = true
return _node, nil
}
func (dc *DictionaryCreate) createSpec() (*Dictionary, *sqlgraph.CreateSpec) {
var (
_node = &Dictionary{config: dc.config}
_spec = sqlgraph.NewCreateSpec(dictionary.Table, sqlgraph.NewFieldSpec(dictionary.FieldID, field.TypeInt64))
)
_spec.OnConflict = dc.conflict
if id, ok := dc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := dc.mutation.CreatedAt(); ok {
_spec.SetField(dictionary.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := dc.mutation.UpdatedAt(); ok {
_spec.SetField(dictionary.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := dc.mutation.Status(); ok {
_spec.SetField(dictionary.FieldStatus, field.TypeEnum, value)
_node.Status = value
}
if value, ok := dc.mutation.Version(); ok {
_spec.SetField(dictionary.FieldVersion, field.TypeInt64, value)
_node.Version = value
}
if value, ok := dc.mutation.Title(); ok {
_spec.SetField(dictionary.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := dc.mutation.Name(); ok {
_spec.SetField(dictionary.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := dc.mutation.Description(); ok {
_spec.SetField(dictionary.FieldDescription, field.TypeString, value)
_node.Description = value
}
if nodes := dc.mutation.DetailsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: dictionary.DetailsTable,
Columns: []string{dictionary.DetailsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(dictionarydetail.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_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.Dictionary.Create().
// SetCreatedAt(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.DictionaryUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dc *DictionaryCreate) OnConflict(opts ...sql.ConflictOption) *DictionaryUpsertOne {
dc.conflict = opts
return &DictionaryUpsertOne{
create: dc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Dictionary.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dc *DictionaryCreate) OnConflictColumns(columns ...string) *DictionaryUpsertOne {
dc.conflict = append(dc.conflict, sql.ConflictColumns(columns...))
return &DictionaryUpsertOne{
create: dc,
}
}
type (
// DictionaryUpsertOne is the builder for "upsert"-ing
// one Dictionary node.
DictionaryUpsertOne struct {
create *DictionaryCreate
}
// DictionaryUpsert is the "OnConflict" setter.
DictionaryUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *DictionaryUpsert) SetUpdatedAt(v time.Time) *DictionaryUpsert {
u.Set(dictionary.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DictionaryUpsert) UpdateUpdatedAt() *DictionaryUpsert {
u.SetExcluded(dictionary.FieldUpdatedAt)
return u
}
// SetStatus sets the "status" field.
func (u *DictionaryUpsert) SetStatus(v types.Status) *DictionaryUpsert {
u.Set(dictionary.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DictionaryUpsert) UpdateStatus() *DictionaryUpsert {
u.SetExcluded(dictionary.FieldStatus)
return u
}
// SetVersion sets the "version" field.
func (u *DictionaryUpsert) SetVersion(v int64) *DictionaryUpsert {
u.Set(dictionary.FieldVersion, v)
return u
}
// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *DictionaryUpsert) UpdateVersion() *DictionaryUpsert {
u.SetExcluded(dictionary.FieldVersion)
return u
}
// AddVersion adds v to the "version" field.
func (u *DictionaryUpsert) AddVersion(v int64) *DictionaryUpsert {
u.Add(dictionary.FieldVersion, v)
return u
}
// SetTitle sets the "title" field.
func (u *DictionaryUpsert) SetTitle(v string) *DictionaryUpsert {
u.Set(dictionary.FieldTitle, v)
return u
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *DictionaryUpsert) UpdateTitle() *DictionaryUpsert {
u.SetExcluded(dictionary.FieldTitle)
return u
}
// SetName sets the "name" field.
func (u *DictionaryUpsert) SetName(v string) *DictionaryUpsert {
u.Set(dictionary.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *DictionaryUpsert) UpdateName() *DictionaryUpsert {
u.SetExcluded(dictionary.FieldName)
return u
}
// SetDescription sets the "description" field.
func (u *DictionaryUpsert) SetDescription(v string) *DictionaryUpsert {
u.Set(dictionary.FieldDescription, v)
return u
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *DictionaryUpsert) UpdateDescription() *DictionaryUpsert {
u.SetExcluded(dictionary.FieldDescription)
return u
}
// ClearDescription clears the value of the "description" field.
func (u *DictionaryUpsert) ClearDescription() *DictionaryUpsert {
u.SetNull(dictionary.FieldDescription)
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.Dictionary.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(dictionary.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DictionaryUpsertOne) UpdateNewValues() *DictionaryUpsertOne {
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(dictionary.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(dictionary.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Dictionary.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DictionaryUpsertOne) Ignore() *DictionaryUpsertOne {
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 *DictionaryUpsertOne) DoNothing() *DictionaryUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DictionaryCreate.OnConflict
// documentation for more info.
func (u *DictionaryUpsertOne) Update(set func(*DictionaryUpsert)) *DictionaryUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DictionaryUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DictionaryUpsertOne) SetUpdatedAt(v time.Time) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DictionaryUpsertOne) UpdateUpdatedAt() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DictionaryUpsertOne) SetStatus(v types.Status) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DictionaryUpsertOne) UpdateStatus() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateStatus()
})
}
// SetVersion sets the "version" field.
func (u *DictionaryUpsertOne) SetVersion(v int64) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.SetVersion(v)
})
}
// AddVersion adds v to the "version" field.
func (u *DictionaryUpsertOne) AddVersion(v int64) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.AddVersion(v)
})
}
// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *DictionaryUpsertOne) UpdateVersion() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateVersion()
})
}
// SetTitle sets the "title" field.
func (u *DictionaryUpsertOne) SetTitle(v string) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *DictionaryUpsertOne) UpdateTitle() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateTitle()
})
}
// SetName sets the "name" field.
func (u *DictionaryUpsertOne) SetName(v string) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *DictionaryUpsertOne) UpdateName() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateName()
})
}
// SetDescription sets the "description" field.
func (u *DictionaryUpsertOne) SetDescription(v string) *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.SetDescription(v)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *DictionaryUpsertOne) UpdateDescription() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateDescription()
})
}
// ClearDescription clears the value of the "description" field.
func (u *DictionaryUpsertOne) ClearDescription() *DictionaryUpsertOne {
return u.Update(func(s *DictionaryUpsert) {
s.ClearDescription()
})
}
// Exec executes the query.
func (u *DictionaryUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DictionaryCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DictionaryUpsertOne) 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 *DictionaryUpsertOne) ID(ctx context.Context) (id int64, err error) {
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 *DictionaryUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// DictionaryCreateBulk is the builder for creating many Dictionary entities in bulk.
type DictionaryCreateBulk struct {
config
builders []*DictionaryCreate
conflict []sql.ConflictOption
}
// Save creates the Dictionary entities in the database.
func (dcb *DictionaryCreateBulk) Save(ctx context.Context) ([]*Dictionary, error) {
specs := make([]*sqlgraph.CreateSpec, len(dcb.builders))
nodes := make([]*Dictionary, len(dcb.builders))
mutators := make([]Mutator, len(dcb.builders))
for i := range dcb.builders {
func(i int, root context.Context) {
builder := dcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*DictionaryMutation)
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, dcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = dcb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, dcb.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
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(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, dcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (dcb *DictionaryCreateBulk) SaveX(ctx context.Context) []*Dictionary {
v, err := dcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (dcb *DictionaryCreateBulk) Exec(ctx context.Context) error {
_, err := dcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (dcb *DictionaryCreateBulk) ExecX(ctx context.Context) {
if err := dcb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Dictionary.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.DictionaryUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (dcb *DictionaryCreateBulk) OnConflict(opts ...sql.ConflictOption) *DictionaryUpsertBulk {
dcb.conflict = opts
return &DictionaryUpsertBulk{
create: dcb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Dictionary.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (dcb *DictionaryCreateBulk) OnConflictColumns(columns ...string) *DictionaryUpsertBulk {
dcb.conflict = append(dcb.conflict, sql.ConflictColumns(columns...))
return &DictionaryUpsertBulk{
create: dcb,
}
}
// DictionaryUpsertBulk is the builder for "upsert"-ing
// a bulk of Dictionary nodes.
type DictionaryUpsertBulk struct {
create *DictionaryCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Dictionary.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(dictionary.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DictionaryUpsertBulk) UpdateNewValues() *DictionaryUpsertBulk {
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(dictionary.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(dictionary.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Dictionary.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DictionaryUpsertBulk) Ignore() *DictionaryUpsertBulk {
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 *DictionaryUpsertBulk) DoNothing() *DictionaryUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DictionaryCreateBulk.OnConflict
// documentation for more info.
func (u *DictionaryUpsertBulk) Update(set func(*DictionaryUpsert)) *DictionaryUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DictionaryUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *DictionaryUpsertBulk) SetUpdatedAt(v time.Time) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *DictionaryUpsertBulk) UpdateUpdatedAt() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateUpdatedAt()
})
}
// SetStatus sets the "status" field.
func (u *DictionaryUpsertBulk) SetStatus(v types.Status) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DictionaryUpsertBulk) UpdateStatus() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateStatus()
})
}
// SetVersion sets the "version" field.
func (u *DictionaryUpsertBulk) SetVersion(v int64) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.SetVersion(v)
})
}
// AddVersion adds v to the "version" field.
func (u *DictionaryUpsertBulk) AddVersion(v int64) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.AddVersion(v)
})
}
// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *DictionaryUpsertBulk) UpdateVersion() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateVersion()
})
}
// SetTitle sets the "title" field.
func (u *DictionaryUpsertBulk) SetTitle(v string) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *DictionaryUpsertBulk) UpdateTitle() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateTitle()
})
}
// SetName sets the "name" field.
func (u *DictionaryUpsertBulk) SetName(v string) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *DictionaryUpsertBulk) UpdateName() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateName()
})
}
// SetDescription sets the "description" field.
func (u *DictionaryUpsertBulk) SetDescription(v string) *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.SetDescription(v)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *DictionaryUpsertBulk) UpdateDescription() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.UpdateDescription()
})
}
// ClearDescription clears the value of the "description" field.
func (u *DictionaryUpsertBulk) ClearDescription() *DictionaryUpsertBulk {
return u.Update(func(s *DictionaryUpsert) {
s.ClearDescription()
})
}
// Exec executes the query.
func (u *DictionaryUpsertBulk) Exec(ctx context.Context) error {
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the DictionaryCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DictionaryCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DictionaryUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}