addwechatfriendlog_update.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "wechat-api/ent/addwechatfriendlog"
  8. "wechat-api/ent/predicate"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // AddWechatFriendLogUpdate is the builder for updating AddWechatFriendLog entities.
  14. type AddWechatFriendLogUpdate struct {
  15. config
  16. hooks []Hook
  17. mutation *AddWechatFriendLogMutation
  18. }
  19. // Where appends a list predicates to the AddWechatFriendLogUpdate builder.
  20. func (awflu *AddWechatFriendLogUpdate) Where(ps ...predicate.AddWechatFriendLog) *AddWechatFriendLogUpdate {
  21. awflu.mutation.Where(ps...)
  22. return awflu
  23. }
  24. // SetOwnerWxID sets the "owner_wx_id" field.
  25. func (awflu *AddWechatFriendLogUpdate) SetOwnerWxID(s string) *AddWechatFriendLogUpdate {
  26. awflu.mutation.SetOwnerWxID(s)
  27. return awflu
  28. }
  29. // SetNillableOwnerWxID sets the "owner_wx_id" field if the given value is not nil.
  30. func (awflu *AddWechatFriendLogUpdate) SetNillableOwnerWxID(s *string) *AddWechatFriendLogUpdate {
  31. if s != nil {
  32. awflu.SetOwnerWxID(*s)
  33. }
  34. return awflu
  35. }
  36. // SetOwnerWxType sets the "owner_wx_type" field.
  37. func (awflu *AddWechatFriendLogUpdate) SetOwnerWxType(i int) *AddWechatFriendLogUpdate {
  38. awflu.mutation.ResetOwnerWxType()
  39. awflu.mutation.SetOwnerWxType(i)
  40. return awflu
  41. }
  42. // SetNillableOwnerWxType sets the "owner_wx_type" field if the given value is not nil.
  43. func (awflu *AddWechatFriendLogUpdate) SetNillableOwnerWxType(i *int) *AddWechatFriendLogUpdate {
  44. if i != nil {
  45. awflu.SetOwnerWxType(*i)
  46. }
  47. return awflu
  48. }
  49. // AddOwnerWxType adds i to the "owner_wx_type" field.
  50. func (awflu *AddWechatFriendLogUpdate) AddOwnerWxType(i int) *AddWechatFriendLogUpdate {
  51. awflu.mutation.AddOwnerWxType(i)
  52. return awflu
  53. }
  54. // SetFindContent sets the "find_content" field.
  55. func (awflu *AddWechatFriendLogUpdate) SetFindContent(s string) *AddWechatFriendLogUpdate {
  56. awflu.mutation.SetFindContent(s)
  57. return awflu
  58. }
  59. // SetNillableFindContent sets the "find_content" field if the given value is not nil.
  60. func (awflu *AddWechatFriendLogUpdate) SetNillableFindContent(s *string) *AddWechatFriendLogUpdate {
  61. if s != nil {
  62. awflu.SetFindContent(*s)
  63. }
  64. return awflu
  65. }
  66. // SetMessage sets the "message" field.
  67. func (awflu *AddWechatFriendLogUpdate) SetMessage(s string) *AddWechatFriendLogUpdate {
  68. awflu.mutation.SetMessage(s)
  69. return awflu
  70. }
  71. // SetNillableMessage sets the "message" field if the given value is not nil.
  72. func (awflu *AddWechatFriendLogUpdate) SetNillableMessage(s *string) *AddWechatFriendLogUpdate {
  73. if s != nil {
  74. awflu.SetMessage(*s)
  75. }
  76. return awflu
  77. }
  78. // SetFindRequest sets the "find_request" field.
  79. func (awflu *AddWechatFriendLogUpdate) SetFindRequest(m map[string]interface{}) *AddWechatFriendLogUpdate {
  80. awflu.mutation.SetFindRequest(m)
  81. return awflu
  82. }
  83. // ClearFindRequest clears the value of the "find_request" field.
  84. func (awflu *AddWechatFriendLogUpdate) ClearFindRequest() *AddWechatFriendLogUpdate {
  85. awflu.mutation.ClearFindRequest()
  86. return awflu
  87. }
  88. // SetFindResult sets the "find_result" field.
  89. func (awflu *AddWechatFriendLogUpdate) SetFindResult(m map[string]interface{}) *AddWechatFriendLogUpdate {
  90. awflu.mutation.SetFindResult(m)
  91. return awflu
  92. }
  93. // ClearFindResult clears the value of the "find_result" field.
  94. func (awflu *AddWechatFriendLogUpdate) ClearFindResult() *AddWechatFriendLogUpdate {
  95. awflu.mutation.ClearFindResult()
  96. return awflu
  97. }
  98. // SetIsCanAdd sets the "is_can_add" field.
  99. func (awflu *AddWechatFriendLogUpdate) SetIsCanAdd(i int) *AddWechatFriendLogUpdate {
  100. awflu.mutation.ResetIsCanAdd()
  101. awflu.mutation.SetIsCanAdd(i)
  102. return awflu
  103. }
  104. // SetNillableIsCanAdd sets the "is_can_add" field if the given value is not nil.
  105. func (awflu *AddWechatFriendLogUpdate) SetNillableIsCanAdd(i *int) *AddWechatFriendLogUpdate {
  106. if i != nil {
  107. awflu.SetIsCanAdd(*i)
  108. }
  109. return awflu
  110. }
  111. // AddIsCanAdd adds i to the "is_can_add" field.
  112. func (awflu *AddWechatFriendLogUpdate) AddIsCanAdd(i int) *AddWechatFriendLogUpdate {
  113. awflu.mutation.AddIsCanAdd(i)
  114. return awflu
  115. }
  116. // SetTaskID sets the "task_id" field.
  117. func (awflu *AddWechatFriendLogUpdate) SetTaskID(i int64) *AddWechatFriendLogUpdate {
  118. awflu.mutation.ResetTaskID()
  119. awflu.mutation.SetTaskID(i)
  120. return awflu
  121. }
  122. // SetNillableTaskID sets the "task_id" field if the given value is not nil.
  123. func (awflu *AddWechatFriendLogUpdate) SetNillableTaskID(i *int64) *AddWechatFriendLogUpdate {
  124. if i != nil {
  125. awflu.SetTaskID(*i)
  126. }
  127. return awflu
  128. }
  129. // AddTaskID adds i to the "task_id" field.
  130. func (awflu *AddWechatFriendLogUpdate) AddTaskID(i int64) *AddWechatFriendLogUpdate {
  131. awflu.mutation.AddTaskID(i)
  132. return awflu
  133. }
  134. // SetAddRequest sets the "add_request" field.
  135. func (awflu *AddWechatFriendLogUpdate) SetAddRequest(m map[string]interface{}) *AddWechatFriendLogUpdate {
  136. awflu.mutation.SetAddRequest(m)
  137. return awflu
  138. }
  139. // ClearAddRequest clears the value of the "add_request" field.
  140. func (awflu *AddWechatFriendLogUpdate) ClearAddRequest() *AddWechatFriendLogUpdate {
  141. awflu.mutation.ClearAddRequest()
  142. return awflu
  143. }
  144. // SetAddResult sets the "add_result" field.
  145. func (awflu *AddWechatFriendLogUpdate) SetAddResult(m map[string]interface{}) *AddWechatFriendLogUpdate {
  146. awflu.mutation.SetAddResult(m)
  147. return awflu
  148. }
  149. // ClearAddResult clears the value of the "add_result" field.
  150. func (awflu *AddWechatFriendLogUpdate) ClearAddResult() *AddWechatFriendLogUpdate {
  151. awflu.mutation.ClearAddResult()
  152. return awflu
  153. }
  154. // SetCreatedAt sets the "created_at" field.
  155. func (awflu *AddWechatFriendLogUpdate) SetCreatedAt(i int64) *AddWechatFriendLogUpdate {
  156. awflu.mutation.ResetCreatedAt()
  157. awflu.mutation.SetCreatedAt(i)
  158. return awflu
  159. }
  160. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  161. func (awflu *AddWechatFriendLogUpdate) SetNillableCreatedAt(i *int64) *AddWechatFriendLogUpdate {
  162. if i != nil {
  163. awflu.SetCreatedAt(*i)
  164. }
  165. return awflu
  166. }
  167. // AddCreatedAt adds i to the "created_at" field.
  168. func (awflu *AddWechatFriendLogUpdate) AddCreatedAt(i int64) *AddWechatFriendLogUpdate {
  169. awflu.mutation.AddCreatedAt(i)
  170. return awflu
  171. }
  172. // SetUpdatedAt sets the "updated_at" field.
  173. func (awflu *AddWechatFriendLogUpdate) SetUpdatedAt(i int64) *AddWechatFriendLogUpdate {
  174. awflu.mutation.ResetUpdatedAt()
  175. awflu.mutation.SetUpdatedAt(i)
  176. return awflu
  177. }
  178. // AddUpdatedAt adds i to the "updated_at" field.
  179. func (awflu *AddWechatFriendLogUpdate) AddUpdatedAt(i int64) *AddWechatFriendLogUpdate {
  180. awflu.mutation.AddUpdatedAt(i)
  181. return awflu
  182. }
  183. // Mutation returns the AddWechatFriendLogMutation object of the builder.
  184. func (awflu *AddWechatFriendLogUpdate) Mutation() *AddWechatFriendLogMutation {
  185. return awflu.mutation
  186. }
  187. // Save executes the query and returns the number of nodes affected by the update operation.
  188. func (awflu *AddWechatFriendLogUpdate) Save(ctx context.Context) (int, error) {
  189. awflu.defaults()
  190. return withHooks(ctx, awflu.sqlSave, awflu.mutation, awflu.hooks)
  191. }
  192. // SaveX is like Save, but panics if an error occurs.
  193. func (awflu *AddWechatFriendLogUpdate) SaveX(ctx context.Context) int {
  194. affected, err := awflu.Save(ctx)
  195. if err != nil {
  196. panic(err)
  197. }
  198. return affected
  199. }
  200. // Exec executes the query.
  201. func (awflu *AddWechatFriendLogUpdate) Exec(ctx context.Context) error {
  202. _, err := awflu.Save(ctx)
  203. return err
  204. }
  205. // ExecX is like Exec, but panics if an error occurs.
  206. func (awflu *AddWechatFriendLogUpdate) ExecX(ctx context.Context) {
  207. if err := awflu.Exec(ctx); err != nil {
  208. panic(err)
  209. }
  210. }
  211. // defaults sets the default values of the builder before save.
  212. func (awflu *AddWechatFriendLogUpdate) defaults() {
  213. if _, ok := awflu.mutation.UpdatedAt(); !ok {
  214. v := addwechatfriendlog.UpdateDefaultUpdatedAt()
  215. awflu.mutation.SetUpdatedAt(v)
  216. }
  217. }
  218. // check runs all checks and user-defined validators on the builder.
  219. func (awflu *AddWechatFriendLogUpdate) check() error {
  220. if v, ok := awflu.mutation.OwnerWxID(); ok {
  221. if err := addwechatfriendlog.OwnerWxIDValidator(v); err != nil {
  222. return &ValidationError{Name: "owner_wx_id", err: fmt.Errorf(`ent: validator failed for field "AddWechatFriendLog.owner_wx_id": %w`, err)}
  223. }
  224. }
  225. if v, ok := awflu.mutation.FindContent(); ok {
  226. if err := addwechatfriendlog.FindContentValidator(v); err != nil {
  227. return &ValidationError{Name: "find_content", err: fmt.Errorf(`ent: validator failed for field "AddWechatFriendLog.find_content": %w`, err)}
  228. }
  229. }
  230. if v, ok := awflu.mutation.Message(); ok {
  231. if err := addwechatfriendlog.MessageValidator(v); err != nil {
  232. return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "AddWechatFriendLog.message": %w`, err)}
  233. }
  234. }
  235. return nil
  236. }
  237. func (awflu *AddWechatFriendLogUpdate) sqlSave(ctx context.Context) (n int, err error) {
  238. if err := awflu.check(); err != nil {
  239. return n, err
  240. }
  241. _spec := sqlgraph.NewUpdateSpec(addwechatfriendlog.Table, addwechatfriendlog.Columns, sqlgraph.NewFieldSpec(addwechatfriendlog.FieldID, field.TypeInt64))
  242. if ps := awflu.mutation.predicates; len(ps) > 0 {
  243. _spec.Predicate = func(selector *sql.Selector) {
  244. for i := range ps {
  245. ps[i](selector)
  246. }
  247. }
  248. }
  249. if value, ok := awflu.mutation.OwnerWxID(); ok {
  250. _spec.SetField(addwechatfriendlog.FieldOwnerWxID, field.TypeString, value)
  251. }
  252. if value, ok := awflu.mutation.OwnerWxType(); ok {
  253. _spec.SetField(addwechatfriendlog.FieldOwnerWxType, field.TypeInt, value)
  254. }
  255. if value, ok := awflu.mutation.AddedOwnerWxType(); ok {
  256. _spec.AddField(addwechatfriendlog.FieldOwnerWxType, field.TypeInt, value)
  257. }
  258. if value, ok := awflu.mutation.FindContent(); ok {
  259. _spec.SetField(addwechatfriendlog.FieldFindContent, field.TypeString, value)
  260. }
  261. if value, ok := awflu.mutation.Message(); ok {
  262. _spec.SetField(addwechatfriendlog.FieldMessage, field.TypeString, value)
  263. }
  264. if value, ok := awflu.mutation.FindRequest(); ok {
  265. _spec.SetField(addwechatfriendlog.FieldFindRequest, field.TypeJSON, value)
  266. }
  267. if awflu.mutation.FindRequestCleared() {
  268. _spec.ClearField(addwechatfriendlog.FieldFindRequest, field.TypeJSON)
  269. }
  270. if value, ok := awflu.mutation.FindResult(); ok {
  271. _spec.SetField(addwechatfriendlog.FieldFindResult, field.TypeJSON, value)
  272. }
  273. if awflu.mutation.FindResultCleared() {
  274. _spec.ClearField(addwechatfriendlog.FieldFindResult, field.TypeJSON)
  275. }
  276. if value, ok := awflu.mutation.IsCanAdd(); ok {
  277. _spec.SetField(addwechatfriendlog.FieldIsCanAdd, field.TypeInt, value)
  278. }
  279. if value, ok := awflu.mutation.AddedIsCanAdd(); ok {
  280. _spec.AddField(addwechatfriendlog.FieldIsCanAdd, field.TypeInt, value)
  281. }
  282. if value, ok := awflu.mutation.TaskID(); ok {
  283. _spec.SetField(addwechatfriendlog.FieldTaskID, field.TypeInt64, value)
  284. }
  285. if value, ok := awflu.mutation.AddedTaskID(); ok {
  286. _spec.AddField(addwechatfriendlog.FieldTaskID, field.TypeInt64, value)
  287. }
  288. if value, ok := awflu.mutation.AddRequest(); ok {
  289. _spec.SetField(addwechatfriendlog.FieldAddRequest, field.TypeJSON, value)
  290. }
  291. if awflu.mutation.AddRequestCleared() {
  292. _spec.ClearField(addwechatfriendlog.FieldAddRequest, field.TypeJSON)
  293. }
  294. if value, ok := awflu.mutation.AddResult(); ok {
  295. _spec.SetField(addwechatfriendlog.FieldAddResult, field.TypeJSON, value)
  296. }
  297. if awflu.mutation.AddResultCleared() {
  298. _spec.ClearField(addwechatfriendlog.FieldAddResult, field.TypeJSON)
  299. }
  300. if value, ok := awflu.mutation.CreatedAt(); ok {
  301. _spec.SetField(addwechatfriendlog.FieldCreatedAt, field.TypeInt64, value)
  302. }
  303. if value, ok := awflu.mutation.AddedCreatedAt(); ok {
  304. _spec.AddField(addwechatfriendlog.FieldCreatedAt, field.TypeInt64, value)
  305. }
  306. if value, ok := awflu.mutation.UpdatedAt(); ok {
  307. _spec.SetField(addwechatfriendlog.FieldUpdatedAt, field.TypeInt64, value)
  308. }
  309. if value, ok := awflu.mutation.AddedUpdatedAt(); ok {
  310. _spec.AddField(addwechatfriendlog.FieldUpdatedAt, field.TypeInt64, value)
  311. }
  312. if n, err = sqlgraph.UpdateNodes(ctx, awflu.driver, _spec); err != nil {
  313. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  314. err = &NotFoundError{addwechatfriendlog.Label}
  315. } else if sqlgraph.IsConstraintError(err) {
  316. err = &ConstraintError{msg: err.Error(), wrap: err}
  317. }
  318. return 0, err
  319. }
  320. awflu.mutation.done = true
  321. return n, nil
  322. }
  323. // AddWechatFriendLogUpdateOne is the builder for updating a single AddWechatFriendLog entity.
  324. type AddWechatFriendLogUpdateOne struct {
  325. config
  326. fields []string
  327. hooks []Hook
  328. mutation *AddWechatFriendLogMutation
  329. }
  330. // SetOwnerWxID sets the "owner_wx_id" field.
  331. func (awfluo *AddWechatFriendLogUpdateOne) SetOwnerWxID(s string) *AddWechatFriendLogUpdateOne {
  332. awfluo.mutation.SetOwnerWxID(s)
  333. return awfluo
  334. }
  335. // SetNillableOwnerWxID sets the "owner_wx_id" field if the given value is not nil.
  336. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableOwnerWxID(s *string) *AddWechatFriendLogUpdateOne {
  337. if s != nil {
  338. awfluo.SetOwnerWxID(*s)
  339. }
  340. return awfluo
  341. }
  342. // SetOwnerWxType sets the "owner_wx_type" field.
  343. func (awfluo *AddWechatFriendLogUpdateOne) SetOwnerWxType(i int) *AddWechatFriendLogUpdateOne {
  344. awfluo.mutation.ResetOwnerWxType()
  345. awfluo.mutation.SetOwnerWxType(i)
  346. return awfluo
  347. }
  348. // SetNillableOwnerWxType sets the "owner_wx_type" field if the given value is not nil.
  349. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableOwnerWxType(i *int) *AddWechatFriendLogUpdateOne {
  350. if i != nil {
  351. awfluo.SetOwnerWxType(*i)
  352. }
  353. return awfluo
  354. }
  355. // AddOwnerWxType adds i to the "owner_wx_type" field.
  356. func (awfluo *AddWechatFriendLogUpdateOne) AddOwnerWxType(i int) *AddWechatFriendLogUpdateOne {
  357. awfluo.mutation.AddOwnerWxType(i)
  358. return awfluo
  359. }
  360. // SetFindContent sets the "find_content" field.
  361. func (awfluo *AddWechatFriendLogUpdateOne) SetFindContent(s string) *AddWechatFriendLogUpdateOne {
  362. awfluo.mutation.SetFindContent(s)
  363. return awfluo
  364. }
  365. // SetNillableFindContent sets the "find_content" field if the given value is not nil.
  366. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableFindContent(s *string) *AddWechatFriendLogUpdateOne {
  367. if s != nil {
  368. awfluo.SetFindContent(*s)
  369. }
  370. return awfluo
  371. }
  372. // SetMessage sets the "message" field.
  373. func (awfluo *AddWechatFriendLogUpdateOne) SetMessage(s string) *AddWechatFriendLogUpdateOne {
  374. awfluo.mutation.SetMessage(s)
  375. return awfluo
  376. }
  377. // SetNillableMessage sets the "message" field if the given value is not nil.
  378. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableMessage(s *string) *AddWechatFriendLogUpdateOne {
  379. if s != nil {
  380. awfluo.SetMessage(*s)
  381. }
  382. return awfluo
  383. }
  384. // SetFindRequest sets the "find_request" field.
  385. func (awfluo *AddWechatFriendLogUpdateOne) SetFindRequest(m map[string]interface{}) *AddWechatFriendLogUpdateOne {
  386. awfluo.mutation.SetFindRequest(m)
  387. return awfluo
  388. }
  389. // ClearFindRequest clears the value of the "find_request" field.
  390. func (awfluo *AddWechatFriendLogUpdateOne) ClearFindRequest() *AddWechatFriendLogUpdateOne {
  391. awfluo.mutation.ClearFindRequest()
  392. return awfluo
  393. }
  394. // SetFindResult sets the "find_result" field.
  395. func (awfluo *AddWechatFriendLogUpdateOne) SetFindResult(m map[string]interface{}) *AddWechatFriendLogUpdateOne {
  396. awfluo.mutation.SetFindResult(m)
  397. return awfluo
  398. }
  399. // ClearFindResult clears the value of the "find_result" field.
  400. func (awfluo *AddWechatFriendLogUpdateOne) ClearFindResult() *AddWechatFriendLogUpdateOne {
  401. awfluo.mutation.ClearFindResult()
  402. return awfluo
  403. }
  404. // SetIsCanAdd sets the "is_can_add" field.
  405. func (awfluo *AddWechatFriendLogUpdateOne) SetIsCanAdd(i int) *AddWechatFriendLogUpdateOne {
  406. awfluo.mutation.ResetIsCanAdd()
  407. awfluo.mutation.SetIsCanAdd(i)
  408. return awfluo
  409. }
  410. // SetNillableIsCanAdd sets the "is_can_add" field if the given value is not nil.
  411. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableIsCanAdd(i *int) *AddWechatFriendLogUpdateOne {
  412. if i != nil {
  413. awfluo.SetIsCanAdd(*i)
  414. }
  415. return awfluo
  416. }
  417. // AddIsCanAdd adds i to the "is_can_add" field.
  418. func (awfluo *AddWechatFriendLogUpdateOne) AddIsCanAdd(i int) *AddWechatFriendLogUpdateOne {
  419. awfluo.mutation.AddIsCanAdd(i)
  420. return awfluo
  421. }
  422. // SetTaskID sets the "task_id" field.
  423. func (awfluo *AddWechatFriendLogUpdateOne) SetTaskID(i int64) *AddWechatFriendLogUpdateOne {
  424. awfluo.mutation.ResetTaskID()
  425. awfluo.mutation.SetTaskID(i)
  426. return awfluo
  427. }
  428. // SetNillableTaskID sets the "task_id" field if the given value is not nil.
  429. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableTaskID(i *int64) *AddWechatFriendLogUpdateOne {
  430. if i != nil {
  431. awfluo.SetTaskID(*i)
  432. }
  433. return awfluo
  434. }
  435. // AddTaskID adds i to the "task_id" field.
  436. func (awfluo *AddWechatFriendLogUpdateOne) AddTaskID(i int64) *AddWechatFriendLogUpdateOne {
  437. awfluo.mutation.AddTaskID(i)
  438. return awfluo
  439. }
  440. // SetAddRequest sets the "add_request" field.
  441. func (awfluo *AddWechatFriendLogUpdateOne) SetAddRequest(m map[string]interface{}) *AddWechatFriendLogUpdateOne {
  442. awfluo.mutation.SetAddRequest(m)
  443. return awfluo
  444. }
  445. // ClearAddRequest clears the value of the "add_request" field.
  446. func (awfluo *AddWechatFriendLogUpdateOne) ClearAddRequest() *AddWechatFriendLogUpdateOne {
  447. awfluo.mutation.ClearAddRequest()
  448. return awfluo
  449. }
  450. // SetAddResult sets the "add_result" field.
  451. func (awfluo *AddWechatFriendLogUpdateOne) SetAddResult(m map[string]interface{}) *AddWechatFriendLogUpdateOne {
  452. awfluo.mutation.SetAddResult(m)
  453. return awfluo
  454. }
  455. // ClearAddResult clears the value of the "add_result" field.
  456. func (awfluo *AddWechatFriendLogUpdateOne) ClearAddResult() *AddWechatFriendLogUpdateOne {
  457. awfluo.mutation.ClearAddResult()
  458. return awfluo
  459. }
  460. // SetCreatedAt sets the "created_at" field.
  461. func (awfluo *AddWechatFriendLogUpdateOne) SetCreatedAt(i int64) *AddWechatFriendLogUpdateOne {
  462. awfluo.mutation.ResetCreatedAt()
  463. awfluo.mutation.SetCreatedAt(i)
  464. return awfluo
  465. }
  466. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  467. func (awfluo *AddWechatFriendLogUpdateOne) SetNillableCreatedAt(i *int64) *AddWechatFriendLogUpdateOne {
  468. if i != nil {
  469. awfluo.SetCreatedAt(*i)
  470. }
  471. return awfluo
  472. }
  473. // AddCreatedAt adds i to the "created_at" field.
  474. func (awfluo *AddWechatFriendLogUpdateOne) AddCreatedAt(i int64) *AddWechatFriendLogUpdateOne {
  475. awfluo.mutation.AddCreatedAt(i)
  476. return awfluo
  477. }
  478. // SetUpdatedAt sets the "updated_at" field.
  479. func (awfluo *AddWechatFriendLogUpdateOne) SetUpdatedAt(i int64) *AddWechatFriendLogUpdateOne {
  480. awfluo.mutation.ResetUpdatedAt()
  481. awfluo.mutation.SetUpdatedAt(i)
  482. return awfluo
  483. }
  484. // AddUpdatedAt adds i to the "updated_at" field.
  485. func (awfluo *AddWechatFriendLogUpdateOne) AddUpdatedAt(i int64) *AddWechatFriendLogUpdateOne {
  486. awfluo.mutation.AddUpdatedAt(i)
  487. return awfluo
  488. }
  489. // Mutation returns the AddWechatFriendLogMutation object of the builder.
  490. func (awfluo *AddWechatFriendLogUpdateOne) Mutation() *AddWechatFriendLogMutation {
  491. return awfluo.mutation
  492. }
  493. // Where appends a list predicates to the AddWechatFriendLogUpdate builder.
  494. func (awfluo *AddWechatFriendLogUpdateOne) Where(ps ...predicate.AddWechatFriendLog) *AddWechatFriendLogUpdateOne {
  495. awfluo.mutation.Where(ps...)
  496. return awfluo
  497. }
  498. // Select allows selecting one or more fields (columns) of the returned entity.
  499. // The default is selecting all fields defined in the entity schema.
  500. func (awfluo *AddWechatFriendLogUpdateOne) Select(field string, fields ...string) *AddWechatFriendLogUpdateOne {
  501. awfluo.fields = append([]string{field}, fields...)
  502. return awfluo
  503. }
  504. // Save executes the query and returns the updated AddWechatFriendLog entity.
  505. func (awfluo *AddWechatFriendLogUpdateOne) Save(ctx context.Context) (*AddWechatFriendLog, error) {
  506. awfluo.defaults()
  507. return withHooks(ctx, awfluo.sqlSave, awfluo.mutation, awfluo.hooks)
  508. }
  509. // SaveX is like Save, but panics if an error occurs.
  510. func (awfluo *AddWechatFriendLogUpdateOne) SaveX(ctx context.Context) *AddWechatFriendLog {
  511. node, err := awfluo.Save(ctx)
  512. if err != nil {
  513. panic(err)
  514. }
  515. return node
  516. }
  517. // Exec executes the query on the entity.
  518. func (awfluo *AddWechatFriendLogUpdateOne) Exec(ctx context.Context) error {
  519. _, err := awfluo.Save(ctx)
  520. return err
  521. }
  522. // ExecX is like Exec, but panics if an error occurs.
  523. func (awfluo *AddWechatFriendLogUpdateOne) ExecX(ctx context.Context) {
  524. if err := awfluo.Exec(ctx); err != nil {
  525. panic(err)
  526. }
  527. }
  528. // defaults sets the default values of the builder before save.
  529. func (awfluo *AddWechatFriendLogUpdateOne) defaults() {
  530. if _, ok := awfluo.mutation.UpdatedAt(); !ok {
  531. v := addwechatfriendlog.UpdateDefaultUpdatedAt()
  532. awfluo.mutation.SetUpdatedAt(v)
  533. }
  534. }
  535. // check runs all checks and user-defined validators on the builder.
  536. func (awfluo *AddWechatFriendLogUpdateOne) check() error {
  537. if v, ok := awfluo.mutation.OwnerWxID(); ok {
  538. if err := addwechatfriendlog.OwnerWxIDValidator(v); err != nil {
  539. return &ValidationError{Name: "owner_wx_id", err: fmt.Errorf(`ent: validator failed for field "AddWechatFriendLog.owner_wx_id": %w`, err)}
  540. }
  541. }
  542. if v, ok := awfluo.mutation.FindContent(); ok {
  543. if err := addwechatfriendlog.FindContentValidator(v); err != nil {
  544. return &ValidationError{Name: "find_content", err: fmt.Errorf(`ent: validator failed for field "AddWechatFriendLog.find_content": %w`, err)}
  545. }
  546. }
  547. if v, ok := awfluo.mutation.Message(); ok {
  548. if err := addwechatfriendlog.MessageValidator(v); err != nil {
  549. return &ValidationError{Name: "message", err: fmt.Errorf(`ent: validator failed for field "AddWechatFriendLog.message": %w`, err)}
  550. }
  551. }
  552. return nil
  553. }
  554. func (awfluo *AddWechatFriendLogUpdateOne) sqlSave(ctx context.Context) (_node *AddWechatFriendLog, err error) {
  555. if err := awfluo.check(); err != nil {
  556. return _node, err
  557. }
  558. _spec := sqlgraph.NewUpdateSpec(addwechatfriendlog.Table, addwechatfriendlog.Columns, sqlgraph.NewFieldSpec(addwechatfriendlog.FieldID, field.TypeInt64))
  559. id, ok := awfluo.mutation.ID()
  560. if !ok {
  561. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AddWechatFriendLog.id" for update`)}
  562. }
  563. _spec.Node.ID.Value = id
  564. if fields := awfluo.fields; len(fields) > 0 {
  565. _spec.Node.Columns = make([]string, 0, len(fields))
  566. _spec.Node.Columns = append(_spec.Node.Columns, addwechatfriendlog.FieldID)
  567. for _, f := range fields {
  568. if !addwechatfriendlog.ValidColumn(f) {
  569. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  570. }
  571. if f != addwechatfriendlog.FieldID {
  572. _spec.Node.Columns = append(_spec.Node.Columns, f)
  573. }
  574. }
  575. }
  576. if ps := awfluo.mutation.predicates; len(ps) > 0 {
  577. _spec.Predicate = func(selector *sql.Selector) {
  578. for i := range ps {
  579. ps[i](selector)
  580. }
  581. }
  582. }
  583. if value, ok := awfluo.mutation.OwnerWxID(); ok {
  584. _spec.SetField(addwechatfriendlog.FieldOwnerWxID, field.TypeString, value)
  585. }
  586. if value, ok := awfluo.mutation.OwnerWxType(); ok {
  587. _spec.SetField(addwechatfriendlog.FieldOwnerWxType, field.TypeInt, value)
  588. }
  589. if value, ok := awfluo.mutation.AddedOwnerWxType(); ok {
  590. _spec.AddField(addwechatfriendlog.FieldOwnerWxType, field.TypeInt, value)
  591. }
  592. if value, ok := awfluo.mutation.FindContent(); ok {
  593. _spec.SetField(addwechatfriendlog.FieldFindContent, field.TypeString, value)
  594. }
  595. if value, ok := awfluo.mutation.Message(); ok {
  596. _spec.SetField(addwechatfriendlog.FieldMessage, field.TypeString, value)
  597. }
  598. if value, ok := awfluo.mutation.FindRequest(); ok {
  599. _spec.SetField(addwechatfriendlog.FieldFindRequest, field.TypeJSON, value)
  600. }
  601. if awfluo.mutation.FindRequestCleared() {
  602. _spec.ClearField(addwechatfriendlog.FieldFindRequest, field.TypeJSON)
  603. }
  604. if value, ok := awfluo.mutation.FindResult(); ok {
  605. _spec.SetField(addwechatfriendlog.FieldFindResult, field.TypeJSON, value)
  606. }
  607. if awfluo.mutation.FindResultCleared() {
  608. _spec.ClearField(addwechatfriendlog.FieldFindResult, field.TypeJSON)
  609. }
  610. if value, ok := awfluo.mutation.IsCanAdd(); ok {
  611. _spec.SetField(addwechatfriendlog.FieldIsCanAdd, field.TypeInt, value)
  612. }
  613. if value, ok := awfluo.mutation.AddedIsCanAdd(); ok {
  614. _spec.AddField(addwechatfriendlog.FieldIsCanAdd, field.TypeInt, value)
  615. }
  616. if value, ok := awfluo.mutation.TaskID(); ok {
  617. _spec.SetField(addwechatfriendlog.FieldTaskID, field.TypeInt64, value)
  618. }
  619. if value, ok := awfluo.mutation.AddedTaskID(); ok {
  620. _spec.AddField(addwechatfriendlog.FieldTaskID, field.TypeInt64, value)
  621. }
  622. if value, ok := awfluo.mutation.AddRequest(); ok {
  623. _spec.SetField(addwechatfriendlog.FieldAddRequest, field.TypeJSON, value)
  624. }
  625. if awfluo.mutation.AddRequestCleared() {
  626. _spec.ClearField(addwechatfriendlog.FieldAddRequest, field.TypeJSON)
  627. }
  628. if value, ok := awfluo.mutation.AddResult(); ok {
  629. _spec.SetField(addwechatfriendlog.FieldAddResult, field.TypeJSON, value)
  630. }
  631. if awfluo.mutation.AddResultCleared() {
  632. _spec.ClearField(addwechatfriendlog.FieldAddResult, field.TypeJSON)
  633. }
  634. if value, ok := awfluo.mutation.CreatedAt(); ok {
  635. _spec.SetField(addwechatfriendlog.FieldCreatedAt, field.TypeInt64, value)
  636. }
  637. if value, ok := awfluo.mutation.AddedCreatedAt(); ok {
  638. _spec.AddField(addwechatfriendlog.FieldCreatedAt, field.TypeInt64, value)
  639. }
  640. if value, ok := awfluo.mutation.UpdatedAt(); ok {
  641. _spec.SetField(addwechatfriendlog.FieldUpdatedAt, field.TypeInt64, value)
  642. }
  643. if value, ok := awfluo.mutation.AddedUpdatedAt(); ok {
  644. _spec.AddField(addwechatfriendlog.FieldUpdatedAt, field.TypeInt64, value)
  645. }
  646. _node = &AddWechatFriendLog{config: awfluo.config}
  647. _spec.Assign = _node.assignValues
  648. _spec.ScanValues = _node.scanValues
  649. if err = sqlgraph.UpdateNode(ctx, awfluo.driver, _spec); err != nil {
  650. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  651. err = &NotFoundError{addwechatfriendlog.Label}
  652. } else if sqlgraph.IsConstraintError(err) {
  653. err = &ConstraintError{msg: err.Error(), wrap: err}
  654. }
  655. return nil, err
  656. }
  657. awfluo.mutation.done = true
  658. return _node, nil
  659. }