authidentity_create.go 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  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/user"
  15. )
  16. // AuthIdentityCreate is the builder for creating a AuthIdentity entity.
  17. type AuthIdentityCreate struct {
  18. config
  19. mutation *AuthIdentityMutation
  20. hooks []Hook
  21. conflict []sql.ConflictOption
  22. }
  23. // SetCreatedAt sets the "created_at" field.
  24. func (_c *AuthIdentityCreate) SetCreatedAt(v time.Time) *AuthIdentityCreate {
  25. _c.mutation.SetCreatedAt(v)
  26. return _c
  27. }
  28. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  29. func (_c *AuthIdentityCreate) SetNillableCreatedAt(v *time.Time) *AuthIdentityCreate {
  30. if v != nil {
  31. _c.SetCreatedAt(*v)
  32. }
  33. return _c
  34. }
  35. // SetUpdatedAt sets the "updated_at" field.
  36. func (_c *AuthIdentityCreate) SetUpdatedAt(v time.Time) *AuthIdentityCreate {
  37. _c.mutation.SetUpdatedAt(v)
  38. return _c
  39. }
  40. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  41. func (_c *AuthIdentityCreate) SetNillableUpdatedAt(v *time.Time) *AuthIdentityCreate {
  42. if v != nil {
  43. _c.SetUpdatedAt(*v)
  44. }
  45. return _c
  46. }
  47. // SetUserID sets the "user_id" field.
  48. func (_c *AuthIdentityCreate) SetUserID(v int64) *AuthIdentityCreate {
  49. _c.mutation.SetUserID(v)
  50. return _c
  51. }
  52. // SetProviderType sets the "provider_type" field.
  53. func (_c *AuthIdentityCreate) SetProviderType(v string) *AuthIdentityCreate {
  54. _c.mutation.SetProviderType(v)
  55. return _c
  56. }
  57. // SetProviderKey sets the "provider_key" field.
  58. func (_c *AuthIdentityCreate) SetProviderKey(v string) *AuthIdentityCreate {
  59. _c.mutation.SetProviderKey(v)
  60. return _c
  61. }
  62. // SetProviderSubject sets the "provider_subject" field.
  63. func (_c *AuthIdentityCreate) SetProviderSubject(v string) *AuthIdentityCreate {
  64. _c.mutation.SetProviderSubject(v)
  65. return _c
  66. }
  67. // SetVerifiedAt sets the "verified_at" field.
  68. func (_c *AuthIdentityCreate) SetVerifiedAt(v time.Time) *AuthIdentityCreate {
  69. _c.mutation.SetVerifiedAt(v)
  70. return _c
  71. }
  72. // SetNillableVerifiedAt sets the "verified_at" field if the given value is not nil.
  73. func (_c *AuthIdentityCreate) SetNillableVerifiedAt(v *time.Time) *AuthIdentityCreate {
  74. if v != nil {
  75. _c.SetVerifiedAt(*v)
  76. }
  77. return _c
  78. }
  79. // SetIssuer sets the "issuer" field.
  80. func (_c *AuthIdentityCreate) SetIssuer(v string) *AuthIdentityCreate {
  81. _c.mutation.SetIssuer(v)
  82. return _c
  83. }
  84. // SetNillableIssuer sets the "issuer" field if the given value is not nil.
  85. func (_c *AuthIdentityCreate) SetNillableIssuer(v *string) *AuthIdentityCreate {
  86. if v != nil {
  87. _c.SetIssuer(*v)
  88. }
  89. return _c
  90. }
  91. // SetMetadata sets the "metadata" field.
  92. func (_c *AuthIdentityCreate) SetMetadata(v map[string]interface{}) *AuthIdentityCreate {
  93. _c.mutation.SetMetadata(v)
  94. return _c
  95. }
  96. // SetUser sets the "user" edge to the User entity.
  97. func (_c *AuthIdentityCreate) SetUser(v *User) *AuthIdentityCreate {
  98. return _c.SetUserID(v.ID)
  99. }
  100. // AddChannelIDs adds the "channels" edge to the AuthIdentityChannel entity by IDs.
  101. func (_c *AuthIdentityCreate) AddChannelIDs(ids ...int64) *AuthIdentityCreate {
  102. _c.mutation.AddChannelIDs(ids...)
  103. return _c
  104. }
  105. // AddChannels adds the "channels" edges to the AuthIdentityChannel entity.
  106. func (_c *AuthIdentityCreate) AddChannels(v ...*AuthIdentityChannel) *AuthIdentityCreate {
  107. ids := make([]int64, len(v))
  108. for i := range v {
  109. ids[i] = v[i].ID
  110. }
  111. return _c.AddChannelIDs(ids...)
  112. }
  113. // AddAdoptionDecisionIDs adds the "adoption_decisions" edge to the IdentityAdoptionDecision entity by IDs.
  114. func (_c *AuthIdentityCreate) AddAdoptionDecisionIDs(ids ...int64) *AuthIdentityCreate {
  115. _c.mutation.AddAdoptionDecisionIDs(ids...)
  116. return _c
  117. }
  118. // AddAdoptionDecisions adds the "adoption_decisions" edges to the IdentityAdoptionDecision entity.
  119. func (_c *AuthIdentityCreate) AddAdoptionDecisions(v ...*IdentityAdoptionDecision) *AuthIdentityCreate {
  120. ids := make([]int64, len(v))
  121. for i := range v {
  122. ids[i] = v[i].ID
  123. }
  124. return _c.AddAdoptionDecisionIDs(ids...)
  125. }
  126. // Mutation returns the AuthIdentityMutation object of the builder.
  127. func (_c *AuthIdentityCreate) Mutation() *AuthIdentityMutation {
  128. return _c.mutation
  129. }
  130. // Save creates the AuthIdentity in the database.
  131. func (_c *AuthIdentityCreate) Save(ctx context.Context) (*AuthIdentity, error) {
  132. _c.defaults()
  133. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  134. }
  135. // SaveX calls Save and panics if Save returns an error.
  136. func (_c *AuthIdentityCreate) SaveX(ctx context.Context) *AuthIdentity {
  137. v, err := _c.Save(ctx)
  138. if err != nil {
  139. panic(err)
  140. }
  141. return v
  142. }
  143. // Exec executes the query.
  144. func (_c *AuthIdentityCreate) Exec(ctx context.Context) error {
  145. _, err := _c.Save(ctx)
  146. return err
  147. }
  148. // ExecX is like Exec, but panics if an error occurs.
  149. func (_c *AuthIdentityCreate) ExecX(ctx context.Context) {
  150. if err := _c.Exec(ctx); err != nil {
  151. panic(err)
  152. }
  153. }
  154. // defaults sets the default values of the builder before save.
  155. func (_c *AuthIdentityCreate) defaults() {
  156. if _, ok := _c.mutation.CreatedAt(); !ok {
  157. v := authidentity.DefaultCreatedAt()
  158. _c.mutation.SetCreatedAt(v)
  159. }
  160. if _, ok := _c.mutation.UpdatedAt(); !ok {
  161. v := authidentity.DefaultUpdatedAt()
  162. _c.mutation.SetUpdatedAt(v)
  163. }
  164. if _, ok := _c.mutation.Metadata(); !ok {
  165. v := authidentity.DefaultMetadata()
  166. _c.mutation.SetMetadata(v)
  167. }
  168. }
  169. // check runs all checks and user-defined validators on the builder.
  170. func (_c *AuthIdentityCreate) check() error {
  171. if _, ok := _c.mutation.CreatedAt(); !ok {
  172. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AuthIdentity.created_at"`)}
  173. }
  174. if _, ok := _c.mutation.UpdatedAt(); !ok {
  175. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "AuthIdentity.updated_at"`)}
  176. }
  177. if _, ok := _c.mutation.UserID(); !ok {
  178. return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "AuthIdentity.user_id"`)}
  179. }
  180. if _, ok := _c.mutation.ProviderType(); !ok {
  181. return &ValidationError{Name: "provider_type", err: errors.New(`ent: missing required field "AuthIdentity.provider_type"`)}
  182. }
  183. if v, ok := _c.mutation.ProviderType(); ok {
  184. if err := authidentity.ProviderTypeValidator(v); err != nil {
  185. return &ValidationError{Name: "provider_type", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_type": %w`, err)}
  186. }
  187. }
  188. if _, ok := _c.mutation.ProviderKey(); !ok {
  189. return &ValidationError{Name: "provider_key", err: errors.New(`ent: missing required field "AuthIdentity.provider_key"`)}
  190. }
  191. if v, ok := _c.mutation.ProviderKey(); ok {
  192. if err := authidentity.ProviderKeyValidator(v); err != nil {
  193. return &ValidationError{Name: "provider_key", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_key": %w`, err)}
  194. }
  195. }
  196. if _, ok := _c.mutation.ProviderSubject(); !ok {
  197. return &ValidationError{Name: "provider_subject", err: errors.New(`ent: missing required field "AuthIdentity.provider_subject"`)}
  198. }
  199. if v, ok := _c.mutation.ProviderSubject(); ok {
  200. if err := authidentity.ProviderSubjectValidator(v); err != nil {
  201. return &ValidationError{Name: "provider_subject", err: fmt.Errorf(`ent: validator failed for field "AuthIdentity.provider_subject": %w`, err)}
  202. }
  203. }
  204. if _, ok := _c.mutation.Metadata(); !ok {
  205. return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "AuthIdentity.metadata"`)}
  206. }
  207. if len(_c.mutation.UserIDs()) == 0 {
  208. return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "AuthIdentity.user"`)}
  209. }
  210. return nil
  211. }
  212. func (_c *AuthIdentityCreate) sqlSave(ctx context.Context) (*AuthIdentity, error) {
  213. if err := _c.check(); err != nil {
  214. return nil, err
  215. }
  216. _node, _spec := _c.createSpec()
  217. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  218. if sqlgraph.IsConstraintError(err) {
  219. err = &ConstraintError{msg: err.Error(), wrap: err}
  220. }
  221. return nil, err
  222. }
  223. id := _spec.ID.Value.(int64)
  224. _node.ID = int64(id)
  225. _c.mutation.id = &_node.ID
  226. _c.mutation.done = true
  227. return _node, nil
  228. }
  229. func (_c *AuthIdentityCreate) createSpec() (*AuthIdentity, *sqlgraph.CreateSpec) {
  230. var (
  231. _node = &AuthIdentity{config: _c.config}
  232. _spec = sqlgraph.NewCreateSpec(authidentity.Table, sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64))
  233. )
  234. _spec.OnConflict = _c.conflict
  235. if value, ok := _c.mutation.CreatedAt(); ok {
  236. _spec.SetField(authidentity.FieldCreatedAt, field.TypeTime, value)
  237. _node.CreatedAt = value
  238. }
  239. if value, ok := _c.mutation.UpdatedAt(); ok {
  240. _spec.SetField(authidentity.FieldUpdatedAt, field.TypeTime, value)
  241. _node.UpdatedAt = value
  242. }
  243. if value, ok := _c.mutation.ProviderType(); ok {
  244. _spec.SetField(authidentity.FieldProviderType, field.TypeString, value)
  245. _node.ProviderType = value
  246. }
  247. if value, ok := _c.mutation.ProviderKey(); ok {
  248. _spec.SetField(authidentity.FieldProviderKey, field.TypeString, value)
  249. _node.ProviderKey = value
  250. }
  251. if value, ok := _c.mutation.ProviderSubject(); ok {
  252. _spec.SetField(authidentity.FieldProviderSubject, field.TypeString, value)
  253. _node.ProviderSubject = value
  254. }
  255. if value, ok := _c.mutation.VerifiedAt(); ok {
  256. _spec.SetField(authidentity.FieldVerifiedAt, field.TypeTime, value)
  257. _node.VerifiedAt = &value
  258. }
  259. if value, ok := _c.mutation.Issuer(); ok {
  260. _spec.SetField(authidentity.FieldIssuer, field.TypeString, value)
  261. _node.Issuer = &value
  262. }
  263. if value, ok := _c.mutation.Metadata(); ok {
  264. _spec.SetField(authidentity.FieldMetadata, field.TypeJSON, value)
  265. _node.Metadata = value
  266. }
  267. if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
  268. edge := &sqlgraph.EdgeSpec{
  269. Rel: sqlgraph.M2O,
  270. Inverse: true,
  271. Table: authidentity.UserTable,
  272. Columns: []string{authidentity.UserColumn},
  273. Bidi: false,
  274. Target: &sqlgraph.EdgeTarget{
  275. IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
  276. },
  277. }
  278. for _, k := range nodes {
  279. edge.Target.Nodes = append(edge.Target.Nodes, k)
  280. }
  281. _node.UserID = nodes[0]
  282. _spec.Edges = append(_spec.Edges, edge)
  283. }
  284. if nodes := _c.mutation.ChannelsIDs(); len(nodes) > 0 {
  285. edge := &sqlgraph.EdgeSpec{
  286. Rel: sqlgraph.O2M,
  287. Inverse: false,
  288. Table: authidentity.ChannelsTable,
  289. Columns: []string{authidentity.ChannelsColumn},
  290. Bidi: false,
  291. Target: &sqlgraph.EdgeTarget{
  292. IDSpec: sqlgraph.NewFieldSpec(authidentitychannel.FieldID, field.TypeInt64),
  293. },
  294. }
  295. for _, k := range nodes {
  296. edge.Target.Nodes = append(edge.Target.Nodes, k)
  297. }
  298. _spec.Edges = append(_spec.Edges, edge)
  299. }
  300. if nodes := _c.mutation.AdoptionDecisionsIDs(); len(nodes) > 0 {
  301. edge := &sqlgraph.EdgeSpec{
  302. Rel: sqlgraph.O2M,
  303. Inverse: false,
  304. Table: authidentity.AdoptionDecisionsTable,
  305. Columns: []string{authidentity.AdoptionDecisionsColumn},
  306. Bidi: false,
  307. Target: &sqlgraph.EdgeTarget{
  308. IDSpec: sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64),
  309. },
  310. }
  311. for _, k := range nodes {
  312. edge.Target.Nodes = append(edge.Target.Nodes, k)
  313. }
  314. _spec.Edges = append(_spec.Edges, edge)
  315. }
  316. return _node, _spec
  317. }
  318. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  319. // of the `INSERT` statement. For example:
  320. //
  321. // client.AuthIdentity.Create().
  322. // SetCreatedAt(v).
  323. // OnConflict(
  324. // // Update the row with the new values
  325. // // the was proposed for insertion.
  326. // sql.ResolveWithNewValues(),
  327. // ).
  328. // // Override some of the fields with custom
  329. // // update values.
  330. // Update(func(u *ent.AuthIdentityUpsert) {
  331. // SetCreatedAt(v+v).
  332. // }).
  333. // Exec(ctx)
  334. func (_c *AuthIdentityCreate) OnConflict(opts ...sql.ConflictOption) *AuthIdentityUpsertOne {
  335. _c.conflict = opts
  336. return &AuthIdentityUpsertOne{
  337. create: _c,
  338. }
  339. }
  340. // OnConflictColumns calls `OnConflict` and configures the columns
  341. // as conflict target. Using this option is equivalent to using:
  342. //
  343. // client.AuthIdentity.Create().
  344. // OnConflict(sql.ConflictColumns(columns...)).
  345. // Exec(ctx)
  346. func (_c *AuthIdentityCreate) OnConflictColumns(columns ...string) *AuthIdentityUpsertOne {
  347. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  348. return &AuthIdentityUpsertOne{
  349. create: _c,
  350. }
  351. }
  352. type (
  353. // AuthIdentityUpsertOne is the builder for "upsert"-ing
  354. // one AuthIdentity node.
  355. AuthIdentityUpsertOne struct {
  356. create *AuthIdentityCreate
  357. }
  358. // AuthIdentityUpsert is the "OnConflict" setter.
  359. AuthIdentityUpsert struct {
  360. *sql.UpdateSet
  361. }
  362. )
  363. // SetUpdatedAt sets the "updated_at" field.
  364. func (u *AuthIdentityUpsert) SetUpdatedAt(v time.Time) *AuthIdentityUpsert {
  365. u.Set(authidentity.FieldUpdatedAt, v)
  366. return u
  367. }
  368. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  369. func (u *AuthIdentityUpsert) UpdateUpdatedAt() *AuthIdentityUpsert {
  370. u.SetExcluded(authidentity.FieldUpdatedAt)
  371. return u
  372. }
  373. // SetUserID sets the "user_id" field.
  374. func (u *AuthIdentityUpsert) SetUserID(v int64) *AuthIdentityUpsert {
  375. u.Set(authidentity.FieldUserID, v)
  376. return u
  377. }
  378. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  379. func (u *AuthIdentityUpsert) UpdateUserID() *AuthIdentityUpsert {
  380. u.SetExcluded(authidentity.FieldUserID)
  381. return u
  382. }
  383. // SetProviderType sets the "provider_type" field.
  384. func (u *AuthIdentityUpsert) SetProviderType(v string) *AuthIdentityUpsert {
  385. u.Set(authidentity.FieldProviderType, v)
  386. return u
  387. }
  388. // UpdateProviderType sets the "provider_type" field to the value that was provided on create.
  389. func (u *AuthIdentityUpsert) UpdateProviderType() *AuthIdentityUpsert {
  390. u.SetExcluded(authidentity.FieldProviderType)
  391. return u
  392. }
  393. // SetProviderKey sets the "provider_key" field.
  394. func (u *AuthIdentityUpsert) SetProviderKey(v string) *AuthIdentityUpsert {
  395. u.Set(authidentity.FieldProviderKey, v)
  396. return u
  397. }
  398. // UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
  399. func (u *AuthIdentityUpsert) UpdateProviderKey() *AuthIdentityUpsert {
  400. u.SetExcluded(authidentity.FieldProviderKey)
  401. return u
  402. }
  403. // SetProviderSubject sets the "provider_subject" field.
  404. func (u *AuthIdentityUpsert) SetProviderSubject(v string) *AuthIdentityUpsert {
  405. u.Set(authidentity.FieldProviderSubject, v)
  406. return u
  407. }
  408. // UpdateProviderSubject sets the "provider_subject" field to the value that was provided on create.
  409. func (u *AuthIdentityUpsert) UpdateProviderSubject() *AuthIdentityUpsert {
  410. u.SetExcluded(authidentity.FieldProviderSubject)
  411. return u
  412. }
  413. // SetVerifiedAt sets the "verified_at" field.
  414. func (u *AuthIdentityUpsert) SetVerifiedAt(v time.Time) *AuthIdentityUpsert {
  415. u.Set(authidentity.FieldVerifiedAt, v)
  416. return u
  417. }
  418. // UpdateVerifiedAt sets the "verified_at" field to the value that was provided on create.
  419. func (u *AuthIdentityUpsert) UpdateVerifiedAt() *AuthIdentityUpsert {
  420. u.SetExcluded(authidentity.FieldVerifiedAt)
  421. return u
  422. }
  423. // ClearVerifiedAt clears the value of the "verified_at" field.
  424. func (u *AuthIdentityUpsert) ClearVerifiedAt() *AuthIdentityUpsert {
  425. u.SetNull(authidentity.FieldVerifiedAt)
  426. return u
  427. }
  428. // SetIssuer sets the "issuer" field.
  429. func (u *AuthIdentityUpsert) SetIssuer(v string) *AuthIdentityUpsert {
  430. u.Set(authidentity.FieldIssuer, v)
  431. return u
  432. }
  433. // UpdateIssuer sets the "issuer" field to the value that was provided on create.
  434. func (u *AuthIdentityUpsert) UpdateIssuer() *AuthIdentityUpsert {
  435. u.SetExcluded(authidentity.FieldIssuer)
  436. return u
  437. }
  438. // ClearIssuer clears the value of the "issuer" field.
  439. func (u *AuthIdentityUpsert) ClearIssuer() *AuthIdentityUpsert {
  440. u.SetNull(authidentity.FieldIssuer)
  441. return u
  442. }
  443. // SetMetadata sets the "metadata" field.
  444. func (u *AuthIdentityUpsert) SetMetadata(v map[string]interface{}) *AuthIdentityUpsert {
  445. u.Set(authidentity.FieldMetadata, v)
  446. return u
  447. }
  448. // UpdateMetadata sets the "metadata" field to the value that was provided on create.
  449. func (u *AuthIdentityUpsert) UpdateMetadata() *AuthIdentityUpsert {
  450. u.SetExcluded(authidentity.FieldMetadata)
  451. return u
  452. }
  453. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  454. // Using this option is equivalent to using:
  455. //
  456. // client.AuthIdentity.Create().
  457. // OnConflict(
  458. // sql.ResolveWithNewValues(),
  459. // ).
  460. // Exec(ctx)
  461. func (u *AuthIdentityUpsertOne) UpdateNewValues() *AuthIdentityUpsertOne {
  462. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  463. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  464. if _, exists := u.create.mutation.CreatedAt(); exists {
  465. s.SetIgnore(authidentity.FieldCreatedAt)
  466. }
  467. }))
  468. return u
  469. }
  470. // Ignore sets each column to itself in case of conflict.
  471. // Using this option is equivalent to using:
  472. //
  473. // client.AuthIdentity.Create().
  474. // OnConflict(sql.ResolveWithIgnore()).
  475. // Exec(ctx)
  476. func (u *AuthIdentityUpsertOne) Ignore() *AuthIdentityUpsertOne {
  477. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  478. return u
  479. }
  480. // DoNothing configures the conflict_action to `DO NOTHING`.
  481. // Supported only by SQLite and PostgreSQL.
  482. func (u *AuthIdentityUpsertOne) DoNothing() *AuthIdentityUpsertOne {
  483. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  484. return u
  485. }
  486. // Update allows overriding fields `UPDATE` values. See the AuthIdentityCreate.OnConflict
  487. // documentation for more info.
  488. func (u *AuthIdentityUpsertOne) Update(set func(*AuthIdentityUpsert)) *AuthIdentityUpsertOne {
  489. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  490. set(&AuthIdentityUpsert{UpdateSet: update})
  491. }))
  492. return u
  493. }
  494. // SetUpdatedAt sets the "updated_at" field.
  495. func (u *AuthIdentityUpsertOne) SetUpdatedAt(v time.Time) *AuthIdentityUpsertOne {
  496. return u.Update(func(s *AuthIdentityUpsert) {
  497. s.SetUpdatedAt(v)
  498. })
  499. }
  500. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  501. func (u *AuthIdentityUpsertOne) UpdateUpdatedAt() *AuthIdentityUpsertOne {
  502. return u.Update(func(s *AuthIdentityUpsert) {
  503. s.UpdateUpdatedAt()
  504. })
  505. }
  506. // SetUserID sets the "user_id" field.
  507. func (u *AuthIdentityUpsertOne) SetUserID(v int64) *AuthIdentityUpsertOne {
  508. return u.Update(func(s *AuthIdentityUpsert) {
  509. s.SetUserID(v)
  510. })
  511. }
  512. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  513. func (u *AuthIdentityUpsertOne) UpdateUserID() *AuthIdentityUpsertOne {
  514. return u.Update(func(s *AuthIdentityUpsert) {
  515. s.UpdateUserID()
  516. })
  517. }
  518. // SetProviderType sets the "provider_type" field.
  519. func (u *AuthIdentityUpsertOne) SetProviderType(v string) *AuthIdentityUpsertOne {
  520. return u.Update(func(s *AuthIdentityUpsert) {
  521. s.SetProviderType(v)
  522. })
  523. }
  524. // UpdateProviderType sets the "provider_type" field to the value that was provided on create.
  525. func (u *AuthIdentityUpsertOne) UpdateProviderType() *AuthIdentityUpsertOne {
  526. return u.Update(func(s *AuthIdentityUpsert) {
  527. s.UpdateProviderType()
  528. })
  529. }
  530. // SetProviderKey sets the "provider_key" field.
  531. func (u *AuthIdentityUpsertOne) SetProviderKey(v string) *AuthIdentityUpsertOne {
  532. return u.Update(func(s *AuthIdentityUpsert) {
  533. s.SetProviderKey(v)
  534. })
  535. }
  536. // UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
  537. func (u *AuthIdentityUpsertOne) UpdateProviderKey() *AuthIdentityUpsertOne {
  538. return u.Update(func(s *AuthIdentityUpsert) {
  539. s.UpdateProviderKey()
  540. })
  541. }
  542. // SetProviderSubject sets the "provider_subject" field.
  543. func (u *AuthIdentityUpsertOne) SetProviderSubject(v string) *AuthIdentityUpsertOne {
  544. return u.Update(func(s *AuthIdentityUpsert) {
  545. s.SetProviderSubject(v)
  546. })
  547. }
  548. // UpdateProviderSubject sets the "provider_subject" field to the value that was provided on create.
  549. func (u *AuthIdentityUpsertOne) UpdateProviderSubject() *AuthIdentityUpsertOne {
  550. return u.Update(func(s *AuthIdentityUpsert) {
  551. s.UpdateProviderSubject()
  552. })
  553. }
  554. // SetVerifiedAt sets the "verified_at" field.
  555. func (u *AuthIdentityUpsertOne) SetVerifiedAt(v time.Time) *AuthIdentityUpsertOne {
  556. return u.Update(func(s *AuthIdentityUpsert) {
  557. s.SetVerifiedAt(v)
  558. })
  559. }
  560. // UpdateVerifiedAt sets the "verified_at" field to the value that was provided on create.
  561. func (u *AuthIdentityUpsertOne) UpdateVerifiedAt() *AuthIdentityUpsertOne {
  562. return u.Update(func(s *AuthIdentityUpsert) {
  563. s.UpdateVerifiedAt()
  564. })
  565. }
  566. // ClearVerifiedAt clears the value of the "verified_at" field.
  567. func (u *AuthIdentityUpsertOne) ClearVerifiedAt() *AuthIdentityUpsertOne {
  568. return u.Update(func(s *AuthIdentityUpsert) {
  569. s.ClearVerifiedAt()
  570. })
  571. }
  572. // SetIssuer sets the "issuer" field.
  573. func (u *AuthIdentityUpsertOne) SetIssuer(v string) *AuthIdentityUpsertOne {
  574. return u.Update(func(s *AuthIdentityUpsert) {
  575. s.SetIssuer(v)
  576. })
  577. }
  578. // UpdateIssuer sets the "issuer" field to the value that was provided on create.
  579. func (u *AuthIdentityUpsertOne) UpdateIssuer() *AuthIdentityUpsertOne {
  580. return u.Update(func(s *AuthIdentityUpsert) {
  581. s.UpdateIssuer()
  582. })
  583. }
  584. // ClearIssuer clears the value of the "issuer" field.
  585. func (u *AuthIdentityUpsertOne) ClearIssuer() *AuthIdentityUpsertOne {
  586. return u.Update(func(s *AuthIdentityUpsert) {
  587. s.ClearIssuer()
  588. })
  589. }
  590. // SetMetadata sets the "metadata" field.
  591. func (u *AuthIdentityUpsertOne) SetMetadata(v map[string]interface{}) *AuthIdentityUpsertOne {
  592. return u.Update(func(s *AuthIdentityUpsert) {
  593. s.SetMetadata(v)
  594. })
  595. }
  596. // UpdateMetadata sets the "metadata" field to the value that was provided on create.
  597. func (u *AuthIdentityUpsertOne) UpdateMetadata() *AuthIdentityUpsertOne {
  598. return u.Update(func(s *AuthIdentityUpsert) {
  599. s.UpdateMetadata()
  600. })
  601. }
  602. // Exec executes the query.
  603. func (u *AuthIdentityUpsertOne) Exec(ctx context.Context) error {
  604. if len(u.create.conflict) == 0 {
  605. return errors.New("ent: missing options for AuthIdentityCreate.OnConflict")
  606. }
  607. return u.create.Exec(ctx)
  608. }
  609. // ExecX is like Exec, but panics if an error occurs.
  610. func (u *AuthIdentityUpsertOne) ExecX(ctx context.Context) {
  611. if err := u.create.Exec(ctx); err != nil {
  612. panic(err)
  613. }
  614. }
  615. // Exec executes the UPSERT query and returns the inserted/updated ID.
  616. func (u *AuthIdentityUpsertOne) ID(ctx context.Context) (id int64, err error) {
  617. node, err := u.create.Save(ctx)
  618. if err != nil {
  619. return id, err
  620. }
  621. return node.ID, nil
  622. }
  623. // IDX is like ID, but panics if an error occurs.
  624. func (u *AuthIdentityUpsertOne) IDX(ctx context.Context) int64 {
  625. id, err := u.ID(ctx)
  626. if err != nil {
  627. panic(err)
  628. }
  629. return id
  630. }
  631. // AuthIdentityCreateBulk is the builder for creating many AuthIdentity entities in bulk.
  632. type AuthIdentityCreateBulk struct {
  633. config
  634. err error
  635. builders []*AuthIdentityCreate
  636. conflict []sql.ConflictOption
  637. }
  638. // Save creates the AuthIdentity entities in the database.
  639. func (_c *AuthIdentityCreateBulk) Save(ctx context.Context) ([]*AuthIdentity, error) {
  640. if _c.err != nil {
  641. return nil, _c.err
  642. }
  643. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  644. nodes := make([]*AuthIdentity, len(_c.builders))
  645. mutators := make([]Mutator, len(_c.builders))
  646. for i := range _c.builders {
  647. func(i int, root context.Context) {
  648. builder := _c.builders[i]
  649. builder.defaults()
  650. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  651. mutation, ok := m.(*AuthIdentityMutation)
  652. if !ok {
  653. return nil, fmt.Errorf("unexpected mutation type %T", m)
  654. }
  655. if err := builder.check(); err != nil {
  656. return nil, err
  657. }
  658. builder.mutation = mutation
  659. var err error
  660. nodes[i], specs[i] = builder.createSpec()
  661. if i < len(mutators)-1 {
  662. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  663. } else {
  664. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  665. spec.OnConflict = _c.conflict
  666. // Invoke the actual operation on the latest mutation in the chain.
  667. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  668. if sqlgraph.IsConstraintError(err) {
  669. err = &ConstraintError{msg: err.Error(), wrap: err}
  670. }
  671. }
  672. }
  673. if err != nil {
  674. return nil, err
  675. }
  676. mutation.id = &nodes[i].ID
  677. if specs[i].ID.Value != nil {
  678. id := specs[i].ID.Value.(int64)
  679. nodes[i].ID = int64(id)
  680. }
  681. mutation.done = true
  682. return nodes[i], nil
  683. })
  684. for i := len(builder.hooks) - 1; i >= 0; i-- {
  685. mut = builder.hooks[i](mut)
  686. }
  687. mutators[i] = mut
  688. }(i, ctx)
  689. }
  690. if len(mutators) > 0 {
  691. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  692. return nil, err
  693. }
  694. }
  695. return nodes, nil
  696. }
  697. // SaveX is like Save, but panics if an error occurs.
  698. func (_c *AuthIdentityCreateBulk) SaveX(ctx context.Context) []*AuthIdentity {
  699. v, err := _c.Save(ctx)
  700. if err != nil {
  701. panic(err)
  702. }
  703. return v
  704. }
  705. // Exec executes the query.
  706. func (_c *AuthIdentityCreateBulk) Exec(ctx context.Context) error {
  707. _, err := _c.Save(ctx)
  708. return err
  709. }
  710. // ExecX is like Exec, but panics if an error occurs.
  711. func (_c *AuthIdentityCreateBulk) ExecX(ctx context.Context) {
  712. if err := _c.Exec(ctx); err != nil {
  713. panic(err)
  714. }
  715. }
  716. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  717. // of the `INSERT` statement. For example:
  718. //
  719. // client.AuthIdentity.CreateBulk(builders...).
  720. // OnConflict(
  721. // // Update the row with the new values
  722. // // the was proposed for insertion.
  723. // sql.ResolveWithNewValues(),
  724. // ).
  725. // // Override some of the fields with custom
  726. // // update values.
  727. // Update(func(u *ent.AuthIdentityUpsert) {
  728. // SetCreatedAt(v+v).
  729. // }).
  730. // Exec(ctx)
  731. func (_c *AuthIdentityCreateBulk) OnConflict(opts ...sql.ConflictOption) *AuthIdentityUpsertBulk {
  732. _c.conflict = opts
  733. return &AuthIdentityUpsertBulk{
  734. create: _c,
  735. }
  736. }
  737. // OnConflictColumns calls `OnConflict` and configures the columns
  738. // as conflict target. Using this option is equivalent to using:
  739. //
  740. // client.AuthIdentity.Create().
  741. // OnConflict(sql.ConflictColumns(columns...)).
  742. // Exec(ctx)
  743. func (_c *AuthIdentityCreateBulk) OnConflictColumns(columns ...string) *AuthIdentityUpsertBulk {
  744. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  745. return &AuthIdentityUpsertBulk{
  746. create: _c,
  747. }
  748. }
  749. // AuthIdentityUpsertBulk is the builder for "upsert"-ing
  750. // a bulk of AuthIdentity nodes.
  751. type AuthIdentityUpsertBulk struct {
  752. create *AuthIdentityCreateBulk
  753. }
  754. // UpdateNewValues updates the mutable fields using the new values that
  755. // were set on create. Using this option is equivalent to using:
  756. //
  757. // client.AuthIdentity.Create().
  758. // OnConflict(
  759. // sql.ResolveWithNewValues(),
  760. // ).
  761. // Exec(ctx)
  762. func (u *AuthIdentityUpsertBulk) UpdateNewValues() *AuthIdentityUpsertBulk {
  763. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  764. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  765. for _, b := range u.create.builders {
  766. if _, exists := b.mutation.CreatedAt(); exists {
  767. s.SetIgnore(authidentity.FieldCreatedAt)
  768. }
  769. }
  770. }))
  771. return u
  772. }
  773. // Ignore sets each column to itself in case of conflict.
  774. // Using this option is equivalent to using:
  775. //
  776. // client.AuthIdentity.Create().
  777. // OnConflict(sql.ResolveWithIgnore()).
  778. // Exec(ctx)
  779. func (u *AuthIdentityUpsertBulk) Ignore() *AuthIdentityUpsertBulk {
  780. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  781. return u
  782. }
  783. // DoNothing configures the conflict_action to `DO NOTHING`.
  784. // Supported only by SQLite and PostgreSQL.
  785. func (u *AuthIdentityUpsertBulk) DoNothing() *AuthIdentityUpsertBulk {
  786. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  787. return u
  788. }
  789. // Update allows overriding fields `UPDATE` values. See the AuthIdentityCreateBulk.OnConflict
  790. // documentation for more info.
  791. func (u *AuthIdentityUpsertBulk) Update(set func(*AuthIdentityUpsert)) *AuthIdentityUpsertBulk {
  792. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  793. set(&AuthIdentityUpsert{UpdateSet: update})
  794. }))
  795. return u
  796. }
  797. // SetUpdatedAt sets the "updated_at" field.
  798. func (u *AuthIdentityUpsertBulk) SetUpdatedAt(v time.Time) *AuthIdentityUpsertBulk {
  799. return u.Update(func(s *AuthIdentityUpsert) {
  800. s.SetUpdatedAt(v)
  801. })
  802. }
  803. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  804. func (u *AuthIdentityUpsertBulk) UpdateUpdatedAt() *AuthIdentityUpsertBulk {
  805. return u.Update(func(s *AuthIdentityUpsert) {
  806. s.UpdateUpdatedAt()
  807. })
  808. }
  809. // SetUserID sets the "user_id" field.
  810. func (u *AuthIdentityUpsertBulk) SetUserID(v int64) *AuthIdentityUpsertBulk {
  811. return u.Update(func(s *AuthIdentityUpsert) {
  812. s.SetUserID(v)
  813. })
  814. }
  815. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  816. func (u *AuthIdentityUpsertBulk) UpdateUserID() *AuthIdentityUpsertBulk {
  817. return u.Update(func(s *AuthIdentityUpsert) {
  818. s.UpdateUserID()
  819. })
  820. }
  821. // SetProviderType sets the "provider_type" field.
  822. func (u *AuthIdentityUpsertBulk) SetProviderType(v string) *AuthIdentityUpsertBulk {
  823. return u.Update(func(s *AuthIdentityUpsert) {
  824. s.SetProviderType(v)
  825. })
  826. }
  827. // UpdateProviderType sets the "provider_type" field to the value that was provided on create.
  828. func (u *AuthIdentityUpsertBulk) UpdateProviderType() *AuthIdentityUpsertBulk {
  829. return u.Update(func(s *AuthIdentityUpsert) {
  830. s.UpdateProviderType()
  831. })
  832. }
  833. // SetProviderKey sets the "provider_key" field.
  834. func (u *AuthIdentityUpsertBulk) SetProviderKey(v string) *AuthIdentityUpsertBulk {
  835. return u.Update(func(s *AuthIdentityUpsert) {
  836. s.SetProviderKey(v)
  837. })
  838. }
  839. // UpdateProviderKey sets the "provider_key" field to the value that was provided on create.
  840. func (u *AuthIdentityUpsertBulk) UpdateProviderKey() *AuthIdentityUpsertBulk {
  841. return u.Update(func(s *AuthIdentityUpsert) {
  842. s.UpdateProviderKey()
  843. })
  844. }
  845. // SetProviderSubject sets the "provider_subject" field.
  846. func (u *AuthIdentityUpsertBulk) SetProviderSubject(v string) *AuthIdentityUpsertBulk {
  847. return u.Update(func(s *AuthIdentityUpsert) {
  848. s.SetProviderSubject(v)
  849. })
  850. }
  851. // UpdateProviderSubject sets the "provider_subject" field to the value that was provided on create.
  852. func (u *AuthIdentityUpsertBulk) UpdateProviderSubject() *AuthIdentityUpsertBulk {
  853. return u.Update(func(s *AuthIdentityUpsert) {
  854. s.UpdateProviderSubject()
  855. })
  856. }
  857. // SetVerifiedAt sets the "verified_at" field.
  858. func (u *AuthIdentityUpsertBulk) SetVerifiedAt(v time.Time) *AuthIdentityUpsertBulk {
  859. return u.Update(func(s *AuthIdentityUpsert) {
  860. s.SetVerifiedAt(v)
  861. })
  862. }
  863. // UpdateVerifiedAt sets the "verified_at" field to the value that was provided on create.
  864. func (u *AuthIdentityUpsertBulk) UpdateVerifiedAt() *AuthIdentityUpsertBulk {
  865. return u.Update(func(s *AuthIdentityUpsert) {
  866. s.UpdateVerifiedAt()
  867. })
  868. }
  869. // ClearVerifiedAt clears the value of the "verified_at" field.
  870. func (u *AuthIdentityUpsertBulk) ClearVerifiedAt() *AuthIdentityUpsertBulk {
  871. return u.Update(func(s *AuthIdentityUpsert) {
  872. s.ClearVerifiedAt()
  873. })
  874. }
  875. // SetIssuer sets the "issuer" field.
  876. func (u *AuthIdentityUpsertBulk) SetIssuer(v string) *AuthIdentityUpsertBulk {
  877. return u.Update(func(s *AuthIdentityUpsert) {
  878. s.SetIssuer(v)
  879. })
  880. }
  881. // UpdateIssuer sets the "issuer" field to the value that was provided on create.
  882. func (u *AuthIdentityUpsertBulk) UpdateIssuer() *AuthIdentityUpsertBulk {
  883. return u.Update(func(s *AuthIdentityUpsert) {
  884. s.UpdateIssuer()
  885. })
  886. }
  887. // ClearIssuer clears the value of the "issuer" field.
  888. func (u *AuthIdentityUpsertBulk) ClearIssuer() *AuthIdentityUpsertBulk {
  889. return u.Update(func(s *AuthIdentityUpsert) {
  890. s.ClearIssuer()
  891. })
  892. }
  893. // SetMetadata sets the "metadata" field.
  894. func (u *AuthIdentityUpsertBulk) SetMetadata(v map[string]interface{}) *AuthIdentityUpsertBulk {
  895. return u.Update(func(s *AuthIdentityUpsert) {
  896. s.SetMetadata(v)
  897. })
  898. }
  899. // UpdateMetadata sets the "metadata" field to the value that was provided on create.
  900. func (u *AuthIdentityUpsertBulk) UpdateMetadata() *AuthIdentityUpsertBulk {
  901. return u.Update(func(s *AuthIdentityUpsert) {
  902. s.UpdateMetadata()
  903. })
  904. }
  905. // Exec executes the query.
  906. func (u *AuthIdentityUpsertBulk) Exec(ctx context.Context) error {
  907. if u.create.err != nil {
  908. return u.create.err
  909. }
  910. for i, b := range u.create.builders {
  911. if len(b.conflict) != 0 {
  912. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AuthIdentityCreateBulk instead", i)
  913. }
  914. }
  915. if len(u.create.conflict) == 0 {
  916. return errors.New("ent: missing options for AuthIdentityCreateBulk.OnConflict")
  917. }
  918. return u.create.Exec(ctx)
  919. }
  920. // ExecX is like Exec, but panics if an error occurs.
  921. func (u *AuthIdentityUpsertBulk) ExecX(ctx context.Context) {
  922. if err := u.create.Exec(ctx); err != nil {
  923. panic(err)
  924. }
  925. }