paymentauditlog_update.go 11 KB

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