wpchatroommember_update.go 13 KB

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