xunji_update.go 17 KB

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