addwechatfriendlog_update.go 23 KB

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