publishregistration_update.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "w303a/server/app/push/internal/data/ent/predicate"
  9. "w303a/server/app/push/internal/data/ent/publishregistration"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. "github.com/google/uuid"
  14. )
  15. // PublishRegistrationUpdate is the builder for updating PublishRegistration entities.
  16. type PublishRegistrationUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *PublishRegistrationMutation
  20. }
  21. // Where appends a list predicates to the PublishRegistrationUpdate builder.
  22. func (pru *PublishRegistrationUpdate) Where(ps ...predicate.PublishRegistration) *PublishRegistrationUpdate {
  23. pru.mutation.Where(ps...)
  24. return pru
  25. }
  26. // SetCreatedAt sets the "created_at" field.
  27. func (pru *PublishRegistrationUpdate) SetCreatedAt(t time.Time) *PublishRegistrationUpdate {
  28. pru.mutation.SetCreatedAt(t)
  29. return pru
  30. }
  31. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  32. func (pru *PublishRegistrationUpdate) SetNillableCreatedAt(t *time.Time) *PublishRegistrationUpdate {
  33. if t != nil {
  34. pru.SetCreatedAt(*t)
  35. }
  36. return pru
  37. }
  38. // SetUpdatedAt sets the "updated_at" field.
  39. func (pru *PublishRegistrationUpdate) SetUpdatedAt(t time.Time) *PublishRegistrationUpdate {
  40. pru.mutation.SetUpdatedAt(t)
  41. return pru
  42. }
  43. // SetDeletedAt sets the "deleted_at" field.
  44. func (pru *PublishRegistrationUpdate) SetDeletedAt(t time.Time) *PublishRegistrationUpdate {
  45. pru.mutation.SetDeletedAt(t)
  46. return pru
  47. }
  48. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  49. func (pru *PublishRegistrationUpdate) SetNillableDeletedAt(t *time.Time) *PublishRegistrationUpdate {
  50. if t != nil {
  51. pru.SetDeletedAt(*t)
  52. }
  53. return pru
  54. }
  55. // ClearDeletedAt clears the value of the "deleted_at" field.
  56. func (pru *PublishRegistrationUpdate) ClearDeletedAt() *PublishRegistrationUpdate {
  57. pru.mutation.ClearDeletedAt()
  58. return pru
  59. }
  60. // SetUserID sets the "user_id" field.
  61. func (pru *PublishRegistrationUpdate) SetUserID(u uuid.UUID) *PublishRegistrationUpdate {
  62. pru.mutation.SetUserID(u)
  63. return pru
  64. }
  65. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  66. func (pru *PublishRegistrationUpdate) SetNillableUserID(u *uuid.UUID) *PublishRegistrationUpdate {
  67. if u != nil {
  68. pru.SetUserID(*u)
  69. }
  70. return pru
  71. }
  72. // SetRegID sets the "reg_id" field.
  73. func (pru *PublishRegistrationUpdate) SetRegID(s string) *PublishRegistrationUpdate {
  74. pru.mutation.SetRegID(s)
  75. return pru
  76. }
  77. // SetNillableRegID sets the "reg_id" field if the given value is not nil.
  78. func (pru *PublishRegistrationUpdate) SetNillableRegID(s *string) *PublishRegistrationUpdate {
  79. if s != nil {
  80. pru.SetRegID(*s)
  81. }
  82. return pru
  83. }
  84. // SetRegistrantPlatformType sets the "registrant_platform_type" field.
  85. func (pru *PublishRegistrationUpdate) SetRegistrantPlatformType(i int8) *PublishRegistrationUpdate {
  86. pru.mutation.ResetRegistrantPlatformType()
  87. pru.mutation.SetRegistrantPlatformType(i)
  88. return pru
  89. }
  90. // SetNillableRegistrantPlatformType sets the "registrant_platform_type" field if the given value is not nil.
  91. func (pru *PublishRegistrationUpdate) SetNillableRegistrantPlatformType(i *int8) *PublishRegistrationUpdate {
  92. if i != nil {
  93. pru.SetRegistrantPlatformType(*i)
  94. }
  95. return pru
  96. }
  97. // AddRegistrantPlatformType adds i to the "registrant_platform_type" field.
  98. func (pru *PublishRegistrationUpdate) AddRegistrantPlatformType(i int8) *PublishRegistrationUpdate {
  99. pru.mutation.AddRegistrantPlatformType(i)
  100. return pru
  101. }
  102. // SetLanguage sets the "language" field.
  103. func (pru *PublishRegistrationUpdate) SetLanguage(s string) *PublishRegistrationUpdate {
  104. pru.mutation.SetLanguage(s)
  105. return pru
  106. }
  107. // SetNillableLanguage sets the "language" field if the given value is not nil.
  108. func (pru *PublishRegistrationUpdate) SetNillableLanguage(s *string) *PublishRegistrationUpdate {
  109. if s != nil {
  110. pru.SetLanguage(*s)
  111. }
  112. return pru
  113. }
  114. // SetDeviceModel sets the "device_model" field.
  115. func (pru *PublishRegistrationUpdate) SetDeviceModel(s string) *PublishRegistrationUpdate {
  116. pru.mutation.SetDeviceModel(s)
  117. return pru
  118. }
  119. // SetNillableDeviceModel sets the "device_model" field if the given value is not nil.
  120. func (pru *PublishRegistrationUpdate) SetNillableDeviceModel(s *string) *PublishRegistrationUpdate {
  121. if s != nil {
  122. pru.SetDeviceModel(*s)
  123. }
  124. return pru
  125. }
  126. // SetDeviceManufacturer sets the "device_manufacturer" field.
  127. func (pru *PublishRegistrationUpdate) SetDeviceManufacturer(s string) *PublishRegistrationUpdate {
  128. pru.mutation.SetDeviceManufacturer(s)
  129. return pru
  130. }
  131. // SetNillableDeviceManufacturer sets the "device_manufacturer" field if the given value is not nil.
  132. func (pru *PublishRegistrationUpdate) SetNillableDeviceManufacturer(s *string) *PublishRegistrationUpdate {
  133. if s != nil {
  134. pru.SetDeviceManufacturer(*s)
  135. }
  136. return pru
  137. }
  138. // SetDeviceSystemVersion sets the "device_system_version" field.
  139. func (pru *PublishRegistrationUpdate) SetDeviceSystemVersion(s string) *PublishRegistrationUpdate {
  140. pru.mutation.SetDeviceSystemVersion(s)
  141. return pru
  142. }
  143. // SetNillableDeviceSystemVersion sets the "device_system_version" field if the given value is not nil.
  144. func (pru *PublishRegistrationUpdate) SetNillableDeviceSystemVersion(s *string) *PublishRegistrationUpdate {
  145. if s != nil {
  146. pru.SetDeviceSystemVersion(*s)
  147. }
  148. return pru
  149. }
  150. // SetDeviceSystem sets the "device_system" field.
  151. func (pru *PublishRegistrationUpdate) SetDeviceSystem(s string) *PublishRegistrationUpdate {
  152. pru.mutation.SetDeviceSystem(s)
  153. return pru
  154. }
  155. // SetNillableDeviceSystem sets the "device_system" field if the given value is not nil.
  156. func (pru *PublishRegistrationUpdate) SetNillableDeviceSystem(s *string) *PublishRegistrationUpdate {
  157. if s != nil {
  158. pru.SetDeviceSystem(*s)
  159. }
  160. return pru
  161. }
  162. // Mutation returns the PublishRegistrationMutation object of the builder.
  163. func (pru *PublishRegistrationUpdate) Mutation() *PublishRegistrationMutation {
  164. return pru.mutation
  165. }
  166. // Save executes the query and returns the number of nodes affected by the update operation.
  167. func (pru *PublishRegistrationUpdate) Save(ctx context.Context) (int, error) {
  168. pru.defaults()
  169. return withHooks(ctx, pru.sqlSave, pru.mutation, pru.hooks)
  170. }
  171. // SaveX is like Save, but panics if an error occurs.
  172. func (pru *PublishRegistrationUpdate) SaveX(ctx context.Context) int {
  173. affected, err := pru.Save(ctx)
  174. if err != nil {
  175. panic(err)
  176. }
  177. return affected
  178. }
  179. // Exec executes the query.
  180. func (pru *PublishRegistrationUpdate) Exec(ctx context.Context) error {
  181. _, err := pru.Save(ctx)
  182. return err
  183. }
  184. // ExecX is like Exec, but panics if an error occurs.
  185. func (pru *PublishRegistrationUpdate) ExecX(ctx context.Context) {
  186. if err := pru.Exec(ctx); err != nil {
  187. panic(err)
  188. }
  189. }
  190. // defaults sets the default values of the builder before save.
  191. func (pru *PublishRegistrationUpdate) defaults() {
  192. if _, ok := pru.mutation.UpdatedAt(); !ok {
  193. v := publishregistration.UpdateDefaultUpdatedAt()
  194. pru.mutation.SetUpdatedAt(v)
  195. }
  196. }
  197. // check runs all checks and user-defined validators on the builder.
  198. func (pru *PublishRegistrationUpdate) check() error {
  199. if v, ok := pru.mutation.Language(); ok {
  200. if err := publishregistration.LanguageValidator(v); err != nil {
  201. return &ValidationError{Name: "language", err: fmt.Errorf(`ent: validator failed for field "PublishRegistration.language": %w`, err)}
  202. }
  203. }
  204. return nil
  205. }
  206. func (pru *PublishRegistrationUpdate) sqlSave(ctx context.Context) (n int, err error) {
  207. if err := pru.check(); err != nil {
  208. return n, err
  209. }
  210. _spec := sqlgraph.NewUpdateSpec(publishregistration.Table, publishregistration.Columns, sqlgraph.NewFieldSpec(publishregistration.FieldID, field.TypeInt))
  211. if ps := pru.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 := pru.mutation.CreatedAt(); ok {
  219. _spec.SetField(publishregistration.FieldCreatedAt, field.TypeTime, value)
  220. }
  221. if value, ok := pru.mutation.UpdatedAt(); ok {
  222. _spec.SetField(publishregistration.FieldUpdatedAt, field.TypeTime, value)
  223. }
  224. if value, ok := pru.mutation.DeletedAt(); ok {
  225. _spec.SetField(publishregistration.FieldDeletedAt, field.TypeTime, value)
  226. }
  227. if pru.mutation.DeletedAtCleared() {
  228. _spec.ClearField(publishregistration.FieldDeletedAt, field.TypeTime)
  229. }
  230. if value, ok := pru.mutation.UserID(); ok {
  231. _spec.SetField(publishregistration.FieldUserID, field.TypeUUID, value)
  232. }
  233. if value, ok := pru.mutation.RegID(); ok {
  234. _spec.SetField(publishregistration.FieldRegID, field.TypeString, value)
  235. }
  236. if value, ok := pru.mutation.RegistrantPlatformType(); ok {
  237. _spec.SetField(publishregistration.FieldRegistrantPlatformType, field.TypeInt8, value)
  238. }
  239. if value, ok := pru.mutation.AddedRegistrantPlatformType(); ok {
  240. _spec.AddField(publishregistration.FieldRegistrantPlatformType, field.TypeInt8, value)
  241. }
  242. if value, ok := pru.mutation.Language(); ok {
  243. _spec.SetField(publishregistration.FieldLanguage, field.TypeString, value)
  244. }
  245. if value, ok := pru.mutation.DeviceModel(); ok {
  246. _spec.SetField(publishregistration.FieldDeviceModel, field.TypeString, value)
  247. }
  248. if value, ok := pru.mutation.DeviceManufacturer(); ok {
  249. _spec.SetField(publishregistration.FieldDeviceManufacturer, field.TypeString, value)
  250. }
  251. if value, ok := pru.mutation.DeviceSystemVersion(); ok {
  252. _spec.SetField(publishregistration.FieldDeviceSystemVersion, field.TypeString, value)
  253. }
  254. if value, ok := pru.mutation.DeviceSystem(); ok {
  255. _spec.SetField(publishregistration.FieldDeviceSystem, field.TypeString, value)
  256. }
  257. if n, err = sqlgraph.UpdateNodes(ctx, pru.driver, _spec); err != nil {
  258. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  259. err = &NotFoundError{publishregistration.Label}
  260. } else if sqlgraph.IsConstraintError(err) {
  261. err = &ConstraintError{msg: err.Error(), wrap: err}
  262. }
  263. return 0, err
  264. }
  265. pru.mutation.done = true
  266. return n, nil
  267. }
  268. // PublishRegistrationUpdateOne is the builder for updating a single PublishRegistration entity.
  269. type PublishRegistrationUpdateOne struct {
  270. config
  271. fields []string
  272. hooks []Hook
  273. mutation *PublishRegistrationMutation
  274. }
  275. // SetCreatedAt sets the "created_at" field.
  276. func (pruo *PublishRegistrationUpdateOne) SetCreatedAt(t time.Time) *PublishRegistrationUpdateOne {
  277. pruo.mutation.SetCreatedAt(t)
  278. return pruo
  279. }
  280. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  281. func (pruo *PublishRegistrationUpdateOne) SetNillableCreatedAt(t *time.Time) *PublishRegistrationUpdateOne {
  282. if t != nil {
  283. pruo.SetCreatedAt(*t)
  284. }
  285. return pruo
  286. }
  287. // SetUpdatedAt sets the "updated_at" field.
  288. func (pruo *PublishRegistrationUpdateOne) SetUpdatedAt(t time.Time) *PublishRegistrationUpdateOne {
  289. pruo.mutation.SetUpdatedAt(t)
  290. return pruo
  291. }
  292. // SetDeletedAt sets the "deleted_at" field.
  293. func (pruo *PublishRegistrationUpdateOne) SetDeletedAt(t time.Time) *PublishRegistrationUpdateOne {
  294. pruo.mutation.SetDeletedAt(t)
  295. return pruo
  296. }
  297. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  298. func (pruo *PublishRegistrationUpdateOne) SetNillableDeletedAt(t *time.Time) *PublishRegistrationUpdateOne {
  299. if t != nil {
  300. pruo.SetDeletedAt(*t)
  301. }
  302. return pruo
  303. }
  304. // ClearDeletedAt clears the value of the "deleted_at" field.
  305. func (pruo *PublishRegistrationUpdateOne) ClearDeletedAt() *PublishRegistrationUpdateOne {
  306. pruo.mutation.ClearDeletedAt()
  307. return pruo
  308. }
  309. // SetUserID sets the "user_id" field.
  310. func (pruo *PublishRegistrationUpdateOne) SetUserID(u uuid.UUID) *PublishRegistrationUpdateOne {
  311. pruo.mutation.SetUserID(u)
  312. return pruo
  313. }
  314. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  315. func (pruo *PublishRegistrationUpdateOne) SetNillableUserID(u *uuid.UUID) *PublishRegistrationUpdateOne {
  316. if u != nil {
  317. pruo.SetUserID(*u)
  318. }
  319. return pruo
  320. }
  321. // SetRegID sets the "reg_id" field.
  322. func (pruo *PublishRegistrationUpdateOne) SetRegID(s string) *PublishRegistrationUpdateOne {
  323. pruo.mutation.SetRegID(s)
  324. return pruo
  325. }
  326. // SetNillableRegID sets the "reg_id" field if the given value is not nil.
  327. func (pruo *PublishRegistrationUpdateOne) SetNillableRegID(s *string) *PublishRegistrationUpdateOne {
  328. if s != nil {
  329. pruo.SetRegID(*s)
  330. }
  331. return pruo
  332. }
  333. // SetRegistrantPlatformType sets the "registrant_platform_type" field.
  334. func (pruo *PublishRegistrationUpdateOne) SetRegistrantPlatformType(i int8) *PublishRegistrationUpdateOne {
  335. pruo.mutation.ResetRegistrantPlatformType()
  336. pruo.mutation.SetRegistrantPlatformType(i)
  337. return pruo
  338. }
  339. // SetNillableRegistrantPlatformType sets the "registrant_platform_type" field if the given value is not nil.
  340. func (pruo *PublishRegistrationUpdateOne) SetNillableRegistrantPlatformType(i *int8) *PublishRegistrationUpdateOne {
  341. if i != nil {
  342. pruo.SetRegistrantPlatformType(*i)
  343. }
  344. return pruo
  345. }
  346. // AddRegistrantPlatformType adds i to the "registrant_platform_type" field.
  347. func (pruo *PublishRegistrationUpdateOne) AddRegistrantPlatformType(i int8) *PublishRegistrationUpdateOne {
  348. pruo.mutation.AddRegistrantPlatformType(i)
  349. return pruo
  350. }
  351. // SetLanguage sets the "language" field.
  352. func (pruo *PublishRegistrationUpdateOne) SetLanguage(s string) *PublishRegistrationUpdateOne {
  353. pruo.mutation.SetLanguage(s)
  354. return pruo
  355. }
  356. // SetNillableLanguage sets the "language" field if the given value is not nil.
  357. func (pruo *PublishRegistrationUpdateOne) SetNillableLanguage(s *string) *PublishRegistrationUpdateOne {
  358. if s != nil {
  359. pruo.SetLanguage(*s)
  360. }
  361. return pruo
  362. }
  363. // SetDeviceModel sets the "device_model" field.
  364. func (pruo *PublishRegistrationUpdateOne) SetDeviceModel(s string) *PublishRegistrationUpdateOne {
  365. pruo.mutation.SetDeviceModel(s)
  366. return pruo
  367. }
  368. // SetNillableDeviceModel sets the "device_model" field if the given value is not nil.
  369. func (pruo *PublishRegistrationUpdateOne) SetNillableDeviceModel(s *string) *PublishRegistrationUpdateOne {
  370. if s != nil {
  371. pruo.SetDeviceModel(*s)
  372. }
  373. return pruo
  374. }
  375. // SetDeviceManufacturer sets the "device_manufacturer" field.
  376. func (pruo *PublishRegistrationUpdateOne) SetDeviceManufacturer(s string) *PublishRegistrationUpdateOne {
  377. pruo.mutation.SetDeviceManufacturer(s)
  378. return pruo
  379. }
  380. // SetNillableDeviceManufacturer sets the "device_manufacturer" field if the given value is not nil.
  381. func (pruo *PublishRegistrationUpdateOne) SetNillableDeviceManufacturer(s *string) *PublishRegistrationUpdateOne {
  382. if s != nil {
  383. pruo.SetDeviceManufacturer(*s)
  384. }
  385. return pruo
  386. }
  387. // SetDeviceSystemVersion sets the "device_system_version" field.
  388. func (pruo *PublishRegistrationUpdateOne) SetDeviceSystemVersion(s string) *PublishRegistrationUpdateOne {
  389. pruo.mutation.SetDeviceSystemVersion(s)
  390. return pruo
  391. }
  392. // SetNillableDeviceSystemVersion sets the "device_system_version" field if the given value is not nil.
  393. func (pruo *PublishRegistrationUpdateOne) SetNillableDeviceSystemVersion(s *string) *PublishRegistrationUpdateOne {
  394. if s != nil {
  395. pruo.SetDeviceSystemVersion(*s)
  396. }
  397. return pruo
  398. }
  399. // SetDeviceSystem sets the "device_system" field.
  400. func (pruo *PublishRegistrationUpdateOne) SetDeviceSystem(s string) *PublishRegistrationUpdateOne {
  401. pruo.mutation.SetDeviceSystem(s)
  402. return pruo
  403. }
  404. // SetNillableDeviceSystem sets the "device_system" field if the given value is not nil.
  405. func (pruo *PublishRegistrationUpdateOne) SetNillableDeviceSystem(s *string) *PublishRegistrationUpdateOne {
  406. if s != nil {
  407. pruo.SetDeviceSystem(*s)
  408. }
  409. return pruo
  410. }
  411. // Mutation returns the PublishRegistrationMutation object of the builder.
  412. func (pruo *PublishRegistrationUpdateOne) Mutation() *PublishRegistrationMutation {
  413. return pruo.mutation
  414. }
  415. // Where appends a list predicates to the PublishRegistrationUpdate builder.
  416. func (pruo *PublishRegistrationUpdateOne) Where(ps ...predicate.PublishRegistration) *PublishRegistrationUpdateOne {
  417. pruo.mutation.Where(ps...)
  418. return pruo
  419. }
  420. // Select allows selecting one or more fields (columns) of the returned entity.
  421. // The default is selecting all fields defined in the entity schema.
  422. func (pruo *PublishRegistrationUpdateOne) Select(field string, fields ...string) *PublishRegistrationUpdateOne {
  423. pruo.fields = append([]string{field}, fields...)
  424. return pruo
  425. }
  426. // Save executes the query and returns the updated PublishRegistration entity.
  427. func (pruo *PublishRegistrationUpdateOne) Save(ctx context.Context) (*PublishRegistration, error) {
  428. pruo.defaults()
  429. return withHooks(ctx, pruo.sqlSave, pruo.mutation, pruo.hooks)
  430. }
  431. // SaveX is like Save, but panics if an error occurs.
  432. func (pruo *PublishRegistrationUpdateOne) SaveX(ctx context.Context) *PublishRegistration {
  433. node, err := pruo.Save(ctx)
  434. if err != nil {
  435. panic(err)
  436. }
  437. return node
  438. }
  439. // Exec executes the query on the entity.
  440. func (pruo *PublishRegistrationUpdateOne) Exec(ctx context.Context) error {
  441. _, err := pruo.Save(ctx)
  442. return err
  443. }
  444. // ExecX is like Exec, but panics if an error occurs.
  445. func (pruo *PublishRegistrationUpdateOne) ExecX(ctx context.Context) {
  446. if err := pruo.Exec(ctx); err != nil {
  447. panic(err)
  448. }
  449. }
  450. // defaults sets the default values of the builder before save.
  451. func (pruo *PublishRegistrationUpdateOne) defaults() {
  452. if _, ok := pruo.mutation.UpdatedAt(); !ok {
  453. v := publishregistration.UpdateDefaultUpdatedAt()
  454. pruo.mutation.SetUpdatedAt(v)
  455. }
  456. }
  457. // check runs all checks and user-defined validators on the builder.
  458. func (pruo *PublishRegistrationUpdateOne) check() error {
  459. if v, ok := pruo.mutation.Language(); ok {
  460. if err := publishregistration.LanguageValidator(v); err != nil {
  461. return &ValidationError{Name: "language", err: fmt.Errorf(`ent: validator failed for field "PublishRegistration.language": %w`, err)}
  462. }
  463. }
  464. return nil
  465. }
  466. func (pruo *PublishRegistrationUpdateOne) sqlSave(ctx context.Context) (_node *PublishRegistration, err error) {
  467. if err := pruo.check(); err != nil {
  468. return _node, err
  469. }
  470. _spec := sqlgraph.NewUpdateSpec(publishregistration.Table, publishregistration.Columns, sqlgraph.NewFieldSpec(publishregistration.FieldID, field.TypeInt))
  471. id, ok := pruo.mutation.ID()
  472. if !ok {
  473. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PublishRegistration.id" for update`)}
  474. }
  475. _spec.Node.ID.Value = id
  476. if fields := pruo.fields; len(fields) > 0 {
  477. _spec.Node.Columns = make([]string, 0, len(fields))
  478. _spec.Node.Columns = append(_spec.Node.Columns, publishregistration.FieldID)
  479. for _, f := range fields {
  480. if !publishregistration.ValidColumn(f) {
  481. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  482. }
  483. if f != publishregistration.FieldID {
  484. _spec.Node.Columns = append(_spec.Node.Columns, f)
  485. }
  486. }
  487. }
  488. if ps := pruo.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 := pruo.mutation.CreatedAt(); ok {
  496. _spec.SetField(publishregistration.FieldCreatedAt, field.TypeTime, value)
  497. }
  498. if value, ok := pruo.mutation.UpdatedAt(); ok {
  499. _spec.SetField(publishregistration.FieldUpdatedAt, field.TypeTime, value)
  500. }
  501. if value, ok := pruo.mutation.DeletedAt(); ok {
  502. _spec.SetField(publishregistration.FieldDeletedAt, field.TypeTime, value)
  503. }
  504. if pruo.mutation.DeletedAtCleared() {
  505. _spec.ClearField(publishregistration.FieldDeletedAt, field.TypeTime)
  506. }
  507. if value, ok := pruo.mutation.UserID(); ok {
  508. _spec.SetField(publishregistration.FieldUserID, field.TypeUUID, value)
  509. }
  510. if value, ok := pruo.mutation.RegID(); ok {
  511. _spec.SetField(publishregistration.FieldRegID, field.TypeString, value)
  512. }
  513. if value, ok := pruo.mutation.RegistrantPlatformType(); ok {
  514. _spec.SetField(publishregistration.FieldRegistrantPlatformType, field.TypeInt8, value)
  515. }
  516. if value, ok := pruo.mutation.AddedRegistrantPlatformType(); ok {
  517. _spec.AddField(publishregistration.FieldRegistrantPlatformType, field.TypeInt8, value)
  518. }
  519. if value, ok := pruo.mutation.Language(); ok {
  520. _spec.SetField(publishregistration.FieldLanguage, field.TypeString, value)
  521. }
  522. if value, ok := pruo.mutation.DeviceModel(); ok {
  523. _spec.SetField(publishregistration.FieldDeviceModel, field.TypeString, value)
  524. }
  525. if value, ok := pruo.mutation.DeviceManufacturer(); ok {
  526. _spec.SetField(publishregistration.FieldDeviceManufacturer, field.TypeString, value)
  527. }
  528. if value, ok := pruo.mutation.DeviceSystemVersion(); ok {
  529. _spec.SetField(publishregistration.FieldDeviceSystemVersion, field.TypeString, value)
  530. }
  531. if value, ok := pruo.mutation.DeviceSystem(); ok {
  532. _spec.SetField(publishregistration.FieldDeviceSystem, field.TypeString, value)
  533. }
  534. _node = &PublishRegistration{config: pruo.config}
  535. _spec.Assign = _node.assignValues
  536. _spec.ScanValues = _node.scanValues
  537. if err = sqlgraph.UpdateNode(ctx, pruo.driver, _spec); err != nil {
  538. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  539. err = &NotFoundError{publishregistration.Label}
  540. } else if sqlgraph.IsConstraintError(err) {
  541. err = &ConstraintError{msg: err.Error(), wrap: err}
  542. }
  543. return nil, err
  544. }
  545. pruo.mutation.done = true
  546. return _node, nil
  547. }