123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/category"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // CategoryCreate is the builder for creating a Category entity.
- type CategoryCreate struct {
- config
- mutation *CategoryMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (cc *CategoryCreate) SetCreatedAt(t time.Time) *CategoryCreate {
- cc.mutation.SetCreatedAt(t)
- return cc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (cc *CategoryCreate) SetNillableCreatedAt(t *time.Time) *CategoryCreate {
- if t != nil {
- cc.SetCreatedAt(*t)
- }
- return cc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cc *CategoryCreate) SetUpdatedAt(t time.Time) *CategoryCreate {
- cc.mutation.SetUpdatedAt(t)
- return cc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (cc *CategoryCreate) SetNillableUpdatedAt(t *time.Time) *CategoryCreate {
- if t != nil {
- cc.SetUpdatedAt(*t)
- }
- return cc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (cc *CategoryCreate) SetDeletedAt(t time.Time) *CategoryCreate {
- cc.mutation.SetDeletedAt(t)
- return cc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (cc *CategoryCreate) SetNillableDeletedAt(t *time.Time) *CategoryCreate {
- if t != nil {
- cc.SetDeletedAt(*t)
- }
- return cc
- }
- // SetName sets the "name" field.
- func (cc *CategoryCreate) SetName(s string) *CategoryCreate {
- cc.mutation.SetName(s)
- return cc
- }
- // SetOrganizationID sets the "organization_id" field.
- func (cc *CategoryCreate) SetOrganizationID(u uint64) *CategoryCreate {
- cc.mutation.SetOrganizationID(u)
- return cc
- }
- // SetID sets the "id" field.
- func (cc *CategoryCreate) SetID(u uint64) *CategoryCreate {
- cc.mutation.SetID(u)
- return cc
- }
- // Mutation returns the CategoryMutation object of the builder.
- func (cc *CategoryCreate) Mutation() *CategoryMutation {
- return cc.mutation
- }
- // Save creates the Category in the database.
- func (cc *CategoryCreate) Save(ctx context.Context) (*Category, error) {
- if err := cc.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (cc *CategoryCreate) SaveX(ctx context.Context) *Category {
- v, err := cc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (cc *CategoryCreate) Exec(ctx context.Context) error {
- _, err := cc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cc *CategoryCreate) ExecX(ctx context.Context) {
- if err := cc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cc *CategoryCreate) defaults() error {
- if _, ok := cc.mutation.CreatedAt(); !ok {
- if category.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized category.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := category.DefaultCreatedAt()
- cc.mutation.SetCreatedAt(v)
- }
- if _, ok := cc.mutation.UpdatedAt(); !ok {
- if category.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized category.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := category.DefaultUpdatedAt()
- cc.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (cc *CategoryCreate) check() error {
- if _, ok := cc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Category.created_at"`)}
- }
- if _, ok := cc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Category.updated_at"`)}
- }
- if _, ok := cc.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Category.name"`)}
- }
- if v, ok := cc.mutation.Name(); ok {
- if err := category.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Category.name": %w`, err)}
- }
- }
- if _, ok := cc.mutation.OrganizationID(); !ok {
- return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Category.organization_id"`)}
- }
- if v, ok := cc.mutation.OrganizationID(); ok {
- if err := category.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Category.organization_id": %w`, err)}
- }
- }
- return nil
- }
- func (cc *CategoryCreate) sqlSave(ctx context.Context) (*Category, 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
- }
- if _spec.ID.Value != _node.ID {
- id := _spec.ID.Value.(int64)
- _node.ID = uint64(id)
- }
- cc.mutation.id = &_node.ID
- cc.mutation.done = true
- return _node, nil
- }
- func (cc *CategoryCreate) createSpec() (*Category, *sqlgraph.CreateSpec) {
- var (
- _node = &Category{config: cc.config}
- _spec = sqlgraph.NewCreateSpec(category.Table, sqlgraph.NewFieldSpec(category.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = cc.conflict
- if id, ok := cc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := cc.mutation.CreatedAt(); ok {
- _spec.SetField(category.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := cc.mutation.UpdatedAt(); ok {
- _spec.SetField(category.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := cc.mutation.DeletedAt(); ok {
- _spec.SetField(category.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := cc.mutation.Name(); ok {
- _spec.SetField(category.FieldName, field.TypeString, value)
- _node.Name = value
- }
- if value, ok := cc.mutation.OrganizationID(); ok {
- _spec.SetField(category.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.Category.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.CategoryUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (cc *CategoryCreate) OnConflict(opts ...sql.ConflictOption) *CategoryUpsertOne {
- cc.conflict = opts
- return &CategoryUpsertOne{
- create: cc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Category.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (cc *CategoryCreate) OnConflictColumns(columns ...string) *CategoryUpsertOne {
- cc.conflict = append(cc.conflict, sql.ConflictColumns(columns...))
- return &CategoryUpsertOne{
- create: cc,
- }
- }
- type (
- // CategoryUpsertOne is the builder for "upsert"-ing
- // one Category node.
- CategoryUpsertOne struct {
- create *CategoryCreate
- }
- // CategoryUpsert is the "OnConflict" setter.
- CategoryUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *CategoryUpsert) SetUpdatedAt(v time.Time) *CategoryUpsert {
- u.Set(category.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *CategoryUpsert) UpdateUpdatedAt() *CategoryUpsert {
- u.SetExcluded(category.FieldUpdatedAt)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *CategoryUpsert) SetDeletedAt(v time.Time) *CategoryUpsert {
- u.Set(category.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *CategoryUpsert) UpdateDeletedAt() *CategoryUpsert {
- u.SetExcluded(category.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *CategoryUpsert) ClearDeletedAt() *CategoryUpsert {
- u.SetNull(category.FieldDeletedAt)
- return u
- }
- // SetName sets the "name" field.
- func (u *CategoryUpsert) SetName(v string) *CategoryUpsert {
- u.Set(category.FieldName, v)
- return u
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *CategoryUpsert) UpdateName() *CategoryUpsert {
- u.SetExcluded(category.FieldName)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *CategoryUpsert) SetOrganizationID(v uint64) *CategoryUpsert {
- u.Set(category.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *CategoryUpsert) UpdateOrganizationID() *CategoryUpsert {
- u.SetExcluded(category.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *CategoryUpsert) AddOrganizationID(v uint64) *CategoryUpsert {
- u.Add(category.FieldOrganizationID, v)
- 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.Category.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(category.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *CategoryUpsertOne) UpdateNewValues() *CategoryUpsertOne {
- 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(category.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(category.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Category.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *CategoryUpsertOne) Ignore() *CategoryUpsertOne {
- 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 *CategoryUpsertOne) DoNothing() *CategoryUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the CategoryCreate.OnConflict
- // documentation for more info.
- func (u *CategoryUpsertOne) Update(set func(*CategoryUpsert)) *CategoryUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&CategoryUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *CategoryUpsertOne) SetUpdatedAt(v time.Time) *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *CategoryUpsertOne) UpdateUpdatedAt() *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *CategoryUpsertOne) SetDeletedAt(v time.Time) *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *CategoryUpsertOne) UpdateDeletedAt() *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *CategoryUpsertOne) ClearDeletedAt() *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetName sets the "name" field.
- func (u *CategoryUpsertOne) SetName(v string) *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *CategoryUpsertOne) UpdateName() *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateName()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *CategoryUpsertOne) SetOrganizationID(v uint64) *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *CategoryUpsertOne) AddOrganizationID(v uint64) *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *CategoryUpsertOne) UpdateOrganizationID() *CategoryUpsertOne {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *CategoryUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for CategoryCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *CategoryUpsertOne) 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 *CategoryUpsertOne) 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 *CategoryUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // CategoryCreateBulk is the builder for creating many Category entities in bulk.
- type CategoryCreateBulk struct {
- config
- err error
- builders []*CategoryCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Category entities in the database.
- func (ccb *CategoryCreateBulk) Save(ctx context.Context) ([]*Category, error) {
- if ccb.err != nil {
- return nil, ccb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
- nodes := make([]*Category, len(ccb.builders))
- mutators := make([]Mutator, len(ccb.builders))
- for i := range ccb.builders {
- func(i int, root context.Context) {
- builder := ccb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*CategoryMutation)
- 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 && 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, ccb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (ccb *CategoryCreateBulk) SaveX(ctx context.Context) []*Category {
- v, err := ccb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (ccb *CategoryCreateBulk) Exec(ctx context.Context) error {
- _, err := ccb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (ccb *CategoryCreateBulk) 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.Category.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.CategoryUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (ccb *CategoryCreateBulk) OnConflict(opts ...sql.ConflictOption) *CategoryUpsertBulk {
- ccb.conflict = opts
- return &CategoryUpsertBulk{
- create: ccb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Category.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (ccb *CategoryCreateBulk) OnConflictColumns(columns ...string) *CategoryUpsertBulk {
- ccb.conflict = append(ccb.conflict, sql.ConflictColumns(columns...))
- return &CategoryUpsertBulk{
- create: ccb,
- }
- }
- // CategoryUpsertBulk is the builder for "upsert"-ing
- // a bulk of Category nodes.
- type CategoryUpsertBulk struct {
- create *CategoryCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Category.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(category.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *CategoryUpsertBulk) UpdateNewValues() *CategoryUpsertBulk {
- 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(category.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(category.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Category.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *CategoryUpsertBulk) Ignore() *CategoryUpsertBulk {
- 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 *CategoryUpsertBulk) DoNothing() *CategoryUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the CategoryCreateBulk.OnConflict
- // documentation for more info.
- func (u *CategoryUpsertBulk) Update(set func(*CategoryUpsert)) *CategoryUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&CategoryUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *CategoryUpsertBulk) SetUpdatedAt(v time.Time) *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *CategoryUpsertBulk) UpdateUpdatedAt() *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *CategoryUpsertBulk) SetDeletedAt(v time.Time) *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *CategoryUpsertBulk) UpdateDeletedAt() *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *CategoryUpsertBulk) ClearDeletedAt() *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetName sets the "name" field.
- func (u *CategoryUpsertBulk) SetName(v string) *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *CategoryUpsertBulk) UpdateName() *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateName()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *CategoryUpsertBulk) SetOrganizationID(v uint64) *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *CategoryUpsertBulk) AddOrganizationID(v uint64) *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *CategoryUpsertBulk) UpdateOrganizationID() *CategoryUpsertBulk {
- return u.Update(func(s *CategoryUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *CategoryUpsertBulk) 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 CategoryCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for CategoryCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *CategoryUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|