errorpassthroughrule_update.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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/dialect/sql/sqljson"
  11. "entgo.io/ent/schema/field"
  12. "github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
  13. "github.com/Wei-Shaw/sub2api/ent/predicate"
  14. )
  15. // ErrorPassthroughRuleUpdate is the builder for updating ErrorPassthroughRule entities.
  16. type ErrorPassthroughRuleUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *ErrorPassthroughRuleMutation
  20. }
  21. // Where appends a list predicates to the ErrorPassthroughRuleUpdate builder.
  22. func (_u *ErrorPassthroughRuleUpdate) Where(ps ...predicate.ErrorPassthroughRule) *ErrorPassthroughRuleUpdate {
  23. _u.mutation.Where(ps...)
  24. return _u
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (_u *ErrorPassthroughRuleUpdate) SetUpdatedAt(v time.Time) *ErrorPassthroughRuleUpdate {
  28. _u.mutation.SetUpdatedAt(v)
  29. return _u
  30. }
  31. // SetName sets the "name" field.
  32. func (_u *ErrorPassthroughRuleUpdate) SetName(v string) *ErrorPassthroughRuleUpdate {
  33. _u.mutation.SetName(v)
  34. return _u
  35. }
  36. // SetNillableName sets the "name" field if the given value is not nil.
  37. func (_u *ErrorPassthroughRuleUpdate) SetNillableName(v *string) *ErrorPassthroughRuleUpdate {
  38. if v != nil {
  39. _u.SetName(*v)
  40. }
  41. return _u
  42. }
  43. // SetEnabled sets the "enabled" field.
  44. func (_u *ErrorPassthroughRuleUpdate) SetEnabled(v bool) *ErrorPassthroughRuleUpdate {
  45. _u.mutation.SetEnabled(v)
  46. return _u
  47. }
  48. // SetNillableEnabled sets the "enabled" field if the given value is not nil.
  49. func (_u *ErrorPassthroughRuleUpdate) SetNillableEnabled(v *bool) *ErrorPassthroughRuleUpdate {
  50. if v != nil {
  51. _u.SetEnabled(*v)
  52. }
  53. return _u
  54. }
  55. // SetPriority sets the "priority" field.
  56. func (_u *ErrorPassthroughRuleUpdate) SetPriority(v int) *ErrorPassthroughRuleUpdate {
  57. _u.mutation.ResetPriority()
  58. _u.mutation.SetPriority(v)
  59. return _u
  60. }
  61. // SetNillablePriority sets the "priority" field if the given value is not nil.
  62. func (_u *ErrorPassthroughRuleUpdate) SetNillablePriority(v *int) *ErrorPassthroughRuleUpdate {
  63. if v != nil {
  64. _u.SetPriority(*v)
  65. }
  66. return _u
  67. }
  68. // AddPriority adds value to the "priority" field.
  69. func (_u *ErrorPassthroughRuleUpdate) AddPriority(v int) *ErrorPassthroughRuleUpdate {
  70. _u.mutation.AddPriority(v)
  71. return _u
  72. }
  73. // SetErrorCodes sets the "error_codes" field.
  74. func (_u *ErrorPassthroughRuleUpdate) SetErrorCodes(v []int) *ErrorPassthroughRuleUpdate {
  75. _u.mutation.SetErrorCodes(v)
  76. return _u
  77. }
  78. // AppendErrorCodes appends value to the "error_codes" field.
  79. func (_u *ErrorPassthroughRuleUpdate) AppendErrorCodes(v []int) *ErrorPassthroughRuleUpdate {
  80. _u.mutation.AppendErrorCodes(v)
  81. return _u
  82. }
  83. // ClearErrorCodes clears the value of the "error_codes" field.
  84. func (_u *ErrorPassthroughRuleUpdate) ClearErrorCodes() *ErrorPassthroughRuleUpdate {
  85. _u.mutation.ClearErrorCodes()
  86. return _u
  87. }
  88. // SetKeywords sets the "keywords" field.
  89. func (_u *ErrorPassthroughRuleUpdate) SetKeywords(v []string) *ErrorPassthroughRuleUpdate {
  90. _u.mutation.SetKeywords(v)
  91. return _u
  92. }
  93. // AppendKeywords appends value to the "keywords" field.
  94. func (_u *ErrorPassthroughRuleUpdate) AppendKeywords(v []string) *ErrorPassthroughRuleUpdate {
  95. _u.mutation.AppendKeywords(v)
  96. return _u
  97. }
  98. // ClearKeywords clears the value of the "keywords" field.
  99. func (_u *ErrorPassthroughRuleUpdate) ClearKeywords() *ErrorPassthroughRuleUpdate {
  100. _u.mutation.ClearKeywords()
  101. return _u
  102. }
  103. // SetMatchMode sets the "match_mode" field.
  104. func (_u *ErrorPassthroughRuleUpdate) SetMatchMode(v string) *ErrorPassthroughRuleUpdate {
  105. _u.mutation.SetMatchMode(v)
  106. return _u
  107. }
  108. // SetNillableMatchMode sets the "match_mode" field if the given value is not nil.
  109. func (_u *ErrorPassthroughRuleUpdate) SetNillableMatchMode(v *string) *ErrorPassthroughRuleUpdate {
  110. if v != nil {
  111. _u.SetMatchMode(*v)
  112. }
  113. return _u
  114. }
  115. // SetPlatforms sets the "platforms" field.
  116. func (_u *ErrorPassthroughRuleUpdate) SetPlatforms(v []string) *ErrorPassthroughRuleUpdate {
  117. _u.mutation.SetPlatforms(v)
  118. return _u
  119. }
  120. // AppendPlatforms appends value to the "platforms" field.
  121. func (_u *ErrorPassthroughRuleUpdate) AppendPlatforms(v []string) *ErrorPassthroughRuleUpdate {
  122. _u.mutation.AppendPlatforms(v)
  123. return _u
  124. }
  125. // ClearPlatforms clears the value of the "platforms" field.
  126. func (_u *ErrorPassthroughRuleUpdate) ClearPlatforms() *ErrorPassthroughRuleUpdate {
  127. _u.mutation.ClearPlatforms()
  128. return _u
  129. }
  130. // SetPassthroughCode sets the "passthrough_code" field.
  131. func (_u *ErrorPassthroughRuleUpdate) SetPassthroughCode(v bool) *ErrorPassthroughRuleUpdate {
  132. _u.mutation.SetPassthroughCode(v)
  133. return _u
  134. }
  135. // SetNillablePassthroughCode sets the "passthrough_code" field if the given value is not nil.
  136. func (_u *ErrorPassthroughRuleUpdate) SetNillablePassthroughCode(v *bool) *ErrorPassthroughRuleUpdate {
  137. if v != nil {
  138. _u.SetPassthroughCode(*v)
  139. }
  140. return _u
  141. }
  142. // SetResponseCode sets the "response_code" field.
  143. func (_u *ErrorPassthroughRuleUpdate) SetResponseCode(v int) *ErrorPassthroughRuleUpdate {
  144. _u.mutation.ResetResponseCode()
  145. _u.mutation.SetResponseCode(v)
  146. return _u
  147. }
  148. // SetNillableResponseCode sets the "response_code" field if the given value is not nil.
  149. func (_u *ErrorPassthroughRuleUpdate) SetNillableResponseCode(v *int) *ErrorPassthroughRuleUpdate {
  150. if v != nil {
  151. _u.SetResponseCode(*v)
  152. }
  153. return _u
  154. }
  155. // AddResponseCode adds value to the "response_code" field.
  156. func (_u *ErrorPassthroughRuleUpdate) AddResponseCode(v int) *ErrorPassthroughRuleUpdate {
  157. _u.mutation.AddResponseCode(v)
  158. return _u
  159. }
  160. // ClearResponseCode clears the value of the "response_code" field.
  161. func (_u *ErrorPassthroughRuleUpdate) ClearResponseCode() *ErrorPassthroughRuleUpdate {
  162. _u.mutation.ClearResponseCode()
  163. return _u
  164. }
  165. // SetPassthroughBody sets the "passthrough_body" field.
  166. func (_u *ErrorPassthroughRuleUpdate) SetPassthroughBody(v bool) *ErrorPassthroughRuleUpdate {
  167. _u.mutation.SetPassthroughBody(v)
  168. return _u
  169. }
  170. // SetNillablePassthroughBody sets the "passthrough_body" field if the given value is not nil.
  171. func (_u *ErrorPassthroughRuleUpdate) SetNillablePassthroughBody(v *bool) *ErrorPassthroughRuleUpdate {
  172. if v != nil {
  173. _u.SetPassthroughBody(*v)
  174. }
  175. return _u
  176. }
  177. // SetCustomMessage sets the "custom_message" field.
  178. func (_u *ErrorPassthroughRuleUpdate) SetCustomMessage(v string) *ErrorPassthroughRuleUpdate {
  179. _u.mutation.SetCustomMessage(v)
  180. return _u
  181. }
  182. // SetNillableCustomMessage sets the "custom_message" field if the given value is not nil.
  183. func (_u *ErrorPassthroughRuleUpdate) SetNillableCustomMessage(v *string) *ErrorPassthroughRuleUpdate {
  184. if v != nil {
  185. _u.SetCustomMessage(*v)
  186. }
  187. return _u
  188. }
  189. // ClearCustomMessage clears the value of the "custom_message" field.
  190. func (_u *ErrorPassthroughRuleUpdate) ClearCustomMessage() *ErrorPassthroughRuleUpdate {
  191. _u.mutation.ClearCustomMessage()
  192. return _u
  193. }
  194. // SetSkipMonitoring sets the "skip_monitoring" field.
  195. func (_u *ErrorPassthroughRuleUpdate) SetSkipMonitoring(v bool) *ErrorPassthroughRuleUpdate {
  196. _u.mutation.SetSkipMonitoring(v)
  197. return _u
  198. }
  199. // SetNillableSkipMonitoring sets the "skip_monitoring" field if the given value is not nil.
  200. func (_u *ErrorPassthroughRuleUpdate) SetNillableSkipMonitoring(v *bool) *ErrorPassthroughRuleUpdate {
  201. if v != nil {
  202. _u.SetSkipMonitoring(*v)
  203. }
  204. return _u
  205. }
  206. // SetDescription sets the "description" field.
  207. func (_u *ErrorPassthroughRuleUpdate) SetDescription(v string) *ErrorPassthroughRuleUpdate {
  208. _u.mutation.SetDescription(v)
  209. return _u
  210. }
  211. // SetNillableDescription sets the "description" field if the given value is not nil.
  212. func (_u *ErrorPassthroughRuleUpdate) SetNillableDescription(v *string) *ErrorPassthroughRuleUpdate {
  213. if v != nil {
  214. _u.SetDescription(*v)
  215. }
  216. return _u
  217. }
  218. // ClearDescription clears the value of the "description" field.
  219. func (_u *ErrorPassthroughRuleUpdate) ClearDescription() *ErrorPassthroughRuleUpdate {
  220. _u.mutation.ClearDescription()
  221. return _u
  222. }
  223. // Mutation returns the ErrorPassthroughRuleMutation object of the builder.
  224. func (_u *ErrorPassthroughRuleUpdate) Mutation() *ErrorPassthroughRuleMutation {
  225. return _u.mutation
  226. }
  227. // Save executes the query and returns the number of nodes affected by the update operation.
  228. func (_u *ErrorPassthroughRuleUpdate) Save(ctx context.Context) (int, error) {
  229. _u.defaults()
  230. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  231. }
  232. // SaveX is like Save, but panics if an error occurs.
  233. func (_u *ErrorPassthroughRuleUpdate) SaveX(ctx context.Context) int {
  234. affected, err := _u.Save(ctx)
  235. if err != nil {
  236. panic(err)
  237. }
  238. return affected
  239. }
  240. // Exec executes the query.
  241. func (_u *ErrorPassthroughRuleUpdate) Exec(ctx context.Context) error {
  242. _, err := _u.Save(ctx)
  243. return err
  244. }
  245. // ExecX is like Exec, but panics if an error occurs.
  246. func (_u *ErrorPassthroughRuleUpdate) ExecX(ctx context.Context) {
  247. if err := _u.Exec(ctx); err != nil {
  248. panic(err)
  249. }
  250. }
  251. // defaults sets the default values of the builder before save.
  252. func (_u *ErrorPassthroughRuleUpdate) defaults() {
  253. if _, ok := _u.mutation.UpdatedAt(); !ok {
  254. v := errorpassthroughrule.UpdateDefaultUpdatedAt()
  255. _u.mutation.SetUpdatedAt(v)
  256. }
  257. }
  258. // check runs all checks and user-defined validators on the builder.
  259. func (_u *ErrorPassthroughRuleUpdate) check() error {
  260. if v, ok := _u.mutation.Name(); ok {
  261. if err := errorpassthroughrule.NameValidator(v); err != nil {
  262. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.name": %w`, err)}
  263. }
  264. }
  265. if v, ok := _u.mutation.MatchMode(); ok {
  266. if err := errorpassthroughrule.MatchModeValidator(v); err != nil {
  267. return &ValidationError{Name: "match_mode", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.match_mode": %w`, err)}
  268. }
  269. }
  270. return nil
  271. }
  272. func (_u *ErrorPassthroughRuleUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  273. if err := _u.check(); err != nil {
  274. return _node, err
  275. }
  276. _spec := sqlgraph.NewUpdateSpec(errorpassthroughrule.Table, errorpassthroughrule.Columns, sqlgraph.NewFieldSpec(errorpassthroughrule.FieldID, field.TypeInt64))
  277. if ps := _u.mutation.predicates; len(ps) > 0 {
  278. _spec.Predicate = func(selector *sql.Selector) {
  279. for i := range ps {
  280. ps[i](selector)
  281. }
  282. }
  283. }
  284. if value, ok := _u.mutation.UpdatedAt(); ok {
  285. _spec.SetField(errorpassthroughrule.FieldUpdatedAt, field.TypeTime, value)
  286. }
  287. if value, ok := _u.mutation.Name(); ok {
  288. _spec.SetField(errorpassthroughrule.FieldName, field.TypeString, value)
  289. }
  290. if value, ok := _u.mutation.Enabled(); ok {
  291. _spec.SetField(errorpassthroughrule.FieldEnabled, field.TypeBool, value)
  292. }
  293. if value, ok := _u.mutation.Priority(); ok {
  294. _spec.SetField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
  295. }
  296. if value, ok := _u.mutation.AddedPriority(); ok {
  297. _spec.AddField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
  298. }
  299. if value, ok := _u.mutation.ErrorCodes(); ok {
  300. _spec.SetField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON, value)
  301. }
  302. if value, ok := _u.mutation.AppendedErrorCodes(); ok {
  303. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  304. sqljson.Append(u, errorpassthroughrule.FieldErrorCodes, value)
  305. })
  306. }
  307. if _u.mutation.ErrorCodesCleared() {
  308. _spec.ClearField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON)
  309. }
  310. if value, ok := _u.mutation.Keywords(); ok {
  311. _spec.SetField(errorpassthroughrule.FieldKeywords, field.TypeJSON, value)
  312. }
  313. if value, ok := _u.mutation.AppendedKeywords(); ok {
  314. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  315. sqljson.Append(u, errorpassthroughrule.FieldKeywords, value)
  316. })
  317. }
  318. if _u.mutation.KeywordsCleared() {
  319. _spec.ClearField(errorpassthroughrule.FieldKeywords, field.TypeJSON)
  320. }
  321. if value, ok := _u.mutation.MatchMode(); ok {
  322. _spec.SetField(errorpassthroughrule.FieldMatchMode, field.TypeString, value)
  323. }
  324. if value, ok := _u.mutation.Platforms(); ok {
  325. _spec.SetField(errorpassthroughrule.FieldPlatforms, field.TypeJSON, value)
  326. }
  327. if value, ok := _u.mutation.AppendedPlatforms(); ok {
  328. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  329. sqljson.Append(u, errorpassthroughrule.FieldPlatforms, value)
  330. })
  331. }
  332. if _u.mutation.PlatformsCleared() {
  333. _spec.ClearField(errorpassthroughrule.FieldPlatforms, field.TypeJSON)
  334. }
  335. if value, ok := _u.mutation.PassthroughCode(); ok {
  336. _spec.SetField(errorpassthroughrule.FieldPassthroughCode, field.TypeBool, value)
  337. }
  338. if value, ok := _u.mutation.ResponseCode(); ok {
  339. _spec.SetField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
  340. }
  341. if value, ok := _u.mutation.AddedResponseCode(); ok {
  342. _spec.AddField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
  343. }
  344. if _u.mutation.ResponseCodeCleared() {
  345. _spec.ClearField(errorpassthroughrule.FieldResponseCode, field.TypeInt)
  346. }
  347. if value, ok := _u.mutation.PassthroughBody(); ok {
  348. _spec.SetField(errorpassthroughrule.FieldPassthroughBody, field.TypeBool, value)
  349. }
  350. if value, ok := _u.mutation.CustomMessage(); ok {
  351. _spec.SetField(errorpassthroughrule.FieldCustomMessage, field.TypeString, value)
  352. }
  353. if _u.mutation.CustomMessageCleared() {
  354. _spec.ClearField(errorpassthroughrule.FieldCustomMessage, field.TypeString)
  355. }
  356. if value, ok := _u.mutation.SkipMonitoring(); ok {
  357. _spec.SetField(errorpassthroughrule.FieldSkipMonitoring, field.TypeBool, value)
  358. }
  359. if value, ok := _u.mutation.Description(); ok {
  360. _spec.SetField(errorpassthroughrule.FieldDescription, field.TypeString, value)
  361. }
  362. if _u.mutation.DescriptionCleared() {
  363. _spec.ClearField(errorpassthroughrule.FieldDescription, field.TypeString)
  364. }
  365. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  366. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  367. err = &NotFoundError{errorpassthroughrule.Label}
  368. } else if sqlgraph.IsConstraintError(err) {
  369. err = &ConstraintError{msg: err.Error(), wrap: err}
  370. }
  371. return 0, err
  372. }
  373. _u.mutation.done = true
  374. return _node, nil
  375. }
  376. // ErrorPassthroughRuleUpdateOne is the builder for updating a single ErrorPassthroughRule entity.
  377. type ErrorPassthroughRuleUpdateOne struct {
  378. config
  379. fields []string
  380. hooks []Hook
  381. mutation *ErrorPassthroughRuleMutation
  382. }
  383. // SetUpdatedAt sets the "updated_at" field.
  384. func (_u *ErrorPassthroughRuleUpdateOne) SetUpdatedAt(v time.Time) *ErrorPassthroughRuleUpdateOne {
  385. _u.mutation.SetUpdatedAt(v)
  386. return _u
  387. }
  388. // SetName sets the "name" field.
  389. func (_u *ErrorPassthroughRuleUpdateOne) SetName(v string) *ErrorPassthroughRuleUpdateOne {
  390. _u.mutation.SetName(v)
  391. return _u
  392. }
  393. // SetNillableName sets the "name" field if the given value is not nil.
  394. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableName(v *string) *ErrorPassthroughRuleUpdateOne {
  395. if v != nil {
  396. _u.SetName(*v)
  397. }
  398. return _u
  399. }
  400. // SetEnabled sets the "enabled" field.
  401. func (_u *ErrorPassthroughRuleUpdateOne) SetEnabled(v bool) *ErrorPassthroughRuleUpdateOne {
  402. _u.mutation.SetEnabled(v)
  403. return _u
  404. }
  405. // SetNillableEnabled sets the "enabled" field if the given value is not nil.
  406. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableEnabled(v *bool) *ErrorPassthroughRuleUpdateOne {
  407. if v != nil {
  408. _u.SetEnabled(*v)
  409. }
  410. return _u
  411. }
  412. // SetPriority sets the "priority" field.
  413. func (_u *ErrorPassthroughRuleUpdateOne) SetPriority(v int) *ErrorPassthroughRuleUpdateOne {
  414. _u.mutation.ResetPriority()
  415. _u.mutation.SetPriority(v)
  416. return _u
  417. }
  418. // SetNillablePriority sets the "priority" field if the given value is not nil.
  419. func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePriority(v *int) *ErrorPassthroughRuleUpdateOne {
  420. if v != nil {
  421. _u.SetPriority(*v)
  422. }
  423. return _u
  424. }
  425. // AddPriority adds value to the "priority" field.
  426. func (_u *ErrorPassthroughRuleUpdateOne) AddPriority(v int) *ErrorPassthroughRuleUpdateOne {
  427. _u.mutation.AddPriority(v)
  428. return _u
  429. }
  430. // SetErrorCodes sets the "error_codes" field.
  431. func (_u *ErrorPassthroughRuleUpdateOne) SetErrorCodes(v []int) *ErrorPassthroughRuleUpdateOne {
  432. _u.mutation.SetErrorCodes(v)
  433. return _u
  434. }
  435. // AppendErrorCodes appends value to the "error_codes" field.
  436. func (_u *ErrorPassthroughRuleUpdateOne) AppendErrorCodes(v []int) *ErrorPassthroughRuleUpdateOne {
  437. _u.mutation.AppendErrorCodes(v)
  438. return _u
  439. }
  440. // ClearErrorCodes clears the value of the "error_codes" field.
  441. func (_u *ErrorPassthroughRuleUpdateOne) ClearErrorCodes() *ErrorPassthroughRuleUpdateOne {
  442. _u.mutation.ClearErrorCodes()
  443. return _u
  444. }
  445. // SetKeywords sets the "keywords" field.
  446. func (_u *ErrorPassthroughRuleUpdateOne) SetKeywords(v []string) *ErrorPassthroughRuleUpdateOne {
  447. _u.mutation.SetKeywords(v)
  448. return _u
  449. }
  450. // AppendKeywords appends value to the "keywords" field.
  451. func (_u *ErrorPassthroughRuleUpdateOne) AppendKeywords(v []string) *ErrorPassthroughRuleUpdateOne {
  452. _u.mutation.AppendKeywords(v)
  453. return _u
  454. }
  455. // ClearKeywords clears the value of the "keywords" field.
  456. func (_u *ErrorPassthroughRuleUpdateOne) ClearKeywords() *ErrorPassthroughRuleUpdateOne {
  457. _u.mutation.ClearKeywords()
  458. return _u
  459. }
  460. // SetMatchMode sets the "match_mode" field.
  461. func (_u *ErrorPassthroughRuleUpdateOne) SetMatchMode(v string) *ErrorPassthroughRuleUpdateOne {
  462. _u.mutation.SetMatchMode(v)
  463. return _u
  464. }
  465. // SetNillableMatchMode sets the "match_mode" field if the given value is not nil.
  466. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableMatchMode(v *string) *ErrorPassthroughRuleUpdateOne {
  467. if v != nil {
  468. _u.SetMatchMode(*v)
  469. }
  470. return _u
  471. }
  472. // SetPlatforms sets the "platforms" field.
  473. func (_u *ErrorPassthroughRuleUpdateOne) SetPlatforms(v []string) *ErrorPassthroughRuleUpdateOne {
  474. _u.mutation.SetPlatforms(v)
  475. return _u
  476. }
  477. // AppendPlatforms appends value to the "platforms" field.
  478. func (_u *ErrorPassthroughRuleUpdateOne) AppendPlatforms(v []string) *ErrorPassthroughRuleUpdateOne {
  479. _u.mutation.AppendPlatforms(v)
  480. return _u
  481. }
  482. // ClearPlatforms clears the value of the "platforms" field.
  483. func (_u *ErrorPassthroughRuleUpdateOne) ClearPlatforms() *ErrorPassthroughRuleUpdateOne {
  484. _u.mutation.ClearPlatforms()
  485. return _u
  486. }
  487. // SetPassthroughCode sets the "passthrough_code" field.
  488. func (_u *ErrorPassthroughRuleUpdateOne) SetPassthroughCode(v bool) *ErrorPassthroughRuleUpdateOne {
  489. _u.mutation.SetPassthroughCode(v)
  490. return _u
  491. }
  492. // SetNillablePassthroughCode sets the "passthrough_code" field if the given value is not nil.
  493. func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePassthroughCode(v *bool) *ErrorPassthroughRuleUpdateOne {
  494. if v != nil {
  495. _u.SetPassthroughCode(*v)
  496. }
  497. return _u
  498. }
  499. // SetResponseCode sets the "response_code" field.
  500. func (_u *ErrorPassthroughRuleUpdateOne) SetResponseCode(v int) *ErrorPassthroughRuleUpdateOne {
  501. _u.mutation.ResetResponseCode()
  502. _u.mutation.SetResponseCode(v)
  503. return _u
  504. }
  505. // SetNillableResponseCode sets the "response_code" field if the given value is not nil.
  506. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableResponseCode(v *int) *ErrorPassthroughRuleUpdateOne {
  507. if v != nil {
  508. _u.SetResponseCode(*v)
  509. }
  510. return _u
  511. }
  512. // AddResponseCode adds value to the "response_code" field.
  513. func (_u *ErrorPassthroughRuleUpdateOne) AddResponseCode(v int) *ErrorPassthroughRuleUpdateOne {
  514. _u.mutation.AddResponseCode(v)
  515. return _u
  516. }
  517. // ClearResponseCode clears the value of the "response_code" field.
  518. func (_u *ErrorPassthroughRuleUpdateOne) ClearResponseCode() *ErrorPassthroughRuleUpdateOne {
  519. _u.mutation.ClearResponseCode()
  520. return _u
  521. }
  522. // SetPassthroughBody sets the "passthrough_body" field.
  523. func (_u *ErrorPassthroughRuleUpdateOne) SetPassthroughBody(v bool) *ErrorPassthroughRuleUpdateOne {
  524. _u.mutation.SetPassthroughBody(v)
  525. return _u
  526. }
  527. // SetNillablePassthroughBody sets the "passthrough_body" field if the given value is not nil.
  528. func (_u *ErrorPassthroughRuleUpdateOne) SetNillablePassthroughBody(v *bool) *ErrorPassthroughRuleUpdateOne {
  529. if v != nil {
  530. _u.SetPassthroughBody(*v)
  531. }
  532. return _u
  533. }
  534. // SetCustomMessage sets the "custom_message" field.
  535. func (_u *ErrorPassthroughRuleUpdateOne) SetCustomMessage(v string) *ErrorPassthroughRuleUpdateOne {
  536. _u.mutation.SetCustomMessage(v)
  537. return _u
  538. }
  539. // SetNillableCustomMessage sets the "custom_message" field if the given value is not nil.
  540. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableCustomMessage(v *string) *ErrorPassthroughRuleUpdateOne {
  541. if v != nil {
  542. _u.SetCustomMessage(*v)
  543. }
  544. return _u
  545. }
  546. // ClearCustomMessage clears the value of the "custom_message" field.
  547. func (_u *ErrorPassthroughRuleUpdateOne) ClearCustomMessage() *ErrorPassthroughRuleUpdateOne {
  548. _u.mutation.ClearCustomMessage()
  549. return _u
  550. }
  551. // SetSkipMonitoring sets the "skip_monitoring" field.
  552. func (_u *ErrorPassthroughRuleUpdateOne) SetSkipMonitoring(v bool) *ErrorPassthroughRuleUpdateOne {
  553. _u.mutation.SetSkipMonitoring(v)
  554. return _u
  555. }
  556. // SetNillableSkipMonitoring sets the "skip_monitoring" field if the given value is not nil.
  557. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableSkipMonitoring(v *bool) *ErrorPassthroughRuleUpdateOne {
  558. if v != nil {
  559. _u.SetSkipMonitoring(*v)
  560. }
  561. return _u
  562. }
  563. // SetDescription sets the "description" field.
  564. func (_u *ErrorPassthroughRuleUpdateOne) SetDescription(v string) *ErrorPassthroughRuleUpdateOne {
  565. _u.mutation.SetDescription(v)
  566. return _u
  567. }
  568. // SetNillableDescription sets the "description" field if the given value is not nil.
  569. func (_u *ErrorPassthroughRuleUpdateOne) SetNillableDescription(v *string) *ErrorPassthroughRuleUpdateOne {
  570. if v != nil {
  571. _u.SetDescription(*v)
  572. }
  573. return _u
  574. }
  575. // ClearDescription clears the value of the "description" field.
  576. func (_u *ErrorPassthroughRuleUpdateOne) ClearDescription() *ErrorPassthroughRuleUpdateOne {
  577. _u.mutation.ClearDescription()
  578. return _u
  579. }
  580. // Mutation returns the ErrorPassthroughRuleMutation object of the builder.
  581. func (_u *ErrorPassthroughRuleUpdateOne) Mutation() *ErrorPassthroughRuleMutation {
  582. return _u.mutation
  583. }
  584. // Where appends a list predicates to the ErrorPassthroughRuleUpdate builder.
  585. func (_u *ErrorPassthroughRuleUpdateOne) Where(ps ...predicate.ErrorPassthroughRule) *ErrorPassthroughRuleUpdateOne {
  586. _u.mutation.Where(ps...)
  587. return _u
  588. }
  589. // Select allows selecting one or more fields (columns) of the returned entity.
  590. // The default is selecting all fields defined in the entity schema.
  591. func (_u *ErrorPassthroughRuleUpdateOne) Select(field string, fields ...string) *ErrorPassthroughRuleUpdateOne {
  592. _u.fields = append([]string{field}, fields...)
  593. return _u
  594. }
  595. // Save executes the query and returns the updated ErrorPassthroughRule entity.
  596. func (_u *ErrorPassthroughRuleUpdateOne) Save(ctx context.Context) (*ErrorPassthroughRule, error) {
  597. _u.defaults()
  598. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  599. }
  600. // SaveX is like Save, but panics if an error occurs.
  601. func (_u *ErrorPassthroughRuleUpdateOne) SaveX(ctx context.Context) *ErrorPassthroughRule {
  602. node, err := _u.Save(ctx)
  603. if err != nil {
  604. panic(err)
  605. }
  606. return node
  607. }
  608. // Exec executes the query on the entity.
  609. func (_u *ErrorPassthroughRuleUpdateOne) Exec(ctx context.Context) error {
  610. _, err := _u.Save(ctx)
  611. return err
  612. }
  613. // ExecX is like Exec, but panics if an error occurs.
  614. func (_u *ErrorPassthroughRuleUpdateOne) ExecX(ctx context.Context) {
  615. if err := _u.Exec(ctx); err != nil {
  616. panic(err)
  617. }
  618. }
  619. // defaults sets the default values of the builder before save.
  620. func (_u *ErrorPassthroughRuleUpdateOne) defaults() {
  621. if _, ok := _u.mutation.UpdatedAt(); !ok {
  622. v := errorpassthroughrule.UpdateDefaultUpdatedAt()
  623. _u.mutation.SetUpdatedAt(v)
  624. }
  625. }
  626. // check runs all checks and user-defined validators on the builder.
  627. func (_u *ErrorPassthroughRuleUpdateOne) check() error {
  628. if v, ok := _u.mutation.Name(); ok {
  629. if err := errorpassthroughrule.NameValidator(v); err != nil {
  630. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.name": %w`, err)}
  631. }
  632. }
  633. if v, ok := _u.mutation.MatchMode(); ok {
  634. if err := errorpassthroughrule.MatchModeValidator(v); err != nil {
  635. return &ValidationError{Name: "match_mode", err: fmt.Errorf(`ent: validator failed for field "ErrorPassthroughRule.match_mode": %w`, err)}
  636. }
  637. }
  638. return nil
  639. }
  640. func (_u *ErrorPassthroughRuleUpdateOne) sqlSave(ctx context.Context) (_node *ErrorPassthroughRule, err error) {
  641. if err := _u.check(); err != nil {
  642. return _node, err
  643. }
  644. _spec := sqlgraph.NewUpdateSpec(errorpassthroughrule.Table, errorpassthroughrule.Columns, sqlgraph.NewFieldSpec(errorpassthroughrule.FieldID, field.TypeInt64))
  645. id, ok := _u.mutation.ID()
  646. if !ok {
  647. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ErrorPassthroughRule.id" for update`)}
  648. }
  649. _spec.Node.ID.Value = id
  650. if fields := _u.fields; len(fields) > 0 {
  651. _spec.Node.Columns = make([]string, 0, len(fields))
  652. _spec.Node.Columns = append(_spec.Node.Columns, errorpassthroughrule.FieldID)
  653. for _, f := range fields {
  654. if !errorpassthroughrule.ValidColumn(f) {
  655. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  656. }
  657. if f != errorpassthroughrule.FieldID {
  658. _spec.Node.Columns = append(_spec.Node.Columns, f)
  659. }
  660. }
  661. }
  662. if ps := _u.mutation.predicates; len(ps) > 0 {
  663. _spec.Predicate = func(selector *sql.Selector) {
  664. for i := range ps {
  665. ps[i](selector)
  666. }
  667. }
  668. }
  669. if value, ok := _u.mutation.UpdatedAt(); ok {
  670. _spec.SetField(errorpassthroughrule.FieldUpdatedAt, field.TypeTime, value)
  671. }
  672. if value, ok := _u.mutation.Name(); ok {
  673. _spec.SetField(errorpassthroughrule.FieldName, field.TypeString, value)
  674. }
  675. if value, ok := _u.mutation.Enabled(); ok {
  676. _spec.SetField(errorpassthroughrule.FieldEnabled, field.TypeBool, value)
  677. }
  678. if value, ok := _u.mutation.Priority(); ok {
  679. _spec.SetField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
  680. }
  681. if value, ok := _u.mutation.AddedPriority(); ok {
  682. _spec.AddField(errorpassthroughrule.FieldPriority, field.TypeInt, value)
  683. }
  684. if value, ok := _u.mutation.ErrorCodes(); ok {
  685. _spec.SetField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON, value)
  686. }
  687. if value, ok := _u.mutation.AppendedErrorCodes(); ok {
  688. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  689. sqljson.Append(u, errorpassthroughrule.FieldErrorCodes, value)
  690. })
  691. }
  692. if _u.mutation.ErrorCodesCleared() {
  693. _spec.ClearField(errorpassthroughrule.FieldErrorCodes, field.TypeJSON)
  694. }
  695. if value, ok := _u.mutation.Keywords(); ok {
  696. _spec.SetField(errorpassthroughrule.FieldKeywords, field.TypeJSON, value)
  697. }
  698. if value, ok := _u.mutation.AppendedKeywords(); ok {
  699. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  700. sqljson.Append(u, errorpassthroughrule.FieldKeywords, value)
  701. })
  702. }
  703. if _u.mutation.KeywordsCleared() {
  704. _spec.ClearField(errorpassthroughrule.FieldKeywords, field.TypeJSON)
  705. }
  706. if value, ok := _u.mutation.MatchMode(); ok {
  707. _spec.SetField(errorpassthroughrule.FieldMatchMode, field.TypeString, value)
  708. }
  709. if value, ok := _u.mutation.Platforms(); ok {
  710. _spec.SetField(errorpassthroughrule.FieldPlatforms, field.TypeJSON, value)
  711. }
  712. if value, ok := _u.mutation.AppendedPlatforms(); ok {
  713. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  714. sqljson.Append(u, errorpassthroughrule.FieldPlatforms, value)
  715. })
  716. }
  717. if _u.mutation.PlatformsCleared() {
  718. _spec.ClearField(errorpassthroughrule.FieldPlatforms, field.TypeJSON)
  719. }
  720. if value, ok := _u.mutation.PassthroughCode(); ok {
  721. _spec.SetField(errorpassthroughrule.FieldPassthroughCode, field.TypeBool, value)
  722. }
  723. if value, ok := _u.mutation.ResponseCode(); ok {
  724. _spec.SetField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
  725. }
  726. if value, ok := _u.mutation.AddedResponseCode(); ok {
  727. _spec.AddField(errorpassthroughrule.FieldResponseCode, field.TypeInt, value)
  728. }
  729. if _u.mutation.ResponseCodeCleared() {
  730. _spec.ClearField(errorpassthroughrule.FieldResponseCode, field.TypeInt)
  731. }
  732. if value, ok := _u.mutation.PassthroughBody(); ok {
  733. _spec.SetField(errorpassthroughrule.FieldPassthroughBody, field.TypeBool, value)
  734. }
  735. if value, ok := _u.mutation.CustomMessage(); ok {
  736. _spec.SetField(errorpassthroughrule.FieldCustomMessage, field.TypeString, value)
  737. }
  738. if _u.mutation.CustomMessageCleared() {
  739. _spec.ClearField(errorpassthroughrule.FieldCustomMessage, field.TypeString)
  740. }
  741. if value, ok := _u.mutation.SkipMonitoring(); ok {
  742. _spec.SetField(errorpassthroughrule.FieldSkipMonitoring, field.TypeBool, value)
  743. }
  744. if value, ok := _u.mutation.Description(); ok {
  745. _spec.SetField(errorpassthroughrule.FieldDescription, field.TypeString, value)
  746. }
  747. if _u.mutation.DescriptionCleared() {
  748. _spec.ClearField(errorpassthroughrule.FieldDescription, field.TypeString)
  749. }
  750. _node = &ErrorPassthroughRule{config: _u.config}
  751. _spec.Assign = _node.assignValues
  752. _spec.ScanValues = _node.scanValues
  753. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  754. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  755. err = &NotFoundError{errorpassthroughrule.Label}
  756. } else if sqlgraph.IsConstraintError(err) {
  757. err = &ConstraintError{msg: err.Error(), wrap: err}
  758. }
  759. return nil, err
  760. }
  761. _u.mutation.done = true
  762. return _node, nil
  763. }