xunji_update.go 18 KB

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