12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172 |
- // 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
- }
- // 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)
- }
- }
- // 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"`)}
- }
- 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 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
- }
- // 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()
- })
- }
- // 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()
- })
- }
- // 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)
- }
- }
|