batchimageevent_update.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "entgo.io/ent/dialect/sql"
  8. "entgo.io/ent/dialect/sql/sqlgraph"
  9. "entgo.io/ent/schema/field"
  10. "github.com/Wei-Shaw/sub2api/ent/batchimageevent"
  11. "github.com/Wei-Shaw/sub2api/ent/predicate"
  12. )
  13. // BatchImageEventUpdate is the builder for updating BatchImageEvent entities.
  14. type BatchImageEventUpdate struct {
  15. config
  16. hooks []Hook
  17. mutation *BatchImageEventMutation
  18. }
  19. // Where appends a list predicates to the BatchImageEventUpdate builder.
  20. func (_u *BatchImageEventUpdate) Where(ps ...predicate.BatchImageEvent) *BatchImageEventUpdate {
  21. _u.mutation.Where(ps...)
  22. return _u
  23. }
  24. // SetJobID sets the "job_id" field.
  25. func (_u *BatchImageEventUpdate) SetJobID(v string) *BatchImageEventUpdate {
  26. _u.mutation.SetJobID(v)
  27. return _u
  28. }
  29. // SetNillableJobID sets the "job_id" field if the given value is not nil.
  30. func (_u *BatchImageEventUpdate) SetNillableJobID(v *string) *BatchImageEventUpdate {
  31. if v != nil {
  32. _u.SetJobID(*v)
  33. }
  34. return _u
  35. }
  36. // SetEventType sets the "event_type" field.
  37. func (_u *BatchImageEventUpdate) SetEventType(v string) *BatchImageEventUpdate {
  38. _u.mutation.SetEventType(v)
  39. return _u
  40. }
  41. // SetNillableEventType sets the "event_type" field if the given value is not nil.
  42. func (_u *BatchImageEventUpdate) SetNillableEventType(v *string) *BatchImageEventUpdate {
  43. if v != nil {
  44. _u.SetEventType(*v)
  45. }
  46. return _u
  47. }
  48. // SetPayload sets the "payload" field.
  49. func (_u *BatchImageEventUpdate) SetPayload(v map[string]interface{}) *BatchImageEventUpdate {
  50. _u.mutation.SetPayload(v)
  51. return _u
  52. }
  53. // ClearPayload clears the value of the "payload" field.
  54. func (_u *BatchImageEventUpdate) ClearPayload() *BatchImageEventUpdate {
  55. _u.mutation.ClearPayload()
  56. return _u
  57. }
  58. // SetEventHash sets the "event_hash" field.
  59. func (_u *BatchImageEventUpdate) SetEventHash(v string) *BatchImageEventUpdate {
  60. _u.mutation.SetEventHash(v)
  61. return _u
  62. }
  63. // SetNillableEventHash sets the "event_hash" field if the given value is not nil.
  64. func (_u *BatchImageEventUpdate) SetNillableEventHash(v *string) *BatchImageEventUpdate {
  65. if v != nil {
  66. _u.SetEventHash(*v)
  67. }
  68. return _u
  69. }
  70. // ClearEventHash clears the value of the "event_hash" field.
  71. func (_u *BatchImageEventUpdate) ClearEventHash() *BatchImageEventUpdate {
  72. _u.mutation.ClearEventHash()
  73. return _u
  74. }
  75. // Mutation returns the BatchImageEventMutation object of the builder.
  76. func (_u *BatchImageEventUpdate) Mutation() *BatchImageEventMutation {
  77. return _u.mutation
  78. }
  79. // Save executes the query and returns the number of nodes affected by the update operation.
  80. func (_u *BatchImageEventUpdate) Save(ctx context.Context) (int, error) {
  81. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  82. }
  83. // SaveX is like Save, but panics if an error occurs.
  84. func (_u *BatchImageEventUpdate) SaveX(ctx context.Context) int {
  85. affected, err := _u.Save(ctx)
  86. if err != nil {
  87. panic(err)
  88. }
  89. return affected
  90. }
  91. // Exec executes the query.
  92. func (_u *BatchImageEventUpdate) Exec(ctx context.Context) error {
  93. _, err := _u.Save(ctx)
  94. return err
  95. }
  96. // ExecX is like Exec, but panics if an error occurs.
  97. func (_u *BatchImageEventUpdate) ExecX(ctx context.Context) {
  98. if err := _u.Exec(ctx); err != nil {
  99. panic(err)
  100. }
  101. }
  102. // check runs all checks and user-defined validators on the builder.
  103. func (_u *BatchImageEventUpdate) check() error {
  104. if v, ok := _u.mutation.JobID(); ok {
  105. if err := batchimageevent.JobIDValidator(v); err != nil {
  106. return &ValidationError{Name: "job_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.job_id": %w`, err)}
  107. }
  108. }
  109. if v, ok := _u.mutation.EventType(); ok {
  110. if err := batchimageevent.EventTypeValidator(v); err != nil {
  111. return &ValidationError{Name: "event_type", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_type": %w`, err)}
  112. }
  113. }
  114. if v, ok := _u.mutation.EventHash(); ok {
  115. if err := batchimageevent.EventHashValidator(v); err != nil {
  116. return &ValidationError{Name: "event_hash", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_hash": %w`, err)}
  117. }
  118. }
  119. return nil
  120. }
  121. func (_u *BatchImageEventUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  122. if err := _u.check(); err != nil {
  123. return _node, err
  124. }
  125. _spec := sqlgraph.NewUpdateSpec(batchimageevent.Table, batchimageevent.Columns, sqlgraph.NewFieldSpec(batchimageevent.FieldID, field.TypeInt64))
  126. if ps := _u.mutation.predicates; len(ps) > 0 {
  127. _spec.Predicate = func(selector *sql.Selector) {
  128. for i := range ps {
  129. ps[i](selector)
  130. }
  131. }
  132. }
  133. if value, ok := _u.mutation.JobID(); ok {
  134. _spec.SetField(batchimageevent.FieldJobID, field.TypeString, value)
  135. }
  136. if value, ok := _u.mutation.EventType(); ok {
  137. _spec.SetField(batchimageevent.FieldEventType, field.TypeString, value)
  138. }
  139. if value, ok := _u.mutation.Payload(); ok {
  140. _spec.SetField(batchimageevent.FieldPayload, field.TypeJSON, value)
  141. }
  142. if _u.mutation.PayloadCleared() {
  143. _spec.ClearField(batchimageevent.FieldPayload, field.TypeJSON)
  144. }
  145. if value, ok := _u.mutation.EventHash(); ok {
  146. _spec.SetField(batchimageevent.FieldEventHash, field.TypeString, value)
  147. }
  148. if _u.mutation.EventHashCleared() {
  149. _spec.ClearField(batchimageevent.FieldEventHash, field.TypeString)
  150. }
  151. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  152. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  153. err = &NotFoundError{batchimageevent.Label}
  154. } else if sqlgraph.IsConstraintError(err) {
  155. err = &ConstraintError{msg: err.Error(), wrap: err}
  156. }
  157. return 0, err
  158. }
  159. _u.mutation.done = true
  160. return _node, nil
  161. }
  162. // BatchImageEventUpdateOne is the builder for updating a single BatchImageEvent entity.
  163. type BatchImageEventUpdateOne struct {
  164. config
  165. fields []string
  166. hooks []Hook
  167. mutation *BatchImageEventMutation
  168. }
  169. // SetJobID sets the "job_id" field.
  170. func (_u *BatchImageEventUpdateOne) SetJobID(v string) *BatchImageEventUpdateOne {
  171. _u.mutation.SetJobID(v)
  172. return _u
  173. }
  174. // SetNillableJobID sets the "job_id" field if the given value is not nil.
  175. func (_u *BatchImageEventUpdateOne) SetNillableJobID(v *string) *BatchImageEventUpdateOne {
  176. if v != nil {
  177. _u.SetJobID(*v)
  178. }
  179. return _u
  180. }
  181. // SetEventType sets the "event_type" field.
  182. func (_u *BatchImageEventUpdateOne) SetEventType(v string) *BatchImageEventUpdateOne {
  183. _u.mutation.SetEventType(v)
  184. return _u
  185. }
  186. // SetNillableEventType sets the "event_type" field if the given value is not nil.
  187. func (_u *BatchImageEventUpdateOne) SetNillableEventType(v *string) *BatchImageEventUpdateOne {
  188. if v != nil {
  189. _u.SetEventType(*v)
  190. }
  191. return _u
  192. }
  193. // SetPayload sets the "payload" field.
  194. func (_u *BatchImageEventUpdateOne) SetPayload(v map[string]interface{}) *BatchImageEventUpdateOne {
  195. _u.mutation.SetPayload(v)
  196. return _u
  197. }
  198. // ClearPayload clears the value of the "payload" field.
  199. func (_u *BatchImageEventUpdateOne) ClearPayload() *BatchImageEventUpdateOne {
  200. _u.mutation.ClearPayload()
  201. return _u
  202. }
  203. // SetEventHash sets the "event_hash" field.
  204. func (_u *BatchImageEventUpdateOne) SetEventHash(v string) *BatchImageEventUpdateOne {
  205. _u.mutation.SetEventHash(v)
  206. return _u
  207. }
  208. // SetNillableEventHash sets the "event_hash" field if the given value is not nil.
  209. func (_u *BatchImageEventUpdateOne) SetNillableEventHash(v *string) *BatchImageEventUpdateOne {
  210. if v != nil {
  211. _u.SetEventHash(*v)
  212. }
  213. return _u
  214. }
  215. // ClearEventHash clears the value of the "event_hash" field.
  216. func (_u *BatchImageEventUpdateOne) ClearEventHash() *BatchImageEventUpdateOne {
  217. _u.mutation.ClearEventHash()
  218. return _u
  219. }
  220. // Mutation returns the BatchImageEventMutation object of the builder.
  221. func (_u *BatchImageEventUpdateOne) Mutation() *BatchImageEventMutation {
  222. return _u.mutation
  223. }
  224. // Where appends a list predicates to the BatchImageEventUpdate builder.
  225. func (_u *BatchImageEventUpdateOne) Where(ps ...predicate.BatchImageEvent) *BatchImageEventUpdateOne {
  226. _u.mutation.Where(ps...)
  227. return _u
  228. }
  229. // Select allows selecting one or more fields (columns) of the returned entity.
  230. // The default is selecting all fields defined in the entity schema.
  231. func (_u *BatchImageEventUpdateOne) Select(field string, fields ...string) *BatchImageEventUpdateOne {
  232. _u.fields = append([]string{field}, fields...)
  233. return _u
  234. }
  235. // Save executes the query and returns the updated BatchImageEvent entity.
  236. func (_u *BatchImageEventUpdateOne) Save(ctx context.Context) (*BatchImageEvent, error) {
  237. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  238. }
  239. // SaveX is like Save, but panics if an error occurs.
  240. func (_u *BatchImageEventUpdateOne) SaveX(ctx context.Context) *BatchImageEvent {
  241. node, err := _u.Save(ctx)
  242. if err != nil {
  243. panic(err)
  244. }
  245. return node
  246. }
  247. // Exec executes the query on the entity.
  248. func (_u *BatchImageEventUpdateOne) Exec(ctx context.Context) error {
  249. _, err := _u.Save(ctx)
  250. return err
  251. }
  252. // ExecX is like Exec, but panics if an error occurs.
  253. func (_u *BatchImageEventUpdateOne) ExecX(ctx context.Context) {
  254. if err := _u.Exec(ctx); err != nil {
  255. panic(err)
  256. }
  257. }
  258. // check runs all checks and user-defined validators on the builder.
  259. func (_u *BatchImageEventUpdateOne) check() error {
  260. if v, ok := _u.mutation.JobID(); ok {
  261. if err := batchimageevent.JobIDValidator(v); err != nil {
  262. return &ValidationError{Name: "job_id", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.job_id": %w`, err)}
  263. }
  264. }
  265. if v, ok := _u.mutation.EventType(); ok {
  266. if err := batchimageevent.EventTypeValidator(v); err != nil {
  267. return &ValidationError{Name: "event_type", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_type": %w`, err)}
  268. }
  269. }
  270. if v, ok := _u.mutation.EventHash(); ok {
  271. if err := batchimageevent.EventHashValidator(v); err != nil {
  272. return &ValidationError{Name: "event_hash", err: fmt.Errorf(`ent: validator failed for field "BatchImageEvent.event_hash": %w`, err)}
  273. }
  274. }
  275. return nil
  276. }
  277. func (_u *BatchImageEventUpdateOne) sqlSave(ctx context.Context) (_node *BatchImageEvent, err error) {
  278. if err := _u.check(); err != nil {
  279. return _node, err
  280. }
  281. _spec := sqlgraph.NewUpdateSpec(batchimageevent.Table, batchimageevent.Columns, sqlgraph.NewFieldSpec(batchimageevent.FieldID, field.TypeInt64))
  282. id, ok := _u.mutation.ID()
  283. if !ok {
  284. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchImageEvent.id" for update`)}
  285. }
  286. _spec.Node.ID.Value = id
  287. if fields := _u.fields; len(fields) > 0 {
  288. _spec.Node.Columns = make([]string, 0, len(fields))
  289. _spec.Node.Columns = append(_spec.Node.Columns, batchimageevent.FieldID)
  290. for _, f := range fields {
  291. if !batchimageevent.ValidColumn(f) {
  292. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  293. }
  294. if f != batchimageevent.FieldID {
  295. _spec.Node.Columns = append(_spec.Node.Columns, f)
  296. }
  297. }
  298. }
  299. if ps := _u.mutation.predicates; len(ps) > 0 {
  300. _spec.Predicate = func(selector *sql.Selector) {
  301. for i := range ps {
  302. ps[i](selector)
  303. }
  304. }
  305. }
  306. if value, ok := _u.mutation.JobID(); ok {
  307. _spec.SetField(batchimageevent.FieldJobID, field.TypeString, value)
  308. }
  309. if value, ok := _u.mutation.EventType(); ok {
  310. _spec.SetField(batchimageevent.FieldEventType, field.TypeString, value)
  311. }
  312. if value, ok := _u.mutation.Payload(); ok {
  313. _spec.SetField(batchimageevent.FieldPayload, field.TypeJSON, value)
  314. }
  315. if _u.mutation.PayloadCleared() {
  316. _spec.ClearField(batchimageevent.FieldPayload, field.TypeJSON)
  317. }
  318. if value, ok := _u.mutation.EventHash(); ok {
  319. _spec.SetField(batchimageevent.FieldEventHash, field.TypeString, value)
  320. }
  321. if _u.mutation.EventHashCleared() {
  322. _spec.ClearField(batchimageevent.FieldEventHash, field.TypeString)
  323. }
  324. _node = &BatchImageEvent{config: _u.config}
  325. _spec.Assign = _node.assignValues
  326. _spec.ScanValues = _node.scanValues
  327. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  328. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  329. err = &NotFoundError{batchimageevent.Label}
  330. } else if sqlgraph.IsConstraintError(err) {
  331. err = &ConstraintError{msg: err.Error(), wrap: err}
  332. }
  333. return nil, err
  334. }
  335. _u.mutation.done = true
  336. return _node, nil
  337. }