1 Star 0 Fork 0

DaMeng/Ent

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
comment_create.go 24.29 KB
一键复制 编辑 原始数据 按行查看 历史
DaMeng 提交于 2024-10-24 16:04 +08:00 . :tada:fork ent
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"gitee.com/damengde/ent/dialect/sql"
"gitee.com/damengde/ent/dialect/sql/sqlgraph"
"gitee.com/damengde/ent/entc/integration/ent/comment"
schemadir "gitee.com/damengde/ent/entc/integration/ent/schema/dir"
"gitee.com/damengde/ent/schema/field"
)
// CommentCreate is the builder for creating a Comment entity.
type CommentCreate struct {
config
mutation *CommentMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetUniqueInt sets the "unique_int" field.
func (cc *CommentCreate) SetUniqueInt(i int) *CommentCreate {
cc.mutation.SetUniqueInt(i)
return cc
}
// SetUniqueFloat sets the "unique_float" field.
func (cc *CommentCreate) SetUniqueFloat(f float64) *CommentCreate {
cc.mutation.SetUniqueFloat(f)
return cc
}
// SetNillableInt sets the "nillable_int" field.
func (cc *CommentCreate) SetNillableInt(i int) *CommentCreate {
cc.mutation.SetNillableInt(i)
return cc
}
// SetNillableNillableInt sets the "nillable_int" field if the given value is not nil.
func (cc *CommentCreate) SetNillableNillableInt(i *int) *CommentCreate {
if i != nil {
cc.SetNillableInt(*i)
}
return cc
}
// SetTable sets the "table" field.
func (cc *CommentCreate) SetTable(s string) *CommentCreate {
cc.mutation.SetTable(s)
return cc
}
// SetNillableTable sets the "table" field if the given value is not nil.
func (cc *CommentCreate) SetNillableTable(s *string) *CommentCreate {
if s != nil {
cc.SetTable(*s)
}
return cc
}
// SetDir sets the "dir" field.
func (cc *CommentCreate) SetDir(s schemadir.Dir) *CommentCreate {
cc.mutation.SetDir(s)
return cc
}
// SetNillableDir sets the "dir" field if the given value is not nil.
func (cc *CommentCreate) SetNillableDir(s *schemadir.Dir) *CommentCreate {
if s != nil {
cc.SetDir(*s)
}
return cc
}
// SetClient sets the "client" field.
func (cc *CommentCreate) SetClient(s string) *CommentCreate {
cc.mutation.SetClient(s)
return cc
}
// SetNillableClient sets the "client" field if the given value is not nil.
func (cc *CommentCreate) SetNillableClient(s *string) *CommentCreate {
if s != nil {
cc.SetClient(*s)
}
return cc
}
// Mutation returns the CommentMutation object of the builder.
func (cc *CommentCreate) Mutation() *CommentMutation {
return cc.mutation
}
// Save creates the Comment in the database.
func (cc *CommentCreate) Save(ctx context.Context) (*Comment, error) {
return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (cc *CommentCreate) SaveX(ctx context.Context) *Comment {
v, err := cc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (cc *CommentCreate) Exec(ctx context.Context) error {
_, err := cc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (cc *CommentCreate) ExecX(ctx context.Context) {
if err := cc.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (cc *CommentCreate) check() error {
if _, ok := cc.mutation.UniqueInt(); !ok {
return &ValidationError{Name: "unique_int", err: errors.New(`ent: missing required field "Comment.unique_int"`)}
}
if _, ok := cc.mutation.UniqueFloat(); !ok {
return &ValidationError{Name: "unique_float", err: errors.New(`ent: missing required field "Comment.unique_float"`)}
}
return nil
}
func (cc *CommentCreate) sqlSave(ctx context.Context) (*Comment, error) {
if err := cc.check(); err != nil {
return nil, err
}
_node, _spec := cc.createSpec()
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
cc.mutation.id = &_node.ID
cc.mutation.done = true
return _node, nil
}
func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) {
var (
_node = &Comment{config: cc.config}
_spec = sqlgraph.NewCreateSpec(comment.Table, sqlgraph.NewFieldSpec(comment.FieldID, field.TypeInt))
)
_spec.OnConflict = cc.conflict
if value, ok := cc.mutation.UniqueInt(); ok {
_spec.SetField(comment.FieldUniqueInt, field.TypeInt, value)
_node.UniqueInt = value
}
if value, ok := cc.mutation.UniqueFloat(); ok {
_spec.SetField(comment.FieldUniqueFloat, field.TypeFloat64, value)
_node.UniqueFloat = value
}
if value, ok := cc.mutation.NillableInt(); ok {
_spec.SetField(comment.FieldNillableInt, field.TypeInt, value)
_node.NillableInt = &value
}
if value, ok := cc.mutation.Table(); ok {
_spec.SetField(comment.FieldTable, field.TypeString, value)
_node.Table = value
}
if value, ok := cc.mutation.Dir(); ok {
_spec.SetField(comment.FieldDir, field.TypeJSON, value)
_node.Dir = value
}
if value, ok := cc.mutation.GetClient(); ok {
_spec.SetField(comment.FieldClient, field.TypeString, value)
_node.Client = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Comment.Create().
// SetUniqueInt(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.CommentUpsert) {
// SetUniqueInt(v+v).
// }).
// Exec(ctx)
func (cc *CommentCreate) OnConflict(opts ...sql.ConflictOption) *CommentUpsertOne {
cc.conflict = opts
return &CommentUpsertOne{
create: cc,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Comment.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (cc *CommentCreate) OnConflictColumns(columns ...string) *CommentUpsertOne {
cc.conflict = append(cc.conflict, sql.ConflictColumns(columns...))
return &CommentUpsertOne{
create: cc,
}
}
type (
// CommentUpsertOne is the builder for "upsert"-ing
// one Comment node.
CommentUpsertOne struct {
create *CommentCreate
}
// CommentUpsert is the "OnConflict" setter.
CommentUpsert struct {
*sql.UpdateSet
}
)
// SetUniqueInt sets the "unique_int" field.
func (u *CommentUpsert) SetUniqueInt(v int) *CommentUpsert {
u.Set(comment.FieldUniqueInt, v)
return u
}
// UpdateUniqueInt sets the "unique_int" field to the value that was provided on create.
func (u *CommentUpsert) UpdateUniqueInt() *CommentUpsert {
u.SetExcluded(comment.FieldUniqueInt)
return u
}
// AddUniqueInt adds v to the "unique_int" field.
func (u *CommentUpsert) AddUniqueInt(v int) *CommentUpsert {
u.Add(comment.FieldUniqueInt, v)
return u
}
// SetUniqueFloat sets the "unique_float" field.
func (u *CommentUpsert) SetUniqueFloat(v float64) *CommentUpsert {
u.Set(comment.FieldUniqueFloat, v)
return u
}
// UpdateUniqueFloat sets the "unique_float" field to the value that was provided on create.
func (u *CommentUpsert) UpdateUniqueFloat() *CommentUpsert {
u.SetExcluded(comment.FieldUniqueFloat)
return u
}
// AddUniqueFloat adds v to the "unique_float" field.
func (u *CommentUpsert) AddUniqueFloat(v float64) *CommentUpsert {
u.Add(comment.FieldUniqueFloat, v)
return u
}
// SetNillableInt sets the "nillable_int" field.
func (u *CommentUpsert) SetNillableInt(v int) *CommentUpsert {
u.Set(comment.FieldNillableInt, v)
return u
}
// UpdateNillableInt sets the "nillable_int" field to the value that was provided on create.
func (u *CommentUpsert) UpdateNillableInt() *CommentUpsert {
u.SetExcluded(comment.FieldNillableInt)
return u
}
// AddNillableInt adds v to the "nillable_int" field.
func (u *CommentUpsert) AddNillableInt(v int) *CommentUpsert {
u.Add(comment.FieldNillableInt, v)
return u
}
// ClearNillableInt clears the value of the "nillable_int" field.
func (u *CommentUpsert) ClearNillableInt() *CommentUpsert {
u.SetNull(comment.FieldNillableInt)
return u
}
// SetTable sets the "table" field.
func (u *CommentUpsert) SetTable(v string) *CommentUpsert {
u.Set(comment.FieldTable, v)
return u
}
// UpdateTable sets the "table" field to the value that was provided on create.
func (u *CommentUpsert) UpdateTable() *CommentUpsert {
u.SetExcluded(comment.FieldTable)
return u
}
// ClearTable clears the value of the "table" field.
func (u *CommentUpsert) ClearTable() *CommentUpsert {
u.SetNull(comment.FieldTable)
return u
}
// SetDir sets the "dir" field.
func (u *CommentUpsert) SetDir(v schemadir.Dir) *CommentUpsert {
u.Set(comment.FieldDir, v)
return u
}
// UpdateDir sets the "dir" field to the value that was provided on create.
func (u *CommentUpsert) UpdateDir() *CommentUpsert {
u.SetExcluded(comment.FieldDir)
return u
}
// ClearDir clears the value of the "dir" field.
func (u *CommentUpsert) ClearDir() *CommentUpsert {
u.SetNull(comment.FieldDir)
return u
}
// SetClient sets the "client" field.
func (u *CommentUpsert) SetClient(v string) *CommentUpsert {
u.Set(comment.FieldClient, v)
return u
}
// UpdateClient sets the "client" field to the value that was provided on create.
func (u *CommentUpsert) UpdateClient() *CommentUpsert {
u.SetExcluded(comment.FieldClient)
return u
}
// ClearClient clears the value of the "client" field.
func (u *CommentUpsert) ClearClient() *CommentUpsert {
u.SetNull(comment.FieldClient)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.Comment.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *CommentUpsertOne) UpdateNewValues() *CommentUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Comment.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *CommentUpsertOne) Ignore() *CommentUpsertOne {
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 *CommentUpsertOne) DoNothing() *CommentUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the CommentCreate.OnConflict
// documentation for more info.
func (u *CommentUpsertOne) Update(set func(*CommentUpsert)) *CommentUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&CommentUpsert{UpdateSet: update})
}))
return u
}
// SetUniqueInt sets the "unique_int" field.
func (u *CommentUpsertOne) SetUniqueInt(v int) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.SetUniqueInt(v)
})
}
// AddUniqueInt adds v to the "unique_int" field.
func (u *CommentUpsertOne) AddUniqueInt(v int) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.AddUniqueInt(v)
})
}
// UpdateUniqueInt sets the "unique_int" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateUniqueInt() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.UpdateUniqueInt()
})
}
// SetUniqueFloat sets the "unique_float" field.
func (u *CommentUpsertOne) SetUniqueFloat(v float64) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.SetUniqueFloat(v)
})
}
// AddUniqueFloat adds v to the "unique_float" field.
func (u *CommentUpsertOne) AddUniqueFloat(v float64) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.AddUniqueFloat(v)
})
}
// UpdateUniqueFloat sets the "unique_float" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateUniqueFloat() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.UpdateUniqueFloat()
})
}
// SetNillableInt sets the "nillable_int" field.
func (u *CommentUpsertOne) SetNillableInt(v int) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.SetNillableInt(v)
})
}
// AddNillableInt adds v to the "nillable_int" field.
func (u *CommentUpsertOne) AddNillableInt(v int) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.AddNillableInt(v)
})
}
// UpdateNillableInt sets the "nillable_int" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateNillableInt() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.UpdateNillableInt()
})
}
// ClearNillableInt clears the value of the "nillable_int" field.
func (u *CommentUpsertOne) ClearNillableInt() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.ClearNillableInt()
})
}
// SetTable sets the "table" field.
func (u *CommentUpsertOne) SetTable(v string) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.SetTable(v)
})
}
// UpdateTable sets the "table" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateTable() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.UpdateTable()
})
}
// ClearTable clears the value of the "table" field.
func (u *CommentUpsertOne) ClearTable() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.ClearTable()
})
}
// SetDir sets the "dir" field.
func (u *CommentUpsertOne) SetDir(v schemadir.Dir) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.SetDir(v)
})
}
// UpdateDir sets the "dir" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateDir() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.UpdateDir()
})
}
// ClearDir clears the value of the "dir" field.
func (u *CommentUpsertOne) ClearDir() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.ClearDir()
})
}
// SetClient sets the "client" field.
func (u *CommentUpsertOne) SetClient(v string) *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.SetClient(v)
})
}
// UpdateClient sets the "client" field to the value that was provided on create.
func (u *CommentUpsertOne) UpdateClient() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.UpdateClient()
})
}
// ClearClient clears the value of the "client" field.
func (u *CommentUpsertOne) ClearClient() *CommentUpsertOne {
return u.Update(func(s *CommentUpsert) {
s.ClearClient()
})
}
// Exec executes the query.
func (u *CommentUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for CommentCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *CommentUpsertOne) 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 *CommentUpsertOne) ID(ctx context.Context) (id int, 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 *CommentUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// CommentCreateBulk is the builder for creating many Comment entities in bulk.
type CommentCreateBulk struct {
config
err error
builders []*CommentCreate
conflict []sql.ConflictOption
}
// Save creates the Comment entities in the database.
func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) {
if ccb.err != nil {
return nil, ccb.err
}
specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
nodes := make([]*Comment, len(ccb.builders))
mutators := make([]Mutator, len(ccb.builders))
for i := range ccb.builders {
func(i int, root context.Context) {
builder := ccb.builders[i]
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*CommentMutation)
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, ccb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = ccb.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, ccb.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 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(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, ccb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (ccb *CommentCreateBulk) SaveX(ctx context.Context) []*Comment {
v, err := ccb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (ccb *CommentCreateBulk) Exec(ctx context.Context) error {
_, err := ccb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (ccb *CommentCreateBulk) ExecX(ctx context.Context) {
if err := ccb.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Comment.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.CommentUpsert) {
// SetUniqueInt(v+v).
// }).
// Exec(ctx)
func (ccb *CommentCreateBulk) OnConflict(opts ...sql.ConflictOption) *CommentUpsertBulk {
ccb.conflict = opts
return &CommentUpsertBulk{
create: ccb,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Comment.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (ccb *CommentCreateBulk) OnConflictColumns(columns ...string) *CommentUpsertBulk {
ccb.conflict = append(ccb.conflict, sql.ConflictColumns(columns...))
return &CommentUpsertBulk{
create: ccb,
}
}
// CommentUpsertBulk is the builder for "upsert"-ing
// a bulk of Comment nodes.
type CommentUpsertBulk struct {
create *CommentCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Comment.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *CommentUpsertBulk) UpdateNewValues() *CommentUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Comment.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *CommentUpsertBulk) Ignore() *CommentUpsertBulk {
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 *CommentUpsertBulk) DoNothing() *CommentUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the CommentCreateBulk.OnConflict
// documentation for more info.
func (u *CommentUpsertBulk) Update(set func(*CommentUpsert)) *CommentUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&CommentUpsert{UpdateSet: update})
}))
return u
}
// SetUniqueInt sets the "unique_int" field.
func (u *CommentUpsertBulk) SetUniqueInt(v int) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.SetUniqueInt(v)
})
}
// AddUniqueInt adds v to the "unique_int" field.
func (u *CommentUpsertBulk) AddUniqueInt(v int) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.AddUniqueInt(v)
})
}
// UpdateUniqueInt sets the "unique_int" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateUniqueInt() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.UpdateUniqueInt()
})
}
// SetUniqueFloat sets the "unique_float" field.
func (u *CommentUpsertBulk) SetUniqueFloat(v float64) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.SetUniqueFloat(v)
})
}
// AddUniqueFloat adds v to the "unique_float" field.
func (u *CommentUpsertBulk) AddUniqueFloat(v float64) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.AddUniqueFloat(v)
})
}
// UpdateUniqueFloat sets the "unique_float" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateUniqueFloat() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.UpdateUniqueFloat()
})
}
// SetNillableInt sets the "nillable_int" field.
func (u *CommentUpsertBulk) SetNillableInt(v int) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.SetNillableInt(v)
})
}
// AddNillableInt adds v to the "nillable_int" field.
func (u *CommentUpsertBulk) AddNillableInt(v int) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.AddNillableInt(v)
})
}
// UpdateNillableInt sets the "nillable_int" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateNillableInt() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.UpdateNillableInt()
})
}
// ClearNillableInt clears the value of the "nillable_int" field.
func (u *CommentUpsertBulk) ClearNillableInt() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.ClearNillableInt()
})
}
// SetTable sets the "table" field.
func (u *CommentUpsertBulk) SetTable(v string) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.SetTable(v)
})
}
// UpdateTable sets the "table" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateTable() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.UpdateTable()
})
}
// ClearTable clears the value of the "table" field.
func (u *CommentUpsertBulk) ClearTable() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.ClearTable()
})
}
// SetDir sets the "dir" field.
func (u *CommentUpsertBulk) SetDir(v schemadir.Dir) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.SetDir(v)
})
}
// UpdateDir sets the "dir" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateDir() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.UpdateDir()
})
}
// ClearDir clears the value of the "dir" field.
func (u *CommentUpsertBulk) ClearDir() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.ClearDir()
})
}
// SetClient sets the "client" field.
func (u *CommentUpsertBulk) SetClient(v string) *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.SetClient(v)
})
}
// UpdateClient sets the "client" field to the value that was provided on create.
func (u *CommentUpsertBulk) UpdateClient() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.UpdateClient()
})
}
// ClearClient clears the value of the "client" field.
func (u *CommentUpsertBulk) ClearClient() *CommentUpsertBulk {
return u.Update(func(s *CommentUpsert) {
s.ClearClient()
})
}
// Exec executes the query.
func (u *CommentUpsertBulk) 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("ent: OnConflict was set for builder %d. Set it on the CommentCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for CommentCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *CommentUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/damengde/ent.git
git@gitee.com:damengde/ent.git
damengde
ent
Ent
90870c5ba095

搜索帮助