12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "wechat-api/ent/agentbase"
- "wechat-api/ent/wx"
- "entgo.io/ent/dialect"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // AgentBaseCreate is the builder for creating a AgentBase entity.
- type AgentBaseCreate struct {
- config
- mutation *AgentBaseMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetQ sets the "q" field.
- func (abc *AgentBaseCreate) SetQ(s string) *AgentBaseCreate {
- abc.mutation.SetQ(s)
- return abc
- }
- // SetNillableQ sets the "q" field if the given value is not nil.
- func (abc *AgentBaseCreate) SetNillableQ(s *string) *AgentBaseCreate {
- if s != nil {
- abc.SetQ(*s)
- }
- return abc
- }
- // SetA sets the "a" field.
- func (abc *AgentBaseCreate) SetA(s string) *AgentBaseCreate {
- abc.mutation.SetA(s)
- return abc
- }
- // SetNillableA sets the "a" field if the given value is not nil.
- func (abc *AgentBaseCreate) SetNillableA(s *string) *AgentBaseCreate {
- if s != nil {
- abc.SetA(*s)
- }
- return abc
- }
- // SetChunkIndex sets the "chunk_index" field.
- func (abc *AgentBaseCreate) SetChunkIndex(u uint64) *AgentBaseCreate {
- abc.mutation.SetChunkIndex(u)
- return abc
- }
- // SetIndexes sets the "indexes" field.
- func (abc *AgentBaseCreate) SetIndexes(s []string) *AgentBaseCreate {
- abc.mutation.SetIndexes(s)
- return abc
- }
- // SetDatasetID sets the "dataset_id" field.
- func (abc *AgentBaseCreate) SetDatasetID(s string) *AgentBaseCreate {
- abc.mutation.SetDatasetID(s)
- return abc
- }
- // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
- func (abc *AgentBaseCreate) SetNillableDatasetID(s *string) *AgentBaseCreate {
- if s != nil {
- abc.SetDatasetID(*s)
- }
- return abc
- }
- // SetCollectionID sets the "collection_id" field.
- func (abc *AgentBaseCreate) SetCollectionID(s string) *AgentBaseCreate {
- abc.mutation.SetCollectionID(s)
- return abc
- }
- // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
- func (abc *AgentBaseCreate) SetNillableCollectionID(s *string) *AgentBaseCreate {
- if s != nil {
- abc.SetCollectionID(*s)
- }
- return abc
- }
- // SetSourceName sets the "source_name" field.
- func (abc *AgentBaseCreate) SetSourceName(s string) *AgentBaseCreate {
- abc.mutation.SetSourceName(s)
- return abc
- }
- // SetNillableSourceName sets the "source_name" field if the given value is not nil.
- func (abc *AgentBaseCreate) SetNillableSourceName(s *string) *AgentBaseCreate {
- if s != nil {
- abc.SetSourceName(*s)
- }
- return abc
- }
- // SetCanWrite sets the "can_write" field.
- func (abc *AgentBaseCreate) SetCanWrite(b []bool) *AgentBaseCreate {
- abc.mutation.SetCanWrite(b)
- return abc
- }
- // SetIsOwner sets the "is_owner" field.
- func (abc *AgentBaseCreate) SetIsOwner(b []bool) *AgentBaseCreate {
- abc.mutation.SetIsOwner(b)
- return abc
- }
- // SetID sets the "id" field.
- func (abc *AgentBaseCreate) SetID(s string) *AgentBaseCreate {
- abc.mutation.SetID(s)
- return abc
- }
- // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
- func (abc *AgentBaseCreate) AddWxAgentIDs(ids ...uint64) *AgentBaseCreate {
- abc.mutation.AddWxAgentIDs(ids...)
- return abc
- }
- // AddWxAgent adds the "wx_agent" edges to the Wx entity.
- func (abc *AgentBaseCreate) AddWxAgent(w ...*Wx) *AgentBaseCreate {
- ids := make([]uint64, len(w))
- for i := range w {
- ids[i] = w[i].ID
- }
- return abc.AddWxAgentIDs(ids...)
- }
- // Mutation returns the AgentBaseMutation object of the builder.
- func (abc *AgentBaseCreate) Mutation() *AgentBaseMutation {
- return abc.mutation
- }
- // Save creates the AgentBase in the database.
- func (abc *AgentBaseCreate) Save(ctx context.Context) (*AgentBase, error) {
- abc.defaults()
- return withHooks(ctx, abc.sqlSave, abc.mutation, abc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (abc *AgentBaseCreate) SaveX(ctx context.Context) *AgentBase {
- v, err := abc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (abc *AgentBaseCreate) Exec(ctx context.Context) error {
- _, err := abc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (abc *AgentBaseCreate) ExecX(ctx context.Context) {
- if err := abc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (abc *AgentBaseCreate) defaults() {
- if _, ok := abc.mutation.Q(); !ok {
- v := agentbase.DefaultQ
- abc.mutation.SetQ(v)
- }
- if _, ok := abc.mutation.A(); !ok {
- v := agentbase.DefaultA
- abc.mutation.SetA(v)
- }
- if _, ok := abc.mutation.DatasetID(); !ok {
- v := agentbase.DefaultDatasetID
- abc.mutation.SetDatasetID(v)
- }
- if _, ok := abc.mutation.CollectionID(); !ok {
- v := agentbase.DefaultCollectionID
- abc.mutation.SetCollectionID(v)
- }
- if _, ok := abc.mutation.SourceName(); !ok {
- v := agentbase.DefaultSourceName
- abc.mutation.SetSourceName(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (abc *AgentBaseCreate) check() error {
- if _, ok := abc.mutation.ChunkIndex(); !ok {
- return &ValidationError{Name: "chunk_index", err: errors.New(`ent: missing required field "AgentBase.chunk_index"`)}
- }
- if v, ok := abc.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 (abc *AgentBaseCreate) sqlSave(ctx context.Context) (*AgentBase, error) {
- if err := abc.check(); err != nil {
- return nil, err
- }
- _node, _spec := abc.createSpec()
- if err := sqlgraph.CreateNode(ctx, abc.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- if _spec.ID.Value != nil {
- if id, ok := _spec.ID.Value.(string); ok {
- _node.ID = id
- } else {
- return nil, fmt.Errorf("unexpected AgentBase.ID type: %T", _spec.ID.Value)
- }
- }
- abc.mutation.id = &_node.ID
- abc.mutation.done = true
- return _node, nil
- }
- func (abc *AgentBaseCreate) createSpec() (*AgentBase, *sqlgraph.CreateSpec) {
- var (
- _node = &AgentBase{config: abc.config}
- _spec = sqlgraph.NewCreateSpec(agentbase.Table, sqlgraph.NewFieldSpec(agentbase.FieldID, field.TypeString))
- )
- _spec.OnConflict = abc.conflict
- if id, ok := abc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := abc.mutation.Q(); ok {
- _spec.SetField(agentbase.FieldQ, field.TypeString, value)
- _node.Q = value
- }
- if value, ok := abc.mutation.A(); ok {
- _spec.SetField(agentbase.FieldA, field.TypeString, value)
- _node.A = value
- }
- if value, ok := abc.mutation.ChunkIndex(); ok {
- _spec.SetField(agentbase.FieldChunkIndex, field.TypeUint64, value)
- _node.ChunkIndex = value
- }
- if value, ok := abc.mutation.Indexes(); ok {
- _spec.SetField(agentbase.FieldIndexes, field.TypeJSON, value)
- _node.Indexes = value
- }
- if value, ok := abc.mutation.DatasetID(); ok {
- _spec.SetField(agentbase.FieldDatasetID, field.TypeString, value)
- _node.DatasetID = value
- }
- if value, ok := abc.mutation.CollectionID(); ok {
- _spec.SetField(agentbase.FieldCollectionID, field.TypeString, value)
- _node.CollectionID = value
- }
- if value, ok := abc.mutation.SourceName(); ok {
- _spec.SetField(agentbase.FieldSourceName, field.TypeString, value)
- _node.SourceName = value
- }
- if value, ok := abc.mutation.CanWrite(); ok {
- _spec.SetField(agentbase.FieldCanWrite, field.TypeJSON, value)
- _node.CanWrite = value
- }
- if value, ok := abc.mutation.IsOwner(); ok {
- _spec.SetField(agentbase.FieldIsOwner, field.TypeJSON, value)
- _node.IsOwner = value
- }
- if nodes := abc.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 = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.AgentBase.Create().
- // SetQ(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.AgentBaseUpsert) {
- // SetQ(v+v).
- // }).
- // Exec(ctx)
- func (abc *AgentBaseCreate) OnConflict(opts ...sql.ConflictOption) *AgentBaseUpsertOne {
- abc.conflict = opts
- return &AgentBaseUpsertOne{
- create: abc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.AgentBase.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (abc *AgentBaseCreate) OnConflictColumns(columns ...string) *AgentBaseUpsertOne {
- abc.conflict = append(abc.conflict, sql.ConflictColumns(columns...))
- return &AgentBaseUpsertOne{
- create: abc,
- }
- }
- type (
- // AgentBaseUpsertOne is the builder for "upsert"-ing
- // one AgentBase node.
- AgentBaseUpsertOne struct {
- create *AgentBaseCreate
- }
- // AgentBaseUpsert is the "OnConflict" setter.
- AgentBaseUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetQ sets the "q" field.
- func (u *AgentBaseUpsert) SetQ(v string) *AgentBaseUpsert {
- u.Set(agentbase.FieldQ, v)
- return u
- }
- // UpdateQ sets the "q" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateQ() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldQ)
- return u
- }
- // ClearQ clears the value of the "q" field.
- func (u *AgentBaseUpsert) ClearQ() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldQ)
- return u
- }
- // SetA sets the "a" field.
- func (u *AgentBaseUpsert) SetA(v string) *AgentBaseUpsert {
- u.Set(agentbase.FieldA, v)
- return u
- }
- // UpdateA sets the "a" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateA() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldA)
- return u
- }
- // ClearA clears the value of the "a" field.
- func (u *AgentBaseUpsert) ClearA() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldA)
- return u
- }
- // SetChunkIndex sets the "chunk_index" field.
- func (u *AgentBaseUpsert) SetChunkIndex(v uint64) *AgentBaseUpsert {
- u.Set(agentbase.FieldChunkIndex, v)
- return u
- }
- // UpdateChunkIndex sets the "chunk_index" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateChunkIndex() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldChunkIndex)
- return u
- }
- // AddChunkIndex adds v to the "chunk_index" field.
- func (u *AgentBaseUpsert) AddChunkIndex(v uint64) *AgentBaseUpsert {
- u.Add(agentbase.FieldChunkIndex, v)
- return u
- }
- // SetIndexes sets the "indexes" field.
- func (u *AgentBaseUpsert) SetIndexes(v []string) *AgentBaseUpsert {
- u.Set(agentbase.FieldIndexes, v)
- return u
- }
- // UpdateIndexes sets the "indexes" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateIndexes() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldIndexes)
- return u
- }
- // ClearIndexes clears the value of the "indexes" field.
- func (u *AgentBaseUpsert) ClearIndexes() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldIndexes)
- return u
- }
- // SetDatasetID sets the "dataset_id" field.
- func (u *AgentBaseUpsert) SetDatasetID(v string) *AgentBaseUpsert {
- u.Set(agentbase.FieldDatasetID, v)
- return u
- }
- // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateDatasetID() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldDatasetID)
- return u
- }
- // ClearDatasetID clears the value of the "dataset_id" field.
- func (u *AgentBaseUpsert) ClearDatasetID() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldDatasetID)
- return u
- }
- // SetCollectionID sets the "collection_id" field.
- func (u *AgentBaseUpsert) SetCollectionID(v string) *AgentBaseUpsert {
- u.Set(agentbase.FieldCollectionID, v)
- return u
- }
- // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateCollectionID() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldCollectionID)
- return u
- }
- // ClearCollectionID clears the value of the "collection_id" field.
- func (u *AgentBaseUpsert) ClearCollectionID() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldCollectionID)
- return u
- }
- // SetSourceName sets the "source_name" field.
- func (u *AgentBaseUpsert) SetSourceName(v string) *AgentBaseUpsert {
- u.Set(agentbase.FieldSourceName, v)
- return u
- }
- // UpdateSourceName sets the "source_name" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateSourceName() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldSourceName)
- return u
- }
- // ClearSourceName clears the value of the "source_name" field.
- func (u *AgentBaseUpsert) ClearSourceName() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldSourceName)
- return u
- }
- // SetCanWrite sets the "can_write" field.
- func (u *AgentBaseUpsert) SetCanWrite(v []bool) *AgentBaseUpsert {
- u.Set(agentbase.FieldCanWrite, v)
- return u
- }
- // UpdateCanWrite sets the "can_write" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateCanWrite() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldCanWrite)
- return u
- }
- // ClearCanWrite clears the value of the "can_write" field.
- func (u *AgentBaseUpsert) ClearCanWrite() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldCanWrite)
- return u
- }
- // SetIsOwner sets the "is_owner" field.
- func (u *AgentBaseUpsert) SetIsOwner(v []bool) *AgentBaseUpsert {
- u.Set(agentbase.FieldIsOwner, v)
- return u
- }
- // UpdateIsOwner sets the "is_owner" field to the value that was provided on create.
- func (u *AgentBaseUpsert) UpdateIsOwner() *AgentBaseUpsert {
- u.SetExcluded(agentbase.FieldIsOwner)
- return u
- }
- // ClearIsOwner clears the value of the "is_owner" field.
- func (u *AgentBaseUpsert) ClearIsOwner() *AgentBaseUpsert {
- u.SetNull(agentbase.FieldIsOwner)
- 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.AgentBase.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(agentbase.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *AgentBaseUpsertOne) UpdateNewValues() *AgentBaseUpsertOne {
- 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(agentbase.FieldID)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.AgentBase.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *AgentBaseUpsertOne) Ignore() *AgentBaseUpsertOne {
- 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 *AgentBaseUpsertOne) DoNothing() *AgentBaseUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the AgentBaseCreate.OnConflict
- // documentation for more info.
- func (u *AgentBaseUpsertOne) Update(set func(*AgentBaseUpsert)) *AgentBaseUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&AgentBaseUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetQ sets the "q" field.
- func (u *AgentBaseUpsertOne) SetQ(v string) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetQ(v)
- })
- }
- // UpdateQ sets the "q" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateQ() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateQ()
- })
- }
- // ClearQ clears the value of the "q" field.
- func (u *AgentBaseUpsertOne) ClearQ() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearQ()
- })
- }
- // SetA sets the "a" field.
- func (u *AgentBaseUpsertOne) SetA(v string) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetA(v)
- })
- }
- // UpdateA sets the "a" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateA() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateA()
- })
- }
- // ClearA clears the value of the "a" field.
- func (u *AgentBaseUpsertOne) ClearA() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearA()
- })
- }
- // SetChunkIndex sets the "chunk_index" field.
- func (u *AgentBaseUpsertOne) SetChunkIndex(v uint64) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetChunkIndex(v)
- })
- }
- // AddChunkIndex adds v to the "chunk_index" field.
- func (u *AgentBaseUpsertOne) AddChunkIndex(v uint64) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.AddChunkIndex(v)
- })
- }
- // UpdateChunkIndex sets the "chunk_index" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateChunkIndex() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateChunkIndex()
- })
- }
- // SetIndexes sets the "indexes" field.
- func (u *AgentBaseUpsertOne) SetIndexes(v []string) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetIndexes(v)
- })
- }
- // UpdateIndexes sets the "indexes" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateIndexes() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateIndexes()
- })
- }
- // ClearIndexes clears the value of the "indexes" field.
- func (u *AgentBaseUpsertOne) ClearIndexes() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearIndexes()
- })
- }
- // SetDatasetID sets the "dataset_id" field.
- func (u *AgentBaseUpsertOne) SetDatasetID(v string) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetDatasetID(v)
- })
- }
- // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateDatasetID() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateDatasetID()
- })
- }
- // ClearDatasetID clears the value of the "dataset_id" field.
- func (u *AgentBaseUpsertOne) ClearDatasetID() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearDatasetID()
- })
- }
- // SetCollectionID sets the "collection_id" field.
- func (u *AgentBaseUpsertOne) SetCollectionID(v string) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetCollectionID(v)
- })
- }
- // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateCollectionID() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateCollectionID()
- })
- }
- // ClearCollectionID clears the value of the "collection_id" field.
- func (u *AgentBaseUpsertOne) ClearCollectionID() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearCollectionID()
- })
- }
- // SetSourceName sets the "source_name" field.
- func (u *AgentBaseUpsertOne) SetSourceName(v string) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetSourceName(v)
- })
- }
- // UpdateSourceName sets the "source_name" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateSourceName() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateSourceName()
- })
- }
- // ClearSourceName clears the value of the "source_name" field.
- func (u *AgentBaseUpsertOne) ClearSourceName() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearSourceName()
- })
- }
- // SetCanWrite sets the "can_write" field.
- func (u *AgentBaseUpsertOne) SetCanWrite(v []bool) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetCanWrite(v)
- })
- }
- // UpdateCanWrite sets the "can_write" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateCanWrite() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateCanWrite()
- })
- }
- // ClearCanWrite clears the value of the "can_write" field.
- func (u *AgentBaseUpsertOne) ClearCanWrite() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearCanWrite()
- })
- }
- // SetIsOwner sets the "is_owner" field.
- func (u *AgentBaseUpsertOne) SetIsOwner(v []bool) *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetIsOwner(v)
- })
- }
- // UpdateIsOwner sets the "is_owner" field to the value that was provided on create.
- func (u *AgentBaseUpsertOne) UpdateIsOwner() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateIsOwner()
- })
- }
- // ClearIsOwner clears the value of the "is_owner" field.
- func (u *AgentBaseUpsertOne) ClearIsOwner() *AgentBaseUpsertOne {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearIsOwner()
- })
- }
- // Exec executes the query.
- func (u *AgentBaseUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for AgentBaseCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *AgentBaseUpsertOne) 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 *AgentBaseUpsertOne) ID(ctx context.Context) (id string, err error) {
- if u.create.driver.Dialect() == dialect.MySQL {
- // In case of "ON CONFLICT", there is no way to get back non-numeric ID
- // fields from the database since MySQL does not support the RETURNING clause.
- return id, errors.New("ent: AgentBaseUpsertOne.ID is not supported by MySQL driver. Use AgentBaseUpsertOne.Exec instead")
- }
- 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 *AgentBaseUpsertOne) IDX(ctx context.Context) string {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // AgentBaseCreateBulk is the builder for creating many AgentBase entities in bulk.
- type AgentBaseCreateBulk struct {
- config
- err error
- builders []*AgentBaseCreate
- conflict []sql.ConflictOption
- }
- // Save creates the AgentBase entities in the database.
- func (abcb *AgentBaseCreateBulk) Save(ctx context.Context) ([]*AgentBase, error) {
- if abcb.err != nil {
- return nil, abcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(abcb.builders))
- nodes := make([]*AgentBase, len(abcb.builders))
- mutators := make([]Mutator, len(abcb.builders))
- for i := range abcb.builders {
- func(i int, root context.Context) {
- builder := abcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*AgentBaseMutation)
- 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, abcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = abcb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, abcb.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
- 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, abcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (abcb *AgentBaseCreateBulk) SaveX(ctx context.Context) []*AgentBase {
- v, err := abcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (abcb *AgentBaseCreateBulk) Exec(ctx context.Context) error {
- _, err := abcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (abcb *AgentBaseCreateBulk) ExecX(ctx context.Context) {
- if err := abcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.AgentBase.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.AgentBaseUpsert) {
- // SetQ(v+v).
- // }).
- // Exec(ctx)
- func (abcb *AgentBaseCreateBulk) OnConflict(opts ...sql.ConflictOption) *AgentBaseUpsertBulk {
- abcb.conflict = opts
- return &AgentBaseUpsertBulk{
- create: abcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.AgentBase.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (abcb *AgentBaseCreateBulk) OnConflictColumns(columns ...string) *AgentBaseUpsertBulk {
- abcb.conflict = append(abcb.conflict, sql.ConflictColumns(columns...))
- return &AgentBaseUpsertBulk{
- create: abcb,
- }
- }
- // AgentBaseUpsertBulk is the builder for "upsert"-ing
- // a bulk of AgentBase nodes.
- type AgentBaseUpsertBulk struct {
- create *AgentBaseCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.AgentBase.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(agentbase.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *AgentBaseUpsertBulk) UpdateNewValues() *AgentBaseUpsertBulk {
- 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(agentbase.FieldID)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.AgentBase.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *AgentBaseUpsertBulk) Ignore() *AgentBaseUpsertBulk {
- 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 *AgentBaseUpsertBulk) DoNothing() *AgentBaseUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the AgentBaseCreateBulk.OnConflict
- // documentation for more info.
- func (u *AgentBaseUpsertBulk) Update(set func(*AgentBaseUpsert)) *AgentBaseUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&AgentBaseUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetQ sets the "q" field.
- func (u *AgentBaseUpsertBulk) SetQ(v string) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetQ(v)
- })
- }
- // UpdateQ sets the "q" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateQ() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateQ()
- })
- }
- // ClearQ clears the value of the "q" field.
- func (u *AgentBaseUpsertBulk) ClearQ() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearQ()
- })
- }
- // SetA sets the "a" field.
- func (u *AgentBaseUpsertBulk) SetA(v string) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetA(v)
- })
- }
- // UpdateA sets the "a" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateA() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateA()
- })
- }
- // ClearA clears the value of the "a" field.
- func (u *AgentBaseUpsertBulk) ClearA() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearA()
- })
- }
- // SetChunkIndex sets the "chunk_index" field.
- func (u *AgentBaseUpsertBulk) SetChunkIndex(v uint64) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetChunkIndex(v)
- })
- }
- // AddChunkIndex adds v to the "chunk_index" field.
- func (u *AgentBaseUpsertBulk) AddChunkIndex(v uint64) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.AddChunkIndex(v)
- })
- }
- // UpdateChunkIndex sets the "chunk_index" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateChunkIndex() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateChunkIndex()
- })
- }
- // SetIndexes sets the "indexes" field.
- func (u *AgentBaseUpsertBulk) SetIndexes(v []string) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetIndexes(v)
- })
- }
- // UpdateIndexes sets the "indexes" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateIndexes() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateIndexes()
- })
- }
- // ClearIndexes clears the value of the "indexes" field.
- func (u *AgentBaseUpsertBulk) ClearIndexes() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearIndexes()
- })
- }
- // SetDatasetID sets the "dataset_id" field.
- func (u *AgentBaseUpsertBulk) SetDatasetID(v string) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetDatasetID(v)
- })
- }
- // UpdateDatasetID sets the "dataset_id" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateDatasetID() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateDatasetID()
- })
- }
- // ClearDatasetID clears the value of the "dataset_id" field.
- func (u *AgentBaseUpsertBulk) ClearDatasetID() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearDatasetID()
- })
- }
- // SetCollectionID sets the "collection_id" field.
- func (u *AgentBaseUpsertBulk) SetCollectionID(v string) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetCollectionID(v)
- })
- }
- // UpdateCollectionID sets the "collection_id" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateCollectionID() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateCollectionID()
- })
- }
- // ClearCollectionID clears the value of the "collection_id" field.
- func (u *AgentBaseUpsertBulk) ClearCollectionID() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearCollectionID()
- })
- }
- // SetSourceName sets the "source_name" field.
- func (u *AgentBaseUpsertBulk) SetSourceName(v string) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetSourceName(v)
- })
- }
- // UpdateSourceName sets the "source_name" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateSourceName() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateSourceName()
- })
- }
- // ClearSourceName clears the value of the "source_name" field.
- func (u *AgentBaseUpsertBulk) ClearSourceName() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearSourceName()
- })
- }
- // SetCanWrite sets the "can_write" field.
- func (u *AgentBaseUpsertBulk) SetCanWrite(v []bool) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetCanWrite(v)
- })
- }
- // UpdateCanWrite sets the "can_write" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateCanWrite() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateCanWrite()
- })
- }
- // ClearCanWrite clears the value of the "can_write" field.
- func (u *AgentBaseUpsertBulk) ClearCanWrite() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearCanWrite()
- })
- }
- // SetIsOwner sets the "is_owner" field.
- func (u *AgentBaseUpsertBulk) SetIsOwner(v []bool) *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.SetIsOwner(v)
- })
- }
- // UpdateIsOwner sets the "is_owner" field to the value that was provided on create.
- func (u *AgentBaseUpsertBulk) UpdateIsOwner() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.UpdateIsOwner()
- })
- }
- // ClearIsOwner clears the value of the "is_owner" field.
- func (u *AgentBaseUpsertBulk) ClearIsOwner() *AgentBaseUpsertBulk {
- return u.Update(func(s *AgentBaseUpsert) {
- s.ClearIsOwner()
- })
- }
- // Exec executes the query.
- func (u *AgentBaseUpsertBulk) 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 AgentBaseCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for AgentBaseCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *AgentBaseUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|