1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/agent"
- "wechat-api/ent/token"
- "wechat-api/ent/wx"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // AgentCreate is the builder for creating a Agent entity.
- type AgentCreate struct {
- config
- mutation *AgentMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (ac *AgentCreate) SetCreatedAt(t time.Time) *AgentCreate {
- ac.mutation.SetCreatedAt(t)
- return ac
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableCreatedAt(t *time.Time) *AgentCreate {
- if t != nil {
- ac.SetCreatedAt(*t)
- }
- return ac
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (ac *AgentCreate) SetUpdatedAt(t time.Time) *AgentCreate {
- ac.mutation.SetUpdatedAt(t)
- return ac
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableUpdatedAt(t *time.Time) *AgentCreate {
- if t != nil {
- ac.SetUpdatedAt(*t)
- }
- return ac
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (ac *AgentCreate) SetDeletedAt(t time.Time) *AgentCreate {
- ac.mutation.SetDeletedAt(t)
- return ac
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableDeletedAt(t *time.Time) *AgentCreate {
- if t != nil {
- ac.SetDeletedAt(*t)
- }
- return ac
- }
- // SetName sets the "name" field.
- func (ac *AgentCreate) SetName(s string) *AgentCreate {
- ac.mutation.SetName(s)
- return ac
- }
- // SetRole sets the "role" field.
- func (ac *AgentCreate) SetRole(s string) *AgentCreate {
- ac.mutation.SetRole(s)
- return ac
- }
- // SetStatus sets the "status" field.
- func (ac *AgentCreate) SetStatus(i int) *AgentCreate {
- ac.mutation.SetStatus(i)
- return ac
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableStatus(i *int) *AgentCreate {
- if i != nil {
- ac.SetStatus(*i)
- }
- return ac
- }
- // SetBackground sets the "background" field.
- func (ac *AgentCreate) SetBackground(s string) *AgentCreate {
- ac.mutation.SetBackground(s)
- return ac
- }
- // SetNillableBackground sets the "background" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableBackground(s *string) *AgentCreate {
- if s != nil {
- ac.SetBackground(*s)
- }
- return ac
- }
- // SetExamples sets the "examples" field.
- func (ac *AgentCreate) SetExamples(s string) *AgentCreate {
- ac.mutation.SetExamples(s)
- return ac
- }
- // SetNillableExamples sets the "examples" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableExamples(s *string) *AgentCreate {
- if s != nil {
- ac.SetExamples(*s)
- }
- return ac
- }
- // SetOrganizationID sets the "organization_id" field.
- func (ac *AgentCreate) SetOrganizationID(u uint64) *AgentCreate {
- ac.mutation.SetOrganizationID(u)
- return ac
- }
- // SetDatasetID sets the "dataset_id" field.
- func (ac *AgentCreate) SetDatasetID(s string) *AgentCreate {
- ac.mutation.SetDatasetID(s)
- return ac
- }
- // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableDatasetID(s *string) *AgentCreate {
- if s != nil {
- ac.SetDatasetID(*s)
- }
- return ac
- }
- // SetCollectionID sets the "collection_id" field.
- func (ac *AgentCreate) SetCollectionID(s string) *AgentCreate {
- ac.mutation.SetCollectionID(s)
- return ac
- }
- // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
- func (ac *AgentCreate) SetNillableCollectionID(s *string) *AgentCreate {
- if s != nil {
- ac.SetCollectionID(*s)
- }
- return ac
- }
- // SetID sets the "id" field.
- func (ac *AgentCreate) SetID(u uint64) *AgentCreate {
- ac.mutation.SetID(u)
- return ac
- }
- // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
- func (ac *AgentCreate) AddWxAgentIDs(ids ...uint64) *AgentCreate {
- ac.mutation.AddWxAgentIDs(ids...)
- return ac
- }
- // AddWxAgent adds the "wx_agent" edges to the Wx entity.
- func (ac *AgentCreate) AddWxAgent(w ...*Wx) *AgentCreate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return ac.AddWxAgentIDs(ids...)
- }
- // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
- func (ac *AgentCreate) AddTokenAgentIDs(ids ...uint64) *AgentCreate {
- ac.mutation.AddTokenAgentIDs(ids...)
- return ac
- }
- // AddTokenAgent adds the "token_agent" edges to the Token entity.
- func (ac *AgentCreate) AddTokenAgent(t ...*Token) *AgentCreate {
- ids := make([]uint64, len(t))
- for i := range t {
- ids[i] = t[i].ID
- }
- return ac.AddTokenAgentIDs(ids...)
- }
- // Mutation returns the AgentMutation object of the builder.
- func (ac *AgentCreate) Mutation() *AgentMutation {
- return ac.mutation
- }
- // Save creates the Agent in the database.
- func (ac *AgentCreate) Save(ctx context.Context) (*Agent, error) {
- if err := ac.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, ac.sqlSave, ac.mutation, ac.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (ac *AgentCreate) SaveX(ctx context.Context) *Agent {
- v, err := ac.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (ac *AgentCreate) Exec(ctx context.Context) error {
- _, err := ac.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (ac *AgentCreate) ExecX(ctx context.Context) {
- if err := ac.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (ac *AgentCreate) defaults() error {
- if _, ok := ac.mutation.CreatedAt(); !ok {
- if agent.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized agent.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := agent.DefaultCreatedAt()
- ac.mutation.SetCreatedAt(v)
- }
- if _, ok := ac.mutation.UpdatedAt(); !ok {
- if agent.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized agent.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := agent.DefaultUpdatedAt()
- ac.mutation.SetUpdatedAt(v)
- }
- if _, ok := ac.mutation.Status(); !ok {
- v := agent.DefaultStatus
- ac.mutation.SetStatus(v)
- }
- if _, ok := ac.mutation.Background(); !ok {
- v := agent.DefaultBackground
- ac.mutation.SetBackground(v)
- }
- if _, ok := ac.mutation.Examples(); !ok {
- v := agent.DefaultExamples
- ac.mutation.SetExamples(v)
- }
- if _, ok := ac.mutation.DatasetID(); !ok {
- v := agent.DefaultDatasetID
- ac.mutation.SetDatasetID(v)
- }
- if _, ok := ac.mutation.CollectionID(); !ok {
- v := agent.DefaultCollectionID
- ac.mutation.SetCollectionID(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (ac *AgentCreate) check() error {
- if _, ok := ac.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Agent.created_at"`)}
- }
- if _, ok := ac.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Agent.updated_at"`)}
- }
- if _, ok := ac.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Agent.name"`)}
- }
- if v, ok := ac.mutation.Name(); ok {
- if err := agent.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
- }
- }
- if _, ok := ac.mutation.Role(); !ok {
- return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "Agent.role"`)}
- }
- if v, ok := ac.mutation.Status(); ok {
- if err := agent.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
- }
- }
- if _, ok := ac.mutation.OrganizationID(); !ok {
- return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "Agent.organization_id"`)}
- }
- if v, ok := ac.mutation.OrganizationID(); ok {
- if err := agent.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
- }
- }
- if _, ok := ac.mutation.DatasetID(); !ok {
- return &ValidationError{Name: "dataset_id", err: errors.New(`ent: missing required field "Agent.dataset_id"`)}
- }
- if v, ok := ac.mutation.DatasetID(); ok {
- if err := agent.DatasetIDValidator(v); err != nil {
- return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
- }
- }
- if _, ok := ac.mutation.CollectionID(); !ok {
- return &ValidationError{Name: "collection_id", err: errors.New(`ent: missing required field "Agent.collection_id"`)}
- }
- if v, ok := ac.mutation.CollectionID(); ok {
- if err := agent.CollectionIDValidator(v); err != nil {
- return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
- }
- }
- return nil
- }
- func (ac *AgentCreate) sqlSave(ctx context.Context) (*Agent, error) {
- if err := ac.check(); err != nil {
- return nil, err
- }
- _node, _spec := ac.createSpec()
- if err := sqlgraph.CreateNode(ctx, ac.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)
- }
- ac.mutation.id = &_node.ID
- ac.mutation.done = true
- return _node, nil
- }
- func (ac *AgentCreate) createSpec() (*Agent, *sqlgraph.CreateSpec) {
- var (
- _node = &Agent{config: ac.config}
- _spec = sqlgraph.NewCreateSpec(agent.Table, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = ac.conflict
- if id, ok := ac.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := ac.mutation.CreatedAt(); ok {
- _spec.SetField(agent.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := ac.mutation.UpdatedAt(); ok {
- _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := ac.mutation.DeletedAt(); ok {
- _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := ac.mutation.Name(); ok {
- _spec.SetField(agent.FieldName, field.TypeString, value)
- _node.Name = value
- }
- if value, ok := ac.mutation.Role(); ok {
- _spec.SetField(agent.FieldRole, field.TypeString, value)
- _node.Role = value
- }
- if value, ok := ac.mutation.Status(); ok {
- _spec.SetField(agent.FieldStatus, field.TypeInt, value)
- _node.Status = value
- }
- if value, ok := ac.mutation.Background(); ok {
- _spec.SetField(agent.FieldBackground, field.TypeString, value)
- _node.Background = value
- }
- if value, ok := ac.mutation.Examples(); ok {
- _spec.SetField(agent.FieldExamples, field.TypeString, value)
- _node.Examples = value
- }
- if value, ok := ac.mutation.OrganizationID(); ok {
- _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if value, ok := ac.mutation.DatasetID(); ok {
- _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
- _node.DatasetID = value
- }
- if value, ok := ac.mutation.CollectionID(); ok {
- _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
- _node.CollectionID = value
- }
- if nodes := ac.mutation.WxAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.WxAgentTable,
- Columns: []string{agent.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := ac.mutation.TokenAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agent.TokenAgentTable,
- Columns: []string{agent.TokenAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(token.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.Agent.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.AgentUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (ac *AgentCreate) OnConflict(opts ...sql.ConflictOption) *AgentUpsertOne {
- ac.conflict = opts
- return &AgentUpsertOne{
- create: ac,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Agent.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (ac *AgentCreate) OnConflictColumns(columns ...string) *AgentUpsertOne {
- ac.conflict = append(ac.conflict, sql.ConflictColumns(columns...))
- return &AgentUpsertOne{
- create: ac,
- }
- }
- type (
- // AgentUpsertOne is the builder for "upsert"-ing
- // one Agent node.
- AgentUpsertOne struct {
- create *AgentCreate
- }
- // AgentUpsert is the "OnConflict" setter.
- AgentUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *AgentUpsert) SetUpdatedAt(v time.Time) *AgentUpsert {
- u.Set(agent.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateUpdatedAt() *AgentUpsert {
- u.SetExcluded(agent.FieldUpdatedAt)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *AgentUpsert) SetDeletedAt(v time.Time) *AgentUpsert {
- u.Set(agent.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateDeletedAt() *AgentUpsert {
- u.SetExcluded(agent.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *AgentUpsert) ClearDeletedAt() *AgentUpsert {
- u.SetNull(agent.FieldDeletedAt)
- return u
- }
- // SetName sets the "name" field.
- func (u *AgentUpsert) SetName(v string) *AgentUpsert {
- u.Set(agent.FieldName, v)
- return u
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateName() *AgentUpsert {
- u.SetExcluded(agent.FieldName)
- return u
- }
- // SetRole sets the "role" field.
- func (u *AgentUpsert) SetRole(v string) *AgentUpsert {
- u.Set(agent.FieldRole, v)
- return u
- }
- // UpdateRole sets the "role" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateRole() *AgentUpsert {
- u.SetExcluded(agent.FieldRole)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *AgentUpsert) SetStatus(v int) *AgentUpsert {
- u.Set(agent.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateStatus() *AgentUpsert {
- u.SetExcluded(agent.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *AgentUpsert) AddStatus(v int) *AgentUpsert {
- u.Add(agent.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *AgentUpsert) ClearStatus() *AgentUpsert {
- u.SetNull(agent.FieldStatus)
- return u
- }
- // SetBackground sets the "background" field.
- func (u *AgentUpsert) SetBackground(v string) *AgentUpsert {
- u.Set(agent.FieldBackground, v)
- return u
- }
- // UpdateBackground sets the "background" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateBackground() *AgentUpsert {
- u.SetExcluded(agent.FieldBackground)
- return u
- }
- // ClearBackground clears the value of the "background" field.
- func (u *AgentUpsert) ClearBackground() *AgentUpsert {
- u.SetNull(agent.FieldBackground)
- return u
- }
- // SetExamples sets the "examples" field.
- func (u *AgentUpsert) SetExamples(v string) *AgentUpsert {
- u.Set(agent.FieldExamples, v)
- return u
- }
- // UpdateExamples sets the "examples" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateExamples() *AgentUpsert {
- u.SetExcluded(agent.FieldExamples)
- return u
- }
- // ClearExamples clears the value of the "examples" field.
- func (u *AgentUpsert) ClearExamples() *AgentUpsert {
- u.SetNull(agent.FieldExamples)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *AgentUpsert) SetOrganizationID(v uint64) *AgentUpsert {
- u.Set(agent.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateOrganizationID() *AgentUpsert {
- u.SetExcluded(agent.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *AgentUpsert) AddOrganizationID(v uint64) *AgentUpsert {
- u.Add(agent.FieldOrganizationID, v)
- return u
- }
- // SetDatasetID sets the "dataset_id" field.
- func (u *AgentUpsert) SetDatasetID(v string) *AgentUpsert {
- u.Set(agent.FieldDatasetID, v)
- return u
- }
- // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateDatasetID() *AgentUpsert {
- u.SetExcluded(agent.FieldDatasetID)
- return u
- }
- // SetCollectionID sets the "collection_id" field.
- func (u *AgentUpsert) SetCollectionID(v string) *AgentUpsert {
- u.Set(agent.FieldCollectionID, v)
- return u
- }
- // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
- func (u *AgentUpsert) UpdateCollectionID() *AgentUpsert {
- u.SetExcluded(agent.FieldCollectionID)
- 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.Agent.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(agent.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *AgentUpsertOne) UpdateNewValues() *AgentUpsertOne {
- 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(agent.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(agent.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Agent.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *AgentUpsertOne) Ignore() *AgentUpsertOne {
- 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 *AgentUpsertOne) DoNothing() *AgentUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the AgentCreate.OnConflict
- // documentation for more info.
- func (u *AgentUpsertOne) Update(set func(*AgentUpsert)) *AgentUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&AgentUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *AgentUpsertOne) SetUpdatedAt(v time.Time) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateUpdatedAt() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *AgentUpsertOne) SetDeletedAt(v time.Time) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateDeletedAt() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *AgentUpsertOne) ClearDeletedAt() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetName sets the "name" field.
- func (u *AgentUpsertOne) SetName(v string) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateName() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateName()
- })
- }
- // SetRole sets the "role" field.
- func (u *AgentUpsertOne) SetRole(v string) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetRole(v)
- })
- }
- // UpdateRole sets the "role" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateRole() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateRole()
- })
- }
- // SetStatus sets the "status" field.
- func (u *AgentUpsertOne) SetStatus(v int) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *AgentUpsertOne) AddStatus(v int) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateStatus() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *AgentUpsertOne) ClearStatus() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.ClearStatus()
- })
- }
- // SetBackground sets the "background" field.
- func (u *AgentUpsertOne) SetBackground(v string) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetBackground(v)
- })
- }
- // UpdateBackground sets the "background" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateBackground() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateBackground()
- })
- }
- // ClearBackground clears the value of the "background" field.
- func (u *AgentUpsertOne) ClearBackground() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.ClearBackground()
- })
- }
- // SetExamples sets the "examples" field.
- func (u *AgentUpsertOne) SetExamples(v string) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetExamples(v)
- })
- }
- // UpdateExamples sets the "examples" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateExamples() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateExamples()
- })
- }
- // ClearExamples clears the value of the "examples" field.
- func (u *AgentUpsertOne) ClearExamples() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.ClearExamples()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *AgentUpsertOne) SetOrganizationID(v uint64) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *AgentUpsertOne) AddOrganizationID(v uint64) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateOrganizationID() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // SetDatasetID sets the "dataset_id" field.
- func (u *AgentUpsertOne) SetDatasetID(v string) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetDatasetID(v)
- })
- }
- // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateDatasetID() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateDatasetID()
- })
- }
- // SetCollectionID sets the "collection_id" field.
- func (u *AgentUpsertOne) SetCollectionID(v string) *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.SetCollectionID(v)
- })
- }
- // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
- func (u *AgentUpsertOne) UpdateCollectionID() *AgentUpsertOne {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateCollectionID()
- })
- }
- // Exec executes the query.
- func (u *AgentUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for AgentCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *AgentUpsertOne) 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 *AgentUpsertOne) 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 *AgentUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // AgentCreateBulk is the builder for creating many Agent entities in bulk.
- type AgentCreateBulk struct {
- config
- err error
- builders []*AgentCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Agent entities in the database.
- func (acb *AgentCreateBulk) Save(ctx context.Context) ([]*Agent, error) {
- if acb.err != nil {
- return nil, acb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(acb.builders))
- nodes := make([]*Agent, len(acb.builders))
- mutators := make([]Mutator, len(acb.builders))
- for i := range acb.builders {
- func(i int, root context.Context) {
- builder := acb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*AgentMutation)
- 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, acb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = acb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, acb.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, acb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (acb *AgentCreateBulk) SaveX(ctx context.Context) []*Agent {
- v, err := acb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (acb *AgentCreateBulk) Exec(ctx context.Context) error {
- _, err := acb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (acb *AgentCreateBulk) ExecX(ctx context.Context) {
- if err := acb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Agent.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.AgentUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (acb *AgentCreateBulk) OnConflict(opts ...sql.ConflictOption) *AgentUpsertBulk {
- acb.conflict = opts
- return &AgentUpsertBulk{
- create: acb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Agent.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (acb *AgentCreateBulk) OnConflictColumns(columns ...string) *AgentUpsertBulk {
- acb.conflict = append(acb.conflict, sql.ConflictColumns(columns...))
- return &AgentUpsertBulk{
- create: acb,
- }
- }
- // AgentUpsertBulk is the builder for "upsert"-ing
- // a bulk of Agent nodes.
- type AgentUpsertBulk struct {
- create *AgentCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Agent.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(agent.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *AgentUpsertBulk) UpdateNewValues() *AgentUpsertBulk {
- 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(agent.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(agent.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Agent.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *AgentUpsertBulk) Ignore() *AgentUpsertBulk {
- 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 *AgentUpsertBulk) DoNothing() *AgentUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the AgentCreateBulk.OnConflict
- // documentation for more info.
- func (u *AgentUpsertBulk) Update(set func(*AgentUpsert)) *AgentUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&AgentUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *AgentUpsertBulk) SetUpdatedAt(v time.Time) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateUpdatedAt() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *AgentUpsertBulk) SetDeletedAt(v time.Time) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateDeletedAt() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *AgentUpsertBulk) ClearDeletedAt() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetName sets the "name" field.
- func (u *AgentUpsertBulk) SetName(v string) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetName(v)
- })
- }
- // UpdateName sets the "name" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateName() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateName()
- })
- }
- // SetRole sets the "role" field.
- func (u *AgentUpsertBulk) SetRole(v string) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetRole(v)
- })
- }
- // UpdateRole sets the "role" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateRole() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateRole()
- })
- }
- // SetStatus sets the "status" field.
- func (u *AgentUpsertBulk) SetStatus(v int) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *AgentUpsertBulk) AddStatus(v int) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateStatus() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *AgentUpsertBulk) ClearStatus() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.ClearStatus()
- })
- }
- // SetBackground sets the "background" field.
- func (u *AgentUpsertBulk) SetBackground(v string) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetBackground(v)
- })
- }
- // UpdateBackground sets the "background" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateBackground() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateBackground()
- })
- }
- // ClearBackground clears the value of the "background" field.
- func (u *AgentUpsertBulk) ClearBackground() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.ClearBackground()
- })
- }
- // SetExamples sets the "examples" field.
- func (u *AgentUpsertBulk) SetExamples(v string) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetExamples(v)
- })
- }
- // UpdateExamples sets the "examples" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateExamples() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateExamples()
- })
- }
- // ClearExamples clears the value of the "examples" field.
- func (u *AgentUpsertBulk) ClearExamples() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.ClearExamples()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *AgentUpsertBulk) SetOrganizationID(v uint64) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *AgentUpsertBulk) AddOrganizationID(v uint64) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateOrganizationID() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // SetDatasetID sets the "dataset_id" field.
- func (u *AgentUpsertBulk) SetDatasetID(v string) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetDatasetID(v)
- })
- }
- // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateDatasetID() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateDatasetID()
- })
- }
- // SetCollectionID sets the "collection_id" field.
- func (u *AgentUpsertBulk) SetCollectionID(v string) *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.SetCollectionID(v)
- })
- }
- // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
- func (u *AgentUpsertBulk) UpdateCollectionID() *AgentUpsertBulk {
- return u.Update(func(s *AgentUpsert) {
- s.UpdateCollectionID()
- })
- }
- // Exec executes the query.
- func (u *AgentUpsertBulk) 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 AgentCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for AgentCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *AgentUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|