proxy_update.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/account"
  12. "github.com/Wei-Shaw/sub2api/ent/predicate"
  13. "github.com/Wei-Shaw/sub2api/ent/proxy"
  14. )
  15. // ProxyUpdate is the builder for updating Proxy entities.
  16. type ProxyUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *ProxyMutation
  20. }
  21. // Where appends a list predicates to the ProxyUpdate builder.
  22. func (_u *ProxyUpdate) Where(ps ...predicate.Proxy) *ProxyUpdate {
  23. _u.mutation.Where(ps...)
  24. return _u
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (_u *ProxyUpdate) SetUpdatedAt(v time.Time) *ProxyUpdate {
  28. _u.mutation.SetUpdatedAt(v)
  29. return _u
  30. }
  31. // SetDeletedAt sets the "deleted_at" field.
  32. func (_u *ProxyUpdate) SetDeletedAt(v time.Time) *ProxyUpdate {
  33. _u.mutation.SetDeletedAt(v)
  34. return _u
  35. }
  36. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  37. func (_u *ProxyUpdate) SetNillableDeletedAt(v *time.Time) *ProxyUpdate {
  38. if v != nil {
  39. _u.SetDeletedAt(*v)
  40. }
  41. return _u
  42. }
  43. // ClearDeletedAt clears the value of the "deleted_at" field.
  44. func (_u *ProxyUpdate) ClearDeletedAt() *ProxyUpdate {
  45. _u.mutation.ClearDeletedAt()
  46. return _u
  47. }
  48. // SetName sets the "name" field.
  49. func (_u *ProxyUpdate) SetName(v string) *ProxyUpdate {
  50. _u.mutation.SetName(v)
  51. return _u
  52. }
  53. // SetNillableName sets the "name" field if the given value is not nil.
  54. func (_u *ProxyUpdate) SetNillableName(v *string) *ProxyUpdate {
  55. if v != nil {
  56. _u.SetName(*v)
  57. }
  58. return _u
  59. }
  60. // SetProtocol sets the "protocol" field.
  61. func (_u *ProxyUpdate) SetProtocol(v string) *ProxyUpdate {
  62. _u.mutation.SetProtocol(v)
  63. return _u
  64. }
  65. // SetNillableProtocol sets the "protocol" field if the given value is not nil.
  66. func (_u *ProxyUpdate) SetNillableProtocol(v *string) *ProxyUpdate {
  67. if v != nil {
  68. _u.SetProtocol(*v)
  69. }
  70. return _u
  71. }
  72. // SetHost sets the "host" field.
  73. func (_u *ProxyUpdate) SetHost(v string) *ProxyUpdate {
  74. _u.mutation.SetHost(v)
  75. return _u
  76. }
  77. // SetNillableHost sets the "host" field if the given value is not nil.
  78. func (_u *ProxyUpdate) SetNillableHost(v *string) *ProxyUpdate {
  79. if v != nil {
  80. _u.SetHost(*v)
  81. }
  82. return _u
  83. }
  84. // SetPort sets the "port" field.
  85. func (_u *ProxyUpdate) SetPort(v int) *ProxyUpdate {
  86. _u.mutation.ResetPort()
  87. _u.mutation.SetPort(v)
  88. return _u
  89. }
  90. // SetNillablePort sets the "port" field if the given value is not nil.
  91. func (_u *ProxyUpdate) SetNillablePort(v *int) *ProxyUpdate {
  92. if v != nil {
  93. _u.SetPort(*v)
  94. }
  95. return _u
  96. }
  97. // AddPort adds value to the "port" field.
  98. func (_u *ProxyUpdate) AddPort(v int) *ProxyUpdate {
  99. _u.mutation.AddPort(v)
  100. return _u
  101. }
  102. // SetUsername sets the "username" field.
  103. func (_u *ProxyUpdate) SetUsername(v string) *ProxyUpdate {
  104. _u.mutation.SetUsername(v)
  105. return _u
  106. }
  107. // SetNillableUsername sets the "username" field if the given value is not nil.
  108. func (_u *ProxyUpdate) SetNillableUsername(v *string) *ProxyUpdate {
  109. if v != nil {
  110. _u.SetUsername(*v)
  111. }
  112. return _u
  113. }
  114. // ClearUsername clears the value of the "username" field.
  115. func (_u *ProxyUpdate) ClearUsername() *ProxyUpdate {
  116. _u.mutation.ClearUsername()
  117. return _u
  118. }
  119. // SetPassword sets the "password" field.
  120. func (_u *ProxyUpdate) SetPassword(v string) *ProxyUpdate {
  121. _u.mutation.SetPassword(v)
  122. return _u
  123. }
  124. // SetNillablePassword sets the "password" field if the given value is not nil.
  125. func (_u *ProxyUpdate) SetNillablePassword(v *string) *ProxyUpdate {
  126. if v != nil {
  127. _u.SetPassword(*v)
  128. }
  129. return _u
  130. }
  131. // ClearPassword clears the value of the "password" field.
  132. func (_u *ProxyUpdate) ClearPassword() *ProxyUpdate {
  133. _u.mutation.ClearPassword()
  134. return _u
  135. }
  136. // SetStatus sets the "status" field.
  137. func (_u *ProxyUpdate) SetStatus(v string) *ProxyUpdate {
  138. _u.mutation.SetStatus(v)
  139. return _u
  140. }
  141. // SetNillableStatus sets the "status" field if the given value is not nil.
  142. func (_u *ProxyUpdate) SetNillableStatus(v *string) *ProxyUpdate {
  143. if v != nil {
  144. _u.SetStatus(*v)
  145. }
  146. return _u
  147. }
  148. // SetExpiresAt sets the "expires_at" field.
  149. func (_u *ProxyUpdate) SetExpiresAt(v time.Time) *ProxyUpdate {
  150. _u.mutation.SetExpiresAt(v)
  151. return _u
  152. }
  153. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  154. func (_u *ProxyUpdate) SetNillableExpiresAt(v *time.Time) *ProxyUpdate {
  155. if v != nil {
  156. _u.SetExpiresAt(*v)
  157. }
  158. return _u
  159. }
  160. // ClearExpiresAt clears the value of the "expires_at" field.
  161. func (_u *ProxyUpdate) ClearExpiresAt() *ProxyUpdate {
  162. _u.mutation.ClearExpiresAt()
  163. return _u
  164. }
  165. // SetFallbackMode sets the "fallback_mode" field.
  166. func (_u *ProxyUpdate) SetFallbackMode(v string) *ProxyUpdate {
  167. _u.mutation.SetFallbackMode(v)
  168. return _u
  169. }
  170. // SetNillableFallbackMode sets the "fallback_mode" field if the given value is not nil.
  171. func (_u *ProxyUpdate) SetNillableFallbackMode(v *string) *ProxyUpdate {
  172. if v != nil {
  173. _u.SetFallbackMode(*v)
  174. }
  175. return _u
  176. }
  177. // SetBackupProxyID sets the "backup_proxy_id" field.
  178. func (_u *ProxyUpdate) SetBackupProxyID(v int64) *ProxyUpdate {
  179. _u.mutation.SetBackupProxyID(v)
  180. return _u
  181. }
  182. // SetNillableBackupProxyID sets the "backup_proxy_id" field if the given value is not nil.
  183. func (_u *ProxyUpdate) SetNillableBackupProxyID(v *int64) *ProxyUpdate {
  184. if v != nil {
  185. _u.SetBackupProxyID(*v)
  186. }
  187. return _u
  188. }
  189. // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
  190. func (_u *ProxyUpdate) ClearBackupProxyID() *ProxyUpdate {
  191. _u.mutation.ClearBackupProxyID()
  192. return _u
  193. }
  194. // SetExpiryWarnDays sets the "expiry_warn_days" field.
  195. func (_u *ProxyUpdate) SetExpiryWarnDays(v int) *ProxyUpdate {
  196. _u.mutation.ResetExpiryWarnDays()
  197. _u.mutation.SetExpiryWarnDays(v)
  198. return _u
  199. }
  200. // SetNillableExpiryWarnDays sets the "expiry_warn_days" field if the given value is not nil.
  201. func (_u *ProxyUpdate) SetNillableExpiryWarnDays(v *int) *ProxyUpdate {
  202. if v != nil {
  203. _u.SetExpiryWarnDays(*v)
  204. }
  205. return _u
  206. }
  207. // AddExpiryWarnDays adds value to the "expiry_warn_days" field.
  208. func (_u *ProxyUpdate) AddExpiryWarnDays(v int) *ProxyUpdate {
  209. _u.mutation.AddExpiryWarnDays(v)
  210. return _u
  211. }
  212. // AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
  213. func (_u *ProxyUpdate) AddAccountIDs(ids ...int64) *ProxyUpdate {
  214. _u.mutation.AddAccountIDs(ids...)
  215. return _u
  216. }
  217. // AddAccounts adds the "accounts" edges to the Account entity.
  218. func (_u *ProxyUpdate) AddAccounts(v ...*Account) *ProxyUpdate {
  219. ids := make([]int64, len(v))
  220. for i := range v {
  221. ids[i] = v[i].ID
  222. }
  223. return _u.AddAccountIDs(ids...)
  224. }
  225. // AddPrimaryProxyIDs adds the "primary_proxies" edge to the Proxy entity by IDs.
  226. func (_u *ProxyUpdate) AddPrimaryProxyIDs(ids ...int64) *ProxyUpdate {
  227. _u.mutation.AddPrimaryProxyIDs(ids...)
  228. return _u
  229. }
  230. // AddPrimaryProxies adds the "primary_proxies" edges to the Proxy entity.
  231. func (_u *ProxyUpdate) AddPrimaryProxies(v ...*Proxy) *ProxyUpdate {
  232. ids := make([]int64, len(v))
  233. for i := range v {
  234. ids[i] = v[i].ID
  235. }
  236. return _u.AddPrimaryProxyIDs(ids...)
  237. }
  238. // SetBackupProxy sets the "backup_proxy" edge to the Proxy entity.
  239. func (_u *ProxyUpdate) SetBackupProxy(v *Proxy) *ProxyUpdate {
  240. return _u.SetBackupProxyID(v.ID)
  241. }
  242. // Mutation returns the ProxyMutation object of the builder.
  243. func (_u *ProxyUpdate) Mutation() *ProxyMutation {
  244. return _u.mutation
  245. }
  246. // ClearAccounts clears all "accounts" edges to the Account entity.
  247. func (_u *ProxyUpdate) ClearAccounts() *ProxyUpdate {
  248. _u.mutation.ClearAccounts()
  249. return _u
  250. }
  251. // RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
  252. func (_u *ProxyUpdate) RemoveAccountIDs(ids ...int64) *ProxyUpdate {
  253. _u.mutation.RemoveAccountIDs(ids...)
  254. return _u
  255. }
  256. // RemoveAccounts removes "accounts" edges to Account entities.
  257. func (_u *ProxyUpdate) RemoveAccounts(v ...*Account) *ProxyUpdate {
  258. ids := make([]int64, len(v))
  259. for i := range v {
  260. ids[i] = v[i].ID
  261. }
  262. return _u.RemoveAccountIDs(ids...)
  263. }
  264. // ClearPrimaryProxies clears all "primary_proxies" edges to the Proxy entity.
  265. func (_u *ProxyUpdate) ClearPrimaryProxies() *ProxyUpdate {
  266. _u.mutation.ClearPrimaryProxies()
  267. return _u
  268. }
  269. // RemovePrimaryProxyIDs removes the "primary_proxies" edge to Proxy entities by IDs.
  270. func (_u *ProxyUpdate) RemovePrimaryProxyIDs(ids ...int64) *ProxyUpdate {
  271. _u.mutation.RemovePrimaryProxyIDs(ids...)
  272. return _u
  273. }
  274. // RemovePrimaryProxies removes "primary_proxies" edges to Proxy entities.
  275. func (_u *ProxyUpdate) RemovePrimaryProxies(v ...*Proxy) *ProxyUpdate {
  276. ids := make([]int64, len(v))
  277. for i := range v {
  278. ids[i] = v[i].ID
  279. }
  280. return _u.RemovePrimaryProxyIDs(ids...)
  281. }
  282. // ClearBackupProxy clears the "backup_proxy" edge to the Proxy entity.
  283. func (_u *ProxyUpdate) ClearBackupProxy() *ProxyUpdate {
  284. _u.mutation.ClearBackupProxy()
  285. return _u
  286. }
  287. // Save executes the query and returns the number of nodes affected by the update operation.
  288. func (_u *ProxyUpdate) Save(ctx context.Context) (int, error) {
  289. if err := _u.defaults(); err != nil {
  290. return 0, err
  291. }
  292. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  293. }
  294. // SaveX is like Save, but panics if an error occurs.
  295. func (_u *ProxyUpdate) SaveX(ctx context.Context) int {
  296. affected, err := _u.Save(ctx)
  297. if err != nil {
  298. panic(err)
  299. }
  300. return affected
  301. }
  302. // Exec executes the query.
  303. func (_u *ProxyUpdate) Exec(ctx context.Context) error {
  304. _, err := _u.Save(ctx)
  305. return err
  306. }
  307. // ExecX is like Exec, but panics if an error occurs.
  308. func (_u *ProxyUpdate) ExecX(ctx context.Context) {
  309. if err := _u.Exec(ctx); err != nil {
  310. panic(err)
  311. }
  312. }
  313. // defaults sets the default values of the builder before save.
  314. func (_u *ProxyUpdate) defaults() error {
  315. if _, ok := _u.mutation.UpdatedAt(); !ok {
  316. if proxy.UpdateDefaultUpdatedAt == nil {
  317. return fmt.Errorf("ent: uninitialized proxy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  318. }
  319. v := proxy.UpdateDefaultUpdatedAt()
  320. _u.mutation.SetUpdatedAt(v)
  321. }
  322. return nil
  323. }
  324. // check runs all checks and user-defined validators on the builder.
  325. func (_u *ProxyUpdate) check() error {
  326. if v, ok := _u.mutation.Name(); ok {
  327. if err := proxy.NameValidator(v); err != nil {
  328. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
  329. }
  330. }
  331. if v, ok := _u.mutation.Protocol(); ok {
  332. if err := proxy.ProtocolValidator(v); err != nil {
  333. return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
  334. }
  335. }
  336. if v, ok := _u.mutation.Host(); ok {
  337. if err := proxy.HostValidator(v); err != nil {
  338. return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
  339. }
  340. }
  341. if v, ok := _u.mutation.Username(); ok {
  342. if err := proxy.UsernameValidator(v); err != nil {
  343. return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
  344. }
  345. }
  346. if v, ok := _u.mutation.Password(); ok {
  347. if err := proxy.PasswordValidator(v); err != nil {
  348. return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
  349. }
  350. }
  351. if v, ok := _u.mutation.Status(); ok {
  352. if err := proxy.StatusValidator(v); err != nil {
  353. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
  354. }
  355. }
  356. if v, ok := _u.mutation.FallbackMode(); ok {
  357. if err := proxy.FallbackModeValidator(v); err != nil {
  358. return &ValidationError{Name: "fallback_mode", err: fmt.Errorf(`ent: validator failed for field "Proxy.fallback_mode": %w`, err)}
  359. }
  360. }
  361. return nil
  362. }
  363. func (_u *ProxyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  364. if err := _u.check(); err != nil {
  365. return _node, err
  366. }
  367. _spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
  368. if ps := _u.mutation.predicates; len(ps) > 0 {
  369. _spec.Predicate = func(selector *sql.Selector) {
  370. for i := range ps {
  371. ps[i](selector)
  372. }
  373. }
  374. }
  375. if value, ok := _u.mutation.UpdatedAt(); ok {
  376. _spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
  377. }
  378. if value, ok := _u.mutation.DeletedAt(); ok {
  379. _spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
  380. }
  381. if _u.mutation.DeletedAtCleared() {
  382. _spec.ClearField(proxy.FieldDeletedAt, field.TypeTime)
  383. }
  384. if value, ok := _u.mutation.Name(); ok {
  385. _spec.SetField(proxy.FieldName, field.TypeString, value)
  386. }
  387. if value, ok := _u.mutation.Protocol(); ok {
  388. _spec.SetField(proxy.FieldProtocol, field.TypeString, value)
  389. }
  390. if value, ok := _u.mutation.Host(); ok {
  391. _spec.SetField(proxy.FieldHost, field.TypeString, value)
  392. }
  393. if value, ok := _u.mutation.Port(); ok {
  394. _spec.SetField(proxy.FieldPort, field.TypeInt, value)
  395. }
  396. if value, ok := _u.mutation.AddedPort(); ok {
  397. _spec.AddField(proxy.FieldPort, field.TypeInt, value)
  398. }
  399. if value, ok := _u.mutation.Username(); ok {
  400. _spec.SetField(proxy.FieldUsername, field.TypeString, value)
  401. }
  402. if _u.mutation.UsernameCleared() {
  403. _spec.ClearField(proxy.FieldUsername, field.TypeString)
  404. }
  405. if value, ok := _u.mutation.Password(); ok {
  406. _spec.SetField(proxy.FieldPassword, field.TypeString, value)
  407. }
  408. if _u.mutation.PasswordCleared() {
  409. _spec.ClearField(proxy.FieldPassword, field.TypeString)
  410. }
  411. if value, ok := _u.mutation.Status(); ok {
  412. _spec.SetField(proxy.FieldStatus, field.TypeString, value)
  413. }
  414. if value, ok := _u.mutation.ExpiresAt(); ok {
  415. _spec.SetField(proxy.FieldExpiresAt, field.TypeTime, value)
  416. }
  417. if _u.mutation.ExpiresAtCleared() {
  418. _spec.ClearField(proxy.FieldExpiresAt, field.TypeTime)
  419. }
  420. if value, ok := _u.mutation.FallbackMode(); ok {
  421. _spec.SetField(proxy.FieldFallbackMode, field.TypeString, value)
  422. }
  423. if value, ok := _u.mutation.ExpiryWarnDays(); ok {
  424. _spec.SetField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
  425. }
  426. if value, ok := _u.mutation.AddedExpiryWarnDays(); ok {
  427. _spec.AddField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
  428. }
  429. if _u.mutation.AccountsCleared() {
  430. edge := &sqlgraph.EdgeSpec{
  431. Rel: sqlgraph.O2M,
  432. Inverse: true,
  433. Table: proxy.AccountsTable,
  434. Columns: []string{proxy.AccountsColumn},
  435. Bidi: false,
  436. Target: &sqlgraph.EdgeTarget{
  437. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  438. },
  439. }
  440. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  441. }
  442. if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
  443. edge := &sqlgraph.EdgeSpec{
  444. Rel: sqlgraph.O2M,
  445. Inverse: true,
  446. Table: proxy.AccountsTable,
  447. Columns: []string{proxy.AccountsColumn},
  448. Bidi: false,
  449. Target: &sqlgraph.EdgeTarget{
  450. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  451. },
  452. }
  453. for _, k := range nodes {
  454. edge.Target.Nodes = append(edge.Target.Nodes, k)
  455. }
  456. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  457. }
  458. if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
  459. edge := &sqlgraph.EdgeSpec{
  460. Rel: sqlgraph.O2M,
  461. Inverse: true,
  462. Table: proxy.AccountsTable,
  463. Columns: []string{proxy.AccountsColumn},
  464. Bidi: false,
  465. Target: &sqlgraph.EdgeTarget{
  466. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  467. },
  468. }
  469. for _, k := range nodes {
  470. edge.Target.Nodes = append(edge.Target.Nodes, k)
  471. }
  472. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  473. }
  474. if _u.mutation.PrimaryProxiesCleared() {
  475. edge := &sqlgraph.EdgeSpec{
  476. Rel: sqlgraph.O2M,
  477. Inverse: true,
  478. Table: proxy.PrimaryProxiesTable,
  479. Columns: []string{proxy.PrimaryProxiesColumn},
  480. Bidi: false,
  481. Target: &sqlgraph.EdgeTarget{
  482. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  483. },
  484. }
  485. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  486. }
  487. if nodes := _u.mutation.RemovedPrimaryProxiesIDs(); len(nodes) > 0 && !_u.mutation.PrimaryProxiesCleared() {
  488. edge := &sqlgraph.EdgeSpec{
  489. Rel: sqlgraph.O2M,
  490. Inverse: true,
  491. Table: proxy.PrimaryProxiesTable,
  492. Columns: []string{proxy.PrimaryProxiesColumn},
  493. Bidi: false,
  494. Target: &sqlgraph.EdgeTarget{
  495. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  496. },
  497. }
  498. for _, k := range nodes {
  499. edge.Target.Nodes = append(edge.Target.Nodes, k)
  500. }
  501. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  502. }
  503. if nodes := _u.mutation.PrimaryProxiesIDs(); len(nodes) > 0 {
  504. edge := &sqlgraph.EdgeSpec{
  505. Rel: sqlgraph.O2M,
  506. Inverse: true,
  507. Table: proxy.PrimaryProxiesTable,
  508. Columns: []string{proxy.PrimaryProxiesColumn},
  509. Bidi: false,
  510. Target: &sqlgraph.EdgeTarget{
  511. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  512. },
  513. }
  514. for _, k := range nodes {
  515. edge.Target.Nodes = append(edge.Target.Nodes, k)
  516. }
  517. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  518. }
  519. if _u.mutation.BackupProxyCleared() {
  520. edge := &sqlgraph.EdgeSpec{
  521. Rel: sqlgraph.M2O,
  522. Inverse: false,
  523. Table: proxy.BackupProxyTable,
  524. Columns: []string{proxy.BackupProxyColumn},
  525. Bidi: false,
  526. Target: &sqlgraph.EdgeTarget{
  527. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  528. },
  529. }
  530. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  531. }
  532. if nodes := _u.mutation.BackupProxyIDs(); len(nodes) > 0 {
  533. edge := &sqlgraph.EdgeSpec{
  534. Rel: sqlgraph.M2O,
  535. Inverse: false,
  536. Table: proxy.BackupProxyTable,
  537. Columns: []string{proxy.BackupProxyColumn},
  538. Bidi: false,
  539. Target: &sqlgraph.EdgeTarget{
  540. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  541. },
  542. }
  543. for _, k := range nodes {
  544. edge.Target.Nodes = append(edge.Target.Nodes, k)
  545. }
  546. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  547. }
  548. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  549. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  550. err = &NotFoundError{proxy.Label}
  551. } else if sqlgraph.IsConstraintError(err) {
  552. err = &ConstraintError{msg: err.Error(), wrap: err}
  553. }
  554. return 0, err
  555. }
  556. _u.mutation.done = true
  557. return _node, nil
  558. }
  559. // ProxyUpdateOne is the builder for updating a single Proxy entity.
  560. type ProxyUpdateOne struct {
  561. config
  562. fields []string
  563. hooks []Hook
  564. mutation *ProxyMutation
  565. }
  566. // SetUpdatedAt sets the "updated_at" field.
  567. func (_u *ProxyUpdateOne) SetUpdatedAt(v time.Time) *ProxyUpdateOne {
  568. _u.mutation.SetUpdatedAt(v)
  569. return _u
  570. }
  571. // SetDeletedAt sets the "deleted_at" field.
  572. func (_u *ProxyUpdateOne) SetDeletedAt(v time.Time) *ProxyUpdateOne {
  573. _u.mutation.SetDeletedAt(v)
  574. return _u
  575. }
  576. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  577. func (_u *ProxyUpdateOne) SetNillableDeletedAt(v *time.Time) *ProxyUpdateOne {
  578. if v != nil {
  579. _u.SetDeletedAt(*v)
  580. }
  581. return _u
  582. }
  583. // ClearDeletedAt clears the value of the "deleted_at" field.
  584. func (_u *ProxyUpdateOne) ClearDeletedAt() *ProxyUpdateOne {
  585. _u.mutation.ClearDeletedAt()
  586. return _u
  587. }
  588. // SetName sets the "name" field.
  589. func (_u *ProxyUpdateOne) SetName(v string) *ProxyUpdateOne {
  590. _u.mutation.SetName(v)
  591. return _u
  592. }
  593. // SetNillableName sets the "name" field if the given value is not nil.
  594. func (_u *ProxyUpdateOne) SetNillableName(v *string) *ProxyUpdateOne {
  595. if v != nil {
  596. _u.SetName(*v)
  597. }
  598. return _u
  599. }
  600. // SetProtocol sets the "protocol" field.
  601. func (_u *ProxyUpdateOne) SetProtocol(v string) *ProxyUpdateOne {
  602. _u.mutation.SetProtocol(v)
  603. return _u
  604. }
  605. // SetNillableProtocol sets the "protocol" field if the given value is not nil.
  606. func (_u *ProxyUpdateOne) SetNillableProtocol(v *string) *ProxyUpdateOne {
  607. if v != nil {
  608. _u.SetProtocol(*v)
  609. }
  610. return _u
  611. }
  612. // SetHost sets the "host" field.
  613. func (_u *ProxyUpdateOne) SetHost(v string) *ProxyUpdateOne {
  614. _u.mutation.SetHost(v)
  615. return _u
  616. }
  617. // SetNillableHost sets the "host" field if the given value is not nil.
  618. func (_u *ProxyUpdateOne) SetNillableHost(v *string) *ProxyUpdateOne {
  619. if v != nil {
  620. _u.SetHost(*v)
  621. }
  622. return _u
  623. }
  624. // SetPort sets the "port" field.
  625. func (_u *ProxyUpdateOne) SetPort(v int) *ProxyUpdateOne {
  626. _u.mutation.ResetPort()
  627. _u.mutation.SetPort(v)
  628. return _u
  629. }
  630. // SetNillablePort sets the "port" field if the given value is not nil.
  631. func (_u *ProxyUpdateOne) SetNillablePort(v *int) *ProxyUpdateOne {
  632. if v != nil {
  633. _u.SetPort(*v)
  634. }
  635. return _u
  636. }
  637. // AddPort adds value to the "port" field.
  638. func (_u *ProxyUpdateOne) AddPort(v int) *ProxyUpdateOne {
  639. _u.mutation.AddPort(v)
  640. return _u
  641. }
  642. // SetUsername sets the "username" field.
  643. func (_u *ProxyUpdateOne) SetUsername(v string) *ProxyUpdateOne {
  644. _u.mutation.SetUsername(v)
  645. return _u
  646. }
  647. // SetNillableUsername sets the "username" field if the given value is not nil.
  648. func (_u *ProxyUpdateOne) SetNillableUsername(v *string) *ProxyUpdateOne {
  649. if v != nil {
  650. _u.SetUsername(*v)
  651. }
  652. return _u
  653. }
  654. // ClearUsername clears the value of the "username" field.
  655. func (_u *ProxyUpdateOne) ClearUsername() *ProxyUpdateOne {
  656. _u.mutation.ClearUsername()
  657. return _u
  658. }
  659. // SetPassword sets the "password" field.
  660. func (_u *ProxyUpdateOne) SetPassword(v string) *ProxyUpdateOne {
  661. _u.mutation.SetPassword(v)
  662. return _u
  663. }
  664. // SetNillablePassword sets the "password" field if the given value is not nil.
  665. func (_u *ProxyUpdateOne) SetNillablePassword(v *string) *ProxyUpdateOne {
  666. if v != nil {
  667. _u.SetPassword(*v)
  668. }
  669. return _u
  670. }
  671. // ClearPassword clears the value of the "password" field.
  672. func (_u *ProxyUpdateOne) ClearPassword() *ProxyUpdateOne {
  673. _u.mutation.ClearPassword()
  674. return _u
  675. }
  676. // SetStatus sets the "status" field.
  677. func (_u *ProxyUpdateOne) SetStatus(v string) *ProxyUpdateOne {
  678. _u.mutation.SetStatus(v)
  679. return _u
  680. }
  681. // SetNillableStatus sets the "status" field if the given value is not nil.
  682. func (_u *ProxyUpdateOne) SetNillableStatus(v *string) *ProxyUpdateOne {
  683. if v != nil {
  684. _u.SetStatus(*v)
  685. }
  686. return _u
  687. }
  688. // SetExpiresAt sets the "expires_at" field.
  689. func (_u *ProxyUpdateOne) SetExpiresAt(v time.Time) *ProxyUpdateOne {
  690. _u.mutation.SetExpiresAt(v)
  691. return _u
  692. }
  693. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  694. func (_u *ProxyUpdateOne) SetNillableExpiresAt(v *time.Time) *ProxyUpdateOne {
  695. if v != nil {
  696. _u.SetExpiresAt(*v)
  697. }
  698. return _u
  699. }
  700. // ClearExpiresAt clears the value of the "expires_at" field.
  701. func (_u *ProxyUpdateOne) ClearExpiresAt() *ProxyUpdateOne {
  702. _u.mutation.ClearExpiresAt()
  703. return _u
  704. }
  705. // SetFallbackMode sets the "fallback_mode" field.
  706. func (_u *ProxyUpdateOne) SetFallbackMode(v string) *ProxyUpdateOne {
  707. _u.mutation.SetFallbackMode(v)
  708. return _u
  709. }
  710. // SetNillableFallbackMode sets the "fallback_mode" field if the given value is not nil.
  711. func (_u *ProxyUpdateOne) SetNillableFallbackMode(v *string) *ProxyUpdateOne {
  712. if v != nil {
  713. _u.SetFallbackMode(*v)
  714. }
  715. return _u
  716. }
  717. // SetBackupProxyID sets the "backup_proxy_id" field.
  718. func (_u *ProxyUpdateOne) SetBackupProxyID(v int64) *ProxyUpdateOne {
  719. _u.mutation.SetBackupProxyID(v)
  720. return _u
  721. }
  722. // SetNillableBackupProxyID sets the "backup_proxy_id" field if the given value is not nil.
  723. func (_u *ProxyUpdateOne) SetNillableBackupProxyID(v *int64) *ProxyUpdateOne {
  724. if v != nil {
  725. _u.SetBackupProxyID(*v)
  726. }
  727. return _u
  728. }
  729. // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
  730. func (_u *ProxyUpdateOne) ClearBackupProxyID() *ProxyUpdateOne {
  731. _u.mutation.ClearBackupProxyID()
  732. return _u
  733. }
  734. // SetExpiryWarnDays sets the "expiry_warn_days" field.
  735. func (_u *ProxyUpdateOne) SetExpiryWarnDays(v int) *ProxyUpdateOne {
  736. _u.mutation.ResetExpiryWarnDays()
  737. _u.mutation.SetExpiryWarnDays(v)
  738. return _u
  739. }
  740. // SetNillableExpiryWarnDays sets the "expiry_warn_days" field if the given value is not nil.
  741. func (_u *ProxyUpdateOne) SetNillableExpiryWarnDays(v *int) *ProxyUpdateOne {
  742. if v != nil {
  743. _u.SetExpiryWarnDays(*v)
  744. }
  745. return _u
  746. }
  747. // AddExpiryWarnDays adds value to the "expiry_warn_days" field.
  748. func (_u *ProxyUpdateOne) AddExpiryWarnDays(v int) *ProxyUpdateOne {
  749. _u.mutation.AddExpiryWarnDays(v)
  750. return _u
  751. }
  752. // AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
  753. func (_u *ProxyUpdateOne) AddAccountIDs(ids ...int64) *ProxyUpdateOne {
  754. _u.mutation.AddAccountIDs(ids...)
  755. return _u
  756. }
  757. // AddAccounts adds the "accounts" edges to the Account entity.
  758. func (_u *ProxyUpdateOne) AddAccounts(v ...*Account) *ProxyUpdateOne {
  759. ids := make([]int64, len(v))
  760. for i := range v {
  761. ids[i] = v[i].ID
  762. }
  763. return _u.AddAccountIDs(ids...)
  764. }
  765. // AddPrimaryProxyIDs adds the "primary_proxies" edge to the Proxy entity by IDs.
  766. func (_u *ProxyUpdateOne) AddPrimaryProxyIDs(ids ...int64) *ProxyUpdateOne {
  767. _u.mutation.AddPrimaryProxyIDs(ids...)
  768. return _u
  769. }
  770. // AddPrimaryProxies adds the "primary_proxies" edges to the Proxy entity.
  771. func (_u *ProxyUpdateOne) AddPrimaryProxies(v ...*Proxy) *ProxyUpdateOne {
  772. ids := make([]int64, len(v))
  773. for i := range v {
  774. ids[i] = v[i].ID
  775. }
  776. return _u.AddPrimaryProxyIDs(ids...)
  777. }
  778. // SetBackupProxy sets the "backup_proxy" edge to the Proxy entity.
  779. func (_u *ProxyUpdateOne) SetBackupProxy(v *Proxy) *ProxyUpdateOne {
  780. return _u.SetBackupProxyID(v.ID)
  781. }
  782. // Mutation returns the ProxyMutation object of the builder.
  783. func (_u *ProxyUpdateOne) Mutation() *ProxyMutation {
  784. return _u.mutation
  785. }
  786. // ClearAccounts clears all "accounts" edges to the Account entity.
  787. func (_u *ProxyUpdateOne) ClearAccounts() *ProxyUpdateOne {
  788. _u.mutation.ClearAccounts()
  789. return _u
  790. }
  791. // RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
  792. func (_u *ProxyUpdateOne) RemoveAccountIDs(ids ...int64) *ProxyUpdateOne {
  793. _u.mutation.RemoveAccountIDs(ids...)
  794. return _u
  795. }
  796. // RemoveAccounts removes "accounts" edges to Account entities.
  797. func (_u *ProxyUpdateOne) RemoveAccounts(v ...*Account) *ProxyUpdateOne {
  798. ids := make([]int64, len(v))
  799. for i := range v {
  800. ids[i] = v[i].ID
  801. }
  802. return _u.RemoveAccountIDs(ids...)
  803. }
  804. // ClearPrimaryProxies clears all "primary_proxies" edges to the Proxy entity.
  805. func (_u *ProxyUpdateOne) ClearPrimaryProxies() *ProxyUpdateOne {
  806. _u.mutation.ClearPrimaryProxies()
  807. return _u
  808. }
  809. // RemovePrimaryProxyIDs removes the "primary_proxies" edge to Proxy entities by IDs.
  810. func (_u *ProxyUpdateOne) RemovePrimaryProxyIDs(ids ...int64) *ProxyUpdateOne {
  811. _u.mutation.RemovePrimaryProxyIDs(ids...)
  812. return _u
  813. }
  814. // RemovePrimaryProxies removes "primary_proxies" edges to Proxy entities.
  815. func (_u *ProxyUpdateOne) RemovePrimaryProxies(v ...*Proxy) *ProxyUpdateOne {
  816. ids := make([]int64, len(v))
  817. for i := range v {
  818. ids[i] = v[i].ID
  819. }
  820. return _u.RemovePrimaryProxyIDs(ids...)
  821. }
  822. // ClearBackupProxy clears the "backup_proxy" edge to the Proxy entity.
  823. func (_u *ProxyUpdateOne) ClearBackupProxy() *ProxyUpdateOne {
  824. _u.mutation.ClearBackupProxy()
  825. return _u
  826. }
  827. // Where appends a list predicates to the ProxyUpdate builder.
  828. func (_u *ProxyUpdateOne) Where(ps ...predicate.Proxy) *ProxyUpdateOne {
  829. _u.mutation.Where(ps...)
  830. return _u
  831. }
  832. // Select allows selecting one or more fields (columns) of the returned entity.
  833. // The default is selecting all fields defined in the entity schema.
  834. func (_u *ProxyUpdateOne) Select(field string, fields ...string) *ProxyUpdateOne {
  835. _u.fields = append([]string{field}, fields...)
  836. return _u
  837. }
  838. // Save executes the query and returns the updated Proxy entity.
  839. func (_u *ProxyUpdateOne) Save(ctx context.Context) (*Proxy, error) {
  840. if err := _u.defaults(); err != nil {
  841. return nil, err
  842. }
  843. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  844. }
  845. // SaveX is like Save, but panics if an error occurs.
  846. func (_u *ProxyUpdateOne) SaveX(ctx context.Context) *Proxy {
  847. node, err := _u.Save(ctx)
  848. if err != nil {
  849. panic(err)
  850. }
  851. return node
  852. }
  853. // Exec executes the query on the entity.
  854. func (_u *ProxyUpdateOne) Exec(ctx context.Context) error {
  855. _, err := _u.Save(ctx)
  856. return err
  857. }
  858. // ExecX is like Exec, but panics if an error occurs.
  859. func (_u *ProxyUpdateOne) ExecX(ctx context.Context) {
  860. if err := _u.Exec(ctx); err != nil {
  861. panic(err)
  862. }
  863. }
  864. // defaults sets the default values of the builder before save.
  865. func (_u *ProxyUpdateOne) defaults() error {
  866. if _, ok := _u.mutation.UpdatedAt(); !ok {
  867. if proxy.UpdateDefaultUpdatedAt == nil {
  868. return fmt.Errorf("ent: uninitialized proxy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  869. }
  870. v := proxy.UpdateDefaultUpdatedAt()
  871. _u.mutation.SetUpdatedAt(v)
  872. }
  873. return nil
  874. }
  875. // check runs all checks and user-defined validators on the builder.
  876. func (_u *ProxyUpdateOne) check() error {
  877. if v, ok := _u.mutation.Name(); ok {
  878. if err := proxy.NameValidator(v); err != nil {
  879. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
  880. }
  881. }
  882. if v, ok := _u.mutation.Protocol(); ok {
  883. if err := proxy.ProtocolValidator(v); err != nil {
  884. return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
  885. }
  886. }
  887. if v, ok := _u.mutation.Host(); ok {
  888. if err := proxy.HostValidator(v); err != nil {
  889. return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
  890. }
  891. }
  892. if v, ok := _u.mutation.Username(); ok {
  893. if err := proxy.UsernameValidator(v); err != nil {
  894. return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
  895. }
  896. }
  897. if v, ok := _u.mutation.Password(); ok {
  898. if err := proxy.PasswordValidator(v); err != nil {
  899. return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
  900. }
  901. }
  902. if v, ok := _u.mutation.Status(); ok {
  903. if err := proxy.StatusValidator(v); err != nil {
  904. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
  905. }
  906. }
  907. if v, ok := _u.mutation.FallbackMode(); ok {
  908. if err := proxy.FallbackModeValidator(v); err != nil {
  909. return &ValidationError{Name: "fallback_mode", err: fmt.Errorf(`ent: validator failed for field "Proxy.fallback_mode": %w`, err)}
  910. }
  911. }
  912. return nil
  913. }
  914. func (_u *ProxyUpdateOne) sqlSave(ctx context.Context) (_node *Proxy, err error) {
  915. if err := _u.check(); err != nil {
  916. return _node, err
  917. }
  918. _spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
  919. id, ok := _u.mutation.ID()
  920. if !ok {
  921. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Proxy.id" for update`)}
  922. }
  923. _spec.Node.ID.Value = id
  924. if fields := _u.fields; len(fields) > 0 {
  925. _spec.Node.Columns = make([]string, 0, len(fields))
  926. _spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
  927. for _, f := range fields {
  928. if !proxy.ValidColumn(f) {
  929. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  930. }
  931. if f != proxy.FieldID {
  932. _spec.Node.Columns = append(_spec.Node.Columns, f)
  933. }
  934. }
  935. }
  936. if ps := _u.mutation.predicates; len(ps) > 0 {
  937. _spec.Predicate = func(selector *sql.Selector) {
  938. for i := range ps {
  939. ps[i](selector)
  940. }
  941. }
  942. }
  943. if value, ok := _u.mutation.UpdatedAt(); ok {
  944. _spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
  945. }
  946. if value, ok := _u.mutation.DeletedAt(); ok {
  947. _spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
  948. }
  949. if _u.mutation.DeletedAtCleared() {
  950. _spec.ClearField(proxy.FieldDeletedAt, field.TypeTime)
  951. }
  952. if value, ok := _u.mutation.Name(); ok {
  953. _spec.SetField(proxy.FieldName, field.TypeString, value)
  954. }
  955. if value, ok := _u.mutation.Protocol(); ok {
  956. _spec.SetField(proxy.FieldProtocol, field.TypeString, value)
  957. }
  958. if value, ok := _u.mutation.Host(); ok {
  959. _spec.SetField(proxy.FieldHost, field.TypeString, value)
  960. }
  961. if value, ok := _u.mutation.Port(); ok {
  962. _spec.SetField(proxy.FieldPort, field.TypeInt, value)
  963. }
  964. if value, ok := _u.mutation.AddedPort(); ok {
  965. _spec.AddField(proxy.FieldPort, field.TypeInt, value)
  966. }
  967. if value, ok := _u.mutation.Username(); ok {
  968. _spec.SetField(proxy.FieldUsername, field.TypeString, value)
  969. }
  970. if _u.mutation.UsernameCleared() {
  971. _spec.ClearField(proxy.FieldUsername, field.TypeString)
  972. }
  973. if value, ok := _u.mutation.Password(); ok {
  974. _spec.SetField(proxy.FieldPassword, field.TypeString, value)
  975. }
  976. if _u.mutation.PasswordCleared() {
  977. _spec.ClearField(proxy.FieldPassword, field.TypeString)
  978. }
  979. if value, ok := _u.mutation.Status(); ok {
  980. _spec.SetField(proxy.FieldStatus, field.TypeString, value)
  981. }
  982. if value, ok := _u.mutation.ExpiresAt(); ok {
  983. _spec.SetField(proxy.FieldExpiresAt, field.TypeTime, value)
  984. }
  985. if _u.mutation.ExpiresAtCleared() {
  986. _spec.ClearField(proxy.FieldExpiresAt, field.TypeTime)
  987. }
  988. if value, ok := _u.mutation.FallbackMode(); ok {
  989. _spec.SetField(proxy.FieldFallbackMode, field.TypeString, value)
  990. }
  991. if value, ok := _u.mutation.ExpiryWarnDays(); ok {
  992. _spec.SetField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
  993. }
  994. if value, ok := _u.mutation.AddedExpiryWarnDays(); ok {
  995. _spec.AddField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
  996. }
  997. if _u.mutation.AccountsCleared() {
  998. edge := &sqlgraph.EdgeSpec{
  999. Rel: sqlgraph.O2M,
  1000. Inverse: true,
  1001. Table: proxy.AccountsTable,
  1002. Columns: []string{proxy.AccountsColumn},
  1003. Bidi: false,
  1004. Target: &sqlgraph.EdgeTarget{
  1005. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  1006. },
  1007. }
  1008. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1009. }
  1010. if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
  1011. edge := &sqlgraph.EdgeSpec{
  1012. Rel: sqlgraph.O2M,
  1013. Inverse: true,
  1014. Table: proxy.AccountsTable,
  1015. Columns: []string{proxy.AccountsColumn},
  1016. Bidi: false,
  1017. Target: &sqlgraph.EdgeTarget{
  1018. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  1019. },
  1020. }
  1021. for _, k := range nodes {
  1022. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1023. }
  1024. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1025. }
  1026. if nodes := _u.mutation.AccountsIDs(); len(nodes) > 0 {
  1027. edge := &sqlgraph.EdgeSpec{
  1028. Rel: sqlgraph.O2M,
  1029. Inverse: true,
  1030. Table: proxy.AccountsTable,
  1031. Columns: []string{proxy.AccountsColumn},
  1032. Bidi: false,
  1033. Target: &sqlgraph.EdgeTarget{
  1034. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  1035. },
  1036. }
  1037. for _, k := range nodes {
  1038. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1039. }
  1040. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1041. }
  1042. if _u.mutation.PrimaryProxiesCleared() {
  1043. edge := &sqlgraph.EdgeSpec{
  1044. Rel: sqlgraph.O2M,
  1045. Inverse: true,
  1046. Table: proxy.PrimaryProxiesTable,
  1047. Columns: []string{proxy.PrimaryProxiesColumn},
  1048. Bidi: false,
  1049. Target: &sqlgraph.EdgeTarget{
  1050. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  1051. },
  1052. }
  1053. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1054. }
  1055. if nodes := _u.mutation.RemovedPrimaryProxiesIDs(); len(nodes) > 0 && !_u.mutation.PrimaryProxiesCleared() {
  1056. edge := &sqlgraph.EdgeSpec{
  1057. Rel: sqlgraph.O2M,
  1058. Inverse: true,
  1059. Table: proxy.PrimaryProxiesTable,
  1060. Columns: []string{proxy.PrimaryProxiesColumn},
  1061. Bidi: false,
  1062. Target: &sqlgraph.EdgeTarget{
  1063. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  1064. },
  1065. }
  1066. for _, k := range nodes {
  1067. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1068. }
  1069. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1070. }
  1071. if nodes := _u.mutation.PrimaryProxiesIDs(); len(nodes) > 0 {
  1072. edge := &sqlgraph.EdgeSpec{
  1073. Rel: sqlgraph.O2M,
  1074. Inverse: true,
  1075. Table: proxy.PrimaryProxiesTable,
  1076. Columns: []string{proxy.PrimaryProxiesColumn},
  1077. Bidi: false,
  1078. Target: &sqlgraph.EdgeTarget{
  1079. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  1080. },
  1081. }
  1082. for _, k := range nodes {
  1083. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1084. }
  1085. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1086. }
  1087. if _u.mutation.BackupProxyCleared() {
  1088. edge := &sqlgraph.EdgeSpec{
  1089. Rel: sqlgraph.M2O,
  1090. Inverse: false,
  1091. Table: proxy.BackupProxyTable,
  1092. Columns: []string{proxy.BackupProxyColumn},
  1093. Bidi: false,
  1094. Target: &sqlgraph.EdgeTarget{
  1095. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  1096. },
  1097. }
  1098. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1099. }
  1100. if nodes := _u.mutation.BackupProxyIDs(); len(nodes) > 0 {
  1101. edge := &sqlgraph.EdgeSpec{
  1102. Rel: sqlgraph.M2O,
  1103. Inverse: false,
  1104. Table: proxy.BackupProxyTable,
  1105. Columns: []string{proxy.BackupProxyColumn},
  1106. Bidi: false,
  1107. Target: &sqlgraph.EdgeTarget{
  1108. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  1109. },
  1110. }
  1111. for _, k := range nodes {
  1112. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1113. }
  1114. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1115. }
  1116. _node = &Proxy{config: _u.config}
  1117. _spec.Assign = _node.assignValues
  1118. _spec.ScanValues = _node.scanValues
  1119. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  1120. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1121. err = &NotFoundError{proxy.Label}
  1122. } else if sqlgraph.IsConstraintError(err) {
  1123. err = &ConstraintError{msg: err.Error(), wrap: err}
  1124. }
  1125. return nil, err
  1126. }
  1127. _u.mutation.done = true
  1128. return _node, nil
  1129. }