proxy_create.go 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  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/proxy"
  13. )
  14. // ProxyCreate is the builder for creating a Proxy entity.
  15. type ProxyCreate struct {
  16. config
  17. mutation *ProxyMutation
  18. hooks []Hook
  19. conflict []sql.ConflictOption
  20. }
  21. // SetCreatedAt sets the "created_at" field.
  22. func (_c *ProxyCreate) SetCreatedAt(v time.Time) *ProxyCreate {
  23. _c.mutation.SetCreatedAt(v)
  24. return _c
  25. }
  26. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  27. func (_c *ProxyCreate) SetNillableCreatedAt(v *time.Time) *ProxyCreate {
  28. if v != nil {
  29. _c.SetCreatedAt(*v)
  30. }
  31. return _c
  32. }
  33. // SetUpdatedAt sets the "updated_at" field.
  34. func (_c *ProxyCreate) SetUpdatedAt(v time.Time) *ProxyCreate {
  35. _c.mutation.SetUpdatedAt(v)
  36. return _c
  37. }
  38. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  39. func (_c *ProxyCreate) SetNillableUpdatedAt(v *time.Time) *ProxyCreate {
  40. if v != nil {
  41. _c.SetUpdatedAt(*v)
  42. }
  43. return _c
  44. }
  45. // SetDeletedAt sets the "deleted_at" field.
  46. func (_c *ProxyCreate) SetDeletedAt(v time.Time) *ProxyCreate {
  47. _c.mutation.SetDeletedAt(v)
  48. return _c
  49. }
  50. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  51. func (_c *ProxyCreate) SetNillableDeletedAt(v *time.Time) *ProxyCreate {
  52. if v != nil {
  53. _c.SetDeletedAt(*v)
  54. }
  55. return _c
  56. }
  57. // SetName sets the "name" field.
  58. func (_c *ProxyCreate) SetName(v string) *ProxyCreate {
  59. _c.mutation.SetName(v)
  60. return _c
  61. }
  62. // SetProtocol sets the "protocol" field.
  63. func (_c *ProxyCreate) SetProtocol(v string) *ProxyCreate {
  64. _c.mutation.SetProtocol(v)
  65. return _c
  66. }
  67. // SetHost sets the "host" field.
  68. func (_c *ProxyCreate) SetHost(v string) *ProxyCreate {
  69. _c.mutation.SetHost(v)
  70. return _c
  71. }
  72. // SetPort sets the "port" field.
  73. func (_c *ProxyCreate) SetPort(v int) *ProxyCreate {
  74. _c.mutation.SetPort(v)
  75. return _c
  76. }
  77. // SetUsername sets the "username" field.
  78. func (_c *ProxyCreate) SetUsername(v string) *ProxyCreate {
  79. _c.mutation.SetUsername(v)
  80. return _c
  81. }
  82. // SetNillableUsername sets the "username" field if the given value is not nil.
  83. func (_c *ProxyCreate) SetNillableUsername(v *string) *ProxyCreate {
  84. if v != nil {
  85. _c.SetUsername(*v)
  86. }
  87. return _c
  88. }
  89. // SetPassword sets the "password" field.
  90. func (_c *ProxyCreate) SetPassword(v string) *ProxyCreate {
  91. _c.mutation.SetPassword(v)
  92. return _c
  93. }
  94. // SetNillablePassword sets the "password" field if the given value is not nil.
  95. func (_c *ProxyCreate) SetNillablePassword(v *string) *ProxyCreate {
  96. if v != nil {
  97. _c.SetPassword(*v)
  98. }
  99. return _c
  100. }
  101. // SetStatus sets the "status" field.
  102. func (_c *ProxyCreate) SetStatus(v string) *ProxyCreate {
  103. _c.mutation.SetStatus(v)
  104. return _c
  105. }
  106. // SetNillableStatus sets the "status" field if the given value is not nil.
  107. func (_c *ProxyCreate) SetNillableStatus(v *string) *ProxyCreate {
  108. if v != nil {
  109. _c.SetStatus(*v)
  110. }
  111. return _c
  112. }
  113. // SetExpiresAt sets the "expires_at" field.
  114. func (_c *ProxyCreate) SetExpiresAt(v time.Time) *ProxyCreate {
  115. _c.mutation.SetExpiresAt(v)
  116. return _c
  117. }
  118. // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
  119. func (_c *ProxyCreate) SetNillableExpiresAt(v *time.Time) *ProxyCreate {
  120. if v != nil {
  121. _c.SetExpiresAt(*v)
  122. }
  123. return _c
  124. }
  125. // SetFallbackMode sets the "fallback_mode" field.
  126. func (_c *ProxyCreate) SetFallbackMode(v string) *ProxyCreate {
  127. _c.mutation.SetFallbackMode(v)
  128. return _c
  129. }
  130. // SetNillableFallbackMode sets the "fallback_mode" field if the given value is not nil.
  131. func (_c *ProxyCreate) SetNillableFallbackMode(v *string) *ProxyCreate {
  132. if v != nil {
  133. _c.SetFallbackMode(*v)
  134. }
  135. return _c
  136. }
  137. // SetBackupProxyID sets the "backup_proxy_id" field.
  138. func (_c *ProxyCreate) SetBackupProxyID(v int64) *ProxyCreate {
  139. _c.mutation.SetBackupProxyID(v)
  140. return _c
  141. }
  142. // SetNillableBackupProxyID sets the "backup_proxy_id" field if the given value is not nil.
  143. func (_c *ProxyCreate) SetNillableBackupProxyID(v *int64) *ProxyCreate {
  144. if v != nil {
  145. _c.SetBackupProxyID(*v)
  146. }
  147. return _c
  148. }
  149. // SetExpiryWarnDays sets the "expiry_warn_days" field.
  150. func (_c *ProxyCreate) SetExpiryWarnDays(v int) *ProxyCreate {
  151. _c.mutation.SetExpiryWarnDays(v)
  152. return _c
  153. }
  154. // SetNillableExpiryWarnDays sets the "expiry_warn_days" field if the given value is not nil.
  155. func (_c *ProxyCreate) SetNillableExpiryWarnDays(v *int) *ProxyCreate {
  156. if v != nil {
  157. _c.SetExpiryWarnDays(*v)
  158. }
  159. return _c
  160. }
  161. // AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
  162. func (_c *ProxyCreate) AddAccountIDs(ids ...int64) *ProxyCreate {
  163. _c.mutation.AddAccountIDs(ids...)
  164. return _c
  165. }
  166. // AddAccounts adds the "accounts" edges to the Account entity.
  167. func (_c *ProxyCreate) AddAccounts(v ...*Account) *ProxyCreate {
  168. ids := make([]int64, len(v))
  169. for i := range v {
  170. ids[i] = v[i].ID
  171. }
  172. return _c.AddAccountIDs(ids...)
  173. }
  174. // AddPrimaryProxyIDs adds the "primary_proxies" edge to the Proxy entity by IDs.
  175. func (_c *ProxyCreate) AddPrimaryProxyIDs(ids ...int64) *ProxyCreate {
  176. _c.mutation.AddPrimaryProxyIDs(ids...)
  177. return _c
  178. }
  179. // AddPrimaryProxies adds the "primary_proxies" edges to the Proxy entity.
  180. func (_c *ProxyCreate) AddPrimaryProxies(v ...*Proxy) *ProxyCreate {
  181. ids := make([]int64, len(v))
  182. for i := range v {
  183. ids[i] = v[i].ID
  184. }
  185. return _c.AddPrimaryProxyIDs(ids...)
  186. }
  187. // SetBackupProxy sets the "backup_proxy" edge to the Proxy entity.
  188. func (_c *ProxyCreate) SetBackupProxy(v *Proxy) *ProxyCreate {
  189. return _c.SetBackupProxyID(v.ID)
  190. }
  191. // Mutation returns the ProxyMutation object of the builder.
  192. func (_c *ProxyCreate) Mutation() *ProxyMutation {
  193. return _c.mutation
  194. }
  195. // Save creates the Proxy in the database.
  196. func (_c *ProxyCreate) Save(ctx context.Context) (*Proxy, error) {
  197. if err := _c.defaults(); err != nil {
  198. return nil, err
  199. }
  200. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  201. }
  202. // SaveX calls Save and panics if Save returns an error.
  203. func (_c *ProxyCreate) SaveX(ctx context.Context) *Proxy {
  204. v, err := _c.Save(ctx)
  205. if err != nil {
  206. panic(err)
  207. }
  208. return v
  209. }
  210. // Exec executes the query.
  211. func (_c *ProxyCreate) Exec(ctx context.Context) error {
  212. _, err := _c.Save(ctx)
  213. return err
  214. }
  215. // ExecX is like Exec, but panics if an error occurs.
  216. func (_c *ProxyCreate) ExecX(ctx context.Context) {
  217. if err := _c.Exec(ctx); err != nil {
  218. panic(err)
  219. }
  220. }
  221. // defaults sets the default values of the builder before save.
  222. func (_c *ProxyCreate) defaults() error {
  223. if _, ok := _c.mutation.CreatedAt(); !ok {
  224. if proxy.DefaultCreatedAt == nil {
  225. return fmt.Errorf("ent: uninitialized proxy.DefaultCreatedAt (forgotten import ent/runtime?)")
  226. }
  227. v := proxy.DefaultCreatedAt()
  228. _c.mutation.SetCreatedAt(v)
  229. }
  230. if _, ok := _c.mutation.UpdatedAt(); !ok {
  231. if proxy.DefaultUpdatedAt == nil {
  232. return fmt.Errorf("ent: uninitialized proxy.DefaultUpdatedAt (forgotten import ent/runtime?)")
  233. }
  234. v := proxy.DefaultUpdatedAt()
  235. _c.mutation.SetUpdatedAt(v)
  236. }
  237. if _, ok := _c.mutation.Status(); !ok {
  238. v := proxy.DefaultStatus
  239. _c.mutation.SetStatus(v)
  240. }
  241. if _, ok := _c.mutation.FallbackMode(); !ok {
  242. v := proxy.DefaultFallbackMode
  243. _c.mutation.SetFallbackMode(v)
  244. }
  245. if _, ok := _c.mutation.ExpiryWarnDays(); !ok {
  246. v := proxy.DefaultExpiryWarnDays
  247. _c.mutation.SetExpiryWarnDays(v)
  248. }
  249. return nil
  250. }
  251. // check runs all checks and user-defined validators on the builder.
  252. func (_c *ProxyCreate) check() error {
  253. if _, ok := _c.mutation.CreatedAt(); !ok {
  254. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Proxy.created_at"`)}
  255. }
  256. if _, ok := _c.mutation.UpdatedAt(); !ok {
  257. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Proxy.updated_at"`)}
  258. }
  259. if _, ok := _c.mutation.Name(); !ok {
  260. return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Proxy.name"`)}
  261. }
  262. if v, ok := _c.mutation.Name(); ok {
  263. if err := proxy.NameValidator(v); err != nil {
  264. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
  265. }
  266. }
  267. if _, ok := _c.mutation.Protocol(); !ok {
  268. return &ValidationError{Name: "protocol", err: errors.New(`ent: missing required field "Proxy.protocol"`)}
  269. }
  270. if v, ok := _c.mutation.Protocol(); ok {
  271. if err := proxy.ProtocolValidator(v); err != nil {
  272. return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
  273. }
  274. }
  275. if _, ok := _c.mutation.Host(); !ok {
  276. return &ValidationError{Name: "host", err: errors.New(`ent: missing required field "Proxy.host"`)}
  277. }
  278. if v, ok := _c.mutation.Host(); ok {
  279. if err := proxy.HostValidator(v); err != nil {
  280. return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
  281. }
  282. }
  283. if _, ok := _c.mutation.Port(); !ok {
  284. return &ValidationError{Name: "port", err: errors.New(`ent: missing required field "Proxy.port"`)}
  285. }
  286. if v, ok := _c.mutation.Username(); ok {
  287. if err := proxy.UsernameValidator(v); err != nil {
  288. return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
  289. }
  290. }
  291. if v, ok := _c.mutation.Password(); ok {
  292. if err := proxy.PasswordValidator(v); err != nil {
  293. return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
  294. }
  295. }
  296. if _, ok := _c.mutation.Status(); !ok {
  297. return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Proxy.status"`)}
  298. }
  299. if v, ok := _c.mutation.Status(); ok {
  300. if err := proxy.StatusValidator(v); err != nil {
  301. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
  302. }
  303. }
  304. if _, ok := _c.mutation.FallbackMode(); !ok {
  305. return &ValidationError{Name: "fallback_mode", err: errors.New(`ent: missing required field "Proxy.fallback_mode"`)}
  306. }
  307. if v, ok := _c.mutation.FallbackMode(); ok {
  308. if err := proxy.FallbackModeValidator(v); err != nil {
  309. return &ValidationError{Name: "fallback_mode", err: fmt.Errorf(`ent: validator failed for field "Proxy.fallback_mode": %w`, err)}
  310. }
  311. }
  312. if _, ok := _c.mutation.ExpiryWarnDays(); !ok {
  313. return &ValidationError{Name: "expiry_warn_days", err: errors.New(`ent: missing required field "Proxy.expiry_warn_days"`)}
  314. }
  315. return nil
  316. }
  317. func (_c *ProxyCreate) sqlSave(ctx context.Context) (*Proxy, error) {
  318. if err := _c.check(); err != nil {
  319. return nil, err
  320. }
  321. _node, _spec := _c.createSpec()
  322. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  323. if sqlgraph.IsConstraintError(err) {
  324. err = &ConstraintError{msg: err.Error(), wrap: err}
  325. }
  326. return nil, err
  327. }
  328. id := _spec.ID.Value.(int64)
  329. _node.ID = int64(id)
  330. _c.mutation.id = &_node.ID
  331. _c.mutation.done = true
  332. return _node, nil
  333. }
  334. func (_c *ProxyCreate) createSpec() (*Proxy, *sqlgraph.CreateSpec) {
  335. var (
  336. _node = &Proxy{config: _c.config}
  337. _spec = sqlgraph.NewCreateSpec(proxy.Table, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
  338. )
  339. _spec.OnConflict = _c.conflict
  340. if value, ok := _c.mutation.CreatedAt(); ok {
  341. _spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
  342. _node.CreatedAt = value
  343. }
  344. if value, ok := _c.mutation.UpdatedAt(); ok {
  345. _spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
  346. _node.UpdatedAt = value
  347. }
  348. if value, ok := _c.mutation.DeletedAt(); ok {
  349. _spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
  350. _node.DeletedAt = &value
  351. }
  352. if value, ok := _c.mutation.Name(); ok {
  353. _spec.SetField(proxy.FieldName, field.TypeString, value)
  354. _node.Name = value
  355. }
  356. if value, ok := _c.mutation.Protocol(); ok {
  357. _spec.SetField(proxy.FieldProtocol, field.TypeString, value)
  358. _node.Protocol = value
  359. }
  360. if value, ok := _c.mutation.Host(); ok {
  361. _spec.SetField(proxy.FieldHost, field.TypeString, value)
  362. _node.Host = value
  363. }
  364. if value, ok := _c.mutation.Port(); ok {
  365. _spec.SetField(proxy.FieldPort, field.TypeInt, value)
  366. _node.Port = value
  367. }
  368. if value, ok := _c.mutation.Username(); ok {
  369. _spec.SetField(proxy.FieldUsername, field.TypeString, value)
  370. _node.Username = &value
  371. }
  372. if value, ok := _c.mutation.Password(); ok {
  373. _spec.SetField(proxy.FieldPassword, field.TypeString, value)
  374. _node.Password = &value
  375. }
  376. if value, ok := _c.mutation.Status(); ok {
  377. _spec.SetField(proxy.FieldStatus, field.TypeString, value)
  378. _node.Status = value
  379. }
  380. if value, ok := _c.mutation.ExpiresAt(); ok {
  381. _spec.SetField(proxy.FieldExpiresAt, field.TypeTime, value)
  382. _node.ExpiresAt = &value
  383. }
  384. if value, ok := _c.mutation.FallbackMode(); ok {
  385. _spec.SetField(proxy.FieldFallbackMode, field.TypeString, value)
  386. _node.FallbackMode = value
  387. }
  388. if value, ok := _c.mutation.ExpiryWarnDays(); ok {
  389. _spec.SetField(proxy.FieldExpiryWarnDays, field.TypeInt, value)
  390. _node.ExpiryWarnDays = value
  391. }
  392. if nodes := _c.mutation.AccountsIDs(); len(nodes) > 0 {
  393. edge := &sqlgraph.EdgeSpec{
  394. Rel: sqlgraph.O2M,
  395. Inverse: true,
  396. Table: proxy.AccountsTable,
  397. Columns: []string{proxy.AccountsColumn},
  398. Bidi: false,
  399. Target: &sqlgraph.EdgeTarget{
  400. IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
  401. },
  402. }
  403. for _, k := range nodes {
  404. edge.Target.Nodes = append(edge.Target.Nodes, k)
  405. }
  406. _spec.Edges = append(_spec.Edges, edge)
  407. }
  408. if nodes := _c.mutation.PrimaryProxiesIDs(); len(nodes) > 0 {
  409. edge := &sqlgraph.EdgeSpec{
  410. Rel: sqlgraph.O2M,
  411. Inverse: true,
  412. Table: proxy.PrimaryProxiesTable,
  413. Columns: []string{proxy.PrimaryProxiesColumn},
  414. Bidi: false,
  415. Target: &sqlgraph.EdgeTarget{
  416. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  417. },
  418. }
  419. for _, k := range nodes {
  420. edge.Target.Nodes = append(edge.Target.Nodes, k)
  421. }
  422. _spec.Edges = append(_spec.Edges, edge)
  423. }
  424. if nodes := _c.mutation.BackupProxyIDs(); len(nodes) > 0 {
  425. edge := &sqlgraph.EdgeSpec{
  426. Rel: sqlgraph.M2O,
  427. Inverse: false,
  428. Table: proxy.BackupProxyTable,
  429. Columns: []string{proxy.BackupProxyColumn},
  430. Bidi: false,
  431. Target: &sqlgraph.EdgeTarget{
  432. IDSpec: sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64),
  433. },
  434. }
  435. for _, k := range nodes {
  436. edge.Target.Nodes = append(edge.Target.Nodes, k)
  437. }
  438. _node.BackupProxyID = &nodes[0]
  439. _spec.Edges = append(_spec.Edges, edge)
  440. }
  441. return _node, _spec
  442. }
  443. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  444. // of the `INSERT` statement. For example:
  445. //
  446. // client.Proxy.Create().
  447. // SetCreatedAt(v).
  448. // OnConflict(
  449. // // Update the row with the new values
  450. // // the was proposed for insertion.
  451. // sql.ResolveWithNewValues(),
  452. // ).
  453. // // Override some of the fields with custom
  454. // // update values.
  455. // Update(func(u *ent.ProxyUpsert) {
  456. // SetCreatedAt(v+v).
  457. // }).
  458. // Exec(ctx)
  459. func (_c *ProxyCreate) OnConflict(opts ...sql.ConflictOption) *ProxyUpsertOne {
  460. _c.conflict = opts
  461. return &ProxyUpsertOne{
  462. create: _c,
  463. }
  464. }
  465. // OnConflictColumns calls `OnConflict` and configures the columns
  466. // as conflict target. Using this option is equivalent to using:
  467. //
  468. // client.Proxy.Create().
  469. // OnConflict(sql.ConflictColumns(columns...)).
  470. // Exec(ctx)
  471. func (_c *ProxyCreate) OnConflictColumns(columns ...string) *ProxyUpsertOne {
  472. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  473. return &ProxyUpsertOne{
  474. create: _c,
  475. }
  476. }
  477. type (
  478. // ProxyUpsertOne is the builder for "upsert"-ing
  479. // one Proxy node.
  480. ProxyUpsertOne struct {
  481. create *ProxyCreate
  482. }
  483. // ProxyUpsert is the "OnConflict" setter.
  484. ProxyUpsert struct {
  485. *sql.UpdateSet
  486. }
  487. )
  488. // SetUpdatedAt sets the "updated_at" field.
  489. func (u *ProxyUpsert) SetUpdatedAt(v time.Time) *ProxyUpsert {
  490. u.Set(proxy.FieldUpdatedAt, v)
  491. return u
  492. }
  493. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  494. func (u *ProxyUpsert) UpdateUpdatedAt() *ProxyUpsert {
  495. u.SetExcluded(proxy.FieldUpdatedAt)
  496. return u
  497. }
  498. // SetDeletedAt sets the "deleted_at" field.
  499. func (u *ProxyUpsert) SetDeletedAt(v time.Time) *ProxyUpsert {
  500. u.Set(proxy.FieldDeletedAt, v)
  501. return u
  502. }
  503. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  504. func (u *ProxyUpsert) UpdateDeletedAt() *ProxyUpsert {
  505. u.SetExcluded(proxy.FieldDeletedAt)
  506. return u
  507. }
  508. // ClearDeletedAt clears the value of the "deleted_at" field.
  509. func (u *ProxyUpsert) ClearDeletedAt() *ProxyUpsert {
  510. u.SetNull(proxy.FieldDeletedAt)
  511. return u
  512. }
  513. // SetName sets the "name" field.
  514. func (u *ProxyUpsert) SetName(v string) *ProxyUpsert {
  515. u.Set(proxy.FieldName, v)
  516. return u
  517. }
  518. // UpdateName sets the "name" field to the value that was provided on create.
  519. func (u *ProxyUpsert) UpdateName() *ProxyUpsert {
  520. u.SetExcluded(proxy.FieldName)
  521. return u
  522. }
  523. // SetProtocol sets the "protocol" field.
  524. func (u *ProxyUpsert) SetProtocol(v string) *ProxyUpsert {
  525. u.Set(proxy.FieldProtocol, v)
  526. return u
  527. }
  528. // UpdateProtocol sets the "protocol" field to the value that was provided on create.
  529. func (u *ProxyUpsert) UpdateProtocol() *ProxyUpsert {
  530. u.SetExcluded(proxy.FieldProtocol)
  531. return u
  532. }
  533. // SetHost sets the "host" field.
  534. func (u *ProxyUpsert) SetHost(v string) *ProxyUpsert {
  535. u.Set(proxy.FieldHost, v)
  536. return u
  537. }
  538. // UpdateHost sets the "host" field to the value that was provided on create.
  539. func (u *ProxyUpsert) UpdateHost() *ProxyUpsert {
  540. u.SetExcluded(proxy.FieldHost)
  541. return u
  542. }
  543. // SetPort sets the "port" field.
  544. func (u *ProxyUpsert) SetPort(v int) *ProxyUpsert {
  545. u.Set(proxy.FieldPort, v)
  546. return u
  547. }
  548. // UpdatePort sets the "port" field to the value that was provided on create.
  549. func (u *ProxyUpsert) UpdatePort() *ProxyUpsert {
  550. u.SetExcluded(proxy.FieldPort)
  551. return u
  552. }
  553. // AddPort adds v to the "port" field.
  554. func (u *ProxyUpsert) AddPort(v int) *ProxyUpsert {
  555. u.Add(proxy.FieldPort, v)
  556. return u
  557. }
  558. // SetUsername sets the "username" field.
  559. func (u *ProxyUpsert) SetUsername(v string) *ProxyUpsert {
  560. u.Set(proxy.FieldUsername, v)
  561. return u
  562. }
  563. // UpdateUsername sets the "username" field to the value that was provided on create.
  564. func (u *ProxyUpsert) UpdateUsername() *ProxyUpsert {
  565. u.SetExcluded(proxy.FieldUsername)
  566. return u
  567. }
  568. // ClearUsername clears the value of the "username" field.
  569. func (u *ProxyUpsert) ClearUsername() *ProxyUpsert {
  570. u.SetNull(proxy.FieldUsername)
  571. return u
  572. }
  573. // SetPassword sets the "password" field.
  574. func (u *ProxyUpsert) SetPassword(v string) *ProxyUpsert {
  575. u.Set(proxy.FieldPassword, v)
  576. return u
  577. }
  578. // UpdatePassword sets the "password" field to the value that was provided on create.
  579. func (u *ProxyUpsert) UpdatePassword() *ProxyUpsert {
  580. u.SetExcluded(proxy.FieldPassword)
  581. return u
  582. }
  583. // ClearPassword clears the value of the "password" field.
  584. func (u *ProxyUpsert) ClearPassword() *ProxyUpsert {
  585. u.SetNull(proxy.FieldPassword)
  586. return u
  587. }
  588. // SetStatus sets the "status" field.
  589. func (u *ProxyUpsert) SetStatus(v string) *ProxyUpsert {
  590. u.Set(proxy.FieldStatus, v)
  591. return u
  592. }
  593. // UpdateStatus sets the "status" field to the value that was provided on create.
  594. func (u *ProxyUpsert) UpdateStatus() *ProxyUpsert {
  595. u.SetExcluded(proxy.FieldStatus)
  596. return u
  597. }
  598. // SetExpiresAt sets the "expires_at" field.
  599. func (u *ProxyUpsert) SetExpiresAt(v time.Time) *ProxyUpsert {
  600. u.Set(proxy.FieldExpiresAt, v)
  601. return u
  602. }
  603. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  604. func (u *ProxyUpsert) UpdateExpiresAt() *ProxyUpsert {
  605. u.SetExcluded(proxy.FieldExpiresAt)
  606. return u
  607. }
  608. // ClearExpiresAt clears the value of the "expires_at" field.
  609. func (u *ProxyUpsert) ClearExpiresAt() *ProxyUpsert {
  610. u.SetNull(proxy.FieldExpiresAt)
  611. return u
  612. }
  613. // SetFallbackMode sets the "fallback_mode" field.
  614. func (u *ProxyUpsert) SetFallbackMode(v string) *ProxyUpsert {
  615. u.Set(proxy.FieldFallbackMode, v)
  616. return u
  617. }
  618. // UpdateFallbackMode sets the "fallback_mode" field to the value that was provided on create.
  619. func (u *ProxyUpsert) UpdateFallbackMode() *ProxyUpsert {
  620. u.SetExcluded(proxy.FieldFallbackMode)
  621. return u
  622. }
  623. // SetBackupProxyID sets the "backup_proxy_id" field.
  624. func (u *ProxyUpsert) SetBackupProxyID(v int64) *ProxyUpsert {
  625. u.Set(proxy.FieldBackupProxyID, v)
  626. return u
  627. }
  628. // UpdateBackupProxyID sets the "backup_proxy_id" field to the value that was provided on create.
  629. func (u *ProxyUpsert) UpdateBackupProxyID() *ProxyUpsert {
  630. u.SetExcluded(proxy.FieldBackupProxyID)
  631. return u
  632. }
  633. // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
  634. func (u *ProxyUpsert) ClearBackupProxyID() *ProxyUpsert {
  635. u.SetNull(proxy.FieldBackupProxyID)
  636. return u
  637. }
  638. // SetExpiryWarnDays sets the "expiry_warn_days" field.
  639. func (u *ProxyUpsert) SetExpiryWarnDays(v int) *ProxyUpsert {
  640. u.Set(proxy.FieldExpiryWarnDays, v)
  641. return u
  642. }
  643. // UpdateExpiryWarnDays sets the "expiry_warn_days" field to the value that was provided on create.
  644. func (u *ProxyUpsert) UpdateExpiryWarnDays() *ProxyUpsert {
  645. u.SetExcluded(proxy.FieldExpiryWarnDays)
  646. return u
  647. }
  648. // AddExpiryWarnDays adds v to the "expiry_warn_days" field.
  649. func (u *ProxyUpsert) AddExpiryWarnDays(v int) *ProxyUpsert {
  650. u.Add(proxy.FieldExpiryWarnDays, v)
  651. return u
  652. }
  653. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  654. // Using this option is equivalent to using:
  655. //
  656. // client.Proxy.Create().
  657. // OnConflict(
  658. // sql.ResolveWithNewValues(),
  659. // ).
  660. // Exec(ctx)
  661. func (u *ProxyUpsertOne) UpdateNewValues() *ProxyUpsertOne {
  662. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  663. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  664. if _, exists := u.create.mutation.CreatedAt(); exists {
  665. s.SetIgnore(proxy.FieldCreatedAt)
  666. }
  667. }))
  668. return u
  669. }
  670. // Ignore sets each column to itself in case of conflict.
  671. // Using this option is equivalent to using:
  672. //
  673. // client.Proxy.Create().
  674. // OnConflict(sql.ResolveWithIgnore()).
  675. // Exec(ctx)
  676. func (u *ProxyUpsertOne) Ignore() *ProxyUpsertOne {
  677. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  678. return u
  679. }
  680. // DoNothing configures the conflict_action to `DO NOTHING`.
  681. // Supported only by SQLite and PostgreSQL.
  682. func (u *ProxyUpsertOne) DoNothing() *ProxyUpsertOne {
  683. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  684. return u
  685. }
  686. // Update allows overriding fields `UPDATE` values. See the ProxyCreate.OnConflict
  687. // documentation for more info.
  688. func (u *ProxyUpsertOne) Update(set func(*ProxyUpsert)) *ProxyUpsertOne {
  689. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  690. set(&ProxyUpsert{UpdateSet: update})
  691. }))
  692. return u
  693. }
  694. // SetUpdatedAt sets the "updated_at" field.
  695. func (u *ProxyUpsertOne) SetUpdatedAt(v time.Time) *ProxyUpsertOne {
  696. return u.Update(func(s *ProxyUpsert) {
  697. s.SetUpdatedAt(v)
  698. })
  699. }
  700. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  701. func (u *ProxyUpsertOne) UpdateUpdatedAt() *ProxyUpsertOne {
  702. return u.Update(func(s *ProxyUpsert) {
  703. s.UpdateUpdatedAt()
  704. })
  705. }
  706. // SetDeletedAt sets the "deleted_at" field.
  707. func (u *ProxyUpsertOne) SetDeletedAt(v time.Time) *ProxyUpsertOne {
  708. return u.Update(func(s *ProxyUpsert) {
  709. s.SetDeletedAt(v)
  710. })
  711. }
  712. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  713. func (u *ProxyUpsertOne) UpdateDeletedAt() *ProxyUpsertOne {
  714. return u.Update(func(s *ProxyUpsert) {
  715. s.UpdateDeletedAt()
  716. })
  717. }
  718. // ClearDeletedAt clears the value of the "deleted_at" field.
  719. func (u *ProxyUpsertOne) ClearDeletedAt() *ProxyUpsertOne {
  720. return u.Update(func(s *ProxyUpsert) {
  721. s.ClearDeletedAt()
  722. })
  723. }
  724. // SetName sets the "name" field.
  725. func (u *ProxyUpsertOne) SetName(v string) *ProxyUpsertOne {
  726. return u.Update(func(s *ProxyUpsert) {
  727. s.SetName(v)
  728. })
  729. }
  730. // UpdateName sets the "name" field to the value that was provided on create.
  731. func (u *ProxyUpsertOne) UpdateName() *ProxyUpsertOne {
  732. return u.Update(func(s *ProxyUpsert) {
  733. s.UpdateName()
  734. })
  735. }
  736. // SetProtocol sets the "protocol" field.
  737. func (u *ProxyUpsertOne) SetProtocol(v string) *ProxyUpsertOne {
  738. return u.Update(func(s *ProxyUpsert) {
  739. s.SetProtocol(v)
  740. })
  741. }
  742. // UpdateProtocol sets the "protocol" field to the value that was provided on create.
  743. func (u *ProxyUpsertOne) UpdateProtocol() *ProxyUpsertOne {
  744. return u.Update(func(s *ProxyUpsert) {
  745. s.UpdateProtocol()
  746. })
  747. }
  748. // SetHost sets the "host" field.
  749. func (u *ProxyUpsertOne) SetHost(v string) *ProxyUpsertOne {
  750. return u.Update(func(s *ProxyUpsert) {
  751. s.SetHost(v)
  752. })
  753. }
  754. // UpdateHost sets the "host" field to the value that was provided on create.
  755. func (u *ProxyUpsertOne) UpdateHost() *ProxyUpsertOne {
  756. return u.Update(func(s *ProxyUpsert) {
  757. s.UpdateHost()
  758. })
  759. }
  760. // SetPort sets the "port" field.
  761. func (u *ProxyUpsertOne) SetPort(v int) *ProxyUpsertOne {
  762. return u.Update(func(s *ProxyUpsert) {
  763. s.SetPort(v)
  764. })
  765. }
  766. // AddPort adds v to the "port" field.
  767. func (u *ProxyUpsertOne) AddPort(v int) *ProxyUpsertOne {
  768. return u.Update(func(s *ProxyUpsert) {
  769. s.AddPort(v)
  770. })
  771. }
  772. // UpdatePort sets the "port" field to the value that was provided on create.
  773. func (u *ProxyUpsertOne) UpdatePort() *ProxyUpsertOne {
  774. return u.Update(func(s *ProxyUpsert) {
  775. s.UpdatePort()
  776. })
  777. }
  778. // SetUsername sets the "username" field.
  779. func (u *ProxyUpsertOne) SetUsername(v string) *ProxyUpsertOne {
  780. return u.Update(func(s *ProxyUpsert) {
  781. s.SetUsername(v)
  782. })
  783. }
  784. // UpdateUsername sets the "username" field to the value that was provided on create.
  785. func (u *ProxyUpsertOne) UpdateUsername() *ProxyUpsertOne {
  786. return u.Update(func(s *ProxyUpsert) {
  787. s.UpdateUsername()
  788. })
  789. }
  790. // ClearUsername clears the value of the "username" field.
  791. func (u *ProxyUpsertOne) ClearUsername() *ProxyUpsertOne {
  792. return u.Update(func(s *ProxyUpsert) {
  793. s.ClearUsername()
  794. })
  795. }
  796. // SetPassword sets the "password" field.
  797. func (u *ProxyUpsertOne) SetPassword(v string) *ProxyUpsertOne {
  798. return u.Update(func(s *ProxyUpsert) {
  799. s.SetPassword(v)
  800. })
  801. }
  802. // UpdatePassword sets the "password" field to the value that was provided on create.
  803. func (u *ProxyUpsertOne) UpdatePassword() *ProxyUpsertOne {
  804. return u.Update(func(s *ProxyUpsert) {
  805. s.UpdatePassword()
  806. })
  807. }
  808. // ClearPassword clears the value of the "password" field.
  809. func (u *ProxyUpsertOne) ClearPassword() *ProxyUpsertOne {
  810. return u.Update(func(s *ProxyUpsert) {
  811. s.ClearPassword()
  812. })
  813. }
  814. // SetStatus sets the "status" field.
  815. func (u *ProxyUpsertOne) SetStatus(v string) *ProxyUpsertOne {
  816. return u.Update(func(s *ProxyUpsert) {
  817. s.SetStatus(v)
  818. })
  819. }
  820. // UpdateStatus sets the "status" field to the value that was provided on create.
  821. func (u *ProxyUpsertOne) UpdateStatus() *ProxyUpsertOne {
  822. return u.Update(func(s *ProxyUpsert) {
  823. s.UpdateStatus()
  824. })
  825. }
  826. // SetExpiresAt sets the "expires_at" field.
  827. func (u *ProxyUpsertOne) SetExpiresAt(v time.Time) *ProxyUpsertOne {
  828. return u.Update(func(s *ProxyUpsert) {
  829. s.SetExpiresAt(v)
  830. })
  831. }
  832. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  833. func (u *ProxyUpsertOne) UpdateExpiresAt() *ProxyUpsertOne {
  834. return u.Update(func(s *ProxyUpsert) {
  835. s.UpdateExpiresAt()
  836. })
  837. }
  838. // ClearExpiresAt clears the value of the "expires_at" field.
  839. func (u *ProxyUpsertOne) ClearExpiresAt() *ProxyUpsertOne {
  840. return u.Update(func(s *ProxyUpsert) {
  841. s.ClearExpiresAt()
  842. })
  843. }
  844. // SetFallbackMode sets the "fallback_mode" field.
  845. func (u *ProxyUpsertOne) SetFallbackMode(v string) *ProxyUpsertOne {
  846. return u.Update(func(s *ProxyUpsert) {
  847. s.SetFallbackMode(v)
  848. })
  849. }
  850. // UpdateFallbackMode sets the "fallback_mode" field to the value that was provided on create.
  851. func (u *ProxyUpsertOne) UpdateFallbackMode() *ProxyUpsertOne {
  852. return u.Update(func(s *ProxyUpsert) {
  853. s.UpdateFallbackMode()
  854. })
  855. }
  856. // SetBackupProxyID sets the "backup_proxy_id" field.
  857. func (u *ProxyUpsertOne) SetBackupProxyID(v int64) *ProxyUpsertOne {
  858. return u.Update(func(s *ProxyUpsert) {
  859. s.SetBackupProxyID(v)
  860. })
  861. }
  862. // UpdateBackupProxyID sets the "backup_proxy_id" field to the value that was provided on create.
  863. func (u *ProxyUpsertOne) UpdateBackupProxyID() *ProxyUpsertOne {
  864. return u.Update(func(s *ProxyUpsert) {
  865. s.UpdateBackupProxyID()
  866. })
  867. }
  868. // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
  869. func (u *ProxyUpsertOne) ClearBackupProxyID() *ProxyUpsertOne {
  870. return u.Update(func(s *ProxyUpsert) {
  871. s.ClearBackupProxyID()
  872. })
  873. }
  874. // SetExpiryWarnDays sets the "expiry_warn_days" field.
  875. func (u *ProxyUpsertOne) SetExpiryWarnDays(v int) *ProxyUpsertOne {
  876. return u.Update(func(s *ProxyUpsert) {
  877. s.SetExpiryWarnDays(v)
  878. })
  879. }
  880. // AddExpiryWarnDays adds v to the "expiry_warn_days" field.
  881. func (u *ProxyUpsertOne) AddExpiryWarnDays(v int) *ProxyUpsertOne {
  882. return u.Update(func(s *ProxyUpsert) {
  883. s.AddExpiryWarnDays(v)
  884. })
  885. }
  886. // UpdateExpiryWarnDays sets the "expiry_warn_days" field to the value that was provided on create.
  887. func (u *ProxyUpsertOne) UpdateExpiryWarnDays() *ProxyUpsertOne {
  888. return u.Update(func(s *ProxyUpsert) {
  889. s.UpdateExpiryWarnDays()
  890. })
  891. }
  892. // Exec executes the query.
  893. func (u *ProxyUpsertOne) Exec(ctx context.Context) error {
  894. if len(u.create.conflict) == 0 {
  895. return errors.New("ent: missing options for ProxyCreate.OnConflict")
  896. }
  897. return u.create.Exec(ctx)
  898. }
  899. // ExecX is like Exec, but panics if an error occurs.
  900. func (u *ProxyUpsertOne) ExecX(ctx context.Context) {
  901. if err := u.create.Exec(ctx); err != nil {
  902. panic(err)
  903. }
  904. }
  905. // Exec executes the UPSERT query and returns the inserted/updated ID.
  906. func (u *ProxyUpsertOne) ID(ctx context.Context) (id int64, err error) {
  907. node, err := u.create.Save(ctx)
  908. if err != nil {
  909. return id, err
  910. }
  911. return node.ID, nil
  912. }
  913. // IDX is like ID, but panics if an error occurs.
  914. func (u *ProxyUpsertOne) IDX(ctx context.Context) int64 {
  915. id, err := u.ID(ctx)
  916. if err != nil {
  917. panic(err)
  918. }
  919. return id
  920. }
  921. // ProxyCreateBulk is the builder for creating many Proxy entities in bulk.
  922. type ProxyCreateBulk struct {
  923. config
  924. err error
  925. builders []*ProxyCreate
  926. conflict []sql.ConflictOption
  927. }
  928. // Save creates the Proxy entities in the database.
  929. func (_c *ProxyCreateBulk) Save(ctx context.Context) ([]*Proxy, error) {
  930. if _c.err != nil {
  931. return nil, _c.err
  932. }
  933. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  934. nodes := make([]*Proxy, len(_c.builders))
  935. mutators := make([]Mutator, len(_c.builders))
  936. for i := range _c.builders {
  937. func(i int, root context.Context) {
  938. builder := _c.builders[i]
  939. builder.defaults()
  940. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  941. mutation, ok := m.(*ProxyMutation)
  942. if !ok {
  943. return nil, fmt.Errorf("unexpected mutation type %T", m)
  944. }
  945. if err := builder.check(); err != nil {
  946. return nil, err
  947. }
  948. builder.mutation = mutation
  949. var err error
  950. nodes[i], specs[i] = builder.createSpec()
  951. if i < len(mutators)-1 {
  952. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  953. } else {
  954. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  955. spec.OnConflict = _c.conflict
  956. // Invoke the actual operation on the latest mutation in the chain.
  957. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  958. if sqlgraph.IsConstraintError(err) {
  959. err = &ConstraintError{msg: err.Error(), wrap: err}
  960. }
  961. }
  962. }
  963. if err != nil {
  964. return nil, err
  965. }
  966. mutation.id = &nodes[i].ID
  967. if specs[i].ID.Value != nil {
  968. id := specs[i].ID.Value.(int64)
  969. nodes[i].ID = int64(id)
  970. }
  971. mutation.done = true
  972. return nodes[i], nil
  973. })
  974. for i := len(builder.hooks) - 1; i >= 0; i-- {
  975. mut = builder.hooks[i](mut)
  976. }
  977. mutators[i] = mut
  978. }(i, ctx)
  979. }
  980. if len(mutators) > 0 {
  981. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  982. return nil, err
  983. }
  984. }
  985. return nodes, nil
  986. }
  987. // SaveX is like Save, but panics if an error occurs.
  988. func (_c *ProxyCreateBulk) SaveX(ctx context.Context) []*Proxy {
  989. v, err := _c.Save(ctx)
  990. if err != nil {
  991. panic(err)
  992. }
  993. return v
  994. }
  995. // Exec executes the query.
  996. func (_c *ProxyCreateBulk) Exec(ctx context.Context) error {
  997. _, err := _c.Save(ctx)
  998. return err
  999. }
  1000. // ExecX is like Exec, but panics if an error occurs.
  1001. func (_c *ProxyCreateBulk) ExecX(ctx context.Context) {
  1002. if err := _c.Exec(ctx); err != nil {
  1003. panic(err)
  1004. }
  1005. }
  1006. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  1007. // of the `INSERT` statement. For example:
  1008. //
  1009. // client.Proxy.CreateBulk(builders...).
  1010. // OnConflict(
  1011. // // Update the row with the new values
  1012. // // the was proposed for insertion.
  1013. // sql.ResolveWithNewValues(),
  1014. // ).
  1015. // // Override some of the fields with custom
  1016. // // update values.
  1017. // Update(func(u *ent.ProxyUpsert) {
  1018. // SetCreatedAt(v+v).
  1019. // }).
  1020. // Exec(ctx)
  1021. func (_c *ProxyCreateBulk) OnConflict(opts ...sql.ConflictOption) *ProxyUpsertBulk {
  1022. _c.conflict = opts
  1023. return &ProxyUpsertBulk{
  1024. create: _c,
  1025. }
  1026. }
  1027. // OnConflictColumns calls `OnConflict` and configures the columns
  1028. // as conflict target. Using this option is equivalent to using:
  1029. //
  1030. // client.Proxy.Create().
  1031. // OnConflict(sql.ConflictColumns(columns...)).
  1032. // Exec(ctx)
  1033. func (_c *ProxyCreateBulk) OnConflictColumns(columns ...string) *ProxyUpsertBulk {
  1034. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  1035. return &ProxyUpsertBulk{
  1036. create: _c,
  1037. }
  1038. }
  1039. // ProxyUpsertBulk is the builder for "upsert"-ing
  1040. // a bulk of Proxy nodes.
  1041. type ProxyUpsertBulk struct {
  1042. create *ProxyCreateBulk
  1043. }
  1044. // UpdateNewValues updates the mutable fields using the new values that
  1045. // were set on create. Using this option is equivalent to using:
  1046. //
  1047. // client.Proxy.Create().
  1048. // OnConflict(
  1049. // sql.ResolveWithNewValues(),
  1050. // ).
  1051. // Exec(ctx)
  1052. func (u *ProxyUpsertBulk) UpdateNewValues() *ProxyUpsertBulk {
  1053. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  1054. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  1055. for _, b := range u.create.builders {
  1056. if _, exists := b.mutation.CreatedAt(); exists {
  1057. s.SetIgnore(proxy.FieldCreatedAt)
  1058. }
  1059. }
  1060. }))
  1061. return u
  1062. }
  1063. // Ignore sets each column to itself in case of conflict.
  1064. // Using this option is equivalent to using:
  1065. //
  1066. // client.Proxy.Create().
  1067. // OnConflict(sql.ResolveWithIgnore()).
  1068. // Exec(ctx)
  1069. func (u *ProxyUpsertBulk) Ignore() *ProxyUpsertBulk {
  1070. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  1071. return u
  1072. }
  1073. // DoNothing configures the conflict_action to `DO NOTHING`.
  1074. // Supported only by SQLite and PostgreSQL.
  1075. func (u *ProxyUpsertBulk) DoNothing() *ProxyUpsertBulk {
  1076. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  1077. return u
  1078. }
  1079. // Update allows overriding fields `UPDATE` values. See the ProxyCreateBulk.OnConflict
  1080. // documentation for more info.
  1081. func (u *ProxyUpsertBulk) Update(set func(*ProxyUpsert)) *ProxyUpsertBulk {
  1082. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  1083. set(&ProxyUpsert{UpdateSet: update})
  1084. }))
  1085. return u
  1086. }
  1087. // SetUpdatedAt sets the "updated_at" field.
  1088. func (u *ProxyUpsertBulk) SetUpdatedAt(v time.Time) *ProxyUpsertBulk {
  1089. return u.Update(func(s *ProxyUpsert) {
  1090. s.SetUpdatedAt(v)
  1091. })
  1092. }
  1093. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  1094. func (u *ProxyUpsertBulk) UpdateUpdatedAt() *ProxyUpsertBulk {
  1095. return u.Update(func(s *ProxyUpsert) {
  1096. s.UpdateUpdatedAt()
  1097. })
  1098. }
  1099. // SetDeletedAt sets the "deleted_at" field.
  1100. func (u *ProxyUpsertBulk) SetDeletedAt(v time.Time) *ProxyUpsertBulk {
  1101. return u.Update(func(s *ProxyUpsert) {
  1102. s.SetDeletedAt(v)
  1103. })
  1104. }
  1105. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  1106. func (u *ProxyUpsertBulk) UpdateDeletedAt() *ProxyUpsertBulk {
  1107. return u.Update(func(s *ProxyUpsert) {
  1108. s.UpdateDeletedAt()
  1109. })
  1110. }
  1111. // ClearDeletedAt clears the value of the "deleted_at" field.
  1112. func (u *ProxyUpsertBulk) ClearDeletedAt() *ProxyUpsertBulk {
  1113. return u.Update(func(s *ProxyUpsert) {
  1114. s.ClearDeletedAt()
  1115. })
  1116. }
  1117. // SetName sets the "name" field.
  1118. func (u *ProxyUpsertBulk) SetName(v string) *ProxyUpsertBulk {
  1119. return u.Update(func(s *ProxyUpsert) {
  1120. s.SetName(v)
  1121. })
  1122. }
  1123. // UpdateName sets the "name" field to the value that was provided on create.
  1124. func (u *ProxyUpsertBulk) UpdateName() *ProxyUpsertBulk {
  1125. return u.Update(func(s *ProxyUpsert) {
  1126. s.UpdateName()
  1127. })
  1128. }
  1129. // SetProtocol sets the "protocol" field.
  1130. func (u *ProxyUpsertBulk) SetProtocol(v string) *ProxyUpsertBulk {
  1131. return u.Update(func(s *ProxyUpsert) {
  1132. s.SetProtocol(v)
  1133. })
  1134. }
  1135. // UpdateProtocol sets the "protocol" field to the value that was provided on create.
  1136. func (u *ProxyUpsertBulk) UpdateProtocol() *ProxyUpsertBulk {
  1137. return u.Update(func(s *ProxyUpsert) {
  1138. s.UpdateProtocol()
  1139. })
  1140. }
  1141. // SetHost sets the "host" field.
  1142. func (u *ProxyUpsertBulk) SetHost(v string) *ProxyUpsertBulk {
  1143. return u.Update(func(s *ProxyUpsert) {
  1144. s.SetHost(v)
  1145. })
  1146. }
  1147. // UpdateHost sets the "host" field to the value that was provided on create.
  1148. func (u *ProxyUpsertBulk) UpdateHost() *ProxyUpsertBulk {
  1149. return u.Update(func(s *ProxyUpsert) {
  1150. s.UpdateHost()
  1151. })
  1152. }
  1153. // SetPort sets the "port" field.
  1154. func (u *ProxyUpsertBulk) SetPort(v int) *ProxyUpsertBulk {
  1155. return u.Update(func(s *ProxyUpsert) {
  1156. s.SetPort(v)
  1157. })
  1158. }
  1159. // AddPort adds v to the "port" field.
  1160. func (u *ProxyUpsertBulk) AddPort(v int) *ProxyUpsertBulk {
  1161. return u.Update(func(s *ProxyUpsert) {
  1162. s.AddPort(v)
  1163. })
  1164. }
  1165. // UpdatePort sets the "port" field to the value that was provided on create.
  1166. func (u *ProxyUpsertBulk) UpdatePort() *ProxyUpsertBulk {
  1167. return u.Update(func(s *ProxyUpsert) {
  1168. s.UpdatePort()
  1169. })
  1170. }
  1171. // SetUsername sets the "username" field.
  1172. func (u *ProxyUpsertBulk) SetUsername(v string) *ProxyUpsertBulk {
  1173. return u.Update(func(s *ProxyUpsert) {
  1174. s.SetUsername(v)
  1175. })
  1176. }
  1177. // UpdateUsername sets the "username" field to the value that was provided on create.
  1178. func (u *ProxyUpsertBulk) UpdateUsername() *ProxyUpsertBulk {
  1179. return u.Update(func(s *ProxyUpsert) {
  1180. s.UpdateUsername()
  1181. })
  1182. }
  1183. // ClearUsername clears the value of the "username" field.
  1184. func (u *ProxyUpsertBulk) ClearUsername() *ProxyUpsertBulk {
  1185. return u.Update(func(s *ProxyUpsert) {
  1186. s.ClearUsername()
  1187. })
  1188. }
  1189. // SetPassword sets the "password" field.
  1190. func (u *ProxyUpsertBulk) SetPassword(v string) *ProxyUpsertBulk {
  1191. return u.Update(func(s *ProxyUpsert) {
  1192. s.SetPassword(v)
  1193. })
  1194. }
  1195. // UpdatePassword sets the "password" field to the value that was provided on create.
  1196. func (u *ProxyUpsertBulk) UpdatePassword() *ProxyUpsertBulk {
  1197. return u.Update(func(s *ProxyUpsert) {
  1198. s.UpdatePassword()
  1199. })
  1200. }
  1201. // ClearPassword clears the value of the "password" field.
  1202. func (u *ProxyUpsertBulk) ClearPassword() *ProxyUpsertBulk {
  1203. return u.Update(func(s *ProxyUpsert) {
  1204. s.ClearPassword()
  1205. })
  1206. }
  1207. // SetStatus sets the "status" field.
  1208. func (u *ProxyUpsertBulk) SetStatus(v string) *ProxyUpsertBulk {
  1209. return u.Update(func(s *ProxyUpsert) {
  1210. s.SetStatus(v)
  1211. })
  1212. }
  1213. // UpdateStatus sets the "status" field to the value that was provided on create.
  1214. func (u *ProxyUpsertBulk) UpdateStatus() *ProxyUpsertBulk {
  1215. return u.Update(func(s *ProxyUpsert) {
  1216. s.UpdateStatus()
  1217. })
  1218. }
  1219. // SetExpiresAt sets the "expires_at" field.
  1220. func (u *ProxyUpsertBulk) SetExpiresAt(v time.Time) *ProxyUpsertBulk {
  1221. return u.Update(func(s *ProxyUpsert) {
  1222. s.SetExpiresAt(v)
  1223. })
  1224. }
  1225. // UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
  1226. func (u *ProxyUpsertBulk) UpdateExpiresAt() *ProxyUpsertBulk {
  1227. return u.Update(func(s *ProxyUpsert) {
  1228. s.UpdateExpiresAt()
  1229. })
  1230. }
  1231. // ClearExpiresAt clears the value of the "expires_at" field.
  1232. func (u *ProxyUpsertBulk) ClearExpiresAt() *ProxyUpsertBulk {
  1233. return u.Update(func(s *ProxyUpsert) {
  1234. s.ClearExpiresAt()
  1235. })
  1236. }
  1237. // SetFallbackMode sets the "fallback_mode" field.
  1238. func (u *ProxyUpsertBulk) SetFallbackMode(v string) *ProxyUpsertBulk {
  1239. return u.Update(func(s *ProxyUpsert) {
  1240. s.SetFallbackMode(v)
  1241. })
  1242. }
  1243. // UpdateFallbackMode sets the "fallback_mode" field to the value that was provided on create.
  1244. func (u *ProxyUpsertBulk) UpdateFallbackMode() *ProxyUpsertBulk {
  1245. return u.Update(func(s *ProxyUpsert) {
  1246. s.UpdateFallbackMode()
  1247. })
  1248. }
  1249. // SetBackupProxyID sets the "backup_proxy_id" field.
  1250. func (u *ProxyUpsertBulk) SetBackupProxyID(v int64) *ProxyUpsertBulk {
  1251. return u.Update(func(s *ProxyUpsert) {
  1252. s.SetBackupProxyID(v)
  1253. })
  1254. }
  1255. // UpdateBackupProxyID sets the "backup_proxy_id" field to the value that was provided on create.
  1256. func (u *ProxyUpsertBulk) UpdateBackupProxyID() *ProxyUpsertBulk {
  1257. return u.Update(func(s *ProxyUpsert) {
  1258. s.UpdateBackupProxyID()
  1259. })
  1260. }
  1261. // ClearBackupProxyID clears the value of the "backup_proxy_id" field.
  1262. func (u *ProxyUpsertBulk) ClearBackupProxyID() *ProxyUpsertBulk {
  1263. return u.Update(func(s *ProxyUpsert) {
  1264. s.ClearBackupProxyID()
  1265. })
  1266. }
  1267. // SetExpiryWarnDays sets the "expiry_warn_days" field.
  1268. func (u *ProxyUpsertBulk) SetExpiryWarnDays(v int) *ProxyUpsertBulk {
  1269. return u.Update(func(s *ProxyUpsert) {
  1270. s.SetExpiryWarnDays(v)
  1271. })
  1272. }
  1273. // AddExpiryWarnDays adds v to the "expiry_warn_days" field.
  1274. func (u *ProxyUpsertBulk) AddExpiryWarnDays(v int) *ProxyUpsertBulk {
  1275. return u.Update(func(s *ProxyUpsert) {
  1276. s.AddExpiryWarnDays(v)
  1277. })
  1278. }
  1279. // UpdateExpiryWarnDays sets the "expiry_warn_days" field to the value that was provided on create.
  1280. func (u *ProxyUpsertBulk) UpdateExpiryWarnDays() *ProxyUpsertBulk {
  1281. return u.Update(func(s *ProxyUpsert) {
  1282. s.UpdateExpiryWarnDays()
  1283. })
  1284. }
  1285. // Exec executes the query.
  1286. func (u *ProxyUpsertBulk) Exec(ctx context.Context) error {
  1287. if u.create.err != nil {
  1288. return u.create.err
  1289. }
  1290. for i, b := range u.create.builders {
  1291. if len(b.conflict) != 0 {
  1292. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ProxyCreateBulk instead", i)
  1293. }
  1294. }
  1295. if len(u.create.conflict) == 0 {
  1296. return errors.New("ent: missing options for ProxyCreateBulk.OnConflict")
  1297. }
  1298. return u.create.Exec(ctx)
  1299. }
  1300. // ExecX is like Exec, but panics if an error occurs.
  1301. func (u *ProxyUpsertBulk) ExecX(ctx context.Context) {
  1302. if err := u.create.Exec(ctx); err != nil {
  1303. panic(err)
  1304. }
  1305. }