123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/labellog"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // LabelLogCreate is the builder for creating a LabelLog entity.
- type LabelLogCreate struct {
- config
- mutation *LabelLogMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (llc *LabelLogCreate) SetCreatedAt(t time.Time) *LabelLogCreate {
- llc.mutation.SetCreatedAt(t)
- return llc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (llc *LabelLogCreate) SetNillableCreatedAt(t *time.Time) *LabelLogCreate {
- if t != nil {
- llc.SetCreatedAt(*t)
- }
- return llc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (llc *LabelLogCreate) SetUpdatedAt(t time.Time) *LabelLogCreate {
- llc.mutation.SetUpdatedAt(t)
- return llc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (llc *LabelLogCreate) SetNillableUpdatedAt(t *time.Time) *LabelLogCreate {
- if t != nil {
- llc.SetUpdatedAt(*t)
- }
- return llc
- }
- // SetLabelName sets the "label_name" field.
- func (llc *LabelLogCreate) SetLabelName(s string) *LabelLogCreate {
- llc.mutation.SetLabelName(s)
- return llc
- }
- // SetNillableLabelName sets the "label_name" field if the given value is not nil.
- func (llc *LabelLogCreate) SetNillableLabelName(s *string) *LabelLogCreate {
- if s != nil {
- llc.SetLabelName(*s)
- }
- return llc
- }
- // SetLabelID sets the "label_id" field.
- func (llc *LabelLogCreate) SetLabelID(i int) *LabelLogCreate {
- llc.mutation.SetLabelID(i)
- return llc
- }
- // SetNillableLabelID sets the "label_id" field if the given value is not nil.
- func (llc *LabelLogCreate) SetNillableLabelID(i *int) *LabelLogCreate {
- if i != nil {
- llc.SetLabelID(*i)
- }
- return llc
- }
- // SetWxID sets the "wx_id" field.
- func (llc *LabelLogCreate) SetWxID(s string) *LabelLogCreate {
- llc.mutation.SetWxID(s)
- return llc
- }
- // SetNillableWxID sets the "wx_id" field if the given value is not nil.
- func (llc *LabelLogCreate) SetNillableWxID(s *string) *LabelLogCreate {
- if s != nil {
- llc.SetWxID(*s)
- }
- return llc
- }
- // SetOrganizationID sets the "organization_id" field.
- func (llc *LabelLogCreate) SetOrganizationID(u uint64) *LabelLogCreate {
- llc.mutation.SetOrganizationID(u)
- return llc
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (llc *LabelLogCreate) SetNillableOrganizationID(u *uint64) *LabelLogCreate {
- if u != nil {
- llc.SetOrganizationID(*u)
- }
- return llc
- }
- // SetID sets the "id" field.
- func (llc *LabelLogCreate) SetID(u uint64) *LabelLogCreate {
- llc.mutation.SetID(u)
- return llc
- }
- // Mutation returns the LabelLogMutation object of the builder.
- func (llc *LabelLogCreate) Mutation() *LabelLogMutation {
- return llc.mutation
- }
- // Save creates the LabelLog in the database.
- func (llc *LabelLogCreate) Save(ctx context.Context) (*LabelLog, error) {
- llc.defaults()
- return withHooks(ctx, llc.sqlSave, llc.mutation, llc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (llc *LabelLogCreate) SaveX(ctx context.Context) *LabelLog {
- v, err := llc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (llc *LabelLogCreate) Exec(ctx context.Context) error {
- _, err := llc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (llc *LabelLogCreate) ExecX(ctx context.Context) {
- if err := llc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (llc *LabelLogCreate) defaults() {
- if _, ok := llc.mutation.CreatedAt(); !ok {
- v := labellog.DefaultCreatedAt()
- llc.mutation.SetCreatedAt(v)
- }
- if _, ok := llc.mutation.UpdatedAt(); !ok {
- v := labellog.DefaultUpdatedAt()
- llc.mutation.SetUpdatedAt(v)
- }
- if _, ok := llc.mutation.LabelName(); !ok {
- v := labellog.DefaultLabelName
- llc.mutation.SetLabelName(v)
- }
- if _, ok := llc.mutation.LabelID(); !ok {
- v := labellog.DefaultLabelID
- llc.mutation.SetLabelID(v)
- }
- if _, ok := llc.mutation.WxID(); !ok {
- v := labellog.DefaultWxID
- llc.mutation.SetWxID(v)
- }
- if _, ok := llc.mutation.OrganizationID(); !ok {
- v := labellog.DefaultOrganizationID
- llc.mutation.SetOrganizationID(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (llc *LabelLogCreate) check() error {
- if _, ok := llc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "LabelLog.created_at"`)}
- }
- if _, ok := llc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "LabelLog.updated_at"`)}
- }
- if _, ok := llc.mutation.LabelName(); !ok {
- return &ValidationError{Name: "label_name", err: errors.New(`ent: missing required field "LabelLog.label_name"`)}
- }
- if _, ok := llc.mutation.LabelID(); !ok {
- return &ValidationError{Name: "label_id", err: errors.New(`ent: missing required field "LabelLog.label_id"`)}
- }
- if _, ok := llc.mutation.WxID(); !ok {
- return &ValidationError{Name: "wx_id", err: errors.New(`ent: missing required field "LabelLog.wx_id"`)}
- }
- return nil
- }
- func (llc *LabelLogCreate) sqlSave(ctx context.Context) (*LabelLog, error) {
- if err := llc.check(); err != nil {
- return nil, err
- }
- _node, _spec := llc.createSpec()
- if err := sqlgraph.CreateNode(ctx, llc.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 = uint64(id)
- }
- llc.mutation.id = &_node.ID
- llc.mutation.done = true
- return _node, nil
- }
- func (llc *LabelLogCreate) createSpec() (*LabelLog, *sqlgraph.CreateSpec) {
- var (
- _node = &LabelLog{config: llc.config}
- _spec = sqlgraph.NewCreateSpec(labellog.Table, sqlgraph.NewFieldSpec(labellog.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = llc.conflict
- if id, ok := llc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := llc.mutation.CreatedAt(); ok {
- _spec.SetField(labellog.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := llc.mutation.UpdatedAt(); ok {
- _spec.SetField(labellog.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := llc.mutation.LabelName(); ok {
- _spec.SetField(labellog.FieldLabelName, field.TypeString, value)
- _node.LabelName = value
- }
- if value, ok := llc.mutation.LabelID(); ok {
- _spec.SetField(labellog.FieldLabelID, field.TypeInt, value)
- _node.LabelID = value
- }
- if value, ok := llc.mutation.WxID(); ok {
- _spec.SetField(labellog.FieldWxID, field.TypeString, value)
- _node.WxID = value
- }
- if value, ok := llc.mutation.OrganizationID(); ok {
- _spec.SetField(labellog.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.LabelLog.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.LabelLogUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (llc *LabelLogCreate) OnConflict(opts ...sql.ConflictOption) *LabelLogUpsertOne {
- llc.conflict = opts
- return &LabelLogUpsertOne{
- create: llc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.LabelLog.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (llc *LabelLogCreate) OnConflictColumns(columns ...string) *LabelLogUpsertOne {
- llc.conflict = append(llc.conflict, sql.ConflictColumns(columns...))
- return &LabelLogUpsertOne{
- create: llc,
- }
- }
- type (
- // LabelLogUpsertOne is the builder for "upsert"-ing
- // one LabelLog node.
- LabelLogUpsertOne struct {
- create *LabelLogCreate
- }
- // LabelLogUpsert is the "OnConflict" setter.
- LabelLogUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *LabelLogUpsert) SetUpdatedAt(v time.Time) *LabelLogUpsert {
- u.Set(labellog.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *LabelLogUpsert) UpdateUpdatedAt() *LabelLogUpsert {
- u.SetExcluded(labellog.FieldUpdatedAt)
- return u
- }
- // SetLabelName sets the "label_name" field.
- func (u *LabelLogUpsert) SetLabelName(v string) *LabelLogUpsert {
- u.Set(labellog.FieldLabelName, v)
- return u
- }
- // UpdateLabelName sets the "label_name" field to the value that was provided on create.
- func (u *LabelLogUpsert) UpdateLabelName() *LabelLogUpsert {
- u.SetExcluded(labellog.FieldLabelName)
- return u
- }
- // SetLabelID sets the "label_id" field.
- func (u *LabelLogUpsert) SetLabelID(v int) *LabelLogUpsert {
- u.Set(labellog.FieldLabelID, v)
- return u
- }
- // UpdateLabelID sets the "label_id" field to the value that was provided on create.
- func (u *LabelLogUpsert) UpdateLabelID() *LabelLogUpsert {
- u.SetExcluded(labellog.FieldLabelID)
- return u
- }
- // AddLabelID adds v to the "label_id" field.
- func (u *LabelLogUpsert) AddLabelID(v int) *LabelLogUpsert {
- u.Add(labellog.FieldLabelID, v)
- return u
- }
- // SetWxID sets the "wx_id" field.
- func (u *LabelLogUpsert) SetWxID(v string) *LabelLogUpsert {
- u.Set(labellog.FieldWxID, v)
- return u
- }
- // UpdateWxID sets the "wx_id" field to the value that was provided on create.
- func (u *LabelLogUpsert) UpdateWxID() *LabelLogUpsert {
- u.SetExcluded(labellog.FieldWxID)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *LabelLogUpsert) SetOrganizationID(v uint64) *LabelLogUpsert {
- u.Set(labellog.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *LabelLogUpsert) UpdateOrganizationID() *LabelLogUpsert {
- u.SetExcluded(labellog.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *LabelLogUpsert) AddOrganizationID(v uint64) *LabelLogUpsert {
- u.Add(labellog.FieldOrganizationID, v)
- return u
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *LabelLogUpsert) ClearOrganizationID() *LabelLogUpsert {
- u.SetNull(labellog.FieldOrganizationID)
- 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.LabelLog.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(labellog.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *LabelLogUpsertOne) UpdateNewValues() *LabelLogUpsertOne {
- 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(labellog.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(labellog.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.LabelLog.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *LabelLogUpsertOne) Ignore() *LabelLogUpsertOne {
- 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 *LabelLogUpsertOne) DoNothing() *LabelLogUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the LabelLogCreate.OnConflict
- // documentation for more info.
- func (u *LabelLogUpsertOne) Update(set func(*LabelLogUpsert)) *LabelLogUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&LabelLogUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *LabelLogUpsertOne) SetUpdatedAt(v time.Time) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *LabelLogUpsertOne) UpdateUpdatedAt() *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetLabelName sets the "label_name" field.
- func (u *LabelLogUpsertOne) SetLabelName(v string) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetLabelName(v)
- })
- }
- // UpdateLabelName sets the "label_name" field to the value that was provided on create.
- func (u *LabelLogUpsertOne) UpdateLabelName() *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateLabelName()
- })
- }
- // SetLabelID sets the "label_id" field.
- func (u *LabelLogUpsertOne) SetLabelID(v int) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetLabelID(v)
- })
- }
- // AddLabelID adds v to the "label_id" field.
- func (u *LabelLogUpsertOne) AddLabelID(v int) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.AddLabelID(v)
- })
- }
- // UpdateLabelID sets the "label_id" field to the value that was provided on create.
- func (u *LabelLogUpsertOne) UpdateLabelID() *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateLabelID()
- })
- }
- // SetWxID sets the "wx_id" field.
- func (u *LabelLogUpsertOne) SetWxID(v string) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetWxID(v)
- })
- }
- // UpdateWxID sets the "wx_id" field to the value that was provided on create.
- func (u *LabelLogUpsertOne) UpdateWxID() *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateWxID()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *LabelLogUpsertOne) SetOrganizationID(v uint64) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *LabelLogUpsertOne) AddOrganizationID(v uint64) *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *LabelLogUpsertOne) UpdateOrganizationID() *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *LabelLogUpsertOne) ClearOrganizationID() *LabelLogUpsertOne {
- return u.Update(func(s *LabelLogUpsert) {
- s.ClearOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *LabelLogUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for LabelLogCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *LabelLogUpsertOne) 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 *LabelLogUpsertOne) ID(ctx context.Context) (id uint64, 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 *LabelLogUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // LabelLogCreateBulk is the builder for creating many LabelLog entities in bulk.
- type LabelLogCreateBulk struct {
- config
- err error
- builders []*LabelLogCreate
- conflict []sql.ConflictOption
- }
- // Save creates the LabelLog entities in the database.
- func (llcb *LabelLogCreateBulk) Save(ctx context.Context) ([]*LabelLog, error) {
- if llcb.err != nil {
- return nil, llcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(llcb.builders))
- nodes := make([]*LabelLog, len(llcb.builders))
- mutators := make([]Mutator, len(llcb.builders))
- for i := range llcb.builders {
- func(i int, root context.Context) {
- builder := llcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*LabelLogMutation)
- 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, llcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = llcb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, llcb.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 = uint64(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, llcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (llcb *LabelLogCreateBulk) SaveX(ctx context.Context) []*LabelLog {
- v, err := llcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (llcb *LabelLogCreateBulk) Exec(ctx context.Context) error {
- _, err := llcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (llcb *LabelLogCreateBulk) ExecX(ctx context.Context) {
- if err := llcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.LabelLog.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.LabelLogUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (llcb *LabelLogCreateBulk) OnConflict(opts ...sql.ConflictOption) *LabelLogUpsertBulk {
- llcb.conflict = opts
- return &LabelLogUpsertBulk{
- create: llcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.LabelLog.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (llcb *LabelLogCreateBulk) OnConflictColumns(columns ...string) *LabelLogUpsertBulk {
- llcb.conflict = append(llcb.conflict, sql.ConflictColumns(columns...))
- return &LabelLogUpsertBulk{
- create: llcb,
- }
- }
- // LabelLogUpsertBulk is the builder for "upsert"-ing
- // a bulk of LabelLog nodes.
- type LabelLogUpsertBulk struct {
- create *LabelLogCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.LabelLog.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(labellog.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *LabelLogUpsertBulk) UpdateNewValues() *LabelLogUpsertBulk {
- 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(labellog.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(labellog.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.LabelLog.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *LabelLogUpsertBulk) Ignore() *LabelLogUpsertBulk {
- 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 *LabelLogUpsertBulk) DoNothing() *LabelLogUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the LabelLogCreateBulk.OnConflict
- // documentation for more info.
- func (u *LabelLogUpsertBulk) Update(set func(*LabelLogUpsert)) *LabelLogUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&LabelLogUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *LabelLogUpsertBulk) SetUpdatedAt(v time.Time) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *LabelLogUpsertBulk) UpdateUpdatedAt() *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetLabelName sets the "label_name" field.
- func (u *LabelLogUpsertBulk) SetLabelName(v string) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetLabelName(v)
- })
- }
- // UpdateLabelName sets the "label_name" field to the value that was provided on create.
- func (u *LabelLogUpsertBulk) UpdateLabelName() *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateLabelName()
- })
- }
- // SetLabelID sets the "label_id" field.
- func (u *LabelLogUpsertBulk) SetLabelID(v int) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetLabelID(v)
- })
- }
- // AddLabelID adds v to the "label_id" field.
- func (u *LabelLogUpsertBulk) AddLabelID(v int) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.AddLabelID(v)
- })
- }
- // UpdateLabelID sets the "label_id" field to the value that was provided on create.
- func (u *LabelLogUpsertBulk) UpdateLabelID() *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateLabelID()
- })
- }
- // SetWxID sets the "wx_id" field.
- func (u *LabelLogUpsertBulk) SetWxID(v string) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetWxID(v)
- })
- }
- // UpdateWxID sets the "wx_id" field to the value that was provided on create.
- func (u *LabelLogUpsertBulk) UpdateWxID() *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateWxID()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *LabelLogUpsertBulk) SetOrganizationID(v uint64) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *LabelLogUpsertBulk) AddOrganizationID(v uint64) *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *LabelLogUpsertBulk) UpdateOrganizationID() *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *LabelLogUpsertBulk) ClearOrganizationID() *LabelLogUpsertBulk {
- return u.Update(func(s *LabelLogUpsert) {
- s.ClearOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *LabelLogUpsertBulk) 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 LabelLogCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for LabelLogCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *LabelLogUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|