authidentity_update.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "entgo.io/ent/dialect/sql"
  9. "entgo.io/ent/dialect/sql/sqlgraph"
  10. "entgo.io/ent/schema/field"
  11. "github.com/Wei-Shaw/sub2api/ent/authidentity"
  12. "github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
  13. "github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
  14. "github.com/Wei-Shaw/sub2api/ent/predicate"
  15. "github.com/Wei-Shaw/sub2api/ent/user"
  16. )
  17. // AuthIdentityUpdate is the builder for updating AuthIdentity entities.
  18. type AuthIdentityUpdate struct {
  19. config
  20. hooks []Hook
  21. mutation *AuthIdentityMutation
  22. }
  23. // Where appends a list predicates to the AuthIdentityUpdate builder.
  24. func (_u *AuthIdentityUpdate) Where(ps ...predicate.AuthIdentity) *AuthIdentityUpdate {
  25. _u.mutation.Where(ps...)
  26. return _u
  27. }
  28. // SetUpdatedAt sets the "updated_at" field.
  29. func (_u *AuthIdentityUpdate) SetUpdatedAt(v time.Time) *AuthIdentityUpdate {
  30. _u.mutation.SetUpdatedAt(v)
  31. return _u
  32. }
  33. // SetUserID sets the "user_id" field.
  34. func (_u *AuthIdentityUpdate) SetUserID(v int64) *AuthIdentityUpdate {
  35. _u.mutation.SetUserID(v)
  36. return _u
  37. }
  38. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  39. func (_u *AuthIdentityUpdate) SetNillableUserID(v *int64) *AuthIdentityUpdate {
  40. if v != nil {
  41. _u.SetUserID(*v)
  42. }
  43. return _u
  44. }
  45. // SetProviderType sets the "provider_type" field.
  46. func (_u *AuthIdentityUpdate) SetProviderType(v string) *AuthIdentityUpdate {
  47. _u.mutation.SetProviderType(v)
  48. return _u
  49. }
  50. // SetNillableProviderType sets the "provider_type" field if the given value is not nil.
  51. func (_u *AuthIdentityUpdate) SetNillableProviderType(v *string) *AuthIdentityUpdate {
  52. if v != nil {
  53. _u.SetProviderType(*v)
  54. }
  55. return _u
  56. }
  57. // SetProviderKey sets the "provider_key" field.
  58. func (_u *AuthIdentityUpdate) SetProviderKey(v string) *AuthIdentityUpdate {
  59. _u.mutation.SetProviderKey(v)
  60. return _u
  61. }
  62. // SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
  63. func (_u *AuthIdentityUpdate) SetNillableProviderKey(v *string) *AuthIdentityUpdate {
  64. if v != nil {
  65. _u.SetProviderKey(*v)
  66. }
  67. return _u
  68. }
  69. // SetProviderSubject sets the "provider_subject" field.
  70. func (_u *AuthIdentityUpdate) SetProviderSubject(v string) *AuthIdentityUpdate {
  71. _u.mutation.SetProviderSubject(v)
  72. return _u
  73. }
  74. // SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
  75. func (_u *AuthIdentityUpdate) SetNillableProviderSubject(v *string) *AuthIdentityUpdate {
  76. if v != nil {
  77. _u.SetProviderSubject(*v)
  78. }
  79. return _u
  80. }
  81. // SetVerifiedAt sets the "verified_at" field.
  82. func (_u *AuthIdentityUpdate) SetVerifiedAt(v time.Time) *AuthIdentityUpdate {
  83. _u.mutation.SetVerifiedAt(v)
  84. return _u
  85. }
  86. // SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
  87. func (_u *AuthIdentityUpdate) SetNillableVerifiedAt(v *time.Time) *AuthIdentityUpdate {
  88. if v != nil {
  89. _u.SetVerifiedAt(*v)
  90. }
  91. return _u
  92. }
  93. // ClearVerifiedAt clears the value of the "verified_at" field.
  94. func (_u *AuthIdentityUpdate) ClearVerifiedAt() *AuthIdentityUpdate {
  95. _u.mutation.ClearVerifiedAt()
  96. return _u
  97. }
  98. // SetIssuer sets the "issuer" field.
  99. func (_u *AuthIdentityUpdate) SetIssuer(v string) *AuthIdentityUpdate {
  100. _u.mutation.SetIssuer(v)
  101. return _u
  102. }
  103. // SetNillableIssuer sets the "issuer" field if the given value is not nil.
  104. func (_u *AuthIdentityUpdate) SetNillableIssuer(v *string) *AuthIdentityUpdate {
  105. if v != nil {
  106. _u.SetIssuer(*v)
  107. }
  108. return _u
  109. }
  110. // ClearIssuer clears the value of the "issuer" field.
  111. func (_u *AuthIdentityUpdate) ClearIssuer() *AuthIdentityUpdate {
  112. _u.mutation.ClearIssuer()
  113. return _u
  114. }
  115. // SetMetadata sets the "metadata" field.
  116. func (_u *AuthIdentityUpdate) SetMetadata(v map[string]interface{}) *AuthIdentityUpdate {
  117. _u.mutation.SetMetadata(v)
  118. return _u
  119. }
  120. // SetUser sets the "user" edge to the User entity.
  121. func (_u *AuthIdentityUpdate) SetUser(v *User) *AuthIdentityUpdate {
  122. return _u.SetUserID(v.ID)
  123. }
  124. // AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
  125. func (_u *AuthIdentityUpdate) AddChannelIDs(ids ...int64) *AuthIdentityUpdate {
  126. _u.mutation.AddChannelIDs(ids...)
  127. return _u
  128. }
  129. // AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
  130. func (_u *AuthIdentityUpdate) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdate {
  131. ids := make([]int64, len(v))
  132. for i := range v {
  133. ids[i] = v[i].ID
  134. }
  135. return _u.AddChannelIDs(ids...)
  136. }
  137. // AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
  138. func (_u *AuthIdentityUpdate) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdate {
  139. _u.mutation.AddAdoptionDecisionIDs(ids...)
  140. return _u
  141. }
  142. // AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
  143. func (_u *AuthIdentityUpdate) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdate {
  144. ids := make([]int64, len(v))
  145. for i := range v {
  146. ids[i] = v[i].ID
  147. }
  148. return _u.AddAdoptionDecisionIDs(ids...)
  149. }
  150. // Mutation returns the AuthIdentityMutation object of the builder.
  151. func (_u *AuthIdentityUpdate) Mutation() *AuthIdentityMutation {
  152. return _u.mutation
  153. }
  154. // ClearUser clears the "user" edge to the User entity.
  155. func (_u *AuthIdentityUpdate) ClearUser() *AuthIdentityUpdate {
  156. _u.mutation.ClearUser()
  157. return _u
  158. }
  159. // ClearChannels clears all "channels" edges to the AuthIdentityChannel entity.
  160. func (_u *AuthIdentityUpdate) ClearChannels() *AuthIdentityUpdate {
  161. _u.mutation.ClearChannels()
  162. return _u
  163. }
  164. // RemoveChannelIDs removes the "channels" edge to AuthIdentityChannel entities by IDs.
  165. func (_u *AuthIdentityUpdate) RemoveChannelIDs(ids ...int64) *AuthIdentityUpdate {
  166. _u.mutation.RemoveChannelIDs(ids...)
  167. return _u
  168. }
  169. // RemoveChannels removes "channels" edges to AuthIdentityChannel entities.
  170. func (_u *AuthIdentityUpdate) RemoveChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdate {
  171. ids := make([]int64, len(v))
  172. for i := range v {
  173. ids[i] = v[i].ID
  174. }
  175. return _u.RemoveChannelIDs(ids...)
  176. }
  177. // ClearAdoptionDecisions clears all "adoption_decisions" edges to the IdentityAdoptionDecision entity.
  178. func (_u *AuthIdentityUpdate) ClearAdoptionDecisions() *AuthIdentityUpdate {
  179. _u.mutation.ClearAdoptionDecisions()
  180. return _u
  181. }
  182. // RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to IdentityAdoptionDecision entities by IDs.
  183. func (_u *AuthIdentityUpdate) RemoveAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdate {
  184. _u.mutation.RemoveAdoptionDecisionIDs(ids...)
  185. return _u
  186. }
  187. // RemoveAdoptionDecisions removes "adoption_decisions" edges to IdentityAdoptionDecision entities.
  188. func (_u *AuthIdentityUpdate) RemoveAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdate {
  189. ids := make([]int64, len(v))
  190. for i := range v {
  191. ids[i] = v[i].ID
  192. }
  193. return _u.RemoveAdoptionDecisionIDs(ids...)
  194. }
  195. // Save executes the query and returns the number of nodes affected by the update operation.
  196. func (_u *AuthIdentityUpdate) Save(ctx context.Context) (int, error) {
  197. _u.defaults()
  198. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  199. }
  200. // SaveX is like Save, but panics if an error occurs.
  201. func (_u *AuthIdentityUpdate) SaveX(ctx context.Context) int {
  202. affected, err := _u.Save(ctx)
  203. if err != nil {
  204. panic(err)
  205. }
  206. return affected
  207. }
  208. // Exec executes the query.
  209. func (_u *AuthIdentityUpdate) Exec(ctx context.Context) error {
  210. _, err := _u.Save(ctx)
  211. return err
  212. }
  213. // ExecX is like Exec, but panics if an error occurs.
  214. func (_u *AuthIdentityUpdate) ExecX(ctx context.Context) {
  215. if err := _u.Exec(ctx); err != nil {
  216. panic(err)
  217. }
  218. }
  219. // defaults sets the default values of the builder before save.
  220. func (_u *AuthIdentityUpdate) defaults() {
  221. if _, ok := _u.mutation.UpdatedAt(); !ok {
  222. v := authidentity.UpdateDefaultUpdatedAt()
  223. _u.mutation.SetUpdatedAt(v)
  224. }
  225. }
  226. // check runs all checks and user-defined validators on the builder.
  227. func (_u *AuthIdentityUpdate) check() error {
  228. if v, ok := _u.mutation.ProviderType(); ok {
  229. if err := authidentity.ProviderTypeValidator(v); err != nil {
  230. return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
  231. }
  232. }
  233. if v, ok := _u.mutation.ProviderKey(); ok {
  234. if err := authidentity.ProviderKeyValidator(v); err != nil {
  235. return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
  236. }
  237. }
  238. if v, ok := _u.mutation.ProviderSubject(); ok {
  239. if err := authidentity.ProviderSubjectValidator(v); err != nil {
  240. return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
  241. }
  242. }
  243. if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
  244. return errors.New(`ent: clearing a required unique edge "AuthIdentity.user"`)
  245. }
  246. return nil
  247. }
  248. func (_u *AuthIdentityUpdate) sqlSave(ctx context.Context) (_node int, err error) {
  249. if err := _u.check(); err != nil {
  250. return _node, err
  251. }
  252. _spec := sqlgraph.NewUpdateSpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64))
  253. if ps := _u.mutation.predicates; len(ps) > 0 {
  254. _spec.Predicate = func(selector *sql.Selector) {
  255. for i := range ps {
  256. ps[i](selector)
  257. }
  258. }
  259. }
  260. if value, ok := _u.mutation.UpdatedAt(); ok {
  261. _spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
  262. }
  263. if value, ok := _u.mutation.ProviderType(); ok {
  264. _spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
  265. }
  266. if value, ok := _u.mutation.ProviderKey(); ok {
  267. _spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
  268. }
  269. if value, ok := _u.mutation.ProviderSubject(); ok {
  270. _spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
  271. }
  272. if value, ok := _u.mutation.VerifiedAt(); ok {
  273. _spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
  274. }
  275. if _u.mutation.VerifiedAtCleared() {
  276. _spec.ClearField(authidentity.FieldVerifiedAt, field.TypeTime)
  277. }
  278. if value, ok := _u.mutation.Issuer(); ok {
  279. _spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
  280. }
  281. if _u.mutation.IssuerCleared() {
  282. _spec.ClearField(authidentity.FieldIssuer, field.TypeString)
  283. }
  284. if value, ok := _u.mutation.Metadata(); ok {
  285. _spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
  286. }
  287. if _u.mutation.UserCleared() {
  288. edge := &sqlgraph.EdgeSpec{
  289. Rel: sqlgraph.M2O,
  290. Inverse: true,
  291. Table: authidentity.UserTable,
  292. Columns: []string{authidentity.UserColumn},
  293. Bidi: false,
  294. Target: &sqlgraph.EdgeTarget{
  295. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  296. },
  297. }
  298. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  299. }
  300. if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
  301. edge := &sqlgraph.EdgeSpec{
  302. Rel: sqlgraph.M2O,
  303. Inverse: true,
  304. Table: authidentity.UserTable,
  305. Columns: []string{authidentity.UserColumn},
  306. Bidi: false,
  307. Target: &sqlgraph.EdgeTarget{
  308. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  309. },
  310. }
  311. for _, k := range nodes {
  312. edge.Target.Nodes = append(edge.Target.Nodes, k)
  313. }
  314. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  315. }
  316. if _u.mutation.ChannelsCleared() {
  317. edge := &sqlgraph.EdgeSpec{
  318. Rel: sqlgraph.O2M,
  319. Inverse: false,
  320. Table: authidentity.ChannelsTable,
  321. Columns: []string{authidentity.ChannelsColumn},
  322. Bidi: false,
  323. Target: &sqlgraph.EdgeTarget{
  324. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  325. },
  326. }
  327. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  328. }
  329. if nodes := _u.mutation.RemovedChannelsIDs(); len(nodes) > 0 && !_u.mutation.ChannelsCleared() {
  330. edge := &sqlgraph.EdgeSpec{
  331. Rel: sqlgraph.O2M,
  332. Inverse: false,
  333. Table: authidentity.ChannelsTable,
  334. Columns: []string{authidentity.ChannelsColumn},
  335. Bidi: false,
  336. Target: &sqlgraph.EdgeTarget{
  337. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  338. },
  339. }
  340. for _, k := range nodes {
  341. edge.Target.Nodes = append(edge.Target.Nodes, k)
  342. }
  343. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  344. }
  345. if nodes := _u.mutation.ChannelsIDs(); len(nodes) > 0 {
  346. edge := &sqlgraph.EdgeSpec{
  347. Rel: sqlgraph.O2M,
  348. Inverse: false,
  349. Table: authidentity.ChannelsTable,
  350. Columns: []string{authidentity.ChannelsColumn},
  351. Bidi: false,
  352. Target: &sqlgraph.EdgeTarget{
  353. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  354. },
  355. }
  356. for _, k := range nodes {
  357. edge.Target.Nodes = append(edge.Target.Nodes, k)
  358. }
  359. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  360. }
  361. if _u.mutation.AdoptionDecisionsCleared() {
  362. edge := &sqlgraph.EdgeSpec{
  363. Rel: sqlgraph.O2M,
  364. Inverse: false,
  365. Table: authidentity.AdoptionDecisionsTable,
  366. Columns: []string{authidentity.AdoptionDecisionsColumn},
  367. Bidi: false,
  368. Target: &sqlgraph.EdgeTarget{
  369. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  370. },
  371. }
  372. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  373. }
  374. if nodes := _u.mutation.RemovedAdoptionDecisionsIDs(); len(nodes) > 0 && !_u.mutation.AdoptionDecisionsCleared() {
  375. edge := &sqlgraph.EdgeSpec{
  376. Rel: sqlgraph.O2M,
  377. Inverse: false,
  378. Table: authidentity.AdoptionDecisionsTable,
  379. Columns: []string{authidentity.AdoptionDecisionsColumn},
  380. Bidi: false,
  381. Target: &sqlgraph.EdgeTarget{
  382. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  383. },
  384. }
  385. for _, k := range nodes {
  386. edge.Target.Nodes = append(edge.Target.Nodes, k)
  387. }
  388. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  389. }
  390. if nodes := _u.mutation.AdoptionDecisionsIDs(); len(nodes) > 0 {
  391. edge := &sqlgraph.EdgeSpec{
  392. Rel: sqlgraph.O2M,
  393. Inverse: false,
  394. Table: authidentity.AdoptionDecisionsTable,
  395. Columns: []string{authidentity.AdoptionDecisionsColumn},
  396. Bidi: false,
  397. Target: &sqlgraph.EdgeTarget{
  398. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  399. },
  400. }
  401. for _, k := range nodes {
  402. edge.Target.Nodes = append(edge.Target.Nodes, k)
  403. }
  404. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  405. }
  406. if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
  407. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  408. err = &NotFoundError{authidentity.Label}
  409. } else if sqlgraph.IsConstraintError(err) {
  410. err = &ConstraintError{msg: err.Error(), wrap: err}
  411. }
  412. return 0, err
  413. }
  414. _u.mutation.done = true
  415. return _node, nil
  416. }
  417. // AuthIdentityUpdateOne is the builder for updating a single AuthIdentity entity.
  418. type AuthIdentityUpdateOne struct {
  419. config
  420. fields []string
  421. hooks []Hook
  422. mutation *AuthIdentityMutation
  423. }
  424. // SetUpdatedAt sets the "updated_at" field.
  425. func (_u *AuthIdentityUpdateOne) SetUpdatedAt(v time.Time) *AuthIdentityUpdateOne {
  426. _u.mutation.SetUpdatedAt(v)
  427. return _u
  428. }
  429. // SetUserID sets the "user_id" field.
  430. func (_u *AuthIdentityUpdateOne) SetUserID(v int64) *AuthIdentityUpdateOne {
  431. _u.mutation.SetUserID(v)
  432. return _u
  433. }
  434. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  435. func (_u *AuthIdentityUpdateOne) SetNillableUserID(v *int64) *AuthIdentityUpdateOne {
  436. if v != nil {
  437. _u.SetUserID(*v)
  438. }
  439. return _u
  440. }
  441. // SetProviderType sets the "provider_type" field.
  442. func (_u *AuthIdentityUpdateOne) SetProviderType(v string) *AuthIdentityUpdateOne {
  443. _u.mutation.SetProviderType(v)
  444. return _u
  445. }
  446. // SetNillableProviderType sets the "provider_type" field if the given value is not nil.
  447. func (_u *AuthIdentityUpdateOne) SetNillableProviderType(v *string) *AuthIdentityUpdateOne {
  448. if v != nil {
  449. _u.SetProviderType(*v)
  450. }
  451. return _u
  452. }
  453. // SetProviderKey sets the "provider_key" field.
  454. func (_u *AuthIdentityUpdateOne) SetProviderKey(v string) *AuthIdentityUpdateOne {
  455. _u.mutation.SetProviderKey(v)
  456. return _u
  457. }
  458. // SetNillableProviderKey sets the "provider_key" field if the given value is not nil.
  459. func (_u *AuthIdentityUpdateOne) SetNillableProviderKey(v *string) *AuthIdentityUpdateOne {
  460. if v != nil {
  461. _u.SetProviderKey(*v)
  462. }
  463. return _u
  464. }
  465. // SetProviderSubject sets the "provider_subject" field.
  466. func (_u *AuthIdentityUpdateOne) SetProviderSubject(v string) *AuthIdentityUpdateOne {
  467. _u.mutation.SetProviderSubject(v)
  468. return _u
  469. }
  470. // SetNillableProviderSubject sets the "provider_subject" field if the given value is not nil.
  471. func (_u *AuthIdentityUpdateOne) SetNillableProviderSubject(v *string) *AuthIdentityUpdateOne {
  472. if v != nil {
  473. _u.SetProviderSubject(*v)
  474. }
  475. return _u
  476. }
  477. // SetVerifiedAt sets the "verified_at" field.
  478. func (_u *AuthIdentityUpdateOne) SetVerifiedAt(v time.Time) *AuthIdentityUpdateOne {
  479. _u.mutation.SetVerifiedAt(v)
  480. return _u
  481. }
  482. // SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
  483. func (_u *AuthIdentityUpdateOne) SetNillableVerifiedAt(v *time.Time) *AuthIdentityUpdateOne {
  484. if v != nil {
  485. _u.SetVerifiedAt(*v)
  486. }
  487. return _u
  488. }
  489. // ClearVerifiedAt clears the value of the "verified_at" field.
  490. func (_u *AuthIdentityUpdateOne) ClearVerifiedAt() *AuthIdentityUpdateOne {
  491. _u.mutation.ClearVerifiedAt()
  492. return _u
  493. }
  494. // SetIssuer sets the "issuer" field.
  495. func (_u *AuthIdentityUpdateOne) SetIssuer(v string) *AuthIdentityUpdateOne {
  496. _u.mutation.SetIssuer(v)
  497. return _u
  498. }
  499. // SetNillableIssuer sets the "issuer" field if the given value is not nil.
  500. func (_u *AuthIdentityUpdateOne) SetNillableIssuer(v *string) *AuthIdentityUpdateOne {
  501. if v != nil {
  502. _u.SetIssuer(*v)
  503. }
  504. return _u
  505. }
  506. // ClearIssuer clears the value of the "issuer" field.
  507. func (_u *AuthIdentityUpdateOne) ClearIssuer() *AuthIdentityUpdateOne {
  508. _u.mutation.ClearIssuer()
  509. return _u
  510. }
  511. // SetMetadata sets the "metadata" field.
  512. func (_u *AuthIdentityUpdateOne) SetMetadata(v map[string]interface{}) *AuthIdentityUpdateOne {
  513. _u.mutation.SetMetadata(v)
  514. return _u
  515. }
  516. // SetUser sets the "user" edge to the User entity.
  517. func (_u *AuthIdentityUpdateOne) SetUser(v *User) *AuthIdentityUpdateOne {
  518. return _u.SetUserID(v.ID)
  519. }
  520. // AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
  521. func (_u *AuthIdentityUpdateOne) AddChannelIDs(ids ...int64) *AuthIdentityUpdateOne {
  522. _u.mutation.AddChannelIDs(ids...)
  523. return _u
  524. }
  525. // AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
  526. func (_u *AuthIdentityUpdateOne) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdateOne {
  527. ids := make([]int64, len(v))
  528. for i := range v {
  529. ids[i] = v[i].ID
  530. }
  531. return _u.AddChannelIDs(ids...)
  532. }
  533. // AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
  534. func (_u *AuthIdentityUpdateOne) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdateOne {
  535. _u.mutation.AddAdoptionDecisionIDs(ids...)
  536. return _u
  537. }
  538. // AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
  539. func (_u *AuthIdentityUpdateOne) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdateOne {
  540. ids := make([]int64, len(v))
  541. for i := range v {
  542. ids[i] = v[i].ID
  543. }
  544. return _u.AddAdoptionDecisionIDs(ids...)
  545. }
  546. // Mutation returns the AuthIdentityMutation object of the builder.
  547. func (_u *AuthIdentityUpdateOne) Mutation() *AuthIdentityMutation {
  548. return _u.mutation
  549. }
  550. // ClearUser clears the "user" edge to the User entity.
  551. func (_u *AuthIdentityUpdateOne) ClearUser() *AuthIdentityUpdateOne {
  552. _u.mutation.ClearUser()
  553. return _u
  554. }
  555. // ClearChannels clears all "channels" edges to the AuthIdentityChannel entity.
  556. func (_u *AuthIdentityUpdateOne) ClearChannels() *AuthIdentityUpdateOne {
  557. _u.mutation.ClearChannels()
  558. return _u
  559. }
  560. // RemoveChannelIDs removes the "channels" edge to AuthIdentityChannel entities by IDs.
  561. func (_u *AuthIdentityUpdateOne) RemoveChannelIDs(ids ...int64) *AuthIdentityUpdateOne {
  562. _u.mutation.RemoveChannelIDs(ids...)
  563. return _u
  564. }
  565. // RemoveChannels removes "channels" edges to AuthIdentityChannel entities.
  566. func (_u *AuthIdentityUpdateOne) RemoveChannels(v ...*AuthIdentityChannel) *AuthIdentityUpdateOne {
  567. ids := make([]int64, len(v))
  568. for i := range v {
  569. ids[i] = v[i].ID
  570. }
  571. return _u.RemoveChannelIDs(ids...)
  572. }
  573. // ClearAdoptionDecisions clears all "adoption_decisions" edges to the IdentityAdoptionDecision entity.
  574. func (_u *AuthIdentityUpdateOne) ClearAdoptionDecisions() *AuthIdentityUpdateOne {
  575. _u.mutation.ClearAdoptionDecisions()
  576. return _u
  577. }
  578. // RemoveAdoptionDecisionIDs removes the "adoption_decisions" edge to IdentityAdoptionDecision entities by IDs.
  579. func (_u *AuthIdentityUpdateOne) RemoveAdoptionDecisionIDs(ids ...int64) *AuthIdentityUpdateOne {
  580. _u.mutation.RemoveAdoptionDecisionIDs(ids...)
  581. return _u
  582. }
  583. // RemoveAdoptionDecisions removes "adoption_decisions" edges to IdentityAdoptionDecision entities.
  584. func (_u *AuthIdentityUpdateOne) RemoveAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityUpdateOne {
  585. ids := make([]int64, len(v))
  586. for i := range v {
  587. ids[i] = v[i].ID
  588. }
  589. return _u.RemoveAdoptionDecisionIDs(ids...)
  590. }
  591. // Where appends a list predicates to the AuthIdentityUpdate builder.
  592. func (_u *AuthIdentityUpdateOne) Where(ps ...predicate.AuthIdentity) *AuthIdentityUpdateOne {
  593. _u.mutation.Where(ps...)
  594. return _u
  595. }
  596. // Select allows selecting one or more fields (columns) of the returned entity.
  597. // The default is selecting all fields defined in the entity schema.
  598. func (_u *AuthIdentityUpdateOne) Select(field string, fields ...string) *AuthIdentityUpdateOne {
  599. _u.fields = append([]string{field}, fields...)
  600. return _u
  601. }
  602. // Save executes the query and returns the updated AuthIdentity entity.
  603. func (_u *AuthIdentityUpdateOne) Save(ctx context.Context) (*AuthIdentity, error) {
  604. _u.defaults()
  605. return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
  606. }
  607. // SaveX is like Save, but panics if an error occurs.
  608. func (_u *AuthIdentityUpdateOne) SaveX(ctx context.Context) *AuthIdentity {
  609. node, err := _u.Save(ctx)
  610. if err != nil {
  611. panic(err)
  612. }
  613. return node
  614. }
  615. // Exec executes the query on the entity.
  616. func (_u *AuthIdentityUpdateOne) Exec(ctx context.Context) error {
  617. _, err := _u.Save(ctx)
  618. return err
  619. }
  620. // ExecX is like Exec, but panics if an error occurs.
  621. func (_u *AuthIdentityUpdateOne) ExecX(ctx context.Context) {
  622. if err := _u.Exec(ctx); err != nil {
  623. panic(err)
  624. }
  625. }
  626. // defaults sets the default values of the builder before save.
  627. func (_u *AuthIdentityUpdateOne) defaults() {
  628. if _, ok := _u.mutation.UpdatedAt(); !ok {
  629. v := authidentity.UpdateDefaultUpdatedAt()
  630. _u.mutation.SetUpdatedAt(v)
  631. }
  632. }
  633. // check runs all checks and user-defined validators on the builder.
  634. func (_u *AuthIdentityUpdateOne) check() error {
  635. if v, ok := _u.mutation.ProviderType(); ok {
  636. if err := authidentity.ProviderTypeValidator(v); err != nil {
  637. return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
  638. }
  639. }
  640. if v, ok := _u.mutation.ProviderKey(); ok {
  641. if err := authidentity.ProviderKeyValidator(v); err != nil {
  642. return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
  643. }
  644. }
  645. if v, ok := _u.mutation.ProviderSubject(); ok {
  646. if err := authidentity.ProviderSubjectValidator(v); err != nil {
  647. return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
  648. }
  649. }
  650. if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
  651. return errors.New(`ent: clearing a required unique edge "AuthIdentity.user"`)
  652. }
  653. return nil
  654. }
  655. func (_u *AuthIdentityUpdateOne) sqlSave(ctx context.Context) (_node *AuthIdentity, err error) {
  656. if err := _u.check(); err != nil {
  657. return _node, err
  658. }
  659. _spec := sqlgraph.NewUpdateSpec(authidentity.Table, authidentity.Columns, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64))
  660. id, ok := _u.mutation.ID()
  661. if !ok {
  662. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthIdentity.id" for update`)}
  663. }
  664. _spec.Node.ID.Value = id
  665. if fields := _u.fields; len(fields) > 0 {
  666. _spec.Node.Columns = make([]string, 0, len(fields))
  667. _spec.Node.Columns = append(_spec.Node.Columns, authidentity.FieldID)
  668. for _, f := range fields {
  669. if !authidentity.ValidColumn(f) {
  670. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  671. }
  672. if f != authidentity.FieldID {
  673. _spec.Node.Columns = append(_spec.Node.Columns, f)
  674. }
  675. }
  676. }
  677. if ps := _u.mutation.predicates; len(ps) > 0 {
  678. _spec.Predicate = func(selector *sql.Selector) {
  679. for i := range ps {
  680. ps[i](selector)
  681. }
  682. }
  683. }
  684. if value, ok := _u.mutation.UpdatedAt(); ok {
  685. _spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
  686. }
  687. if value, ok := _u.mutation.ProviderType(); ok {
  688. _spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
  689. }
  690. if value, ok := _u.mutation.ProviderKey(); ok {
  691. _spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
  692. }
  693. if value, ok := _u.mutation.ProviderSubject(); ok {
  694. _spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
  695. }
  696. if value, ok := _u.mutation.VerifiedAt(); ok {
  697. _spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
  698. }
  699. if _u.mutation.VerifiedAtCleared() {
  700. _spec.ClearField(authidentity.FieldVerifiedAt, field.TypeTime)
  701. }
  702. if value, ok := _u.mutation.Issuer(); ok {
  703. _spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
  704. }
  705. if _u.mutation.IssuerCleared() {
  706. _spec.ClearField(authidentity.FieldIssuer, field.TypeString)
  707. }
  708. if value, ok := _u.mutation.Metadata(); ok {
  709. _spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
  710. }
  711. if _u.mutation.UserCleared() {
  712. edge := &sqlgraph.EdgeSpec{
  713. Rel: sqlgraph.M2O,
  714. Inverse: true,
  715. Table: authidentity.UserTable,
  716. Columns: []string{authidentity.UserColumn},
  717. Bidi: false,
  718. Target: &sqlgraph.EdgeTarget{
  719. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  720. },
  721. }
  722. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  723. }
  724. if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
  725. edge := &sqlgraph.EdgeSpec{
  726. Rel: sqlgraph.M2O,
  727. Inverse: true,
  728. Table: authidentity.UserTable,
  729. Columns: []string{authidentity.UserColumn},
  730. Bidi: false,
  731. Target: &sqlgraph.EdgeTarget{
  732. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  733. },
  734. }
  735. for _, k := range nodes {
  736. edge.Target.Nodes = append(edge.Target.Nodes, k)
  737. }
  738. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  739. }
  740. if _u.mutation.ChannelsCleared() {
  741. edge := &sqlgraph.EdgeSpec{
  742. Rel: sqlgraph.O2M,
  743. Inverse: false,
  744. Table: authidentity.ChannelsTable,
  745. Columns: []string{authidentity.ChannelsColumn},
  746. Bidi: false,
  747. Target: &sqlgraph.EdgeTarget{
  748. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  749. },
  750. }
  751. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  752. }
  753. if nodes := _u.mutation.RemovedChannelsIDs(); len(nodes) > 0 && !_u.mutation.ChannelsCleared() {
  754. edge := &sqlgraph.EdgeSpec{
  755. Rel: sqlgraph.O2M,
  756. Inverse: false,
  757. Table: authidentity.ChannelsTable,
  758. Columns: []string{authidentity.ChannelsColumn},
  759. Bidi: false,
  760. Target: &sqlgraph.EdgeTarget{
  761. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  762. },
  763. }
  764. for _, k := range nodes {
  765. edge.Target.Nodes = append(edge.Target.Nodes, k)
  766. }
  767. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  768. }
  769. if nodes := _u.mutation.ChannelsIDs(); len(nodes) > 0 {
  770. edge := &sqlgraph.EdgeSpec{
  771. Rel: sqlgraph.O2M,
  772. Inverse: false,
  773. Table: authidentity.ChannelsTable,
  774. Columns: []string{authidentity.ChannelsColumn},
  775. Bidi: false,
  776. Target: &sqlgraph.EdgeTarget{
  777. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  778. },
  779. }
  780. for _, k := range nodes {
  781. edge.Target.Nodes = append(edge.Target.Nodes, k)
  782. }
  783. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  784. }
  785. if _u.mutation.AdoptionDecisionsCleared() {
  786. edge := &sqlgraph.EdgeSpec{
  787. Rel: sqlgraph.O2M,
  788. Inverse: false,
  789. Table: authidentity.AdoptionDecisionsTable,
  790. Columns: []string{authidentity.AdoptionDecisionsColumn},
  791. Bidi: false,
  792. Target: &sqlgraph.EdgeTarget{
  793. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  794. },
  795. }
  796. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  797. }
  798. if nodes := _u.mutation.RemovedAdoptionDecisionsIDs(); len(nodes) > 0 && !_u.mutation.AdoptionDecisionsCleared() {
  799. edge := &sqlgraph.EdgeSpec{
  800. Rel: sqlgraph.O2M,
  801. Inverse: false,
  802. Table: authidentity.AdoptionDecisionsTable,
  803. Columns: []string{authidentity.AdoptionDecisionsColumn},
  804. Bidi: false,
  805. Target: &sqlgraph.EdgeTarget{
  806. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  807. },
  808. }
  809. for _, k := range nodes {
  810. edge.Target.Nodes = append(edge.Target.Nodes, k)
  811. }
  812. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  813. }
  814. if nodes := _u.mutation.AdoptionDecisionsIDs(); len(nodes) > 0 {
  815. edge := &sqlgraph.EdgeSpec{
  816. Rel: sqlgraph.O2M,
  817. Inverse: false,
  818. Table: authidentity.AdoptionDecisionsTable,
  819. Columns: []string{authidentity.AdoptionDecisionsColumn},
  820. Bidi: false,
  821. Target: &sqlgraph.EdgeTarget{
  822. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  823. },
  824. }
  825. for _, k := range nodes {
  826. edge.Target.Nodes = append(edge.Target.Nodes, k)
  827. }
  828. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  829. }
  830. _node = &AuthIdentity{config: _u.config}
  831. _spec.Assign = _node.assignValues
  832. _spec.ScanValues = _node.scanValues
  833. if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
  834. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  835. err = &NotFoundError{authidentity.Label}
  836. } else if sqlgraph.IsConstraintError(err) {
  837. err = &ConstraintError{msg: err.Error(), wrap: err}
  838. }
  839. return nil, err
  840. }
  841. _u.mutation.done = true
  842. return _node, nil
  843. }