123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "wechat-api/ent/agentbase"
- "wechat-api/ent/predicate"
- "wechat-api/ent/wx"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/dialect/sql/sqljson"
- "entgo.io/ent/schema/field"
- )
- // AgentBaseUpdate is the builder for updating AgentBase entities.
- type AgentBaseUpdate struct {
- config
- hooks []Hook
- mutation *AgentBaseMutation
- }
- // Where appends a list predicates to the AgentBaseUpdate builder.
- func (abu *AgentBaseUpdate) Where(ps ...predicate.AgentBase) *AgentBaseUpdate {
- abu.mutation.Where(ps...)
- return abu
- }
- // SetQ sets the "q" field.
- func (abu *AgentBaseUpdate) SetQ(s string) *AgentBaseUpdate {
- abu.mutation.SetQ(s)
- return abu
- }
- // SetNillableQ sets the "q" field if the given value is not nil.
- func (abu *AgentBaseUpdate) SetNillableQ(s *string) *AgentBaseUpdate {
- if s != nil {
- abu.SetQ(*s)
- }
- return abu
- }
- // ClearQ clears the value of the "q" field.
- func (abu *AgentBaseUpdate) ClearQ() *AgentBaseUpdate {
- abu.mutation.ClearQ()
- return abu
- }
- // SetA sets the "a" field.
- func (abu *AgentBaseUpdate) SetA(s string) *AgentBaseUpdate {
- abu.mutation.SetA(s)
- return abu
- }
- // SetNillableA sets the "a" field if the given value is not nil.
- func (abu *AgentBaseUpdate) SetNillableA(s *string) *AgentBaseUpdate {
- if s != nil {
- abu.SetA(*s)
- }
- return abu
- }
- // ClearA clears the value of the "a" field.
- func (abu *AgentBaseUpdate) ClearA() *AgentBaseUpdate {
- abu.mutation.ClearA()
- return abu
- }
- // SetChunkIndex sets the "chunk_index" field.
- func (abu *AgentBaseUpdate) SetChunkIndex(u uint64) *AgentBaseUpdate {
- abu.mutation.ResetChunkIndex()
- abu.mutation.SetChunkIndex(u)
- return abu
- }
- // SetNillableChunkIndex sets the "chunk_index" field if the given value is not nil.
- func (abu *AgentBaseUpdate) SetNillableChunkIndex(u *uint64) *AgentBaseUpdate {
- if u != nil {
- abu.SetChunkIndex(*u)
- }
- return abu
- }
- // AddChunkIndex adds u to the "chunk_index" field.
- func (abu *AgentBaseUpdate) AddChunkIndex(u int64) *AgentBaseUpdate {
- abu.mutation.AddChunkIndex(u)
- return abu
- }
- // SetIndexes sets the "indexes" field.
- func (abu *AgentBaseUpdate) SetIndexes(s []string) *AgentBaseUpdate {
- abu.mutation.SetIndexes(s)
- return abu
- }
- // AppendIndexes appends s to the "indexes" field.
- func (abu *AgentBaseUpdate) AppendIndexes(s []string) *AgentBaseUpdate {
- abu.mutation.AppendIndexes(s)
- return abu
- }
- // ClearIndexes clears the value of the "indexes" field.
- func (abu *AgentBaseUpdate) ClearIndexes() *AgentBaseUpdate {
- abu.mutation.ClearIndexes()
- return abu
- }
- // SetDatasetID sets the "dataset_id" field.
- func (abu *AgentBaseUpdate) SetDatasetID(s string) *AgentBaseUpdate {
- abu.mutation.SetDatasetID(s)
- return abu
- }
- // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
- func (abu *AgentBaseUpdate) SetNillableDatasetID(s *string) *AgentBaseUpdate {
- if s != nil {
- abu.SetDatasetID(*s)
- }
- return abu
- }
- // ClearDatasetID clears the value of the "dataset_id" field.
- func (abu *AgentBaseUpdate) ClearDatasetID() *AgentBaseUpdate {
- abu.mutation.ClearDatasetID()
- return abu
- }
- // SetCollectionID sets the "collection_id" field.
- func (abu *AgentBaseUpdate) SetCollectionID(s string) *AgentBaseUpdate {
- abu.mutation.SetCollectionID(s)
- return abu
- }
- // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
- func (abu *AgentBaseUpdate) SetNillableCollectionID(s *string) *AgentBaseUpdate {
- if s != nil {
- abu.SetCollectionID(*s)
- }
- return abu
- }
- // ClearCollectionID clears the value of the "collection_id" field.
- func (abu *AgentBaseUpdate) ClearCollectionID() *AgentBaseUpdate {
- abu.mutation.ClearCollectionID()
- return abu
- }
- // SetSourceName sets the "source_name" field.
- func (abu *AgentBaseUpdate) SetSourceName(s string) *AgentBaseUpdate {
- abu.mutation.SetSourceName(s)
- return abu
- }
- // SetNillableSourceName sets the "source_name" field if the given value is not nil.
- func (abu *AgentBaseUpdate) SetNillableSourceName(s *string) *AgentBaseUpdate {
- if s != nil {
- abu.SetSourceName(*s)
- }
- return abu
- }
- // ClearSourceName clears the value of the "source_name" field.
- func (abu *AgentBaseUpdate) ClearSourceName() *AgentBaseUpdate {
- abu.mutation.ClearSourceName()
- return abu
- }
- // SetCanWrite sets the "can_write" field.
- func (abu *AgentBaseUpdate) SetCanWrite(b []bool) *AgentBaseUpdate {
- abu.mutation.SetCanWrite(b)
- return abu
- }
- // AppendCanWrite appends b to the "can_write" field.
- func (abu *AgentBaseUpdate) AppendCanWrite(b []bool) *AgentBaseUpdate {
- abu.mutation.AppendCanWrite(b)
- return abu
- }
- // ClearCanWrite clears the value of the "can_write" field.
- func (abu *AgentBaseUpdate) ClearCanWrite() *AgentBaseUpdate {
- abu.mutation.ClearCanWrite()
- return abu
- }
- // SetIsOwner sets the "is_owner" field.
- func (abu *AgentBaseUpdate) SetIsOwner(b []bool) *AgentBaseUpdate {
- abu.mutation.SetIsOwner(b)
- return abu
- }
- // AppendIsOwner appends b to the "is_owner" field.
- func (abu *AgentBaseUpdate) AppendIsOwner(b []bool) *AgentBaseUpdate {
- abu.mutation.AppendIsOwner(b)
- return abu
- }
- // ClearIsOwner clears the value of the "is_owner" field.
- func (abu *AgentBaseUpdate) ClearIsOwner() *AgentBaseUpdate {
- abu.mutation.ClearIsOwner()
- return abu
- }
- // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
- func (abu *AgentBaseUpdate) AddWxAgentIDs(ids ...uint64) *AgentBaseUpdate {
- abu.mutation.AddWxAgentIDs(ids...)
- return abu
- }
- // AddWxAgent adds the "wx_agent" edges to the Wx entity.
- func (abu *AgentBaseUpdate) AddWxAgent(w ...*Wx) *AgentBaseUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return abu.AddWxAgentIDs(ids...)
- }
- // Mutation returns the AgentBaseMutation object of the builder.
- func (abu *AgentBaseUpdate) Mutation() *AgentBaseMutation {
- return abu.mutation
- }
- // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
- func (abu *AgentBaseUpdate) ClearWxAgent() *AgentBaseUpdate {
- abu.mutation.ClearWxAgent()
- return abu
- }
- // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
- func (abu *AgentBaseUpdate) RemoveWxAgentIDs(ids ...uint64) *AgentBaseUpdate {
- abu.mutation.RemoveWxAgentIDs(ids...)
- return abu
- }
- // RemoveWxAgent removes "wx_agent" edges to Wx entities.
- func (abu *AgentBaseUpdate) RemoveWxAgent(w ...*Wx) *AgentBaseUpdate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return abu.RemoveWxAgentIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (abu *AgentBaseUpdate) Save(ctx context.Context) (int, error) {
- return withHooks(ctx, abu.sqlSave, abu.mutation, abu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (abu *AgentBaseUpdate) SaveX(ctx context.Context) int {
- affected, err := abu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (abu *AgentBaseUpdate) Exec(ctx context.Context) error {
- _, err := abu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (abu *AgentBaseUpdate) ExecX(ctx context.Context) {
- if err := abu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (abu *AgentBaseUpdate) check() error {
- if v, ok := abu.mutation.ChunkIndex(); ok {
- if err := agentbase.ChunkIndexValidator(v); err != nil {
- return &ValidationError{Name: "chunk_index", err: fmt.Errorf(`ent: validator failed for field "AgentBase.chunk_index": %w`, err)}
- }
- }
- return nil
- }
- func (abu *AgentBaseUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := abu.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(agentbase.Table, agentbase.Columns, sqlgraph.NewFieldSpec(agentbase.FieldID, field.TypeString))
- if ps := abu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := abu.mutation.Q(); ok {
- _spec.SetField(agentbase.FieldQ, field.TypeString, value)
- }
- if abu.mutation.QCleared() {
- _spec.ClearField(agentbase.FieldQ, field.TypeString)
- }
- if value, ok := abu.mutation.A(); ok {
- _spec.SetField(agentbase.FieldA, field.TypeString, value)
- }
- if abu.mutation.ACleared() {
- _spec.ClearField(agentbase.FieldA, field.TypeString)
- }
- if value, ok := abu.mutation.ChunkIndex(); ok {
- _spec.SetField(agentbase.FieldChunkIndex, field.TypeUint64, value)
- }
- if value, ok := abu.mutation.AddedChunkIndex(); ok {
- _spec.AddField(agentbase.FieldChunkIndex, field.TypeUint64, value)
- }
- if value, ok := abu.mutation.Indexes(); ok {
- _spec.SetField(agentbase.FieldIndexes, field.TypeJSON, value)
- }
- if value, ok := abu.mutation.AppendedIndexes(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, agentbase.FieldIndexes, value)
- })
- }
- if abu.mutation.IndexesCleared() {
- _spec.ClearField(agentbase.FieldIndexes, field.TypeJSON)
- }
- if value, ok := abu.mutation.DatasetID(); ok {
- _spec.SetField(agentbase.FieldDatasetID, field.TypeString, value)
- }
- if abu.mutation.DatasetIDCleared() {
- _spec.ClearField(agentbase.FieldDatasetID, field.TypeString)
- }
- if value, ok := abu.mutation.CollectionID(); ok {
- _spec.SetField(agentbase.FieldCollectionID, field.TypeString, value)
- }
- if abu.mutation.CollectionIDCleared() {
- _spec.ClearField(agentbase.FieldCollectionID, field.TypeString)
- }
- if value, ok := abu.mutation.SourceName(); ok {
- _spec.SetField(agentbase.FieldSourceName, field.TypeString, value)
- }
- if abu.mutation.SourceNameCleared() {
- _spec.ClearField(agentbase.FieldSourceName, field.TypeString)
- }
- if value, ok := abu.mutation.CanWrite(); ok {
- _spec.SetField(agentbase.FieldCanWrite, field.TypeJSON, value)
- }
- if value, ok := abu.mutation.AppendedCanWrite(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, agentbase.FieldCanWrite, value)
- })
- }
- if abu.mutation.CanWriteCleared() {
- _spec.ClearField(agentbase.FieldCanWrite, field.TypeJSON)
- }
- if value, ok := abu.mutation.IsOwner(); ok {
- _spec.SetField(agentbase.FieldIsOwner, field.TypeJSON, value)
- }
- if value, ok := abu.mutation.AppendedIsOwner(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, agentbase.FieldIsOwner, value)
- })
- }
- if abu.mutation.IsOwnerCleared() {
- _spec.ClearField(agentbase.FieldIsOwner, field.TypeJSON)
- }
- if abu.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agentbase.WxAgentTable,
- Columns: []string{agentbase.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := abu.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !abu.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agentbase.WxAgentTable,
- Columns: []string{agentbase.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.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := abu.mutation.WxAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agentbase.WxAgentTable,
- Columns: []string{agentbase.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.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, abu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{agentbase.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- abu.mutation.done = true
- return n, nil
- }
- // AgentBaseUpdateOne is the builder for updating a single AgentBase entity.
- type AgentBaseUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *AgentBaseMutation
- }
- // SetQ sets the "q" field.
- func (abuo *AgentBaseUpdateOne) SetQ(s string) *AgentBaseUpdateOne {
- abuo.mutation.SetQ(s)
- return abuo
- }
- // SetNillableQ sets the "q" field if the given value is not nil.
- func (abuo *AgentBaseUpdateOne) SetNillableQ(s *string) *AgentBaseUpdateOne {
- if s != nil {
- abuo.SetQ(*s)
- }
- return abuo
- }
- // ClearQ clears the value of the "q" field.
- func (abuo *AgentBaseUpdateOne) ClearQ() *AgentBaseUpdateOne {
- abuo.mutation.ClearQ()
- return abuo
- }
- // SetA sets the "a" field.
- func (abuo *AgentBaseUpdateOne) SetA(s string) *AgentBaseUpdateOne {
- abuo.mutation.SetA(s)
- return abuo
- }
- // SetNillableA sets the "a" field if the given value is not nil.
- func (abuo *AgentBaseUpdateOne) SetNillableA(s *string) *AgentBaseUpdateOne {
- if s != nil {
- abuo.SetA(*s)
- }
- return abuo
- }
- // ClearA clears the value of the "a" field.
- func (abuo *AgentBaseUpdateOne) ClearA() *AgentBaseUpdateOne {
- abuo.mutation.ClearA()
- return abuo
- }
- // SetChunkIndex sets the "chunk_index" field.
- func (abuo *AgentBaseUpdateOne) SetChunkIndex(u uint64) *AgentBaseUpdateOne {
- abuo.mutation.ResetChunkIndex()
- abuo.mutation.SetChunkIndex(u)
- return abuo
- }
- // SetNillableChunkIndex sets the "chunk_index" field if the given value is not nil.
- func (abuo *AgentBaseUpdateOne) SetNillableChunkIndex(u *uint64) *AgentBaseUpdateOne {
- if u != nil {
- abuo.SetChunkIndex(*u)
- }
- return abuo
- }
- // AddChunkIndex adds u to the "chunk_index" field.
- func (abuo *AgentBaseUpdateOne) AddChunkIndex(u int64) *AgentBaseUpdateOne {
- abuo.mutation.AddChunkIndex(u)
- return abuo
- }
- // SetIndexes sets the "indexes" field.
- func (abuo *AgentBaseUpdateOne) SetIndexes(s []string) *AgentBaseUpdateOne {
- abuo.mutation.SetIndexes(s)
- return abuo
- }
- // AppendIndexes appends s to the "indexes" field.
- func (abuo *AgentBaseUpdateOne) AppendIndexes(s []string) *AgentBaseUpdateOne {
- abuo.mutation.AppendIndexes(s)
- return abuo
- }
- // ClearIndexes clears the value of the "indexes" field.
- func (abuo *AgentBaseUpdateOne) ClearIndexes() *AgentBaseUpdateOne {
- abuo.mutation.ClearIndexes()
- return abuo
- }
- // SetDatasetID sets the "dataset_id" field.
- func (abuo *AgentBaseUpdateOne) SetDatasetID(s string) *AgentBaseUpdateOne {
- abuo.mutation.SetDatasetID(s)
- return abuo
- }
- // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
- func (abuo *AgentBaseUpdateOne) SetNillableDatasetID(s *string) *AgentBaseUpdateOne {
- if s != nil {
- abuo.SetDatasetID(*s)
- }
- return abuo
- }
- // ClearDatasetID clears the value of the "dataset_id" field.
- func (abuo *AgentBaseUpdateOne) ClearDatasetID() *AgentBaseUpdateOne {
- abuo.mutation.ClearDatasetID()
- return abuo
- }
- // SetCollectionID sets the "collection_id" field.
- func (abuo *AgentBaseUpdateOne) SetCollectionID(s string) *AgentBaseUpdateOne {
- abuo.mutation.SetCollectionID(s)
- return abuo
- }
- // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
- func (abuo *AgentBaseUpdateOne) SetNillableCollectionID(s *string) *AgentBaseUpdateOne {
- if s != nil {
- abuo.SetCollectionID(*s)
- }
- return abuo
- }
- // ClearCollectionID clears the value of the "collection_id" field.
- func (abuo *AgentBaseUpdateOne) ClearCollectionID() *AgentBaseUpdateOne {
- abuo.mutation.ClearCollectionID()
- return abuo
- }
- // SetSourceName sets the "source_name" field.
- func (abuo *AgentBaseUpdateOne) SetSourceName(s string) *AgentBaseUpdateOne {
- abuo.mutation.SetSourceName(s)
- return abuo
- }
- // SetNillableSourceName sets the "source_name" field if the given value is not nil.
- func (abuo *AgentBaseUpdateOne) SetNillableSourceName(s *string) *AgentBaseUpdateOne {
- if s != nil {
- abuo.SetSourceName(*s)
- }
- return abuo
- }
- // ClearSourceName clears the value of the "source_name" field.
- func (abuo *AgentBaseUpdateOne) ClearSourceName() *AgentBaseUpdateOne {
- abuo.mutation.ClearSourceName()
- return abuo
- }
- // SetCanWrite sets the "can_write" field.
- func (abuo *AgentBaseUpdateOne) SetCanWrite(b []bool) *AgentBaseUpdateOne {
- abuo.mutation.SetCanWrite(b)
- return abuo
- }
- // AppendCanWrite appends b to the "can_write" field.
- func (abuo *AgentBaseUpdateOne) AppendCanWrite(b []bool) *AgentBaseUpdateOne {
- abuo.mutation.AppendCanWrite(b)
- return abuo
- }
- // ClearCanWrite clears the value of the "can_write" field.
- func (abuo *AgentBaseUpdateOne) ClearCanWrite() *AgentBaseUpdateOne {
- abuo.mutation.ClearCanWrite()
- return abuo
- }
- // SetIsOwner sets the "is_owner" field.
- func (abuo *AgentBaseUpdateOne) SetIsOwner(b []bool) *AgentBaseUpdateOne {
- abuo.mutation.SetIsOwner(b)
- return abuo
- }
- // AppendIsOwner appends b to the "is_owner" field.
- func (abuo *AgentBaseUpdateOne) AppendIsOwner(b []bool) *AgentBaseUpdateOne {
- abuo.mutation.AppendIsOwner(b)
- return abuo
- }
- // ClearIsOwner clears the value of the "is_owner" field.
- func (abuo *AgentBaseUpdateOne) ClearIsOwner() *AgentBaseUpdateOne {
- abuo.mutation.ClearIsOwner()
- return abuo
- }
- // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
- func (abuo *AgentBaseUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentBaseUpdateOne {
- abuo.mutation.AddWxAgentIDs(ids...)
- return abuo
- }
- // AddWxAgent adds the "wx_agent" edges to the Wx entity.
- func (abuo *AgentBaseUpdateOne) AddWxAgent(w ...*Wx) *AgentBaseUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return abuo.AddWxAgentIDs(ids...)
- }
- // Mutation returns the AgentBaseMutation object of the builder.
- func (abuo *AgentBaseUpdateOne) Mutation() *AgentBaseMutation {
- return abuo.mutation
- }
- // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
- func (abuo *AgentBaseUpdateOne) ClearWxAgent() *AgentBaseUpdateOne {
- abuo.mutation.ClearWxAgent()
- return abuo
- }
- // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
- func (abuo *AgentBaseUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentBaseUpdateOne {
- abuo.mutation.RemoveWxAgentIDs(ids...)
- return abuo
- }
- // RemoveWxAgent removes "wx_agent" edges to Wx entities.
- func (abuo *AgentBaseUpdateOne) RemoveWxAgent(w ...*Wx) *AgentBaseUpdateOne {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return abuo.RemoveWxAgentIDs(ids...)
- }
- // Where appends a list predicates to the AgentBaseUpdate builder.
- func (abuo *AgentBaseUpdateOne) Where(ps ...predicate.AgentBase) *AgentBaseUpdateOne {
- abuo.mutation.Where(ps...)
- return abuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (abuo *AgentBaseUpdateOne) Select(field string, fields ...string) *AgentBaseUpdateOne {
- abuo.fields = append([]string{field}, fields...)
- return abuo
- }
- // Save executes the query and returns the updated AgentBase entity.
- func (abuo *AgentBaseUpdateOne) Save(ctx context.Context) (*AgentBase, error) {
- return withHooks(ctx, abuo.sqlSave, abuo.mutation, abuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (abuo *AgentBaseUpdateOne) SaveX(ctx context.Context) *AgentBase {
- node, err := abuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (abuo *AgentBaseUpdateOne) Exec(ctx context.Context) error {
- _, err := abuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (abuo *AgentBaseUpdateOne) ExecX(ctx context.Context) {
- if err := abuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (abuo *AgentBaseUpdateOne) check() error {
- if v, ok := abuo.mutation.ChunkIndex(); ok {
- if err := agentbase.ChunkIndexValidator(v); err != nil {
- return &ValidationError{Name: "chunk_index", err: fmt.Errorf(`ent: validator failed for field "AgentBase.chunk_index": %w`, err)}
- }
- }
- return nil
- }
- func (abuo *AgentBaseUpdateOne) sqlSave(ctx context.Context) (_node *AgentBase, err error) {
- if err := abuo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(agentbase.Table, agentbase.Columns, sqlgraph.NewFieldSpec(agentbase.FieldID, field.TypeString))
- id, ok := abuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgentBase.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := abuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, agentbase.FieldID)
- for _, f := range fields {
- if !agentbase.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != agentbase.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := abuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := abuo.mutation.Q(); ok {
- _spec.SetField(agentbase.FieldQ, field.TypeString, value)
- }
- if abuo.mutation.QCleared() {
- _spec.ClearField(agentbase.FieldQ, field.TypeString)
- }
- if value, ok := abuo.mutation.A(); ok {
- _spec.SetField(agentbase.FieldA, field.TypeString, value)
- }
- if abuo.mutation.ACleared() {
- _spec.ClearField(agentbase.FieldA, field.TypeString)
- }
- if value, ok := abuo.mutation.ChunkIndex(); ok {
- _spec.SetField(agentbase.FieldChunkIndex, field.TypeUint64, value)
- }
- if value, ok := abuo.mutation.AddedChunkIndex(); ok {
- _spec.AddField(agentbase.FieldChunkIndex, field.TypeUint64, value)
- }
- if value, ok := abuo.mutation.Indexes(); ok {
- _spec.SetField(agentbase.FieldIndexes, field.TypeJSON, value)
- }
- if value, ok := abuo.mutation.AppendedIndexes(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, agentbase.FieldIndexes, value)
- })
- }
- if abuo.mutation.IndexesCleared() {
- _spec.ClearField(agentbase.FieldIndexes, field.TypeJSON)
- }
- if value, ok := abuo.mutation.DatasetID(); ok {
- _spec.SetField(agentbase.FieldDatasetID, field.TypeString, value)
- }
- if abuo.mutation.DatasetIDCleared() {
- _spec.ClearField(agentbase.FieldDatasetID, field.TypeString)
- }
- if value, ok := abuo.mutation.CollectionID(); ok {
- _spec.SetField(agentbase.FieldCollectionID, field.TypeString, value)
- }
- if abuo.mutation.CollectionIDCleared() {
- _spec.ClearField(agentbase.FieldCollectionID, field.TypeString)
- }
- if value, ok := abuo.mutation.SourceName(); ok {
- _spec.SetField(agentbase.FieldSourceName, field.TypeString, value)
- }
- if abuo.mutation.SourceNameCleared() {
- _spec.ClearField(agentbase.FieldSourceName, field.TypeString)
- }
- if value, ok := abuo.mutation.CanWrite(); ok {
- _spec.SetField(agentbase.FieldCanWrite, field.TypeJSON, value)
- }
- if value, ok := abuo.mutation.AppendedCanWrite(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, agentbase.FieldCanWrite, value)
- })
- }
- if abuo.mutation.CanWriteCleared() {
- _spec.ClearField(agentbase.FieldCanWrite, field.TypeJSON)
- }
- if value, ok := abuo.mutation.IsOwner(); ok {
- _spec.SetField(agentbase.FieldIsOwner, field.TypeJSON, value)
- }
- if value, ok := abuo.mutation.AppendedIsOwner(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, agentbase.FieldIsOwner, value)
- })
- }
- if abuo.mutation.IsOwnerCleared() {
- _spec.ClearField(agentbase.FieldIsOwner, field.TypeJSON)
- }
- if abuo.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agentbase.WxAgentTable,
- Columns: []string{agentbase.WxAgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := abuo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !abuo.mutation.WxAgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agentbase.WxAgentTable,
- Columns: []string{agentbase.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.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := abuo.mutation.WxAgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: agentbase.WxAgentTable,
- Columns: []string{agentbase.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.Add = append(_spec.Edges.Add, edge)
- }
- _node = &AgentBase{config: abuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, abuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{agentbase.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- abuo.mutation.done = true
- return _node, nil
- }
|