|
@@ -0,0 +1,955 @@
|
|
|
+// Code generated by ent, DO NOT EDIT.
|
|
|
+
|
|
|
+package ent
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "time"
|
|
|
+ "wechat-api/ent/agent"
|
|
|
+
|
|
|
+ "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
|
|
|
+}
|
|
|
+
|
|
|
+// SetExamples sets the "examples" field.
|
|
|
+func (ac *AgentCreate) SetExamples(s string) *AgentCreate {
|
|
|
+ ac.mutation.SetExamples(s)
|
|
|
+ return ac
|
|
|
+}
|
|
|
+
|
|
|
+// SetID sets the "id" field.
|
|
|
+func (ac *AgentCreate) SetID(u uint64) *AgentCreate {
|
|
|
+ ac.mutation.SetID(u)
|
|
|
+ return ac
|
|
|
+}
|
|
|
+
|
|
|
+// 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)
|
|
|
+ }
|
|
|
+ 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.Role(); ok {
|
|
|
+ if err := agent.RoleValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "Agent.role": %w`, err)}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if _, ok := ac.mutation.Background(); !ok {
|
|
|
+ return &ValidationError{Name: "background", err: errors.New(`ent: missing required field "Agent.background"`)}
|
|
|
+ }
|
|
|
+ if v, ok := ac.mutation.Background(); ok {
|
|
|
+ if err := agent.BackgroundValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "background", err: fmt.Errorf(`ent: validator failed for field "Agent.background": %w`, err)}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if _, ok := ac.mutation.Examples(); !ok {
|
|
|
+ return &ValidationError{Name: "examples", err: errors.New(`ent: missing required field "Agent.examples"`)}
|
|
|
+ }
|
|
|
+ if v, ok := ac.mutation.Examples(); ok {
|
|
|
+ if err := agent.ExamplesValidator(v); err != nil {
|
|
|
+ return &ValidationError{Name: "examples", err: fmt.Errorf(`ent: validator failed for field "Agent.examples": %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
|
|
|
+ }
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
+// 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
|
|
|
+}
|
|
|
+
|
|
|
+// 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()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 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()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 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()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 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()
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 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)
|
|
|
+ }
|
|
|
+}
|