wxcardvisit_update.go 14 KB

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