wpchatroom_update.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/predicate"
  9. "wechat-api/ent/wpchatroom"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/dialect/sql/sqljson"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // WpChatroomUpdate is the builder for updating WpChatroom entities.
  16. type WpChatroomUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *WpChatroomMutation
  20. }
  21. // Where appends a list predicates to the WpChatroomUpdate builder.
  22. func (wcu *WpChatroomUpdate) Where(ps ...predicate.WpChatroom) *WpChatroomUpdate {
  23. wcu.mutation.Where(ps...)
  24. return wcu
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (wcu *WpChatroomUpdate) SetUpdatedAt(t time.Time) *WpChatroomUpdate {
  28. wcu.mutation.SetUpdatedAt(t)
  29. return wcu
  30. }
  31. // SetStatus sets the "status" field.
  32. func (wcu *WpChatroomUpdate) SetStatus(u uint8) *WpChatroomUpdate {
  33. wcu.mutation.ResetStatus()
  34. wcu.mutation.SetStatus(u)
  35. return wcu
  36. }
  37. // SetNillableStatus sets the "status" field if the given value is not nil.
  38. func (wcu *WpChatroomUpdate) SetNillableStatus(u *uint8) *WpChatroomUpdate {
  39. if u != nil {
  40. wcu.SetStatus(*u)
  41. }
  42. return wcu
  43. }
  44. // AddStatus adds u to the "status" field.
  45. func (wcu *WpChatroomUpdate) AddStatus(u int8) *WpChatroomUpdate {
  46. wcu.mutation.AddStatus(u)
  47. return wcu
  48. }
  49. // ClearStatus clears the value of the "status" field.
  50. func (wcu *WpChatroomUpdate) ClearStatus() *WpChatroomUpdate {
  51. wcu.mutation.ClearStatus()
  52. return wcu
  53. }
  54. // SetWxWxid sets the "wx_wxid" field.
  55. func (wcu *WpChatroomUpdate) SetWxWxid(s string) *WpChatroomUpdate {
  56. wcu.mutation.SetWxWxid(s)
  57. return wcu
  58. }
  59. // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
  60. func (wcu *WpChatroomUpdate) SetNillableWxWxid(s *string) *WpChatroomUpdate {
  61. if s != nil {
  62. wcu.SetWxWxid(*s)
  63. }
  64. return wcu
  65. }
  66. // SetChatroomID sets the "chatroom_id" field.
  67. func (wcu *WpChatroomUpdate) SetChatroomID(s string) *WpChatroomUpdate {
  68. wcu.mutation.SetChatroomID(s)
  69. return wcu
  70. }
  71. // SetNillableChatroomID sets the "chatroom_id" field if the given value is not nil.
  72. func (wcu *WpChatroomUpdate) SetNillableChatroomID(s *string) *WpChatroomUpdate {
  73. if s != nil {
  74. wcu.SetChatroomID(*s)
  75. }
  76. return wcu
  77. }
  78. // SetNickname sets the "nickname" field.
  79. func (wcu *WpChatroomUpdate) SetNickname(s string) *WpChatroomUpdate {
  80. wcu.mutation.SetNickname(s)
  81. return wcu
  82. }
  83. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  84. func (wcu *WpChatroomUpdate) SetNillableNickname(s *string) *WpChatroomUpdate {
  85. if s != nil {
  86. wcu.SetNickname(*s)
  87. }
  88. return wcu
  89. }
  90. // SetOwner sets the "owner" field.
  91. func (wcu *WpChatroomUpdate) SetOwner(s string) *WpChatroomUpdate {
  92. wcu.mutation.SetOwner(s)
  93. return wcu
  94. }
  95. // SetNillableOwner sets the "owner" field if the given value is not nil.
  96. func (wcu *WpChatroomUpdate) SetNillableOwner(s *string) *WpChatroomUpdate {
  97. if s != nil {
  98. wcu.SetOwner(*s)
  99. }
  100. return wcu
  101. }
  102. // SetAvatar sets the "avatar" field.
  103. func (wcu *WpChatroomUpdate) SetAvatar(s string) *WpChatroomUpdate {
  104. wcu.mutation.SetAvatar(s)
  105. return wcu
  106. }
  107. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  108. func (wcu *WpChatroomUpdate) SetNillableAvatar(s *string) *WpChatroomUpdate {
  109. if s != nil {
  110. wcu.SetAvatar(*s)
  111. }
  112. return wcu
  113. }
  114. // SetMemberList sets the "member_list" field.
  115. func (wcu *WpChatroomUpdate) SetMemberList(s []string) *WpChatroomUpdate {
  116. wcu.mutation.SetMemberList(s)
  117. return wcu
  118. }
  119. // AppendMemberList appends s to the "member_list" field.
  120. func (wcu *WpChatroomUpdate) AppendMemberList(s []string) *WpChatroomUpdate {
  121. wcu.mutation.AppendMemberList(s)
  122. return wcu
  123. }
  124. // Mutation returns the WpChatroomMutation object of the builder.
  125. func (wcu *WpChatroomUpdate) Mutation() *WpChatroomMutation {
  126. return wcu.mutation
  127. }
  128. // Save executes the query and returns the number of nodes affected by the update operation.
  129. func (wcu *WpChatroomUpdate) Save(ctx context.Context) (int, error) {
  130. wcu.defaults()
  131. return withHooks(ctx, wcu.sqlSave, wcu.mutation, wcu.hooks)
  132. }
  133. // SaveX is like Save, but panics if an error occurs.
  134. func (wcu *WpChatroomUpdate) SaveX(ctx context.Context) int {
  135. affected, err := wcu.Save(ctx)
  136. if err != nil {
  137. panic(err)
  138. }
  139. return affected
  140. }
  141. // Exec executes the query.
  142. func (wcu *WpChatroomUpdate) Exec(ctx context.Context) error {
  143. _, err := wcu.Save(ctx)
  144. return err
  145. }
  146. // ExecX is like Exec, but panics if an error occurs.
  147. func (wcu *WpChatroomUpdate) ExecX(ctx context.Context) {
  148. if err := wcu.Exec(ctx); err != nil {
  149. panic(err)
  150. }
  151. }
  152. // defaults sets the default values of the builder before save.
  153. func (wcu *WpChatroomUpdate) defaults() {
  154. if _, ok := wcu.mutation.UpdatedAt(); !ok {
  155. v := wpchatroom.UpdateDefaultUpdatedAt()
  156. wcu.mutation.SetUpdatedAt(v)
  157. }
  158. }
  159. func (wcu *WpChatroomUpdate) sqlSave(ctx context.Context) (n int, err error) {
  160. _spec := sqlgraph.NewUpdateSpec(wpchatroom.Table, wpchatroom.Columns, sqlgraph.NewFieldSpec(wpchatroom.FieldID, field.TypeUint64))
  161. if ps := wcu.mutation.predicates; len(ps) > 0 {
  162. _spec.Predicate = func(selector *sql.Selector) {
  163. for i := range ps {
  164. ps[i](selector)
  165. }
  166. }
  167. }
  168. if value, ok := wcu.mutation.UpdatedAt(); ok {
  169. _spec.SetField(wpchatroom.FieldUpdatedAt, field.TypeTime, value)
  170. }
  171. if value, ok := wcu.mutation.Status(); ok {
  172. _spec.SetField(wpchatroom.FieldStatus, field.TypeUint8, value)
  173. }
  174. if value, ok := wcu.mutation.AddedStatus(); ok {
  175. _spec.AddField(wpchatroom.FieldStatus, field.TypeUint8, value)
  176. }
  177. if wcu.mutation.StatusCleared() {
  178. _spec.ClearField(wpchatroom.FieldStatus, field.TypeUint8)
  179. }
  180. if value, ok := wcu.mutation.WxWxid(); ok {
  181. _spec.SetField(wpchatroom.FieldWxWxid, field.TypeString, value)
  182. }
  183. if value, ok := wcu.mutation.ChatroomID(); ok {
  184. _spec.SetField(wpchatroom.FieldChatroomID, field.TypeString, value)
  185. }
  186. if value, ok := wcu.mutation.Nickname(); ok {
  187. _spec.SetField(wpchatroom.FieldNickname, field.TypeString, value)
  188. }
  189. if value, ok := wcu.mutation.Owner(); ok {
  190. _spec.SetField(wpchatroom.FieldOwner, field.TypeString, value)
  191. }
  192. if value, ok := wcu.mutation.Avatar(); ok {
  193. _spec.SetField(wpchatroom.FieldAvatar, field.TypeString, value)
  194. }
  195. if value, ok := wcu.mutation.MemberList(); ok {
  196. _spec.SetField(wpchatroom.FieldMemberList, field.TypeJSON, value)
  197. }
  198. if value, ok := wcu.mutation.AppendedMemberList(); ok {
  199. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  200. sqljson.Append(u, wpchatroom.FieldMemberList, value)
  201. })
  202. }
  203. if n, err = sqlgraph.UpdateNodes(ctx, wcu.driver, _spec); err != nil {
  204. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  205. err = &NotFoundError{wpchatroom.Label}
  206. } else if sqlgraph.IsConstraintError(err) {
  207. err = &ConstraintError{msg: err.Error(), wrap: err}
  208. }
  209. return 0, err
  210. }
  211. wcu.mutation.done = true
  212. return n, nil
  213. }
  214. // WpChatroomUpdateOne is the builder for updating a single WpChatroom entity.
  215. type WpChatroomUpdateOne struct {
  216. config
  217. fields []string
  218. hooks []Hook
  219. mutation *WpChatroomMutation
  220. }
  221. // SetUpdatedAt sets the "updated_at" field.
  222. func (wcuo *WpChatroomUpdateOne) SetUpdatedAt(t time.Time) *WpChatroomUpdateOne {
  223. wcuo.mutation.SetUpdatedAt(t)
  224. return wcuo
  225. }
  226. // SetStatus sets the "status" field.
  227. func (wcuo *WpChatroomUpdateOne) SetStatus(u uint8) *WpChatroomUpdateOne {
  228. wcuo.mutation.ResetStatus()
  229. wcuo.mutation.SetStatus(u)
  230. return wcuo
  231. }
  232. // SetNillableStatus sets the "status" field if the given value is not nil.
  233. func (wcuo *WpChatroomUpdateOne) SetNillableStatus(u *uint8) *WpChatroomUpdateOne {
  234. if u != nil {
  235. wcuo.SetStatus(*u)
  236. }
  237. return wcuo
  238. }
  239. // AddStatus adds u to the "status" field.
  240. func (wcuo *WpChatroomUpdateOne) AddStatus(u int8) *WpChatroomUpdateOne {
  241. wcuo.mutation.AddStatus(u)
  242. return wcuo
  243. }
  244. // ClearStatus clears the value of the "status" field.
  245. func (wcuo *WpChatroomUpdateOne) ClearStatus() *WpChatroomUpdateOne {
  246. wcuo.mutation.ClearStatus()
  247. return wcuo
  248. }
  249. // SetWxWxid sets the "wx_wxid" field.
  250. func (wcuo *WpChatroomUpdateOne) SetWxWxid(s string) *WpChatroomUpdateOne {
  251. wcuo.mutation.SetWxWxid(s)
  252. return wcuo
  253. }
  254. // SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
  255. func (wcuo *WpChatroomUpdateOne) SetNillableWxWxid(s *string) *WpChatroomUpdateOne {
  256. if s != nil {
  257. wcuo.SetWxWxid(*s)
  258. }
  259. return wcuo
  260. }
  261. // SetChatroomID sets the "chatroom_id" field.
  262. func (wcuo *WpChatroomUpdateOne) SetChatroomID(s string) *WpChatroomUpdateOne {
  263. wcuo.mutation.SetChatroomID(s)
  264. return wcuo
  265. }
  266. // SetNillableChatroomID sets the "chatroom_id" field if the given value is not nil.
  267. func (wcuo *WpChatroomUpdateOne) SetNillableChatroomID(s *string) *WpChatroomUpdateOne {
  268. if s != nil {
  269. wcuo.SetChatroomID(*s)
  270. }
  271. return wcuo
  272. }
  273. // SetNickname sets the "nickname" field.
  274. func (wcuo *WpChatroomUpdateOne) SetNickname(s string) *WpChatroomUpdateOne {
  275. wcuo.mutation.SetNickname(s)
  276. return wcuo
  277. }
  278. // SetNillableNickname sets the "nickname" field if the given value is not nil.
  279. func (wcuo *WpChatroomUpdateOne) SetNillableNickname(s *string) *WpChatroomUpdateOne {
  280. if s != nil {
  281. wcuo.SetNickname(*s)
  282. }
  283. return wcuo
  284. }
  285. // SetOwner sets the "owner" field.
  286. func (wcuo *WpChatroomUpdateOne) SetOwner(s string) *WpChatroomUpdateOne {
  287. wcuo.mutation.SetOwner(s)
  288. return wcuo
  289. }
  290. // SetNillableOwner sets the "owner" field if the given value is not nil.
  291. func (wcuo *WpChatroomUpdateOne) SetNillableOwner(s *string) *WpChatroomUpdateOne {
  292. if s != nil {
  293. wcuo.SetOwner(*s)
  294. }
  295. return wcuo
  296. }
  297. // SetAvatar sets the "avatar" field.
  298. func (wcuo *WpChatroomUpdateOne) SetAvatar(s string) *WpChatroomUpdateOne {
  299. wcuo.mutation.SetAvatar(s)
  300. return wcuo
  301. }
  302. // SetNillableAvatar sets the "avatar" field if the given value is not nil.
  303. func (wcuo *WpChatroomUpdateOne) SetNillableAvatar(s *string) *WpChatroomUpdateOne {
  304. if s != nil {
  305. wcuo.SetAvatar(*s)
  306. }
  307. return wcuo
  308. }
  309. // SetMemberList sets the "member_list" field.
  310. func (wcuo *WpChatroomUpdateOne) SetMemberList(s []string) *WpChatroomUpdateOne {
  311. wcuo.mutation.SetMemberList(s)
  312. return wcuo
  313. }
  314. // AppendMemberList appends s to the "member_list" field.
  315. func (wcuo *WpChatroomUpdateOne) AppendMemberList(s []string) *WpChatroomUpdateOne {
  316. wcuo.mutation.AppendMemberList(s)
  317. return wcuo
  318. }
  319. // Mutation returns the WpChatroomMutation object of the builder.
  320. func (wcuo *WpChatroomUpdateOne) Mutation() *WpChatroomMutation {
  321. return wcuo.mutation
  322. }
  323. // Where appends a list predicates to the WpChatroomUpdate builder.
  324. func (wcuo *WpChatroomUpdateOne) Where(ps ...predicate.WpChatroom) *WpChatroomUpdateOne {
  325. wcuo.mutation.Where(ps...)
  326. return wcuo
  327. }
  328. // Select allows selecting one or more fields (columns) of the returned entity.
  329. // The default is selecting all fields defined in the entity schema.
  330. func (wcuo *WpChatroomUpdateOne) Select(field string, fields ...string) *WpChatroomUpdateOne {
  331. wcuo.fields = append([]string{field}, fields...)
  332. return wcuo
  333. }
  334. // Save executes the query and returns the updated WpChatroom entity.
  335. func (wcuo *WpChatroomUpdateOne) Save(ctx context.Context) (*WpChatroom, error) {
  336. wcuo.defaults()
  337. return withHooks(ctx, wcuo.sqlSave, wcuo.mutation, wcuo.hooks)
  338. }
  339. // SaveX is like Save, but panics if an error occurs.
  340. func (wcuo *WpChatroomUpdateOne) SaveX(ctx context.Context) *WpChatroom {
  341. node, err := wcuo.Save(ctx)
  342. if err != nil {
  343. panic(err)
  344. }
  345. return node
  346. }
  347. // Exec executes the query on the entity.
  348. func (wcuo *WpChatroomUpdateOne) Exec(ctx context.Context) error {
  349. _, err := wcuo.Save(ctx)
  350. return err
  351. }
  352. // ExecX is like Exec, but panics if an error occurs.
  353. func (wcuo *WpChatroomUpdateOne) ExecX(ctx context.Context) {
  354. if err := wcuo.Exec(ctx); err != nil {
  355. panic(err)
  356. }
  357. }
  358. // defaults sets the default values of the builder before save.
  359. func (wcuo *WpChatroomUpdateOne) defaults() {
  360. if _, ok := wcuo.mutation.UpdatedAt(); !ok {
  361. v := wpchatroom.UpdateDefaultUpdatedAt()
  362. wcuo.mutation.SetUpdatedAt(v)
  363. }
  364. }
  365. func (wcuo *WpChatroomUpdateOne) sqlSave(ctx context.Context) (_node *WpChatroom, err error) {
  366. _spec := sqlgraph.NewUpdateSpec(wpchatroom.Table, wpchatroom.Columns, sqlgraph.NewFieldSpec(wpchatroom.FieldID, field.TypeUint64))
  367. id, ok := wcuo.mutation.ID()
  368. if !ok {
  369. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WpChatroom.id" for update`)}
  370. }
  371. _spec.Node.ID.Value = id
  372. if fields := wcuo.fields; len(fields) > 0 {
  373. _spec.Node.Columns = make([]string, 0, len(fields))
  374. _spec.Node.Columns = append(_spec.Node.Columns, wpchatroom.FieldID)
  375. for _, f := range fields {
  376. if !wpchatroom.ValidColumn(f) {
  377. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  378. }
  379. if f != wpchatroom.FieldID {
  380. _spec.Node.Columns = append(_spec.Node.Columns, f)
  381. }
  382. }
  383. }
  384. if ps := wcuo.mutation.predicates; len(ps) > 0 {
  385. _spec.Predicate = func(selector *sql.Selector) {
  386. for i := range ps {
  387. ps[i](selector)
  388. }
  389. }
  390. }
  391. if value, ok := wcuo.mutation.UpdatedAt(); ok {
  392. _spec.SetField(wpchatroom.FieldUpdatedAt, field.TypeTime, value)
  393. }
  394. if value, ok := wcuo.mutation.Status(); ok {
  395. _spec.SetField(wpchatroom.FieldStatus, field.TypeUint8, value)
  396. }
  397. if value, ok := wcuo.mutation.AddedStatus(); ok {
  398. _spec.AddField(wpchatroom.FieldStatus, field.TypeUint8, value)
  399. }
  400. if wcuo.mutation.StatusCleared() {
  401. _spec.ClearField(wpchatroom.FieldStatus, field.TypeUint8)
  402. }
  403. if value, ok := wcuo.mutation.WxWxid(); ok {
  404. _spec.SetField(wpchatroom.FieldWxWxid, field.TypeString, value)
  405. }
  406. if value, ok := wcuo.mutation.ChatroomID(); ok {
  407. _spec.SetField(wpchatroom.FieldChatroomID, field.TypeString, value)
  408. }
  409. if value, ok := wcuo.mutation.Nickname(); ok {
  410. _spec.SetField(wpchatroom.FieldNickname, field.TypeString, value)
  411. }
  412. if value, ok := wcuo.mutation.Owner(); ok {
  413. _spec.SetField(wpchatroom.FieldOwner, field.TypeString, value)
  414. }
  415. if value, ok := wcuo.mutation.Avatar(); ok {
  416. _spec.SetField(wpchatroom.FieldAvatar, field.TypeString, value)
  417. }
  418. if value, ok := wcuo.mutation.MemberList(); ok {
  419. _spec.SetField(wpchatroom.FieldMemberList, field.TypeJSON, value)
  420. }
  421. if value, ok := wcuo.mutation.AppendedMemberList(); ok {
  422. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  423. sqljson.Append(u, wpchatroom.FieldMemberList, value)
  424. })
  425. }
  426. _node = &WpChatroom{config: wcuo.config}
  427. _spec.Assign = _node.assignValues
  428. _spec.ScanValues = _node.scanValues
  429. if err = sqlgraph.UpdateNode(ctx, wcuo.driver, _spec); err != nil {
  430. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  431. err = &NotFoundError{wpchatroom.Label}
  432. } else if sqlgraph.IsConstraintError(err) {
  433. err = &ConstraintError{msg: err.Error(), wrap: err}
  434. }
  435. return nil, err
  436. }
  437. wcuo.mutation.done = true
  438. return _node, nil
  439. }