| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/account"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- "github.com/Wei-Shaw/sub2api/ent/proxy"
- )
- // ProxyUpdate is the builder for updating Proxy entities.
- type ProxyUpdate struct {
- config
- hooks []Hook
- mutation *ProxyMutation
- }
- // Where appends a list predicates to the ProxyUpdate builder.
- func (_u *ProxyUpdate) Where(ps ...predicate.Proxy) *ProxyUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *ProxyUpdate) SetUpdatedAt(v time.Time) *ProxyUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_u *ProxyUpdate) SetDeletedAt(v time.Time) *ProxyUpdate {
- _u.mutation.SetDeletedAt(v)
- return _u
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableDeletedAt(v *time.Time) *ProxyUpdate {
- if v != nil {
- _u.SetDeletedAt(*v)
- }
- return _u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (_u *ProxyUpdate) ClearDeletedAt() *ProxyUpdate {
- _u.mutation.ClearDeletedAt()
- return _u
- }
- // SetName sets the "name" field.
- func (_u *ProxyUpdate) SetName(v string) *ProxyUpdate {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableName(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetProtocol sets the "protocol" field.
- func (_u *ProxyUpdate) SetProtocol(v string) *ProxyUpdate {
- _u.mutation.SetProtocol(v)
- return _u
- }
- // SetNillableProtocol sets the "protocol" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableProtocol(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetProtocol(*v)
- }
- return _u
- }
- // SetHost sets the "host" field.
- func (_u *ProxyUpdate) SetHost(v string) *ProxyUpdate {
- _u.mutation.SetHost(v)
- return _u
- }
- // SetNillableHost sets the "host" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableHost(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetHost(*v)
- }
- return _u
- }
- // SetPort sets the "port" field.
- func (_u *ProxyUpdate) SetPort(v int) *ProxyUpdate {
- _u.mutation.ResetPort()
- _u.mutation.SetPort(v)
- return _u
- }
- // SetNillablePort sets the "port" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillablePort(v *int) *ProxyUpdate {
- if v != nil {
- _u.SetPort(*v)
- }
- return _u
- }
- // AddPort adds value to the "port" field.
- func (_u *ProxyUpdate) AddPort(v int) *ProxyUpdate {
- _u.mutation.AddPort(v)
- return _u
- }
- // SetUsername sets the "username" field.
- func (_u *ProxyUpdate) SetUsername(v string) *ProxyUpdate {
- _u.mutation.SetUsername(v)
- return _u
- }
- // SetNillableUsername sets the "username" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableUsername(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetUsername(*v)
- }
- return _u
- }
- // ClearUsername clears the value of the "username" field.
- func (_u *ProxyUpdate) ClearUsername() *ProxyUpdate {
- _u.mutation.ClearUsername()
- return _u
- }
- // SetPassword sets the "password" field.
- func (_u *ProxyUpdate) SetPassword(v string) *ProxyUpdate {
- _u.mutation.SetPassword(v)
- return _u
- }
- // SetNillablePassword sets the "password" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillablePassword(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetPassword(*v)
- }
- return _u
- }
- // ClearPassword clears the value of the "password" field.
- func (_u *ProxyUpdate) ClearPassword() *ProxyUpdate {
- _u.mutation.ClearPassword()
- return _u
- }
- // SetStatus sets the "status" field.
- func (_u *ProxyUpdate) SetStatus(v string) *ProxyUpdate {
- _u.mutation.SetStatus(v)
- return _u
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableStatus(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetStatus(*v)
- }
- return _u
- }
- // SetExpiresAt sets the "expires_at" field.
- func (_u *ProxyUpdate) SetExpiresAt(v time.Time) *ProxyUpdate {
- _u.mutation.SetExpiresAt(v)
- return _u
- }
- // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableExpiresAt(v *time.Time) *ProxyUpdate {
- if v != nil {
- _u.SetExpiresAt(*v)
- }
- return _u
- }
- // ClearExpiresAt clears the value of the "expires_at" field.
- func (_u *ProxyUpdate) ClearExpiresAt() *ProxyUpdate {
- _u.mutation.ClearExpiresAt()
- return _u
- }
- // SetFallbackMode sets the "fallback_mode" field.
- func (_u *ProxyUpdate) SetFallbackMode(v string) *ProxyUpdate {
- _u.mutation.SetFallbackMode(v)
- return _u
- }
- // SetNillableFallbackMode sets the "fallback_mode" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableFallbackMode(v *string) *ProxyUpdate {
- if v != nil {
- _u.SetFallbackMode(*v)
- }
- return _u
- }
- // SetBackupProxyID sets the "backup_proxy_id" field.
- func (_u *ProxyUpdate) SetBackupProxyID(v int64) *ProxyUpdate {
- _u.mutation.SetBackupProxyID(v)
- return _u
- }
- // SetNillableBackupProxyID sets the "backup_proxy_id" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableBackupProxyID(v *int64) *ProxyUpdate {
- if v != nil {
- _u.SetBackupProxyID(*v)
- }
- return _u
- }
- // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
- func (_u *ProxyUpdate) ClearBackupProxyID() *ProxyUpdate {
- _u.mutation.ClearBackupProxyID()
- return _u
- }
- // SetExpiryWarnDays sets the "expiry_warn_days" field.
- func (_u *ProxyUpdate) SetExpiryWarnDays(v int) *ProxyUpdate {
- _u.mutation.ResetExpiryWarnDays()
- _u.mutation.SetExpiryWarnDays(v)
- return _u
- }
- // SetNillableExpiryWarnDays sets the "expiry_warn_days" field if the given value is not nil.
- func (_u *ProxyUpdate) SetNillableExpiryWarnDays(v *int) *ProxyUpdate {
- if v != nil {
- _u.SetExpiryWarnDays(*v)
- }
- return _u
- }
- // AddExpiryWarnDays adds value to the "expiry_warn_days" field.
- func (_u *ProxyUpdate) AddExpiryWarnDays(v int) *ProxyUpdate {
- _u.mutation.AddExpiryWarnDays(v)
- return _u
- }
- // AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
- func (_u *ProxyUpdate) AddAccountIDs(ids ...int64) *ProxyUpdate {
- _u.mutation.AddAccountIDs(ids...)
- return _u
- }
- // AddAccounts adds the "accounts" edges to the Account entity.
- func (_u *ProxyUpdate) AddAccounts(v ...*Account) *ProxyUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddAccountIDs(ids...)
- }
- // AddPrimaryProxyIDs adds the "primary_proxies" edge to the Proxy entity by IDs.
- func (_u *ProxyUpdate) AddPrimaryProxyIDs(ids ...int64) *ProxyUpdate {
- _u.mutation.AddPrimaryProxyIDs(ids...)
- return _u
- }
- // AddPrimaryProxies adds the "primary_proxies" edges to the Proxy entity.
- func (_u *ProxyUpdate) AddPrimaryProxies(v ...*Proxy) *ProxyUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddPrimaryProxyIDs(ids...)
- }
- // SetBackupProxy sets the "backup_proxy" edge to the Proxy entity.
- func (_u *ProxyUpdate) SetBackupProxy(v *Proxy) *ProxyUpdate {
- return _u.SetBackupProxyID(v.ID)
- }
- // Mutation returns the ProxyMutation object of the builder.
- func (_u *ProxyUpdate) Mutation() *ProxyMutation {
- return _u.mutation
- }
- // ClearAccounts clears all "accounts" edges to the Account entity.
- func (_u *ProxyUpdate) ClearAccounts() *ProxyUpdate {
- _u.mutation.ClearAccounts()
- return _u
- }
- // RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
- func (_u *ProxyUpdate) RemoveAccountIDs(ids ...int64) *ProxyUpdate {
- _u.mutation.RemoveAccountIDs(ids...)
- return _u
- }
- // RemoveAccounts removes "accounts" edges to Account entities.
- func (_u *ProxyUpdate) RemoveAccounts(v ...*Account) *ProxyUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveAccountIDs(ids...)
- }
- // ClearPrimaryProxies clears all "primary_proxies" edges to the Proxy entity.
- func (_u *ProxyUpdate) ClearPrimaryProxies() *ProxyUpdate {
- _u.mutation.ClearPrimaryProxies()
- return _u
- }
- // RemovePrimaryProxyIDs removes the "primary_proxies" edge to Proxy entities by IDs.
- func (_u *ProxyUpdate) RemovePrimaryProxyIDs(ids ...int64) *ProxyUpdate {
- _u.mutation.RemovePrimaryProxyIDs(ids...)
- return _u
- }
- // RemovePrimaryProxies removes "primary_proxies" edges to Proxy entities.
- func (_u *ProxyUpdate) RemovePrimaryProxies(v ...*Proxy) *ProxyUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemovePrimaryProxyIDs(ids...)
- }
- // ClearBackupProxy clears the "backup_proxy" edge to the Proxy entity.
- func (_u *ProxyUpdate) ClearBackupProxy() *ProxyUpdate {
- _u.mutation.ClearBackupProxy()
- return _u
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *ProxyUpdate) Save(ctx context.Context) (int, error) {
- if err := _u.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ProxyUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *ProxyUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ProxyUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *ProxyUpdate) defaults() error {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- if proxy.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized proxy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := proxy.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ProxyUpdate) check() error {
- if v, ok := _u.mutation.Name(); ok {
- if err := proxy.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Protocol(); ok {
- if err := proxy.ProtocolValidator(v); err != nil {
- return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Host(); ok {
- if err := proxy.HostValidator(v); err != nil {
- return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Username(); ok {
- if err := proxy.UsernameValidator(v); err != nil {
- return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Password(); ok {
- if err := proxy.PasswordValidator(v); err != nil {
- return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Status(); ok {
- if err := proxy.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
- }
- }
- if v, ok := _u.mutation.FallbackMode(); ok {
- if err := proxy.FallbackModeValidator(v); err != nil {
- return &ValidationError{Name: "fallback_mode", err: fmt.Errorf(`ent: validator failed for field "Proxy.fallback_mode": %w`, err)}
- }
- }
- return nil
- }
- func (_u *ProxyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.DeletedAt(); ok {
- _spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
- }
- if _u.mutation.DeletedAtCleared() {
- _spec.ClearField(proxy.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(proxy.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Protocol(); ok {
- _spec.SetField(proxy.FieldProtocol, field.TypeString, value)
- }
- if value, ok := _u.mutation.Host(); ok {
- _spec.SetField(proxy.FieldHost, field.TypeString, value)
- }
- if value, ok := _u.mutation.Port(); ok {
- _spec.SetField(proxy.FieldPort, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedPort(); ok {
- _spec.AddField(proxy.FieldPort, field.TypeInt, value)
- }
- if value, ok := _u.mutation.Username(); ok {
- _spec.SetField(proxy.FieldUsername, field.TypeString, value)
- }
- if _u.mutation.UsernameCleared() {
- _spec.ClearField(proxy.FieldUsername, field.TypeString)
- }
- if value, ok := _u.mutation.Password(); ok {
- _spec.SetField(proxy.FieldPassword, field.TypeString, value)
- }
- if _u.mutation.PasswordCleared() {
- _spec.ClearField(proxy.FieldPassword, field.TypeString)
- }
- if value, ok := _u.mutation.Status(); ok {
- _spec.SetField(proxy.FieldStatus, field.TypeString, value)
- }
- if value, ok := _u.mutation.ExpiresAt(); ok {
- _spec.SetField(proxy.FieldExpiresAt, field.TypeTime, value)
- }
- if _u.mutation.ExpiresAtCleared() {
- _spec.ClearField(proxy.FieldExpiresAt, field.TypeTime)
- }
- if value, ok := _u.mutation.FallbackMode(); ok {
- _spec.SetField(proxy.FieldFallbackMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.ExpiryWarnDays(); ok {
- _spec.SetField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedExpiryWarnDays(); ok {
- _spec.AddField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
- }
- if _u.mutation.AccountsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.AccountsTable,
- Columns: []string{proxy.AccountsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.AccountsTable,
- Columns: []string{proxy.AccountsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.AccountsTable,
- Columns: []string{proxy.AccountsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.PrimaryProxiesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.PrimaryProxiesTable,
- Columns: []string{proxy.PrimaryProxiesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedPrimaryProxiesIDs(); len(nodes) > 0 && !_u.mutation.PrimaryProxiesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.PrimaryProxiesTable,
- Columns: []string{proxy.PrimaryProxiesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.PrimaryProxiesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.PrimaryProxiesTable,
- Columns: []string{proxy.PrimaryProxiesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.BackupProxyCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: proxy.BackupProxyTable,
- Columns: []string{proxy.BackupProxyColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.BackupProxyIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: proxy.BackupProxyTable,
- Columns: []string{proxy.BackupProxyColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{proxy.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // ProxyUpdateOne is the builder for updating a single Proxy entity.
- type ProxyUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ProxyMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *ProxyUpdateOne) SetUpdatedAt(v time.Time) *ProxyUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_u *ProxyUpdateOne) SetDeletedAt(v time.Time) *ProxyUpdateOne {
- _u.mutation.SetDeletedAt(v)
- return _u
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableDeletedAt(v *time.Time) *ProxyUpdateOne {
- if v != nil {
- _u.SetDeletedAt(*v)
- }
- return _u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (_u *ProxyUpdateOne) ClearDeletedAt() *ProxyUpdateOne {
- _u.mutation.ClearDeletedAt()
- return _u
- }
- // SetName sets the "name" field.
- func (_u *ProxyUpdateOne) SetName(v string) *ProxyUpdateOne {
- _u.mutation.SetName(v)
- return _u
- }
- // SetNillableName sets the "name" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableName(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetName(*v)
- }
- return _u
- }
- // SetProtocol sets the "protocol" field.
- func (_u *ProxyUpdateOne) SetProtocol(v string) *ProxyUpdateOne {
- _u.mutation.SetProtocol(v)
- return _u
- }
- // SetNillableProtocol sets the "protocol" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableProtocol(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetProtocol(*v)
- }
- return _u
- }
- // SetHost sets the "host" field.
- func (_u *ProxyUpdateOne) SetHost(v string) *ProxyUpdateOne {
- _u.mutation.SetHost(v)
- return _u
- }
- // SetNillableHost sets the "host" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableHost(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetHost(*v)
- }
- return _u
- }
- // SetPort sets the "port" field.
- func (_u *ProxyUpdateOne) SetPort(v int) *ProxyUpdateOne {
- _u.mutation.ResetPort()
- _u.mutation.SetPort(v)
- return _u
- }
- // SetNillablePort sets the "port" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillablePort(v *int) *ProxyUpdateOne {
- if v != nil {
- _u.SetPort(*v)
- }
- return _u
- }
- // AddPort adds value to the "port" field.
- func (_u *ProxyUpdateOne) AddPort(v int) *ProxyUpdateOne {
- _u.mutation.AddPort(v)
- return _u
- }
- // SetUsername sets the "username" field.
- func (_u *ProxyUpdateOne) SetUsername(v string) *ProxyUpdateOne {
- _u.mutation.SetUsername(v)
- return _u
- }
- // SetNillableUsername sets the "username" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableUsername(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetUsername(*v)
- }
- return _u
- }
- // ClearUsername clears the value of the "username" field.
- func (_u *ProxyUpdateOne) ClearUsername() *ProxyUpdateOne {
- _u.mutation.ClearUsername()
- return _u
- }
- // SetPassword sets the "password" field.
- func (_u *ProxyUpdateOne) SetPassword(v string) *ProxyUpdateOne {
- _u.mutation.SetPassword(v)
- return _u
- }
- // SetNillablePassword sets the "password" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillablePassword(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetPassword(*v)
- }
- return _u
- }
- // ClearPassword clears the value of the "password" field.
- func (_u *ProxyUpdateOne) ClearPassword() *ProxyUpdateOne {
- _u.mutation.ClearPassword()
- return _u
- }
- // SetStatus sets the "status" field.
- func (_u *ProxyUpdateOne) SetStatus(v string) *ProxyUpdateOne {
- _u.mutation.SetStatus(v)
- return _u
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableStatus(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetStatus(*v)
- }
- return _u
- }
- // SetExpiresAt sets the "expires_at" field.
- func (_u *ProxyUpdateOne) SetExpiresAt(v time.Time) *ProxyUpdateOne {
- _u.mutation.SetExpiresAt(v)
- return _u
- }
- // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableExpiresAt(v *time.Time) *ProxyUpdateOne {
- if v != nil {
- _u.SetExpiresAt(*v)
- }
- return _u
- }
- // ClearExpiresAt clears the value of the "expires_at" field.
- func (_u *ProxyUpdateOne) ClearExpiresAt() *ProxyUpdateOne {
- _u.mutation.ClearExpiresAt()
- return _u
- }
- // SetFallbackMode sets the "fallback_mode" field.
- func (_u *ProxyUpdateOne) SetFallbackMode(v string) *ProxyUpdateOne {
- _u.mutation.SetFallbackMode(v)
- return _u
- }
- // SetNillableFallbackMode sets the "fallback_mode" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableFallbackMode(v *string) *ProxyUpdateOne {
- if v != nil {
- _u.SetFallbackMode(*v)
- }
- return _u
- }
- // SetBackupProxyID sets the "backup_proxy_id" field.
- func (_u *ProxyUpdateOne) SetBackupProxyID(v int64) *ProxyUpdateOne {
- _u.mutation.SetBackupProxyID(v)
- return _u
- }
- // SetNillableBackupProxyID sets the "backup_proxy_id" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableBackupProxyID(v *int64) *ProxyUpdateOne {
- if v != nil {
- _u.SetBackupProxyID(*v)
- }
- return _u
- }
- // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
- func (_u *ProxyUpdateOne) ClearBackupProxyID() *ProxyUpdateOne {
- _u.mutation.ClearBackupProxyID()
- return _u
- }
- // SetExpiryWarnDays sets the "expiry_warn_days" field.
- func (_u *ProxyUpdateOne) SetExpiryWarnDays(v int) *ProxyUpdateOne {
- _u.mutation.ResetExpiryWarnDays()
- _u.mutation.SetExpiryWarnDays(v)
- return _u
- }
- // SetNillableExpiryWarnDays sets the "expiry_warn_days" field if the given value is not nil.
- func (_u *ProxyUpdateOne) SetNillableExpiryWarnDays(v *int) *ProxyUpdateOne {
- if v != nil {
- _u.SetExpiryWarnDays(*v)
- }
- return _u
- }
- // AddExpiryWarnDays adds value to the "expiry_warn_days" field.
- func (_u *ProxyUpdateOne) AddExpiryWarnDays(v int) *ProxyUpdateOne {
- _u.mutation.AddExpiryWarnDays(v)
- return _u
- }
- // AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
- func (_u *ProxyUpdateOne) AddAccountIDs(ids ...int64) *ProxyUpdateOne {
- _u.mutation.AddAccountIDs(ids...)
- return _u
- }
- // AddAccounts adds the "accounts" edges to the Account entity.
- func (_u *ProxyUpdateOne) AddAccounts(v ...*Account) *ProxyUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddAccountIDs(ids...)
- }
- // AddPrimaryProxyIDs adds the "primary_proxies" edge to the Proxy entity by IDs.
- func (_u *ProxyUpdateOne) AddPrimaryProxyIDs(ids ...int64) *ProxyUpdateOne {
- _u.mutation.AddPrimaryProxyIDs(ids...)
- return _u
- }
- // AddPrimaryProxies adds the "primary_proxies" edges to the Proxy entity.
- func (_u *ProxyUpdateOne) AddPrimaryProxies(v ...*Proxy) *ProxyUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddPrimaryProxyIDs(ids...)
- }
- // SetBackupProxy sets the "backup_proxy" edge to the Proxy entity.
- func (_u *ProxyUpdateOne) SetBackupProxy(v *Proxy) *ProxyUpdateOne {
- return _u.SetBackupProxyID(v.ID)
- }
- // Mutation returns the ProxyMutation object of the builder.
- func (_u *ProxyUpdateOne) Mutation() *ProxyMutation {
- return _u.mutation
- }
- // ClearAccounts clears all "accounts" edges to the Account entity.
- func (_u *ProxyUpdateOne) ClearAccounts() *ProxyUpdateOne {
- _u.mutation.ClearAccounts()
- return _u
- }
- // RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
- func (_u *ProxyUpdateOne) RemoveAccountIDs(ids ...int64) *ProxyUpdateOne {
- _u.mutation.RemoveAccountIDs(ids...)
- return _u
- }
- // RemoveAccounts removes "accounts" edges to Account entities.
- func (_u *ProxyUpdateOne) RemoveAccounts(v ...*Account) *ProxyUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveAccountIDs(ids...)
- }
- // ClearPrimaryProxies clears all "primary_proxies" edges to the Proxy entity.
- func (_u *ProxyUpdateOne) ClearPrimaryProxies() *ProxyUpdateOne {
- _u.mutation.ClearPrimaryProxies()
- return _u
- }
- // RemovePrimaryProxyIDs removes the "primary_proxies" edge to Proxy entities by IDs.
- func (_u *ProxyUpdateOne) RemovePrimaryProxyIDs(ids ...int64) *ProxyUpdateOne {
- _u.mutation.RemovePrimaryProxyIDs(ids...)
- return _u
- }
- // RemovePrimaryProxies removes "primary_proxies" edges to Proxy entities.
- func (_u *ProxyUpdateOne) RemovePrimaryProxies(v ...*Proxy) *ProxyUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemovePrimaryProxyIDs(ids...)
- }
- // ClearBackupProxy clears the "backup_proxy" edge to the Proxy entity.
- func (_u *ProxyUpdateOne) ClearBackupProxy() *ProxyUpdateOne {
- _u.mutation.ClearBackupProxy()
- return _u
- }
- // Where appends a list predicates to the ProxyUpdate builder.
- func (_u *ProxyUpdateOne) Where(ps ...predicate.Proxy) *ProxyUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *ProxyUpdateOne) Select(field string, fields ...string) *ProxyUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated Proxy entity.
- func (_u *ProxyUpdateOne) Save(ctx context.Context) (*Proxy, error) {
- if err := _u.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *ProxyUpdateOne) SaveX(ctx context.Context) *Proxy {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *ProxyUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *ProxyUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *ProxyUpdateOne) defaults() error {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- if proxy.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized proxy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := proxy.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *ProxyUpdateOne) check() error {
- if v, ok := _u.mutation.Name(); ok {
- if err := proxy.NameValidator(v); err != nil {
- return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Protocol(); ok {
- if err := proxy.ProtocolValidator(v); err != nil {
- return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Host(); ok {
- if err := proxy.HostValidator(v); err != nil {
- return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Username(); ok {
- if err := proxy.UsernameValidator(v); err != nil {
- return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Password(); ok {
- if err := proxy.PasswordValidator(v); err != nil {
- return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
- }
- }
- if v, ok := _u.mutation.Status(); ok {
- if err := proxy.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
- }
- }
- if v, ok := _u.mutation.FallbackMode(); ok {
- if err := proxy.FallbackModeValidator(v); err != nil {
- return &ValidationError{Name: "fallback_mode", err: fmt.Errorf(`ent: validator failed for field "Proxy.fallback_mode": %w`, err)}
- }
- }
- return nil
- }
- func (_u *ProxyUpdateOne) sqlSave(ctx context.Context) (_node *Proxy, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Proxy.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
- for _, f := range fields {
- if !proxy.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != proxy.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.DeletedAt(); ok {
- _spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
- }
- if _u.mutation.DeletedAtCleared() {
- _spec.ClearField(proxy.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.Name(); ok {
- _spec.SetField(proxy.FieldName, field.TypeString, value)
- }
- if value, ok := _u.mutation.Protocol(); ok {
- _spec.SetField(proxy.FieldProtocol, field.TypeString, value)
- }
- if value, ok := _u.mutation.Host(); ok {
- _spec.SetField(proxy.FieldHost, field.TypeString, value)
- }
- if value, ok := _u.mutation.Port(); ok {
- _spec.SetField(proxy.FieldPort, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedPort(); ok {
- _spec.AddField(proxy.FieldPort, field.TypeInt, value)
- }
- if value, ok := _u.mutation.Username(); ok {
- _spec.SetField(proxy.FieldUsername, field.TypeString, value)
- }
- if _u.mutation.UsernameCleared() {
- _spec.ClearField(proxy.FieldUsername, field.TypeString)
- }
- if value, ok := _u.mutation.Password(); ok {
- _spec.SetField(proxy.FieldPassword, field.TypeString, value)
- }
- if _u.mutation.PasswordCleared() {
- _spec.ClearField(proxy.FieldPassword, field.TypeString)
- }
- if value, ok := _u.mutation.Status(); ok {
- _spec.SetField(proxy.FieldStatus, field.TypeString, value)
- }
- if value, ok := _u.mutation.ExpiresAt(); ok {
- _spec.SetField(proxy.FieldExpiresAt, field.TypeTime, value)
- }
- if _u.mutation.ExpiresAtCleared() {
- _spec.ClearField(proxy.FieldExpiresAt, field.TypeTime)
- }
- if value, ok := _u.mutation.FallbackMode(); ok {
- _spec.SetField(proxy.FieldFallbackMode, field.TypeString, value)
- }
- if value, ok := _u.mutation.ExpiryWarnDays(); ok {
- _spec.SetField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
- }
- if value, ok := _u.mutation.AddedExpiryWarnDays(); ok {
- _spec.AddField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
- }
- if _u.mutation.AccountsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.AccountsTable,
- Columns: []string{proxy.AccountsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.AccountsTable,
- Columns: []string{proxy.AccountsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.AccountsTable,
- Columns: []string{proxy.AccountsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.PrimaryProxiesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.PrimaryProxiesTable,
- Columns: []string{proxy.PrimaryProxiesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedPrimaryProxiesIDs(); len(nodes) > 0 && !_u.mutation.PrimaryProxiesCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.PrimaryProxiesTable,
- Columns: []string{proxy.PrimaryProxiesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.PrimaryProxiesIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: true,
- Table: proxy.PrimaryProxiesTable,
- Columns: []string{proxy.PrimaryProxiesColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.BackupProxyCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: proxy.BackupProxyTable,
- Columns: []string{proxy.BackupProxyColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.BackupProxyIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: false,
- Table: proxy.BackupProxyTable,
- Columns: []string{proxy.BackupProxyColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &Proxy{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{proxy.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|