bouncer_update.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. // Code generated by entc, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "fmt"
  6. "time"
  7. "entgo.io/ent/dialect/sql"
  8. "entgo.io/ent/dialect/sql/sqlgraph"
  9. "entgo.io/ent/schema/field"
  10. "github.com/crowdsecurity/crowdsec/pkg/database/ent/bouncer"
  11. "github.com/crowdsecurity/crowdsec/pkg/database/ent/predicate"
  12. )
  13. // BouncerUpdate is the builder for updating Bouncer entities.
  14. type BouncerUpdate struct {
  15. config
  16. hooks []Hook
  17. mutation *BouncerMutation
  18. }
  19. // Where appends a list predicates to the BouncerUpdate builder.
  20. func (bu *BouncerUpdate) Where(ps ...predicate.Bouncer) *BouncerUpdate {
  21. bu.mutation.Where(ps...)
  22. return bu
  23. }
  24. // SetCreatedAt sets the "created_at" field.
  25. func (bu *BouncerUpdate) SetCreatedAt(t time.Time) *BouncerUpdate {
  26. bu.mutation.SetCreatedAt(t)
  27. return bu
  28. }
  29. // ClearCreatedAt clears the value of the "created_at" field.
  30. func (bu *BouncerUpdate) ClearCreatedAt() *BouncerUpdate {
  31. bu.mutation.ClearCreatedAt()
  32. return bu
  33. }
  34. // SetUpdatedAt sets the "updated_at" field.
  35. func (bu *BouncerUpdate) SetUpdatedAt(t time.Time) *BouncerUpdate {
  36. bu.mutation.SetUpdatedAt(t)
  37. return bu
  38. }
  39. // ClearUpdatedAt clears the value of the "updated_at" field.
  40. func (bu *BouncerUpdate) ClearUpdatedAt() *BouncerUpdate {
  41. bu.mutation.ClearUpdatedAt()
  42. return bu
  43. }
  44. // SetName sets the "name" field.
  45. func (bu *BouncerUpdate) SetName(s string) *BouncerUpdate {
  46. bu.mutation.SetName(s)
  47. return bu
  48. }
  49. // SetAPIKey sets the "api_key" field.
  50. func (bu *BouncerUpdate) SetAPIKey(s string) *BouncerUpdate {
  51. bu.mutation.SetAPIKey(s)
  52. return bu
  53. }
  54. // SetRevoked sets the "revoked" field.
  55. func (bu *BouncerUpdate) SetRevoked(b bool) *BouncerUpdate {
  56. bu.mutation.SetRevoked(b)
  57. return bu
  58. }
  59. // SetIPAddress sets the "ip_address" field.
  60. func (bu *BouncerUpdate) SetIPAddress(s string) *BouncerUpdate {
  61. bu.mutation.SetIPAddress(s)
  62. return bu
  63. }
  64. // SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
  65. func (bu *BouncerUpdate) SetNillableIPAddress(s *string) *BouncerUpdate {
  66. if s != nil {
  67. bu.SetIPAddress(*s)
  68. }
  69. return bu
  70. }
  71. // ClearIPAddress clears the value of the "ip_address" field.
  72. func (bu *BouncerUpdate) ClearIPAddress() *BouncerUpdate {
  73. bu.mutation.ClearIPAddress()
  74. return bu
  75. }
  76. // SetType sets the "type" field.
  77. func (bu *BouncerUpdate) SetType(s string) *BouncerUpdate {
  78. bu.mutation.SetType(s)
  79. return bu
  80. }
  81. // SetNillableType sets the "type" field if the given value is not nil.
  82. func (bu *BouncerUpdate) SetNillableType(s *string) *BouncerUpdate {
  83. if s != nil {
  84. bu.SetType(*s)
  85. }
  86. return bu
  87. }
  88. // ClearType clears the value of the "type" field.
  89. func (bu *BouncerUpdate) ClearType() *BouncerUpdate {
  90. bu.mutation.ClearType()
  91. return bu
  92. }
  93. // SetVersion sets the "version" field.
  94. func (bu *BouncerUpdate) SetVersion(s string) *BouncerUpdate {
  95. bu.mutation.SetVersion(s)
  96. return bu
  97. }
  98. // SetNillableVersion sets the "version" field if the given value is not nil.
  99. func (bu *BouncerUpdate) SetNillableVersion(s *string) *BouncerUpdate {
  100. if s != nil {
  101. bu.SetVersion(*s)
  102. }
  103. return bu
  104. }
  105. // ClearVersion clears the value of the "version" field.
  106. func (bu *BouncerUpdate) ClearVersion() *BouncerUpdate {
  107. bu.mutation.ClearVersion()
  108. return bu
  109. }
  110. // SetUntil sets the "until" field.
  111. func (bu *BouncerUpdate) SetUntil(t time.Time) *BouncerUpdate {
  112. bu.mutation.SetUntil(t)
  113. return bu
  114. }
  115. // SetNillableUntil sets the "until" field if the given value is not nil.
  116. func (bu *BouncerUpdate) SetNillableUntil(t *time.Time) *BouncerUpdate {
  117. if t != nil {
  118. bu.SetUntil(*t)
  119. }
  120. return bu
  121. }
  122. // ClearUntil clears the value of the "until" field.
  123. func (bu *BouncerUpdate) ClearUntil() *BouncerUpdate {
  124. bu.mutation.ClearUntil()
  125. return bu
  126. }
  127. // SetLastPull sets the "last_pull" field.
  128. func (bu *BouncerUpdate) SetLastPull(t time.Time) *BouncerUpdate {
  129. bu.mutation.SetLastPull(t)
  130. return bu
  131. }
  132. // SetNillableLastPull sets the "last_pull" field if the given value is not nil.
  133. func (bu *BouncerUpdate) SetNillableLastPull(t *time.Time) *BouncerUpdate {
  134. if t != nil {
  135. bu.SetLastPull(*t)
  136. }
  137. return bu
  138. }
  139. // Mutation returns the BouncerMutation object of the builder.
  140. func (bu *BouncerUpdate) Mutation() *BouncerMutation {
  141. return bu.mutation
  142. }
  143. // Save executes the query and returns the number of nodes affected by the update operation.
  144. func (bu *BouncerUpdate) Save(ctx context.Context) (int, error) {
  145. var (
  146. err error
  147. affected int
  148. )
  149. bu.defaults()
  150. if len(bu.hooks) == 0 {
  151. affected, err = bu.sqlSave(ctx)
  152. } else {
  153. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  154. mutation, ok := m.(*BouncerMutation)
  155. if !ok {
  156. return nil, fmt.Errorf("unexpected mutation type %T", m)
  157. }
  158. bu.mutation = mutation
  159. affected, err = bu.sqlSave(ctx)
  160. mutation.done = true
  161. return affected, err
  162. })
  163. for i := len(bu.hooks) - 1; i >= 0; i-- {
  164. if bu.hooks[i] == nil {
  165. return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  166. }
  167. mut = bu.hooks[i](mut)
  168. }
  169. if _, err := mut.Mutate(ctx, bu.mutation); err != nil {
  170. return 0, err
  171. }
  172. }
  173. return affected, err
  174. }
  175. // SaveX is like Save, but panics if an error occurs.
  176. func (bu *BouncerUpdate) SaveX(ctx context.Context) int {
  177. affected, err := bu.Save(ctx)
  178. if err != nil {
  179. panic(err)
  180. }
  181. return affected
  182. }
  183. // Exec executes the query.
  184. func (bu *BouncerUpdate) Exec(ctx context.Context) error {
  185. _, err := bu.Save(ctx)
  186. return err
  187. }
  188. // ExecX is like Exec, but panics if an error occurs.
  189. func (bu *BouncerUpdate) ExecX(ctx context.Context) {
  190. if err := bu.Exec(ctx); err != nil {
  191. panic(err)
  192. }
  193. }
  194. // defaults sets the default values of the builder before save.
  195. func (bu *BouncerUpdate) defaults() {
  196. if _, ok := bu.mutation.CreatedAt(); !ok && !bu.mutation.CreatedAtCleared() {
  197. v := bouncer.UpdateDefaultCreatedAt()
  198. bu.mutation.SetCreatedAt(v)
  199. }
  200. if _, ok := bu.mutation.UpdatedAt(); !ok && !bu.mutation.UpdatedAtCleared() {
  201. v := bouncer.UpdateDefaultUpdatedAt()
  202. bu.mutation.SetUpdatedAt(v)
  203. }
  204. }
  205. func (bu *BouncerUpdate) sqlSave(ctx context.Context) (n int, err error) {
  206. _spec := &sqlgraph.UpdateSpec{
  207. Node: &sqlgraph.NodeSpec{
  208. Table: bouncer.Table,
  209. Columns: bouncer.Columns,
  210. ID: &sqlgraph.FieldSpec{
  211. Type: field.TypeInt,
  212. Column: bouncer.FieldID,
  213. },
  214. },
  215. }
  216. if ps := bu.mutation.predicates; len(ps) > 0 {
  217. _spec.Predicate = func(selector *sql.Selector) {
  218. for i := range ps {
  219. ps[i](selector)
  220. }
  221. }
  222. }
  223. if value, ok := bu.mutation.CreatedAt(); ok {
  224. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  225. Type: field.TypeTime,
  226. Value: value,
  227. Column: bouncer.FieldCreatedAt,
  228. })
  229. }
  230. if bu.mutation.CreatedAtCleared() {
  231. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  232. Type: field.TypeTime,
  233. Column: bouncer.FieldCreatedAt,
  234. })
  235. }
  236. if value, ok := bu.mutation.UpdatedAt(); ok {
  237. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  238. Type: field.TypeTime,
  239. Value: value,
  240. Column: bouncer.FieldUpdatedAt,
  241. })
  242. }
  243. if bu.mutation.UpdatedAtCleared() {
  244. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  245. Type: field.TypeTime,
  246. Column: bouncer.FieldUpdatedAt,
  247. })
  248. }
  249. if value, ok := bu.mutation.Name(); ok {
  250. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  251. Type: field.TypeString,
  252. Value: value,
  253. Column: bouncer.FieldName,
  254. })
  255. }
  256. if value, ok := bu.mutation.APIKey(); ok {
  257. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  258. Type: field.TypeString,
  259. Value: value,
  260. Column: bouncer.FieldAPIKey,
  261. })
  262. }
  263. if value, ok := bu.mutation.Revoked(); ok {
  264. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  265. Type: field.TypeBool,
  266. Value: value,
  267. Column: bouncer.FieldRevoked,
  268. })
  269. }
  270. if value, ok := bu.mutation.IPAddress(); ok {
  271. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  272. Type: field.TypeString,
  273. Value: value,
  274. Column: bouncer.FieldIPAddress,
  275. })
  276. }
  277. if bu.mutation.IPAddressCleared() {
  278. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  279. Type: field.TypeString,
  280. Column: bouncer.FieldIPAddress,
  281. })
  282. }
  283. if value, ok := bu.mutation.GetType(); ok {
  284. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  285. Type: field.TypeString,
  286. Value: value,
  287. Column: bouncer.FieldType,
  288. })
  289. }
  290. if bu.mutation.TypeCleared() {
  291. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  292. Type: field.TypeString,
  293. Column: bouncer.FieldType,
  294. })
  295. }
  296. if value, ok := bu.mutation.Version(); ok {
  297. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  298. Type: field.TypeString,
  299. Value: value,
  300. Column: bouncer.FieldVersion,
  301. })
  302. }
  303. if bu.mutation.VersionCleared() {
  304. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  305. Type: field.TypeString,
  306. Column: bouncer.FieldVersion,
  307. })
  308. }
  309. if value, ok := bu.mutation.Until(); ok {
  310. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  311. Type: field.TypeTime,
  312. Value: value,
  313. Column: bouncer.FieldUntil,
  314. })
  315. }
  316. if bu.mutation.UntilCleared() {
  317. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  318. Type: field.TypeTime,
  319. Column: bouncer.FieldUntil,
  320. })
  321. }
  322. if value, ok := bu.mutation.LastPull(); ok {
  323. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  324. Type: field.TypeTime,
  325. Value: value,
  326. Column: bouncer.FieldLastPull,
  327. })
  328. }
  329. if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil {
  330. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  331. err = &NotFoundError{bouncer.Label}
  332. } else if sqlgraph.IsConstraintError(err) {
  333. err = &ConstraintError{err.Error(), err}
  334. }
  335. return 0, err
  336. }
  337. return n, nil
  338. }
  339. // BouncerUpdateOne is the builder for updating a single Bouncer entity.
  340. type BouncerUpdateOne struct {
  341. config
  342. fields []string
  343. hooks []Hook
  344. mutation *BouncerMutation
  345. }
  346. // SetCreatedAt sets the "created_at" field.
  347. func (buo *BouncerUpdateOne) SetCreatedAt(t time.Time) *BouncerUpdateOne {
  348. buo.mutation.SetCreatedAt(t)
  349. return buo
  350. }
  351. // ClearCreatedAt clears the value of the "created_at" field.
  352. func (buo *BouncerUpdateOne) ClearCreatedAt() *BouncerUpdateOne {
  353. buo.mutation.ClearCreatedAt()
  354. return buo
  355. }
  356. // SetUpdatedAt sets the "updated_at" field.
  357. func (buo *BouncerUpdateOne) SetUpdatedAt(t time.Time) *BouncerUpdateOne {
  358. buo.mutation.SetUpdatedAt(t)
  359. return buo
  360. }
  361. // ClearUpdatedAt clears the value of the "updated_at" field.
  362. func (buo *BouncerUpdateOne) ClearUpdatedAt() *BouncerUpdateOne {
  363. buo.mutation.ClearUpdatedAt()
  364. return buo
  365. }
  366. // SetName sets the "name" field.
  367. func (buo *BouncerUpdateOne) SetName(s string) *BouncerUpdateOne {
  368. buo.mutation.SetName(s)
  369. return buo
  370. }
  371. // SetAPIKey sets the "api_key" field.
  372. func (buo *BouncerUpdateOne) SetAPIKey(s string) *BouncerUpdateOne {
  373. buo.mutation.SetAPIKey(s)
  374. return buo
  375. }
  376. // SetRevoked sets the "revoked" field.
  377. func (buo *BouncerUpdateOne) SetRevoked(b bool) *BouncerUpdateOne {
  378. buo.mutation.SetRevoked(b)
  379. return buo
  380. }
  381. // SetIPAddress sets the "ip_address" field.
  382. func (buo *BouncerUpdateOne) SetIPAddress(s string) *BouncerUpdateOne {
  383. buo.mutation.SetIPAddress(s)
  384. return buo
  385. }
  386. // SetNillableIPAddress sets the "ip_address" field if the given value is not nil.
  387. func (buo *BouncerUpdateOne) SetNillableIPAddress(s *string) *BouncerUpdateOne {
  388. if s != nil {
  389. buo.SetIPAddress(*s)
  390. }
  391. return buo
  392. }
  393. // ClearIPAddress clears the value of the "ip_address" field.
  394. func (buo *BouncerUpdateOne) ClearIPAddress() *BouncerUpdateOne {
  395. buo.mutation.ClearIPAddress()
  396. return buo
  397. }
  398. // SetType sets the "type" field.
  399. func (buo *BouncerUpdateOne) SetType(s string) *BouncerUpdateOne {
  400. buo.mutation.SetType(s)
  401. return buo
  402. }
  403. // SetNillableType sets the "type" field if the given value is not nil.
  404. func (buo *BouncerUpdateOne) SetNillableType(s *string) *BouncerUpdateOne {
  405. if s != nil {
  406. buo.SetType(*s)
  407. }
  408. return buo
  409. }
  410. // ClearType clears the value of the "type" field.
  411. func (buo *BouncerUpdateOne) ClearType() *BouncerUpdateOne {
  412. buo.mutation.ClearType()
  413. return buo
  414. }
  415. // SetVersion sets the "version" field.
  416. func (buo *BouncerUpdateOne) SetVersion(s string) *BouncerUpdateOne {
  417. buo.mutation.SetVersion(s)
  418. return buo
  419. }
  420. // SetNillableVersion sets the "version" field if the given value is not nil.
  421. func (buo *BouncerUpdateOne) SetNillableVersion(s *string) *BouncerUpdateOne {
  422. if s != nil {
  423. buo.SetVersion(*s)
  424. }
  425. return buo
  426. }
  427. // ClearVersion clears the value of the "version" field.
  428. func (buo *BouncerUpdateOne) ClearVersion() *BouncerUpdateOne {
  429. buo.mutation.ClearVersion()
  430. return buo
  431. }
  432. // SetUntil sets the "until" field.
  433. func (buo *BouncerUpdateOne) SetUntil(t time.Time) *BouncerUpdateOne {
  434. buo.mutation.SetUntil(t)
  435. return buo
  436. }
  437. // SetNillableUntil sets the "until" field if the given value is not nil.
  438. func (buo *BouncerUpdateOne) SetNillableUntil(t *time.Time) *BouncerUpdateOne {
  439. if t != nil {
  440. buo.SetUntil(*t)
  441. }
  442. return buo
  443. }
  444. // ClearUntil clears the value of the "until" field.
  445. func (buo *BouncerUpdateOne) ClearUntil() *BouncerUpdateOne {
  446. buo.mutation.ClearUntil()
  447. return buo
  448. }
  449. // SetLastPull sets the "last_pull" field.
  450. func (buo *BouncerUpdateOne) SetLastPull(t time.Time) *BouncerUpdateOne {
  451. buo.mutation.SetLastPull(t)
  452. return buo
  453. }
  454. // SetNillableLastPull sets the "last_pull" field if the given value is not nil.
  455. func (buo *BouncerUpdateOne) SetNillableLastPull(t *time.Time) *BouncerUpdateOne {
  456. if t != nil {
  457. buo.SetLastPull(*t)
  458. }
  459. return buo
  460. }
  461. // Mutation returns the BouncerMutation object of the builder.
  462. func (buo *BouncerUpdateOne) Mutation() *BouncerMutation {
  463. return buo.mutation
  464. }
  465. // Select allows selecting one or more fields (columns) of the returned entity.
  466. // The default is selecting all fields defined in the entity schema.
  467. func (buo *BouncerUpdateOne) Select(field string, fields ...string) *BouncerUpdateOne {
  468. buo.fields = append([]string{field}, fields...)
  469. return buo
  470. }
  471. // Save executes the query and returns the updated Bouncer entity.
  472. func (buo *BouncerUpdateOne) Save(ctx context.Context) (*Bouncer, error) {
  473. var (
  474. err error
  475. node *Bouncer
  476. )
  477. buo.defaults()
  478. if len(buo.hooks) == 0 {
  479. node, err = buo.sqlSave(ctx)
  480. } else {
  481. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  482. mutation, ok := m.(*BouncerMutation)
  483. if !ok {
  484. return nil, fmt.Errorf("unexpected mutation type %T", m)
  485. }
  486. buo.mutation = mutation
  487. node, err = buo.sqlSave(ctx)
  488. mutation.done = true
  489. return node, err
  490. })
  491. for i := len(buo.hooks) - 1; i >= 0; i-- {
  492. if buo.hooks[i] == nil {
  493. return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
  494. }
  495. mut = buo.hooks[i](mut)
  496. }
  497. if _, err := mut.Mutate(ctx, buo.mutation); err != nil {
  498. return nil, err
  499. }
  500. }
  501. return node, err
  502. }
  503. // SaveX is like Save, but panics if an error occurs.
  504. func (buo *BouncerUpdateOne) SaveX(ctx context.Context) *Bouncer {
  505. node, err := buo.Save(ctx)
  506. if err != nil {
  507. panic(err)
  508. }
  509. return node
  510. }
  511. // Exec executes the query on the entity.
  512. func (buo *BouncerUpdateOne) Exec(ctx context.Context) error {
  513. _, err := buo.Save(ctx)
  514. return err
  515. }
  516. // ExecX is like Exec, but panics if an error occurs.
  517. func (buo *BouncerUpdateOne) ExecX(ctx context.Context) {
  518. if err := buo.Exec(ctx); err != nil {
  519. panic(err)
  520. }
  521. }
  522. // defaults sets the default values of the builder before save.
  523. func (buo *BouncerUpdateOne) defaults() {
  524. if _, ok := buo.mutation.CreatedAt(); !ok && !buo.mutation.CreatedAtCleared() {
  525. v := bouncer.UpdateDefaultCreatedAt()
  526. buo.mutation.SetCreatedAt(v)
  527. }
  528. if _, ok := buo.mutation.UpdatedAt(); !ok && !buo.mutation.UpdatedAtCleared() {
  529. v := bouncer.UpdateDefaultUpdatedAt()
  530. buo.mutation.SetUpdatedAt(v)
  531. }
  532. }
  533. func (buo *BouncerUpdateOne) sqlSave(ctx context.Context) (_node *Bouncer, err error) {
  534. _spec := &sqlgraph.UpdateSpec{
  535. Node: &sqlgraph.NodeSpec{
  536. Table: bouncer.Table,
  537. Columns: bouncer.Columns,
  538. ID: &sqlgraph.FieldSpec{
  539. Type: field.TypeInt,
  540. Column: bouncer.FieldID,
  541. },
  542. },
  543. }
  544. id, ok := buo.mutation.ID()
  545. if !ok {
  546. return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Bouncer.ID for update")}
  547. }
  548. _spec.Node.ID.Value = id
  549. if fields := buo.fields; len(fields) > 0 {
  550. _spec.Node.Columns = make([]string, 0, len(fields))
  551. _spec.Node.Columns = append(_spec.Node.Columns, bouncer.FieldID)
  552. for _, f := range fields {
  553. if !bouncer.ValidColumn(f) {
  554. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  555. }
  556. if f != bouncer.FieldID {
  557. _spec.Node.Columns = append(_spec.Node.Columns, f)
  558. }
  559. }
  560. }
  561. if ps := buo.mutation.predicates; len(ps) > 0 {
  562. _spec.Predicate = func(selector *sql.Selector) {
  563. for i := range ps {
  564. ps[i](selector)
  565. }
  566. }
  567. }
  568. if value, ok := buo.mutation.CreatedAt(); ok {
  569. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  570. Type: field.TypeTime,
  571. Value: value,
  572. Column: bouncer.FieldCreatedAt,
  573. })
  574. }
  575. if buo.mutation.CreatedAtCleared() {
  576. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  577. Type: field.TypeTime,
  578. Column: bouncer.FieldCreatedAt,
  579. })
  580. }
  581. if value, ok := buo.mutation.UpdatedAt(); ok {
  582. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  583. Type: field.TypeTime,
  584. Value: value,
  585. Column: bouncer.FieldUpdatedAt,
  586. })
  587. }
  588. if buo.mutation.UpdatedAtCleared() {
  589. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  590. Type: field.TypeTime,
  591. Column: bouncer.FieldUpdatedAt,
  592. })
  593. }
  594. if value, ok := buo.mutation.Name(); ok {
  595. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  596. Type: field.TypeString,
  597. Value: value,
  598. Column: bouncer.FieldName,
  599. })
  600. }
  601. if value, ok := buo.mutation.APIKey(); ok {
  602. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  603. Type: field.TypeString,
  604. Value: value,
  605. Column: bouncer.FieldAPIKey,
  606. })
  607. }
  608. if value, ok := buo.mutation.Revoked(); ok {
  609. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  610. Type: field.TypeBool,
  611. Value: value,
  612. Column: bouncer.FieldRevoked,
  613. })
  614. }
  615. if value, ok := buo.mutation.IPAddress(); ok {
  616. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  617. Type: field.TypeString,
  618. Value: value,
  619. Column: bouncer.FieldIPAddress,
  620. })
  621. }
  622. if buo.mutation.IPAddressCleared() {
  623. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  624. Type: field.TypeString,
  625. Column: bouncer.FieldIPAddress,
  626. })
  627. }
  628. if value, ok := buo.mutation.GetType(); ok {
  629. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  630. Type: field.TypeString,
  631. Value: value,
  632. Column: bouncer.FieldType,
  633. })
  634. }
  635. if buo.mutation.TypeCleared() {
  636. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  637. Type: field.TypeString,
  638. Column: bouncer.FieldType,
  639. })
  640. }
  641. if value, ok := buo.mutation.Version(); ok {
  642. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  643. Type: field.TypeString,
  644. Value: value,
  645. Column: bouncer.FieldVersion,
  646. })
  647. }
  648. if buo.mutation.VersionCleared() {
  649. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  650. Type: field.TypeString,
  651. Column: bouncer.FieldVersion,
  652. })
  653. }
  654. if value, ok := buo.mutation.Until(); ok {
  655. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  656. Type: field.TypeTime,
  657. Value: value,
  658. Column: bouncer.FieldUntil,
  659. })
  660. }
  661. if buo.mutation.UntilCleared() {
  662. _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
  663. Type: field.TypeTime,
  664. Column: bouncer.FieldUntil,
  665. })
  666. }
  667. if value, ok := buo.mutation.LastPull(); ok {
  668. _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
  669. Type: field.TypeTime,
  670. Value: value,
  671. Column: bouncer.FieldLastPull,
  672. })
  673. }
  674. _node = &Bouncer{config: buo.config}
  675. _spec.Assign = _node.assignValues
  676. _spec.ScanValues = _node.scanValues
  677. if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil {
  678. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  679. err = &NotFoundError{bouncer.Label}
  680. } else if sqlgraph.IsConstraintError(err) {
  681. err = &ConstraintError{err.Error(), err}
  682. }
  683. return nil, err
  684. }
  685. return _node, nil
  686. }