123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/label"
- "wechat-api/ent/labelrelationship"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // LabelCreate is the builder for creating a Label entity.
- type LabelCreate struct {
- config
- mutation *LabelMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (lc *LabelCreate) SetCreatedAt(t time.Time) *LabelCreate {
- lc.mutation.SetCreatedAt(t)
- return lc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableCreatedAt(t *time.Time) *LabelCreate {
- if t != nil {
- lc.SetCreatedAt(*t)
- }
- return lc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (lc *LabelCreate) SetUpdatedAt(t time.Time) *LabelCreate {
- lc.mutation.SetUpdatedAt(t)
- return lc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableUpdatedAt(t *time.Time) *LabelCreate {
- if t != nil {
- lc.SetUpdatedAt(*t)
- }
- return lc
- }
- // SetStatus sets the "status" field.
- func (lc *LabelCreate) SetStatus(u uint8) *LabelCreate {
- lc.mutation.SetStatus(u)
- return lc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableStatus(u *uint8) *LabelCreate {
- if u != nil {
- lc.SetStatus(*u)
- }
- return lc
- }
- // SetType sets the "type" field.
- func (lc *LabelCreate) SetType(i int) *LabelCreate {
- lc.mutation.SetType(i)
- return lc
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableType(i *int) *LabelCreate {
- if i != nil {
- lc.SetType(*i)
- }
- return lc
- }
- // SetName sets the "name" field.
- func (lc *LabelCreate) SetName(s string) *LabelCreate {
- lc.mutation.SetName(s)
- return lc
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableName(s *string) *LabelCreate {
- if s != nil {
- lc.SetName(*s)
- }
- return lc
- }
- // SetFrom sets the "from" field.
- func (lc *LabelCreate) SetFrom(i int) *LabelCreate {
- lc.mutation.SetFrom(i)
- return lc
- }
- // SetNillableFrom sets the "from" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableFrom(i *int) *LabelCreate {
- if i != nil {
- lc.SetFrom(*i)
- }
- return lc
- }
- // SetMode sets the "mode" field.
- func (lc *LabelCreate) SetMode(i int) *LabelCreate {
- lc.mutation.SetMode(i)
- return lc
- }
- // SetNillableMode sets the "mode" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableMode(i *int) *LabelCreate {
- if i != nil {
- lc.SetMode(*i)
- }
- return lc
- }
- // SetConditions sets the "conditions" field.
- func (lc *LabelCreate) SetConditions(s string) *LabelCreate {
- lc.mutation.SetConditions(s)
- return lc
- }
- // SetNillableConditions sets the "conditions" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableConditions(s *string) *LabelCreate {
- if s != nil {
- lc.SetConditions(*s)
- }
- return lc
- }
- // SetOrganizationID sets the "organization_id" field.
- func (lc *LabelCreate) SetOrganizationID(u uint64) *LabelCreate {
- lc.mutation.SetOrganizationID(u)
- return lc
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableOrganizationID(u *uint64) *LabelCreate {
- if u != nil {
- lc.SetOrganizationID(*u)
- }
- return lc
- }
- // SetCtype sets the "ctype" field.
- func (lc *LabelCreate) SetCtype(u uint64) *LabelCreate {
- lc.mutation.SetCtype(u)
- return lc
- }
- // SetNillableCtype sets the "ctype" field if the given value is not nil.
- func (lc *LabelCreate) SetNillableCtype(u *uint64) *LabelCreate {
- if u != nil {
- lc.SetCtype(*u)
- }
- return lc
- }
- // SetID sets the "id" field.
- func (lc *LabelCreate) SetID(u uint64) *LabelCreate {
- lc.mutation.SetID(u)
- return lc
- }
- // AddLabelRelationshipIDs adds the "label_relationships" edge to the LabelRelationship entity by IDs.
- func (lc *LabelCreate) AddLabelRelationshipIDs(ids ...uint64) *LabelCreate {
- lc.mutation.AddLabelRelationshipIDs(ids...)
- return lc
- }
- // AddLabelRelationships adds the "label_relationships" edges to the LabelRelationship entity.
- func (lc *LabelCreate) AddLabelRelationships(l ...*LabelRelationship) *LabelCreate {
- ids := make([]uint64, len(l))
- for i := range l {
- ids[i] = l[i].ID
- }
- return lc.AddLabelRelationshipIDs(ids...)
- }
- // Mutation returns the LabelMutation object of the builder.
- func (lc *LabelCreate) Mutation() *LabelMutation {
- return lc.mutation
- }
- // Save creates the Label in the database.
- func (lc *LabelCreate) Save(ctx context.Context) (*Label, error) {
- lc.defaults()
- return withHooks(ctx, lc.sqlSave, lc.mutation, lc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (lc *LabelCreate) SaveX(ctx context.Context) *Label {
- v, err := lc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (lc *LabelCreate) Exec(ctx context.Context) error {
- _, err := lc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (lc *LabelCreate) ExecX(ctx context.Context) {
- if err := lc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (lc *LabelCreate) defaults() {
- if _, ok := lc.mutation.CreatedAt(); !ok {
- v := label.DefaultCreatedAt()
- lc.mutation.SetCreatedAt(v)
- }
- if _, ok := lc.mutation.UpdatedAt(); !ok {
- v := label.DefaultUpdatedAt()
- lc.mutation.SetUpdatedAt(v)
- }
- if _, ok := lc.mutation.Status(); !ok {
- v := label.DefaultStatus
- lc.mutation.SetStatus(v)
- }
- if _, ok := lc.mutation.GetType(); !ok {
- v := label.DefaultType
- lc.mutation.SetType(v)
- }
- if _, ok := lc.mutation.Name(); !ok {
- v := label.DefaultName
- lc.mutation.SetName(v)
- }
- if _, ok := lc.mutation.From(); !ok {
- v := label.DefaultFrom
- lc.mutation.SetFrom(v)
- }
- if _, ok := lc.mutation.Mode(); !ok {
- v := label.DefaultMode
- lc.mutation.SetMode(v)
- }
- if _, ok := lc.mutation.Conditions(); !ok {
- v := label.DefaultConditions
- lc.mutation.SetConditions(v)
- }
- if _, ok := lc.mutation.OrganizationID(); !ok {
- v := label.DefaultOrganizationID
- lc.mutation.SetOrganizationID(v)
- }
- if _, ok := lc.mutation.Ctype(); !ok {
- v := label.DefaultCtype
- lc.mutation.SetCtype(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (lc *LabelCreate) check() error {
- if _, ok := lc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Label.created_at"`)}
- }
- if _, ok := lc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Label.updated_at"`)}
- }
- if _, ok := lc.mutation.GetType(); !ok {
- return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Label.type"`)}
- }
- if _, ok := lc.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Label.name"`)}
- }
- if _, ok := lc.mutation.From(); !ok {
- return &ValidationError{Name: "from", err: errors.New(`ent: missing required field "Label.from"`)}
- }
- if _, ok := lc.mutation.Mode(); !ok {
- return &ValidationError{Name: "mode", err: errors.New(`ent: missing required field "Label.mode"`)}
- }
- if _, ok := lc.mutation.Ctype(); !ok {
- return &ValidationError{Name: "ctype", err: errors.New(`ent: missing required field "Label.ctype"`)}
- }
- return nil
- }
- func (lc *LabelCreate) sqlSave(ctx context.Context) (*Label, error) {
- if err := lc.check(); err != nil {
- return nil, err
- }
- _node, _spec := lc.createSpec()
- if err := sqlgraph.CreateNode(ctx, lc.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)
- }
- lc.mutation.id = &_node.ID
- lc.mutation.done = true
- return _node, nil
- }
- func (lc *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) {
- var (
- _node = &Label{config: lc.config}
- _spec = sqlgraph.NewCreateSpec(label.Table, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = lc.conflict
- if id, ok := lc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := lc.mutation.CreatedAt(); ok {
- _spec.SetField(label.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := lc.mutation.UpdatedAt(); ok {
- _spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := lc.mutation.Status(); ok {
- _spec.SetField(label.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := lc.mutation.GetType(); ok {
- _spec.SetField(label.FieldType, field.TypeInt, value)
- _node.Type = value
- }
- if value, ok := lc.mutation.Name(); ok {
- _spec.SetField(label.FieldName, field.TypeString, value)
- _node.Name = value
- }
- if value, ok := lc.mutation.From(); ok {
- _spec.SetField(label.FieldFrom, field.TypeInt, value)
- _node.From = value
- }
- if value, ok := lc.mutation.Mode(); ok {
- _spec.SetField(label.FieldMode, field.TypeInt, value)
- _node.Mode = value
- }
- if value, ok := lc.mutation.Conditions(); ok {
- _spec.SetField(label.FieldConditions, field.TypeString, value)
- _node.Conditions = value
- }
- if value, ok := lc.mutation.OrganizationID(); ok {
- _spec.SetField(label.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if value, ok := lc.mutation.Ctype(); ok {
- _spec.SetField(label.FieldCtype, field.TypeUint64, value)
- _node.Ctype = value
- }
- if nodes := lc.mutation.LabelRelationshipsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: label.LabelRelationshipsTable,
- Columns: []string{label.LabelRelationshipsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
- },
- }
- 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.Label.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.LabelUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (lc *LabelCreate) OnConflict(opts ...sql.ConflictOption) *LabelUpsertOne {
- lc.conflict = opts
- return &LabelUpsertOne{
- create: lc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Label.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (lc *LabelCreate) OnConflictColumns(columns ...string) *LabelUpsertOne {
- lc.conflict = append(lc.conflict, sql.ConflictColumns(columns...))
- return &LabelUpsertOne{
- create: lc,
- }
- }
- type (
- // LabelUpsertOne is the builder for "upsert"-ing
- // one Label node.
- LabelUpsertOne struct {
- create *LabelCreate
- }
- // LabelUpsert is the "OnConflict" setter.
- LabelUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *LabelUpsert) SetUpdatedAt(v time.Time) *LabelUpsert {
- u.Set(label.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateUpdatedAt() *LabelUpsert {
- u.SetExcluded(label.FieldUpdatedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *LabelUpsert) SetStatus(v uint8) *LabelUpsert {
- u.Set(label.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateStatus() *LabelUpsert {
- u.SetExcluded(label.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *LabelUpsert) AddStatus(v uint8) *LabelUpsert {
- u.Add(label.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *LabelUpsert) ClearStatus() *LabelUpsert {
- u.SetNull(label.FieldStatus)
- return u
- }
- // SetType sets the "type" field.
- func (u *LabelUpsert) SetType(v int) *LabelUpsert {
- u.Set(label.FieldType, v)
- return u
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateType() *LabelUpsert {
- u.SetExcluded(label.FieldType)
- return u
- }
- // AddType adds v to the "type" field.
- func (u *LabelUpsert) AddType(v int) *LabelUpsert {
- u.Add(label.FieldType, v)
- return u
- }
- // SetName sets the "name" field.
- func (u *LabelUpsert) SetName(v string) *LabelUpsert {
- u.Set(label.FieldName, v)
- return u
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateName() *LabelUpsert {
- u.SetExcluded(label.FieldName)
- return u
- }
- // SetFrom sets the "from" field.
- func (u *LabelUpsert) SetFrom(v int) *LabelUpsert {
- u.Set(label.FieldFrom, v)
- return u
- }
- // UpdateFrom sets the "from" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateFrom() *LabelUpsert {
- u.SetExcluded(label.FieldFrom)
- return u
- }
- // AddFrom adds v to the "from" field.
- func (u *LabelUpsert) AddFrom(v int) *LabelUpsert {
- u.Add(label.FieldFrom, v)
- return u
- }
- // SetMode sets the "mode" field.
- func (u *LabelUpsert) SetMode(v int) *LabelUpsert {
- u.Set(label.FieldMode, v)
- return u
- }
- // UpdateMode sets the "mode" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateMode() *LabelUpsert {
- u.SetExcluded(label.FieldMode)
- return u
- }
- // AddMode adds v to the "mode" field.
- func (u *LabelUpsert) AddMode(v int) *LabelUpsert {
- u.Add(label.FieldMode, v)
- return u
- }
- // SetConditions sets the "conditions" field.
- func (u *LabelUpsert) SetConditions(v string) *LabelUpsert {
- u.Set(label.FieldConditions, v)
- return u
- }
- // UpdateConditions sets the "conditions" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateConditions() *LabelUpsert {
- u.SetExcluded(label.FieldConditions)
- return u
- }
- // ClearConditions clears the value of the "conditions" field.
- func (u *LabelUpsert) ClearConditions() *LabelUpsert {
- u.SetNull(label.FieldConditions)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *LabelUpsert) SetOrganizationID(v uint64) *LabelUpsert {
- u.Set(label.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateOrganizationID() *LabelUpsert {
- u.SetExcluded(label.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *LabelUpsert) AddOrganizationID(v uint64) *LabelUpsert {
- u.Add(label.FieldOrganizationID, v)
- return u
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *LabelUpsert) ClearOrganizationID() *LabelUpsert {
- u.SetNull(label.FieldOrganizationID)
- return u
- }
- // SetCtype sets the "ctype" field.
- func (u *LabelUpsert) SetCtype(v uint64) *LabelUpsert {
- u.Set(label.FieldCtype, v)
- return u
- }
- // UpdateCtype sets the "ctype" field to the value that was provided on create.
- func (u *LabelUpsert) UpdateCtype() *LabelUpsert {
- u.SetExcluded(label.FieldCtype)
- return u
- }
- // AddCtype adds v to the "ctype" field.
- func (u *LabelUpsert) AddCtype(v uint64) *LabelUpsert {
- u.Add(label.FieldCtype, 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.Label.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(label.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *LabelUpsertOne) UpdateNewValues() *LabelUpsertOne {
- 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(label.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(label.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Label.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *LabelUpsertOne) Ignore() *LabelUpsertOne {
- 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 *LabelUpsertOne) DoNothing() *LabelUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the LabelCreate.OnConflict
- // documentation for more info.
- func (u *LabelUpsertOne) Update(set func(*LabelUpsert)) *LabelUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&LabelUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *LabelUpsertOne) SetUpdatedAt(v time.Time) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateUpdatedAt() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *LabelUpsertOne) SetStatus(v uint8) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *LabelUpsertOne) AddStatus(v uint8) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateStatus() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *LabelUpsertOne) ClearStatus() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.ClearStatus()
- })
- }
- // SetType sets the "type" field.
- func (u *LabelUpsertOne) SetType(v int) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetType(v)
- })
- }
- // AddType adds v to the "type" field.
- func (u *LabelUpsertOne) AddType(v int) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.AddType(v)
- })
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateType() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateType()
- })
- }
- // SetName sets the "name" field.
- func (u *LabelUpsertOne) SetName(v string) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateName() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateName()
- })
- }
- // SetFrom sets the "from" field.
- func (u *LabelUpsertOne) SetFrom(v int) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetFrom(v)
- })
- }
- // AddFrom adds v to the "from" field.
- func (u *LabelUpsertOne) AddFrom(v int) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.AddFrom(v)
- })
- }
- // UpdateFrom sets the "from" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateFrom() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateFrom()
- })
- }
- // SetMode sets the "mode" field.
- func (u *LabelUpsertOne) SetMode(v int) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetMode(v)
- })
- }
- // AddMode adds v to the "mode" field.
- func (u *LabelUpsertOne) AddMode(v int) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.AddMode(v)
- })
- }
- // UpdateMode sets the "mode" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateMode() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateMode()
- })
- }
- // SetConditions sets the "conditions" field.
- func (u *LabelUpsertOne) SetConditions(v string) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetConditions(v)
- })
- }
- // UpdateConditions sets the "conditions" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateConditions() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateConditions()
- })
- }
- // ClearConditions clears the value of the "conditions" field.
- func (u *LabelUpsertOne) ClearConditions() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.ClearConditions()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *LabelUpsertOne) SetOrganizationID(v uint64) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *LabelUpsertOne) AddOrganizationID(v uint64) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateOrganizationID() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *LabelUpsertOne) ClearOrganizationID() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.ClearOrganizationID()
- })
- }
- // SetCtype sets the "ctype" field.
- func (u *LabelUpsertOne) SetCtype(v uint64) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.SetCtype(v)
- })
- }
- // AddCtype adds v to the "ctype" field.
- func (u *LabelUpsertOne) AddCtype(v uint64) *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.AddCtype(v)
- })
- }
- // UpdateCtype sets the "ctype" field to the value that was provided on create.
- func (u *LabelUpsertOne) UpdateCtype() *LabelUpsertOne {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateCtype()
- })
- }
- // Exec executes the query.
- func (u *LabelUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for LabelCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *LabelUpsertOne) 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 *LabelUpsertOne) 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 *LabelUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // LabelCreateBulk is the builder for creating many Label entities in bulk.
- type LabelCreateBulk struct {
- config
- err error
- builders []*LabelCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Label entities in the database.
- func (lcb *LabelCreateBulk) Save(ctx context.Context) ([]*Label, error) {
- if lcb.err != nil {
- return nil, lcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(lcb.builders))
- nodes := make([]*Label, len(lcb.builders))
- mutators := make([]Mutator, len(lcb.builders))
- for i := range lcb.builders {
- func(i int, root context.Context) {
- builder := lcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*LabelMutation)
- 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, lcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = lcb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, lcb.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, lcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (lcb *LabelCreateBulk) SaveX(ctx context.Context) []*Label {
- v, err := lcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (lcb *LabelCreateBulk) Exec(ctx context.Context) error {
- _, err := lcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (lcb *LabelCreateBulk) ExecX(ctx context.Context) {
- if err := lcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Label.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.LabelUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (lcb *LabelCreateBulk) OnConflict(opts ...sql.ConflictOption) *LabelUpsertBulk {
- lcb.conflict = opts
- return &LabelUpsertBulk{
- create: lcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Label.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (lcb *LabelCreateBulk) OnConflictColumns(columns ...string) *LabelUpsertBulk {
- lcb.conflict = append(lcb.conflict, sql.ConflictColumns(columns...))
- return &LabelUpsertBulk{
- create: lcb,
- }
- }
- // LabelUpsertBulk is the builder for "upsert"-ing
- // a bulk of Label nodes.
- type LabelUpsertBulk struct {
- create *LabelCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Label.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(label.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *LabelUpsertBulk) UpdateNewValues() *LabelUpsertBulk {
- 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(label.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(label.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Label.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *LabelUpsertBulk) Ignore() *LabelUpsertBulk {
- 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 *LabelUpsertBulk) DoNothing() *LabelUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the LabelCreateBulk.OnConflict
- // documentation for more info.
- func (u *LabelUpsertBulk) Update(set func(*LabelUpsert)) *LabelUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&LabelUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *LabelUpsertBulk) SetUpdatedAt(v time.Time) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateUpdatedAt() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *LabelUpsertBulk) SetStatus(v uint8) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *LabelUpsertBulk) AddStatus(v uint8) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateStatus() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *LabelUpsertBulk) ClearStatus() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.ClearStatus()
- })
- }
- // SetType sets the "type" field.
- func (u *LabelUpsertBulk) SetType(v int) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetType(v)
- })
- }
- // AddType adds v to the "type" field.
- func (u *LabelUpsertBulk) AddType(v int) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.AddType(v)
- })
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateType() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateType()
- })
- }
- // SetName sets the "name" field.
- func (u *LabelUpsertBulk) SetName(v string) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateName() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateName()
- })
- }
- // SetFrom sets the "from" field.
- func (u *LabelUpsertBulk) SetFrom(v int) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetFrom(v)
- })
- }
- // AddFrom adds v to the "from" field.
- func (u *LabelUpsertBulk) AddFrom(v int) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.AddFrom(v)
- })
- }
- // UpdateFrom sets the "from" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateFrom() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateFrom()
- })
- }
- // SetMode sets the "mode" field.
- func (u *LabelUpsertBulk) SetMode(v int) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetMode(v)
- })
- }
- // AddMode adds v to the "mode" field.
- func (u *LabelUpsertBulk) AddMode(v int) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.AddMode(v)
- })
- }
- // UpdateMode sets the "mode" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateMode() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateMode()
- })
- }
- // SetConditions sets the "conditions" field.
- func (u *LabelUpsertBulk) SetConditions(v string) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetConditions(v)
- })
- }
- // UpdateConditions sets the "conditions" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateConditions() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateConditions()
- })
- }
- // ClearConditions clears the value of the "conditions" field.
- func (u *LabelUpsertBulk) ClearConditions() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.ClearConditions()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *LabelUpsertBulk) SetOrganizationID(v uint64) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *LabelUpsertBulk) AddOrganizationID(v uint64) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateOrganizationID() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *LabelUpsertBulk) ClearOrganizationID() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.ClearOrganizationID()
- })
- }
- // SetCtype sets the "ctype" field.
- func (u *LabelUpsertBulk) SetCtype(v uint64) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.SetCtype(v)
- })
- }
- // AddCtype adds v to the "ctype" field.
- func (u *LabelUpsertBulk) AddCtype(v uint64) *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.AddCtype(v)
- })
- }
- // UpdateCtype sets the "ctype" field to the value that was provided on create.
- func (u *LabelUpsertBulk) UpdateCtype() *LabelUpsertBulk {
- return u.Update(func(s *LabelUpsert) {
- s.UpdateCtype()
- })
- }
- // Exec executes the query.
- func (u *LabelUpsertBulk) 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 LabelCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for LabelCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *LabelUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|