xunji_update.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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/xunji"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // XunjiUpdate is the builder for updating Xunji entities.
  15. type XunjiUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *XunjiMutation
  19. }
  20. // Where appends a list predicates to the XunjiUpdate builder.
  21. func (xu *XunjiUpdate) Where(ps ...predicate.Xunji) *XunjiUpdate {
  22. xu.mutation.Where(ps...)
  23. return xu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (xu *XunjiUpdate) SetUpdatedAt(t time.Time) *XunjiUpdate {
  27. xu.mutation.SetUpdatedAt(t)
  28. return xu
  29. }
  30. // SetStatus sets the "status" field.
  31. func (xu *XunjiUpdate) SetStatus(u uint8) *XunjiUpdate {
  32. xu.mutation.ResetStatus()
  33. xu.mutation.SetStatus(u)
  34. return xu
  35. }
  36. // SetNillableStatus sets the "status" field if the given value is not nil.
  37. func (xu *XunjiUpdate) SetNillableStatus(u *uint8) *XunjiUpdate {
  38. if u != nil {
  39. xu.SetStatus(*u)
  40. }
  41. return xu
  42. }
  43. // AddStatus adds u to the "status" field.
  44. func (xu *XunjiUpdate) AddStatus(u int8) *XunjiUpdate {
  45. xu.mutation.AddStatus(u)
  46. return xu
  47. }
  48. // ClearStatus clears the value of the "status" field.
  49. func (xu *XunjiUpdate) ClearStatus() *XunjiUpdate {
  50. xu.mutation.ClearStatus()
  51. return xu
  52. }
  53. // SetDeletedAt sets the "deleted_at" field.
  54. func (xu *XunjiUpdate) SetDeletedAt(t time.Time) *XunjiUpdate {
  55. xu.mutation.SetDeletedAt(t)
  56. return xu
  57. }
  58. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  59. func (xu *XunjiUpdate) SetNillableDeletedAt(t *time.Time) *XunjiUpdate {
  60. if t != nil {
  61. xu.SetDeletedAt(*t)
  62. }
  63. return xu
  64. }
  65. // ClearDeletedAt clears the value of the "deleted_at" field.
  66. func (xu *XunjiUpdate) ClearDeletedAt() *XunjiUpdate {
  67. xu.mutation.ClearDeletedAt()
  68. return xu
  69. }
  70. // SetAppKey sets the "app_key" field.
  71. func (xu *XunjiUpdate) SetAppKey(s string) *XunjiUpdate {
  72. xu.mutation.SetAppKey(s)
  73. return xu
  74. }
  75. // SetNillableAppKey sets the "app_key" field if the given value is not nil.
  76. func (xu *XunjiUpdate) SetNillableAppKey(s *string) *XunjiUpdate {
  77. if s != nil {
  78. xu.SetAppKey(*s)
  79. }
  80. return xu
  81. }
  82. // SetAppSecret sets the "app_secret" field.
  83. func (xu *XunjiUpdate) SetAppSecret(s string) *XunjiUpdate {
  84. xu.mutation.SetAppSecret(s)
  85. return xu
  86. }
  87. // SetNillableAppSecret sets the "app_secret" field if the given value is not nil.
  88. func (xu *XunjiUpdate) SetNillableAppSecret(s *string) *XunjiUpdate {
  89. if s != nil {
  90. xu.SetAppSecret(*s)
  91. }
  92. return xu
  93. }
  94. // SetToken sets the "token" field.
  95. func (xu *XunjiUpdate) SetToken(s string) *XunjiUpdate {
  96. xu.mutation.SetToken(s)
  97. return xu
  98. }
  99. // SetNillableToken sets the "token" field if the given value is not nil.
  100. func (xu *XunjiUpdate) SetNillableToken(s *string) *XunjiUpdate {
  101. if s != nil {
  102. xu.SetToken(*s)
  103. }
  104. return xu
  105. }
  106. // SetEncodingKey sets the "encoding_key" field.
  107. func (xu *XunjiUpdate) SetEncodingKey(s string) *XunjiUpdate {
  108. xu.mutation.SetEncodingKey(s)
  109. return xu
  110. }
  111. // SetNillableEncodingKey sets the "encoding_key" field if the given value is not nil.
  112. func (xu *XunjiUpdate) SetNillableEncodingKey(s *string) *XunjiUpdate {
  113. if s != nil {
  114. xu.SetEncodingKey(*s)
  115. }
  116. return xu
  117. }
  118. // SetOrganizationID sets the "organization_id" field.
  119. func (xu *XunjiUpdate) SetOrganizationID(u uint64) *XunjiUpdate {
  120. xu.mutation.ResetOrganizationID()
  121. xu.mutation.SetOrganizationID(u)
  122. return xu
  123. }
  124. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  125. func (xu *XunjiUpdate) SetNillableOrganizationID(u *uint64) *XunjiUpdate {
  126. if u != nil {
  127. xu.SetOrganizationID(*u)
  128. }
  129. return xu
  130. }
  131. // AddOrganizationID adds u to the "organization_id" field.
  132. func (xu *XunjiUpdate) AddOrganizationID(u int64) *XunjiUpdate {
  133. xu.mutation.AddOrganizationID(u)
  134. return xu
  135. }
  136. // Mutation returns the XunjiMutation object of the builder.
  137. func (xu *XunjiUpdate) Mutation() *XunjiMutation {
  138. return xu.mutation
  139. }
  140. // Save executes the query and returns the number of nodes affected by the update operation.
  141. func (xu *XunjiUpdate) Save(ctx context.Context) (int, error) {
  142. if err := xu.defaults(); err != nil {
  143. return 0, err
  144. }
  145. return withHooks(ctx, xu.sqlSave, xu.mutation, xu.hooks)
  146. }
  147. // SaveX is like Save, but panics if an error occurs.
  148. func (xu *XunjiUpdate) SaveX(ctx context.Context) int {
  149. affected, err := xu.Save(ctx)
  150. if err != nil {
  151. panic(err)
  152. }
  153. return affected
  154. }
  155. // Exec executes the query.
  156. func (xu *XunjiUpdate) Exec(ctx context.Context) error {
  157. _, err := xu.Save(ctx)
  158. return err
  159. }
  160. // ExecX is like Exec, but panics if an error occurs.
  161. func (xu *XunjiUpdate) ExecX(ctx context.Context) {
  162. if err := xu.Exec(ctx); err != nil {
  163. panic(err)
  164. }
  165. }
  166. // defaults sets the default values of the builder before save.
  167. func (xu *XunjiUpdate) defaults() error {
  168. if _, ok := xu.mutation.UpdatedAt(); !ok {
  169. if xunji.UpdateDefaultUpdatedAt == nil {
  170. return fmt.Errorf("ent: uninitialized xunji.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  171. }
  172. v := xunji.UpdateDefaultUpdatedAt()
  173. xu.mutation.SetUpdatedAt(v)
  174. }
  175. return nil
  176. }
  177. // check runs all checks and user-defined validators on the builder.
  178. func (xu *XunjiUpdate) check() error {
  179. if v, ok := xu.mutation.OrganizationID(); ok {
  180. if err := xunji.OrganizationIDValidator(v); err != nil {
  181. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Xunji.organization_id": %w`, err)}
  182. }
  183. }
  184. return nil
  185. }
  186. func (xu *XunjiUpdate) sqlSave(ctx context.Context) (n int, err error) {
  187. if err := xu.check(); err != nil {
  188. return n, err
  189. }
  190. _spec := sqlgraph.NewUpdateSpec(xunji.Table, xunji.Columns, sqlgraph.NewFieldSpec(xunji.FieldID, field.TypeUint64))
  191. if ps := xu.mutation.predicates; len(ps) > 0 {
  192. _spec.Predicate = func(selector *sql.Selector) {
  193. for i := range ps {
  194. ps[i](selector)
  195. }
  196. }
  197. }
  198. if value, ok := xu.mutation.UpdatedAt(); ok {
  199. _spec.SetField(xunji.FieldUpdatedAt, field.TypeTime, value)
  200. }
  201. if value, ok := xu.mutation.Status(); ok {
  202. _spec.SetField(xunji.FieldStatus, field.TypeUint8, value)
  203. }
  204. if value, ok := xu.mutation.AddedStatus(); ok {
  205. _spec.AddField(xunji.FieldStatus, field.TypeUint8, value)
  206. }
  207. if xu.mutation.StatusCleared() {
  208. _spec.ClearField(xunji.FieldStatus, field.TypeUint8)
  209. }
  210. if value, ok := xu.mutation.DeletedAt(); ok {
  211. _spec.SetField(xunji.FieldDeletedAt, field.TypeTime, value)
  212. }
  213. if xu.mutation.DeletedAtCleared() {
  214. _spec.ClearField(xunji.FieldDeletedAt, field.TypeTime)
  215. }
  216. if value, ok := xu.mutation.AppKey(); ok {
  217. _spec.SetField(xunji.FieldAppKey, field.TypeString, value)
  218. }
  219. if value, ok := xu.mutation.AppSecret(); ok {
  220. _spec.SetField(xunji.FieldAppSecret, field.TypeString, value)
  221. }
  222. if value, ok := xu.mutation.Token(); ok {
  223. _spec.SetField(xunji.FieldToken, field.TypeString, value)
  224. }
  225. if value, ok := xu.mutation.EncodingKey(); ok {
  226. _spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
  227. }
  228. if value, ok := xu.mutation.OrganizationID(); ok {
  229. _spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
  230. }
  231. if value, ok := xu.mutation.AddedOrganizationID(); ok {
  232. _spec.AddField(xunji.FieldOrganizationID, field.TypeUint64, value)
  233. }
  234. if n, err = sqlgraph.UpdateNodes(ctx, xu.driver, _spec); err != nil {
  235. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  236. err = &NotFoundError{xunji.Label}
  237. } else if sqlgraph.IsConstraintError(err) {
  238. err = &ConstraintError{msg: err.Error(), wrap: err}
  239. }
  240. return 0, err
  241. }
  242. xu.mutation.done = true
  243. return n, nil
  244. }
  245. // XunjiUpdateOne is the builder for updating a single Xunji entity.
  246. type XunjiUpdateOne struct {
  247. config
  248. fields []string
  249. hooks []Hook
  250. mutation *XunjiMutation
  251. }
  252. // SetUpdatedAt sets the "updated_at" field.
  253. func (xuo *XunjiUpdateOne) SetUpdatedAt(t time.Time) *XunjiUpdateOne {
  254. xuo.mutation.SetUpdatedAt(t)
  255. return xuo
  256. }
  257. // SetStatus sets the "status" field.
  258. func (xuo *XunjiUpdateOne) SetStatus(u uint8) *XunjiUpdateOne {
  259. xuo.mutation.ResetStatus()
  260. xuo.mutation.SetStatus(u)
  261. return xuo
  262. }
  263. // SetNillableStatus sets the "status" field if the given value is not nil.
  264. func (xuo *XunjiUpdateOne) SetNillableStatus(u *uint8) *XunjiUpdateOne {
  265. if u != nil {
  266. xuo.SetStatus(*u)
  267. }
  268. return xuo
  269. }
  270. // AddStatus adds u to the "status" field.
  271. func (xuo *XunjiUpdateOne) AddStatus(u int8) *XunjiUpdateOne {
  272. xuo.mutation.AddStatus(u)
  273. return xuo
  274. }
  275. // ClearStatus clears the value of the "status" field.
  276. func (xuo *XunjiUpdateOne) ClearStatus() *XunjiUpdateOne {
  277. xuo.mutation.ClearStatus()
  278. return xuo
  279. }
  280. // SetDeletedAt sets the "deleted_at" field.
  281. func (xuo *XunjiUpdateOne) SetDeletedAt(t time.Time) *XunjiUpdateOne {
  282. xuo.mutation.SetDeletedAt(t)
  283. return xuo
  284. }
  285. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  286. func (xuo *XunjiUpdateOne) SetNillableDeletedAt(t *time.Time) *XunjiUpdateOne {
  287. if t != nil {
  288. xuo.SetDeletedAt(*t)
  289. }
  290. return xuo
  291. }
  292. // ClearDeletedAt clears the value of the "deleted_at" field.
  293. func (xuo *XunjiUpdateOne) ClearDeletedAt() *XunjiUpdateOne {
  294. xuo.mutation.ClearDeletedAt()
  295. return xuo
  296. }
  297. // SetAppKey sets the "app_key" field.
  298. func (xuo *XunjiUpdateOne) SetAppKey(s string) *XunjiUpdateOne {
  299. xuo.mutation.SetAppKey(s)
  300. return xuo
  301. }
  302. // SetNillableAppKey sets the "app_key" field if the given value is not nil.
  303. func (xuo *XunjiUpdateOne) SetNillableAppKey(s *string) *XunjiUpdateOne {
  304. if s != nil {
  305. xuo.SetAppKey(*s)
  306. }
  307. return xuo
  308. }
  309. // SetAppSecret sets the "app_secret" field.
  310. func (xuo *XunjiUpdateOne) SetAppSecret(s string) *XunjiUpdateOne {
  311. xuo.mutation.SetAppSecret(s)
  312. return xuo
  313. }
  314. // SetNillableAppSecret sets the "app_secret" field if the given value is not nil.
  315. func (xuo *XunjiUpdateOne) SetNillableAppSecret(s *string) *XunjiUpdateOne {
  316. if s != nil {
  317. xuo.SetAppSecret(*s)
  318. }
  319. return xuo
  320. }
  321. // SetToken sets the "token" field.
  322. func (xuo *XunjiUpdateOne) SetToken(s string) *XunjiUpdateOne {
  323. xuo.mutation.SetToken(s)
  324. return xuo
  325. }
  326. // SetNillableToken sets the "token" field if the given value is not nil.
  327. func (xuo *XunjiUpdateOne) SetNillableToken(s *string) *XunjiUpdateOne {
  328. if s != nil {
  329. xuo.SetToken(*s)
  330. }
  331. return xuo
  332. }
  333. // SetEncodingKey sets the "encoding_key" field.
  334. func (xuo *XunjiUpdateOne) SetEncodingKey(s string) *XunjiUpdateOne {
  335. xuo.mutation.SetEncodingKey(s)
  336. return xuo
  337. }
  338. // SetNillableEncodingKey sets the "encoding_key" field if the given value is not nil.
  339. func (xuo *XunjiUpdateOne) SetNillableEncodingKey(s *string) *XunjiUpdateOne {
  340. if s != nil {
  341. xuo.SetEncodingKey(*s)
  342. }
  343. return xuo
  344. }
  345. // SetOrganizationID sets the "organization_id" field.
  346. func (xuo *XunjiUpdateOne) SetOrganizationID(u uint64) *XunjiUpdateOne {
  347. xuo.mutation.ResetOrganizationID()
  348. xuo.mutation.SetOrganizationID(u)
  349. return xuo
  350. }
  351. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  352. func (xuo *XunjiUpdateOne) SetNillableOrganizationID(u *uint64) *XunjiUpdateOne {
  353. if u != nil {
  354. xuo.SetOrganizationID(*u)
  355. }
  356. return xuo
  357. }
  358. // AddOrganizationID adds u to the "organization_id" field.
  359. func (xuo *XunjiUpdateOne) AddOrganizationID(u int64) *XunjiUpdateOne {
  360. xuo.mutation.AddOrganizationID(u)
  361. return xuo
  362. }
  363. // Mutation returns the XunjiMutation object of the builder.
  364. func (xuo *XunjiUpdateOne) Mutation() *XunjiMutation {
  365. return xuo.mutation
  366. }
  367. // Where appends a list predicates to the XunjiUpdate builder.
  368. func (xuo *XunjiUpdateOne) Where(ps ...predicate.Xunji) *XunjiUpdateOne {
  369. xuo.mutation.Where(ps...)
  370. return xuo
  371. }
  372. // Select allows selecting one or more fields (columns) of the returned entity.
  373. // The default is selecting all fields defined in the entity schema.
  374. func (xuo *XunjiUpdateOne) Select(field string, fields ...string) *XunjiUpdateOne {
  375. xuo.fields = append([]string{field}, fields...)
  376. return xuo
  377. }
  378. // Save executes the query and returns the updated Xunji entity.
  379. func (xuo *XunjiUpdateOne) Save(ctx context.Context) (*Xunji, error) {
  380. if err := xuo.defaults(); err != nil {
  381. return nil, err
  382. }
  383. return withHooks(ctx, xuo.sqlSave, xuo.mutation, xuo.hooks)
  384. }
  385. // SaveX is like Save, but panics if an error occurs.
  386. func (xuo *XunjiUpdateOne) SaveX(ctx context.Context) *Xunji {
  387. node, err := xuo.Save(ctx)
  388. if err != nil {
  389. panic(err)
  390. }
  391. return node
  392. }
  393. // Exec executes the query on the entity.
  394. func (xuo *XunjiUpdateOne) Exec(ctx context.Context) error {
  395. _, err := xuo.Save(ctx)
  396. return err
  397. }
  398. // ExecX is like Exec, but panics if an error occurs.
  399. func (xuo *XunjiUpdateOne) ExecX(ctx context.Context) {
  400. if err := xuo.Exec(ctx); err != nil {
  401. panic(err)
  402. }
  403. }
  404. // defaults sets the default values of the builder before save.
  405. func (xuo *XunjiUpdateOne) defaults() error {
  406. if _, ok := xuo.mutation.UpdatedAt(); !ok {
  407. if xunji.UpdateDefaultUpdatedAt == nil {
  408. return fmt.Errorf("ent: uninitialized xunji.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  409. }
  410. v := xunji.UpdateDefaultUpdatedAt()
  411. xuo.mutation.SetUpdatedAt(v)
  412. }
  413. return nil
  414. }
  415. // check runs all checks and user-defined validators on the builder.
  416. func (xuo *XunjiUpdateOne) check() error {
  417. if v, ok := xuo.mutation.OrganizationID(); ok {
  418. if err := xunji.OrganizationIDValidator(v); err != nil {
  419. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Xunji.organization_id": %w`, err)}
  420. }
  421. }
  422. return nil
  423. }
  424. func (xuo *XunjiUpdateOne) sqlSave(ctx context.Context) (_node *Xunji, err error) {
  425. if err := xuo.check(); err != nil {
  426. return _node, err
  427. }
  428. _spec := sqlgraph.NewUpdateSpec(xunji.Table, xunji.Columns, sqlgraph.NewFieldSpec(xunji.FieldID, field.TypeUint64))
  429. id, ok := xuo.mutation.ID()
  430. if !ok {
  431. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Xunji.id" for update`)}
  432. }
  433. _spec.Node.ID.Value = id
  434. if fields := xuo.fields; len(fields) > 0 {
  435. _spec.Node.Columns = make([]string, 0, len(fields))
  436. _spec.Node.Columns = append(_spec.Node.Columns, xunji.FieldID)
  437. for _, f := range fields {
  438. if !xunji.ValidColumn(f) {
  439. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  440. }
  441. if f != xunji.FieldID {
  442. _spec.Node.Columns = append(_spec.Node.Columns, f)
  443. }
  444. }
  445. }
  446. if ps := xuo.mutation.predicates; len(ps) > 0 {
  447. _spec.Predicate = func(selector *sql.Selector) {
  448. for i := range ps {
  449. ps[i](selector)
  450. }
  451. }
  452. }
  453. if value, ok := xuo.mutation.UpdatedAt(); ok {
  454. _spec.SetField(xunji.FieldUpdatedAt, field.TypeTime, value)
  455. }
  456. if value, ok := xuo.mutation.Status(); ok {
  457. _spec.SetField(xunji.FieldStatus, field.TypeUint8, value)
  458. }
  459. if value, ok := xuo.mutation.AddedStatus(); ok {
  460. _spec.AddField(xunji.FieldStatus, field.TypeUint8, value)
  461. }
  462. if xuo.mutation.StatusCleared() {
  463. _spec.ClearField(xunji.FieldStatus, field.TypeUint8)
  464. }
  465. if value, ok := xuo.mutation.DeletedAt(); ok {
  466. _spec.SetField(xunji.FieldDeletedAt, field.TypeTime, value)
  467. }
  468. if xuo.mutation.DeletedAtCleared() {
  469. _spec.ClearField(xunji.FieldDeletedAt, field.TypeTime)
  470. }
  471. if value, ok := xuo.mutation.AppKey(); ok {
  472. _spec.SetField(xunji.FieldAppKey, field.TypeString, value)
  473. }
  474. if value, ok := xuo.mutation.AppSecret(); ok {
  475. _spec.SetField(xunji.FieldAppSecret, field.TypeString, value)
  476. }
  477. if value, ok := xuo.mutation.Token(); ok {
  478. _spec.SetField(xunji.FieldToken, field.TypeString, value)
  479. }
  480. if value, ok := xuo.mutation.EncodingKey(); ok {
  481. _spec.SetField(xunji.FieldEncodingKey, field.TypeString, value)
  482. }
  483. if value, ok := xuo.mutation.OrganizationID(); ok {
  484. _spec.SetField(xunji.FieldOrganizationID, field.TypeUint64, value)
  485. }
  486. if value, ok := xuo.mutation.AddedOrganizationID(); ok {
  487. _spec.AddField(xunji.FieldOrganizationID, field.TypeUint64, value)
  488. }
  489. _node = &Xunji{config: xuo.config}
  490. _spec.Assign = _node.assignValues
  491. _spec.ScanValues = _node.scanValues
  492. if err = sqlgraph.UpdateNode(ctx, xuo.driver, _spec); err != nil {
  493. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  494. err = &NotFoundError{xunji.Label}
  495. } else if sqlgraph.IsConstraintError(err) {
  496. err = &ConstraintError{msg: err.Error(), wrap: err}
  497. }
  498. return nil, err
  499. }
  500. xuo.mutation.done = true
  501. return _node, nil
  502. }