12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/agent"
- "wechat-api/ent/xunjiservice"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // XunjiServiceCreate is the builder for creating a XunjiService entity.
- type XunjiServiceCreate struct {
- config
- mutation *XunjiServiceMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (xsc *XunjiServiceCreate) SetCreatedAt(t time.Time) *XunjiServiceCreate {
- xsc.mutation.SetCreatedAt(t)
- return xsc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableCreatedAt(t *time.Time) *XunjiServiceCreate {
- if t != nil {
- xsc.SetCreatedAt(*t)
- }
- return xsc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (xsc *XunjiServiceCreate) SetUpdatedAt(t time.Time) *XunjiServiceCreate {
- xsc.mutation.SetUpdatedAt(t)
- return xsc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableUpdatedAt(t *time.Time) *XunjiServiceCreate {
- if t != nil {
- xsc.SetUpdatedAt(*t)
- }
- return xsc
- }
- // SetStatus sets the "status" field.
- func (xsc *XunjiServiceCreate) SetStatus(u uint8) *XunjiServiceCreate {
- xsc.mutation.SetStatus(u)
- return xsc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableStatus(u *uint8) *XunjiServiceCreate {
- if u != nil {
- xsc.SetStatus(*u)
- }
- return xsc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (xsc *XunjiServiceCreate) SetDeletedAt(t time.Time) *XunjiServiceCreate {
- xsc.mutation.SetDeletedAt(t)
- return xsc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableDeletedAt(t *time.Time) *XunjiServiceCreate {
- if t != nil {
- xsc.SetDeletedAt(*t)
- }
- return xsc
- }
- // SetXunjiID sets the "xunji_id" field.
- func (xsc *XunjiServiceCreate) SetXunjiID(u uint64) *XunjiServiceCreate {
- xsc.mutation.SetXunjiID(u)
- return xsc
- }
- // SetAgentID sets the "agent_id" field.
- func (xsc *XunjiServiceCreate) SetAgentID(u uint64) *XunjiServiceCreate {
- xsc.mutation.SetAgentID(u)
- return xsc
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableAgentID(u *uint64) *XunjiServiceCreate {
- if u != nil {
- xsc.SetAgentID(*u)
- }
- return xsc
- }
- // SetOrganizationID sets the "organization_id" field.
- func (xsc *XunjiServiceCreate) SetOrganizationID(u uint64) *XunjiServiceCreate {
- xsc.mutation.SetOrganizationID(u)
- return xsc
- }
- // SetWxid sets the "wxid" field.
- func (xsc *XunjiServiceCreate) SetWxid(s string) *XunjiServiceCreate {
- xsc.mutation.SetWxid(s)
- return xsc
- }
- // SetAPIBase sets the "api_base" field.
- func (xsc *XunjiServiceCreate) SetAPIBase(s string) *XunjiServiceCreate {
- xsc.mutation.SetAPIBase(s)
- return xsc
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableAPIBase(s *string) *XunjiServiceCreate {
- if s != nil {
- xsc.SetAPIBase(*s)
- }
- return xsc
- }
- // SetAPIKey sets the "api_key" field.
- func (xsc *XunjiServiceCreate) SetAPIKey(s string) *XunjiServiceCreate {
- xsc.mutation.SetAPIKey(s)
- return xsc
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (xsc *XunjiServiceCreate) SetNillableAPIKey(s *string) *XunjiServiceCreate {
- if s != nil {
- xsc.SetAPIKey(*s)
- }
- return xsc
- }
- // SetID sets the "id" field.
- func (xsc *XunjiServiceCreate) SetID(u uint64) *XunjiServiceCreate {
- xsc.mutation.SetID(u)
- return xsc
- }
- // SetAgent sets the "agent" edge to the Agent entity.
- func (xsc *XunjiServiceCreate) SetAgent(a *Agent) *XunjiServiceCreate {
- return xsc.SetAgentID(a.ID)
- }
- // Mutation returns the XunjiServiceMutation object of the builder.
- func (xsc *XunjiServiceCreate) Mutation() *XunjiServiceMutation {
- return xsc.mutation
- }
- // Save creates the XunjiService in the database.
- func (xsc *XunjiServiceCreate) Save(ctx context.Context) (*XunjiService, error) {
- if err := xsc.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, xsc.sqlSave, xsc.mutation, xsc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (xsc *XunjiServiceCreate) SaveX(ctx context.Context) *XunjiService {
- v, err := xsc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (xsc *XunjiServiceCreate) Exec(ctx context.Context) error {
- _, err := xsc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (xsc *XunjiServiceCreate) ExecX(ctx context.Context) {
- if err := xsc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (xsc *XunjiServiceCreate) defaults() error {
- if _, ok := xsc.mutation.CreatedAt(); !ok {
- if xunjiservice.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized xunjiservice.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := xunjiservice.DefaultCreatedAt()
- xsc.mutation.SetCreatedAt(v)
- }
- if _, ok := xsc.mutation.UpdatedAt(); !ok {
- if xunjiservice.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized xunjiservice.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := xunjiservice.DefaultUpdatedAt()
- xsc.mutation.SetUpdatedAt(v)
- }
- if _, ok := xsc.mutation.Status(); !ok {
- v := xunjiservice.DefaultStatus
- xsc.mutation.SetStatus(v)
- }
- if _, ok := xsc.mutation.AgentID(); !ok {
- v := xunjiservice.DefaultAgentID
- xsc.mutation.SetAgentID(v)
- }
- if _, ok := xsc.mutation.APIBase(); !ok {
- v := xunjiservice.DefaultAPIBase
- xsc.mutation.SetAPIBase(v)
- }
- if _, ok := xsc.mutation.APIKey(); !ok {
- v := xunjiservice.DefaultAPIKey
- xsc.mutation.SetAPIKey(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (xsc *XunjiServiceCreate) check() error {
- if _, ok := xsc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "XunjiService.created_at"`)}
- }
- if _, ok := xsc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "XunjiService.updated_at"`)}
- }
- if _, ok := xsc.mutation.XunjiID(); !ok {
- return &ValidationError{Name: "xunji_id", err: errors.New(`ent: missing required field "XunjiService.xunji_id"`)}
- }
- if _, ok := xsc.mutation.AgentID(); !ok {
- return &ValidationError{Name: "agent_id", err: errors.New(`ent: missing required field "XunjiService.agent_id"`)}
- }
- if _, ok := xsc.mutation.OrganizationID(); !ok {
- return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "XunjiService.organization_id"`)}
- }
- if v, ok := xsc.mutation.OrganizationID(); ok {
- if err := xunjiservice.OrganizationIDValidator(v); err != nil {
- return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "XunjiService.organization_id": %w`, err)}
- }
- }
- if _, ok := xsc.mutation.Wxid(); !ok {
- return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "XunjiService.wxid"`)}
- }
- if _, ok := xsc.mutation.AgentID(); !ok {
- return &ValidationError{Name: "agent", err: errors.New(`ent: missing required edge "XunjiService.agent"`)}
- }
- return nil
- }
- func (xsc *XunjiServiceCreate) sqlSave(ctx context.Context) (*XunjiService, error) {
- if err := xsc.check(); err != nil {
- return nil, err
- }
- _node, _spec := xsc.createSpec()
- if err := sqlgraph.CreateNode(ctx, xsc.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)
- }
- xsc.mutation.id = &_node.ID
- xsc.mutation.done = true
- return _node, nil
- }
- func (xsc *XunjiServiceCreate) createSpec() (*XunjiService, *sqlgraph.CreateSpec) {
- var (
- _node = &XunjiService{config: xsc.config}
- _spec = sqlgraph.NewCreateSpec(xunjiservice.Table, sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = xsc.conflict
- if id, ok := xsc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := xsc.mutation.CreatedAt(); ok {
- _spec.SetField(xunjiservice.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := xsc.mutation.UpdatedAt(); ok {
- _spec.SetField(xunjiservice.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := xsc.mutation.Status(); ok {
- _spec.SetField(xunjiservice.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := xsc.mutation.DeletedAt(); ok {
- _spec.SetField(xunjiservice.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := xsc.mutation.XunjiID(); ok {
- _spec.SetField(xunjiservice.FieldXunjiID, field.TypeUint64, value)
- _node.XunjiID = value
- }
- if value, ok := xsc.mutation.OrganizationID(); ok {
- _spec.SetField(xunjiservice.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if value, ok := xsc.mutation.Wxid(); ok {
- _spec.SetField(xunjiservice.FieldWxid, field.TypeString, value)
- _node.Wxid = value
- }
- if value, ok := xsc.mutation.APIBase(); ok {
- _spec.SetField(xunjiservice.FieldAPIBase, field.TypeString, value)
- _node.APIBase = value
- }
- if value, ok := xsc.mutation.APIKey(); ok {
- _spec.SetField(xunjiservice.FieldAPIKey, field.TypeString, value)
- _node.APIKey = value
- }
- if nodes := xsc.mutation.AgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: xunjiservice.AgentTable,
- Columns: []string{xunjiservice.AgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _node.AgentID = nodes[0]
- _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.XunjiService.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.XunjiServiceUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (xsc *XunjiServiceCreate) OnConflict(opts ...sql.ConflictOption) *XunjiServiceUpsertOne {
- xsc.conflict = opts
- return &XunjiServiceUpsertOne{
- create: xsc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.XunjiService.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (xsc *XunjiServiceCreate) OnConflictColumns(columns ...string) *XunjiServiceUpsertOne {
- xsc.conflict = append(xsc.conflict, sql.ConflictColumns(columns...))
- return &XunjiServiceUpsertOne{
- create: xsc,
- }
- }
- type (
- // XunjiServiceUpsertOne is the builder for "upsert"-ing
- // one XunjiService node.
- XunjiServiceUpsertOne struct {
- create *XunjiServiceCreate
- }
- // XunjiServiceUpsert is the "OnConflict" setter.
- XunjiServiceUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *XunjiServiceUpsert) SetUpdatedAt(v time.Time) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateUpdatedAt() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldUpdatedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *XunjiServiceUpsert) SetStatus(v uint8) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateStatus() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *XunjiServiceUpsert) AddStatus(v uint8) *XunjiServiceUpsert {
- u.Add(xunjiservice.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *XunjiServiceUpsert) ClearStatus() *XunjiServiceUpsert {
- u.SetNull(xunjiservice.FieldStatus)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *XunjiServiceUpsert) SetDeletedAt(v time.Time) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateDeletedAt() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *XunjiServiceUpsert) ClearDeletedAt() *XunjiServiceUpsert {
- u.SetNull(xunjiservice.FieldDeletedAt)
- return u
- }
- // SetXunjiID sets the "xunji_id" field.
- func (u *XunjiServiceUpsert) SetXunjiID(v uint64) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldXunjiID, v)
- return u
- }
- // UpdateXunjiID sets the "xunji_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateXunjiID() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldXunjiID)
- return u
- }
- // AddXunjiID adds v to the "xunji_id" field.
- func (u *XunjiServiceUpsert) AddXunjiID(v uint64) *XunjiServiceUpsert {
- u.Add(xunjiservice.FieldXunjiID, v)
- return u
- }
- // SetAgentID sets the "agent_id" field.
- func (u *XunjiServiceUpsert) SetAgentID(v uint64) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldAgentID, v)
- return u
- }
- // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateAgentID() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldAgentID)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *XunjiServiceUpsert) SetOrganizationID(v uint64) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateOrganizationID() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *XunjiServiceUpsert) AddOrganizationID(v uint64) *XunjiServiceUpsert {
- u.Add(xunjiservice.FieldOrganizationID, v)
- return u
- }
- // SetWxid sets the "wxid" field.
- func (u *XunjiServiceUpsert) SetWxid(v string) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldWxid, v)
- return u
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateWxid() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldWxid)
- return u
- }
- // SetAPIBase sets the "api_base" field.
- func (u *XunjiServiceUpsert) SetAPIBase(v string) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldAPIBase, v)
- return u
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateAPIBase() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldAPIBase)
- return u
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *XunjiServiceUpsert) ClearAPIBase() *XunjiServiceUpsert {
- u.SetNull(xunjiservice.FieldAPIBase)
- return u
- }
- // SetAPIKey sets the "api_key" field.
- func (u *XunjiServiceUpsert) SetAPIKey(v string) *XunjiServiceUpsert {
- u.Set(xunjiservice.FieldAPIKey, v)
- return u
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *XunjiServiceUpsert) UpdateAPIKey() *XunjiServiceUpsert {
- u.SetExcluded(xunjiservice.FieldAPIKey)
- return u
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *XunjiServiceUpsert) ClearAPIKey() *XunjiServiceUpsert {
- u.SetNull(xunjiservice.FieldAPIKey)
- 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.XunjiService.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(xunjiservice.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *XunjiServiceUpsertOne) UpdateNewValues() *XunjiServiceUpsertOne {
- 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(xunjiservice.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(xunjiservice.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.XunjiService.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *XunjiServiceUpsertOne) Ignore() *XunjiServiceUpsertOne {
- 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 *XunjiServiceUpsertOne) DoNothing() *XunjiServiceUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the XunjiServiceCreate.OnConflict
- // documentation for more info.
- func (u *XunjiServiceUpsertOne) Update(set func(*XunjiServiceUpsert)) *XunjiServiceUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&XunjiServiceUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *XunjiServiceUpsertOne) SetUpdatedAt(v time.Time) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateUpdatedAt() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *XunjiServiceUpsertOne) SetStatus(v uint8) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *XunjiServiceUpsertOne) AddStatus(v uint8) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateStatus() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *XunjiServiceUpsertOne) ClearStatus() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearStatus()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *XunjiServiceUpsertOne) SetDeletedAt(v time.Time) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateDeletedAt() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *XunjiServiceUpsertOne) ClearDeletedAt() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetXunjiID sets the "xunji_id" field.
- func (u *XunjiServiceUpsertOne) SetXunjiID(v uint64) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetXunjiID(v)
- })
- }
- // AddXunjiID adds v to the "xunji_id" field.
- func (u *XunjiServiceUpsertOne) AddXunjiID(v uint64) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.AddXunjiID(v)
- })
- }
- // UpdateXunjiID sets the "xunji_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateXunjiID() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateXunjiID()
- })
- }
- // SetAgentID sets the "agent_id" field.
- func (u *XunjiServiceUpsertOne) SetAgentID(v uint64) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetAgentID(v)
- })
- }
- // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateAgentID() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateAgentID()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *XunjiServiceUpsertOne) SetOrganizationID(v uint64) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *XunjiServiceUpsertOne) AddOrganizationID(v uint64) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateOrganizationID() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // SetWxid sets the "wxid" field.
- func (u *XunjiServiceUpsertOne) SetWxid(v string) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetWxid(v)
- })
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateWxid() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateWxid()
- })
- }
- // SetAPIBase sets the "api_base" field.
- func (u *XunjiServiceUpsertOne) SetAPIBase(v string) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetAPIBase(v)
- })
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateAPIBase() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateAPIBase()
- })
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *XunjiServiceUpsertOne) ClearAPIBase() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearAPIBase()
- })
- }
- // SetAPIKey sets the "api_key" field.
- func (u *XunjiServiceUpsertOne) SetAPIKey(v string) *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetAPIKey(v)
- })
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *XunjiServiceUpsertOne) UpdateAPIKey() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateAPIKey()
- })
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *XunjiServiceUpsertOne) ClearAPIKey() *XunjiServiceUpsertOne {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearAPIKey()
- })
- }
- // Exec executes the query.
- func (u *XunjiServiceUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for XunjiServiceCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *XunjiServiceUpsertOne) 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 *XunjiServiceUpsertOne) 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 *XunjiServiceUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // XunjiServiceCreateBulk is the builder for creating many XunjiService entities in bulk.
- type XunjiServiceCreateBulk struct {
- config
- err error
- builders []*XunjiServiceCreate
- conflict []sql.ConflictOption
- }
- // Save creates the XunjiService entities in the database.
- func (xscb *XunjiServiceCreateBulk) Save(ctx context.Context) ([]*XunjiService, error) {
- if xscb.err != nil {
- return nil, xscb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(xscb.builders))
- nodes := make([]*XunjiService, len(xscb.builders))
- mutators := make([]Mutator, len(xscb.builders))
- for i := range xscb.builders {
- func(i int, root context.Context) {
- builder := xscb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*XunjiServiceMutation)
- 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, xscb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = xscb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, xscb.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, xscb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (xscb *XunjiServiceCreateBulk) SaveX(ctx context.Context) []*XunjiService {
- v, err := xscb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (xscb *XunjiServiceCreateBulk) Exec(ctx context.Context) error {
- _, err := xscb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (xscb *XunjiServiceCreateBulk) ExecX(ctx context.Context) {
- if err := xscb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.XunjiService.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.XunjiServiceUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (xscb *XunjiServiceCreateBulk) OnConflict(opts ...sql.ConflictOption) *XunjiServiceUpsertBulk {
- xscb.conflict = opts
- return &XunjiServiceUpsertBulk{
- create: xscb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.XunjiService.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (xscb *XunjiServiceCreateBulk) OnConflictColumns(columns ...string) *XunjiServiceUpsertBulk {
- xscb.conflict = append(xscb.conflict, sql.ConflictColumns(columns...))
- return &XunjiServiceUpsertBulk{
- create: xscb,
- }
- }
- // XunjiServiceUpsertBulk is the builder for "upsert"-ing
- // a bulk of XunjiService nodes.
- type XunjiServiceUpsertBulk struct {
- create *XunjiServiceCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.XunjiService.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(xunjiservice.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *XunjiServiceUpsertBulk) UpdateNewValues() *XunjiServiceUpsertBulk {
- 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(xunjiservice.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(xunjiservice.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.XunjiService.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *XunjiServiceUpsertBulk) Ignore() *XunjiServiceUpsertBulk {
- 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 *XunjiServiceUpsertBulk) DoNothing() *XunjiServiceUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the XunjiServiceCreateBulk.OnConflict
- // documentation for more info.
- func (u *XunjiServiceUpsertBulk) Update(set func(*XunjiServiceUpsert)) *XunjiServiceUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&XunjiServiceUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *XunjiServiceUpsertBulk) SetUpdatedAt(v time.Time) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateUpdatedAt() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *XunjiServiceUpsertBulk) SetStatus(v uint8) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *XunjiServiceUpsertBulk) AddStatus(v uint8) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateStatus() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *XunjiServiceUpsertBulk) ClearStatus() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearStatus()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *XunjiServiceUpsertBulk) SetDeletedAt(v time.Time) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateDeletedAt() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *XunjiServiceUpsertBulk) ClearDeletedAt() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetXunjiID sets the "xunji_id" field.
- func (u *XunjiServiceUpsertBulk) SetXunjiID(v uint64) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetXunjiID(v)
- })
- }
- // AddXunjiID adds v to the "xunji_id" field.
- func (u *XunjiServiceUpsertBulk) AddXunjiID(v uint64) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.AddXunjiID(v)
- })
- }
- // UpdateXunjiID sets the "xunji_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateXunjiID() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateXunjiID()
- })
- }
- // SetAgentID sets the "agent_id" field.
- func (u *XunjiServiceUpsertBulk) SetAgentID(v uint64) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetAgentID(v)
- })
- }
- // UpdateAgentID sets the "agent_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateAgentID() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateAgentID()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *XunjiServiceUpsertBulk) SetOrganizationID(v uint64) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *XunjiServiceUpsertBulk) AddOrganizationID(v uint64) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateOrganizationID() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // SetWxid sets the "wxid" field.
- func (u *XunjiServiceUpsertBulk) SetWxid(v string) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetWxid(v)
- })
- }
- // UpdateWxid sets the "wxid" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateWxid() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateWxid()
- })
- }
- // SetAPIBase sets the "api_base" field.
- func (u *XunjiServiceUpsertBulk) SetAPIBase(v string) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetAPIBase(v)
- })
- }
- // UpdateAPIBase sets the "api_base" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateAPIBase() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateAPIBase()
- })
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (u *XunjiServiceUpsertBulk) ClearAPIBase() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearAPIBase()
- })
- }
- // SetAPIKey sets the "api_key" field.
- func (u *XunjiServiceUpsertBulk) SetAPIKey(v string) *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.SetAPIKey(v)
- })
- }
- // UpdateAPIKey sets the "api_key" field to the value that was provided on create.
- func (u *XunjiServiceUpsertBulk) UpdateAPIKey() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.UpdateAPIKey()
- })
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (u *XunjiServiceUpsertBulk) ClearAPIKey() *XunjiServiceUpsertBulk {
- return u.Update(func(s *XunjiServiceUpsert) {
- s.ClearAPIKey()
- })
- }
- // Exec executes the query.
- func (u *XunjiServiceUpsertBulk) 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 XunjiServiceCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for XunjiServiceCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *XunjiServiceUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|