identityadoptiondecision_create.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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/identityadoptiondecision"
  13. "github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
  14. )
  15. // IdentityAdoptionDecisionCreate is the builder for creating a IdentityAdoptionDecision entity.
  16. type IdentityAdoptionDecisionCreate struct {
  17. config
  18. mutation *IdentityAdoptionDecisionMutation
  19. hooks []Hook
  20. conflict []sql.ConflictOption
  21. }
  22. // SetCreatedAt sets the "created_at" field.
  23. func (_c *IdentityAdoptionDecisionCreate) SetCreatedAt(v time.Time) *IdentityAdoptionDecisionCreate {
  24. _c.mutation.SetCreatedAt(v)
  25. return _c
  26. }
  27. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  28. func (_c *IdentityAdoptionDecisionCreate) SetNillableCreatedAt(v *time.Time) *IdentityAdoptionDecisionCreate {
  29. if v != nil {
  30. _c.SetCreatedAt(*v)
  31. }
  32. return _c
  33. }
  34. // SetUpdatedAt sets the "updated_at" field.
  35. func (_c *IdentityAdoptionDecisionCreate) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionCreate {
  36. _c.mutation.SetUpdatedAt(v)
  37. return _c
  38. }
  39. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  40. func (_c *IdentityAdoptionDecisionCreate) SetNillableUpdatedAt(v *time.Time) *IdentityAdoptionDecisionCreate {
  41. if v != nil {
  42. _c.SetUpdatedAt(*v)
  43. }
  44. return _c
  45. }
  46. // SetPendingAuthSessionID sets the "pending_auth_session_id" field.
  47. func (_c *IdentityAdoptionDecisionCreate) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionCreate {
  48. _c.mutation.SetPendingAuthSessionID(v)
  49. return _c
  50. }
  51. // SetIdentityID sets the "identity_id" field.
  52. func (_c *IdentityAdoptionDecisionCreate) SetIdentityID(v int64) *IdentityAdoptionDecisionCreate {
  53. _c.mutation.SetIdentityID(v)
  54. return _c
  55. }
  56. // SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
  57. func (_c *IdentityAdoptionDecisionCreate) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionCreate {
  58. if v != nil {
  59. _c.SetIdentityID(*v)
  60. }
  61. return _c
  62. }
  63. // SetAdoptDisplayName sets the "adopt_display_name" field.
  64. func (_c *IdentityAdoptionDecisionCreate) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionCreate {
  65. _c.mutation.SetAdoptDisplayName(v)
  66. return _c
  67. }
  68. // SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil.
  69. func (_c *IdentityAdoptionDecisionCreate) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionCreate {
  70. if v != nil {
  71. _c.SetAdoptDisplayName(*v)
  72. }
  73. return _c
  74. }
  75. // SetAdoptAvatar sets the "adopt_avatar" field.
  76. func (_c *IdentityAdoptionDecisionCreate) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionCreate {
  77. _c.mutation.SetAdoptAvatar(v)
  78. return _c
  79. }
  80. // SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil.
  81. func (_c *IdentityAdoptionDecisionCreate) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionCreate {
  82. if v != nil {
  83. _c.SetAdoptAvatar(*v)
  84. }
  85. return _c
  86. }
  87. // SetDecidedAt sets the "decided_at" field.
  88. func (_c *IdentityAdoptionDecisionCreate) SetDecidedAt(v time.Time) *IdentityAdoptionDecisionCreate {
  89. _c.mutation.SetDecidedAt(v)
  90. return _c
  91. }
  92. // SetNillableDecidedAt sets the "decided_at" field if the given value is not nil.
  93. func (_c *IdentityAdoptionDecisionCreate) SetNillableDecidedAt(v *time.Time) *IdentityAdoptionDecisionCreate {
  94. if v != nil {
  95. _c.SetDecidedAt(*v)
  96. }
  97. return _c
  98. }
  99. // SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity.
  100. func (_c *IdentityAdoptionDecisionCreate) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionCreate {
  101. return _c.SetPendingAuthSessionID(v.ID)
  102. }
  103. // SetIdentity sets the "identity" edge to the AuthIdentity entity.
  104. func (_c *IdentityAdoptionDecisionCreate) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionCreate {
  105. return _c.SetIdentityID(v.ID)
  106. }
  107. // Mutation returns the IdentityAdoptionDecisionMutation object of the builder.
  108. func (_c *IdentityAdoptionDecisionCreate) Mutation() *IdentityAdoptionDecisionMutation {
  109. return _c.mutation
  110. }
  111. // Save creates the IdentityAdoptionDecision in the database.
  112. func (_c *IdentityAdoptionDecisionCreate) Save(ctx context.Context) (*IdentityAdoptionDecision, error) {
  113. _c.defaults()
  114. return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
  115. }
  116. // SaveX calls Save and panics if Save returns an error.
  117. func (_c *IdentityAdoptionDecisionCreate) SaveX(ctx context.Context) *IdentityAdoptionDecision {
  118. v, err := _c.Save(ctx)
  119. if err != nil {
  120. panic(err)
  121. }
  122. return v
  123. }
  124. // Exec executes the query.
  125. func (_c *IdentityAdoptionDecisionCreate) Exec(ctx context.Context) error {
  126. _, err := _c.Save(ctx)
  127. return err
  128. }
  129. // ExecX is like Exec, but panics if an error occurs.
  130. func (_c *IdentityAdoptionDecisionCreate) ExecX(ctx context.Context) {
  131. if err := _c.Exec(ctx); err != nil {
  132. panic(err)
  133. }
  134. }
  135. // defaults sets the default values of the builder before save.
  136. func (_c *IdentityAdoptionDecisionCreate) defaults() {
  137. if _, ok := _c.mutation.CreatedAt(); !ok {
  138. v := identityadoptiondecision.DefaultCreatedAt()
  139. _c.mutation.SetCreatedAt(v)
  140. }
  141. if _, ok := _c.mutation.UpdatedAt(); !ok {
  142. v := identityadoptiondecision.DefaultUpdatedAt()
  143. _c.mutation.SetUpdatedAt(v)
  144. }
  145. if _, ok := _c.mutation.AdoptDisplayName(); !ok {
  146. v := identityadoptiondecision.DefaultAdoptDisplayName
  147. _c.mutation.SetAdoptDisplayName(v)
  148. }
  149. if _, ok := _c.mutation.AdoptAvatar(); !ok {
  150. v := identityadoptiondecision.DefaultAdoptAvatar
  151. _c.mutation.SetAdoptAvatar(v)
  152. }
  153. if _, ok := _c.mutation.DecidedAt(); !ok {
  154. v := identityadoptiondecision.DefaultDecidedAt()
  155. _c.mutation.SetDecidedAt(v)
  156. }
  157. }
  158. // check runs all checks and user-defined validators on the builder.
  159. func (_c *IdentityAdoptionDecisionCreate) check() error {
  160. if _, ok := _c.mutation.CreatedAt(); !ok {
  161. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.created_at"`)}
  162. }
  163. if _, ok := _c.mutation.UpdatedAt(); !ok {
  164. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.updated_at"`)}
  165. }
  166. if _, ok := _c.mutation.PendingAuthSessionID(); !ok {
  167. return &ValidationError{Name: "pending_auth_session_id", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.pending_auth_session_id"`)}
  168. }
  169. if _, ok := _c.mutation.AdoptDisplayName(); !ok {
  170. return &ValidationError{Name: "adopt_display_name", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.adopt_display_name"`)}
  171. }
  172. if _, ok := _c.mutation.AdoptAvatar(); !ok {
  173. return &ValidationError{Name: "adopt_avatar", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.adopt_avatar"`)}
  174. }
  175. if _, ok := _c.mutation.DecidedAt(); !ok {
  176. return &ValidationError{Name: "decided_at", err: errors.New(`ent: missing required field "IdentityAdoptionDecision.decided_at"`)}
  177. }
  178. if len(_c.mutation.PendingAuthSessionIDs()) == 0 {
  179. return &ValidationError{Name: "pending_auth_session", err: errors.New(`ent: missing required edge "IdentityAdoptionDecision.pending_auth_session"`)}
  180. }
  181. return nil
  182. }
  183. func (_c *IdentityAdoptionDecisionCreate) sqlSave(ctx context.Context) (*IdentityAdoptionDecision, error) {
  184. if err := _c.check(); err != nil {
  185. return nil, err
  186. }
  187. _node, _spec := _c.createSpec()
  188. if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
  189. if sqlgraph.IsConstraintError(err) {
  190. err = &ConstraintError{msg: err.Error(), wrap: err}
  191. }
  192. return nil, err
  193. }
  194. id := _spec.ID.Value.(int64)
  195. _node.ID = int64(id)
  196. _c.mutation.id = &_node.ID
  197. _c.mutation.done = true
  198. return _node, nil
  199. }
  200. func (_c *IdentityAdoptionDecisionCreate) createSpec() (*IdentityAdoptionDecision, *sqlgraph.CreateSpec) {
  201. var (
  202. _node = &IdentityAdoptionDecision{config: _c.config}
  203. _spec = sqlgraph.NewCreateSpec(identityadoptiondecision.Table, sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64))
  204. )
  205. _spec.OnConflict = _c.conflict
  206. if value, ok := _c.mutation.CreatedAt(); ok {
  207. _spec.SetField(identityadoptiondecision.FieldCreatedAt, field.TypeTime, value)
  208. _node.CreatedAt = value
  209. }
  210. if value, ok := _c.mutation.UpdatedAt(); ok {
  211. _spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value)
  212. _node.UpdatedAt = value
  213. }
  214. if value, ok := _c.mutation.AdoptDisplayName(); ok {
  215. _spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value)
  216. _node.AdoptDisplayName = value
  217. }
  218. if value, ok := _c.mutation.AdoptAvatar(); ok {
  219. _spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value)
  220. _node.AdoptAvatar = value
  221. }
  222. if value, ok := _c.mutation.DecidedAt(); ok {
  223. _spec.SetField(identityadoptiondecision.FieldDecidedAt, field.TypeTime, value)
  224. _node.DecidedAt = value
  225. }
  226. if nodes := _c.mutation.PendingAuthSessionIDs(); len(nodes) > 0 {
  227. edge := &sqlgraph.EdgeSpec{
  228. Rel: sqlgraph.O2O,
  229. Inverse: true,
  230. Table: identityadoptiondecision.PendingAuthSessionTable,
  231. Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
  232. Bidi: false,
  233. Target: &sqlgraph.EdgeTarget{
  234. IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
  235. },
  236. }
  237. for _, k := range nodes {
  238. edge.Target.Nodes = append(edge.Target.Nodes, k)
  239. }
  240. _node.PendingAuthSessionID = nodes[0]
  241. _spec.Edges = append(_spec.Edges, edge)
  242. }
  243. if nodes := _c.mutation.IdentityIDs(); len(nodes) > 0 {
  244. edge := &sqlgraph.EdgeSpec{
  245. Rel: sqlgraph.M2O,
  246. Inverse: true,
  247. Table: identityadoptiondecision.IdentityTable,
  248. Columns: []string{identityadoptiondecision.IdentityColumn},
  249. Bidi: false,
  250. Target: &sqlgraph.EdgeTarget{
  251. IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
  252. },
  253. }
  254. for _, k := range nodes {
  255. edge.Target.Nodes = append(edge.Target.Nodes, k)
  256. }
  257. _node.IdentityID = &nodes[0]
  258. _spec.Edges = append(_spec.Edges, edge)
  259. }
  260. return _node, _spec
  261. }
  262. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  263. // of the `INSERT` statement. For example:
  264. //
  265. // client.IdentityAdoptionDecision.Create().
  266. // SetCreatedAt(v).
  267. // OnConflict(
  268. // // Update the row with the new values
  269. // // the was proposed for insertion.
  270. // sql.ResolveWithNewValues(),
  271. // ).
  272. // // Override some of the fields with custom
  273. // // update values.
  274. // Update(func(u *ent.IdentityAdoptionDecisionUpsert) {
  275. // SetCreatedAt(v+v).
  276. // }).
  277. // Exec(ctx)
  278. func (_c *IdentityAdoptionDecisionCreate) OnConflict(opts ...sql.ConflictOption) *IdentityAdoptionDecisionUpsertOne {
  279. _c.conflict = opts
  280. return &IdentityAdoptionDecisionUpsertOne{
  281. create: _c,
  282. }
  283. }
  284. // OnConflictColumns calls `OnConflict` and configures the columns
  285. // as conflict target. Using this option is equivalent to using:
  286. //
  287. // client.IdentityAdoptionDecision.Create().
  288. // OnConflict(sql.ConflictColumns(columns...)).
  289. // Exec(ctx)
  290. func (_c *IdentityAdoptionDecisionCreate) OnConflictColumns(columns ...string) *IdentityAdoptionDecisionUpsertOne {
  291. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  292. return &IdentityAdoptionDecisionUpsertOne{
  293. create: _c,
  294. }
  295. }
  296. type (
  297. // IdentityAdoptionDecisionUpsertOne is the builder for "upsert"-ing
  298. // one IdentityAdoptionDecision node.
  299. IdentityAdoptionDecisionUpsertOne struct {
  300. create *IdentityAdoptionDecisionCreate
  301. }
  302. // IdentityAdoptionDecisionUpsert is the "OnConflict" setter.
  303. IdentityAdoptionDecisionUpsert struct {
  304. *sql.UpdateSet
  305. }
  306. )
  307. // SetUpdatedAt sets the "updated_at" field.
  308. func (u *IdentityAdoptionDecisionUpsert) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsert {
  309. u.Set(identityadoptiondecision.FieldUpdatedAt, v)
  310. return u
  311. }
  312. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  313. func (u *IdentityAdoptionDecisionUpsert) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsert {
  314. u.SetExcluded(identityadoptiondecision.FieldUpdatedAt)
  315. return u
  316. }
  317. // SetPendingAuthSessionID sets the "pending_auth_session_id" field.
  318. func (u *IdentityAdoptionDecisionUpsert) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsert {
  319. u.Set(identityadoptiondecision.FieldPendingAuthSessionID, v)
  320. return u
  321. }
  322. // UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create.
  323. func (u *IdentityAdoptionDecisionUpsert) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsert {
  324. u.SetExcluded(identityadoptiondecision.FieldPendingAuthSessionID)
  325. return u
  326. }
  327. // SetIdentityID sets the "identity_id" field.
  328. func (u *IdentityAdoptionDecisionUpsert) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsert {
  329. u.Set(identityadoptiondecision.FieldIdentityID, v)
  330. return u
  331. }
  332. // UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
  333. func (u *IdentityAdoptionDecisionUpsert) UpdateIdentityID() *IdentityAdoptionDecisionUpsert {
  334. u.SetExcluded(identityadoptiondecision.FieldIdentityID)
  335. return u
  336. }
  337. // ClearIdentityID clears the value of the "identity_id" field.
  338. func (u *IdentityAdoptionDecisionUpsert) ClearIdentityID() *IdentityAdoptionDecisionUpsert {
  339. u.SetNull(identityadoptiondecision.FieldIdentityID)
  340. return u
  341. }
  342. // SetAdoptDisplayName sets the "adopt_display_name" field.
  343. func (u *IdentityAdoptionDecisionUpsert) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsert {
  344. u.Set(identityadoptiondecision.FieldAdoptDisplayName, v)
  345. return u
  346. }
  347. // UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create.
  348. func (u *IdentityAdoptionDecisionUpsert) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsert {
  349. u.SetExcluded(identityadoptiondecision.FieldAdoptDisplayName)
  350. return u
  351. }
  352. // SetAdoptAvatar sets the "adopt_avatar" field.
  353. func (u *IdentityAdoptionDecisionUpsert) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsert {
  354. u.Set(identityadoptiondecision.FieldAdoptAvatar, v)
  355. return u
  356. }
  357. // UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create.
  358. func (u *IdentityAdoptionDecisionUpsert) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsert {
  359. u.SetExcluded(identityadoptiondecision.FieldAdoptAvatar)
  360. return u
  361. }
  362. // UpdateNewValues updates the mutable fields using the new values that were set on create.
  363. // Using this option is equivalent to using:
  364. //
  365. // client.IdentityAdoptionDecision.Create().
  366. // OnConflict(
  367. // sql.ResolveWithNewValues(),
  368. // ).
  369. // Exec(ctx)
  370. func (u *IdentityAdoptionDecisionUpsertOne) UpdateNewValues() *IdentityAdoptionDecisionUpsertOne {
  371. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  372. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  373. if _, exists := u.create.mutation.CreatedAt(); exists {
  374. s.SetIgnore(identityadoptiondecision.FieldCreatedAt)
  375. }
  376. if _, exists := u.create.mutation.DecidedAt(); exists {
  377. s.SetIgnore(identityadoptiondecision.FieldDecidedAt)
  378. }
  379. }))
  380. return u
  381. }
  382. // Ignore sets each column to itself in case of conflict.
  383. // Using this option is equivalent to using:
  384. //
  385. // client.IdentityAdoptionDecision.Create().
  386. // OnConflict(sql.ResolveWithIgnore()).
  387. // Exec(ctx)
  388. func (u *IdentityAdoptionDecisionUpsertOne) Ignore() *IdentityAdoptionDecisionUpsertOne {
  389. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  390. return u
  391. }
  392. // DoNothing configures the conflict_action to `DO NOTHING`.
  393. // Supported only by SQLite and PostgreSQL.
  394. func (u *IdentityAdoptionDecisionUpsertOne) DoNothing() *IdentityAdoptionDecisionUpsertOne {
  395. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  396. return u
  397. }
  398. // Update allows overriding fields `UPDATE` values. See the IdentityAdoptionDecisionCreate.OnConflict
  399. // documentation for more info.
  400. func (u *IdentityAdoptionDecisionUpsertOne) Update(set func(*IdentityAdoptionDecisionUpsert)) *IdentityAdoptionDecisionUpsertOne {
  401. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  402. set(&IdentityAdoptionDecisionUpsert{UpdateSet: update})
  403. }))
  404. return u
  405. }
  406. // SetUpdatedAt sets the "updated_at" field.
  407. func (u *IdentityAdoptionDecisionUpsertOne) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsertOne {
  408. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  409. s.SetUpdatedAt(v)
  410. })
  411. }
  412. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  413. func (u *IdentityAdoptionDecisionUpsertOne) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsertOne {
  414. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  415. s.UpdateUpdatedAt()
  416. })
  417. }
  418. // SetPendingAuthSessionID sets the "pending_auth_session_id" field.
  419. func (u *IdentityAdoptionDecisionUpsertOne) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsertOne {
  420. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  421. s.SetPendingAuthSessionID(v)
  422. })
  423. }
  424. // UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create.
  425. func (u *IdentityAdoptionDecisionUpsertOne) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsertOne {
  426. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  427. s.UpdatePendingAuthSessionID()
  428. })
  429. }
  430. // SetIdentityID sets the "identity_id" field.
  431. func (u *IdentityAdoptionDecisionUpsertOne) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsertOne {
  432. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  433. s.SetIdentityID(v)
  434. })
  435. }
  436. // UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
  437. func (u *IdentityAdoptionDecisionUpsertOne) UpdateIdentityID() *IdentityAdoptionDecisionUpsertOne {
  438. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  439. s.UpdateIdentityID()
  440. })
  441. }
  442. // ClearIdentityID clears the value of the "identity_id" field.
  443. func (u *IdentityAdoptionDecisionUpsertOne) ClearIdentityID() *IdentityAdoptionDecisionUpsertOne {
  444. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  445. s.ClearIdentityID()
  446. })
  447. }
  448. // SetAdoptDisplayName sets the "adopt_display_name" field.
  449. func (u *IdentityAdoptionDecisionUpsertOne) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsertOne {
  450. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  451. s.SetAdoptDisplayName(v)
  452. })
  453. }
  454. // UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create.
  455. func (u *IdentityAdoptionDecisionUpsertOne) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsertOne {
  456. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  457. s.UpdateAdoptDisplayName()
  458. })
  459. }
  460. // SetAdoptAvatar sets the "adopt_avatar" field.
  461. func (u *IdentityAdoptionDecisionUpsertOne) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsertOne {
  462. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  463. s.SetAdoptAvatar(v)
  464. })
  465. }
  466. // UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create.
  467. func (u *IdentityAdoptionDecisionUpsertOne) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsertOne {
  468. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  469. s.UpdateAdoptAvatar()
  470. })
  471. }
  472. // Exec executes the query.
  473. func (u *IdentityAdoptionDecisionUpsertOne) Exec(ctx context.Context) error {
  474. if len(u.create.conflict) == 0 {
  475. return errors.New("ent: missing options for IdentityAdoptionDecisionCreate.OnConflict")
  476. }
  477. return u.create.Exec(ctx)
  478. }
  479. // ExecX is like Exec, but panics if an error occurs.
  480. func (u *IdentityAdoptionDecisionUpsertOne) ExecX(ctx context.Context) {
  481. if err := u.create.Exec(ctx); err != nil {
  482. panic(err)
  483. }
  484. }
  485. // Exec executes the UPSERT query and returns the inserted/updated ID.
  486. func (u *IdentityAdoptionDecisionUpsertOne) ID(ctx context.Context) (id int64, err error) {
  487. node, err := u.create.Save(ctx)
  488. if err != nil {
  489. return id, err
  490. }
  491. return node.ID, nil
  492. }
  493. // IDX is like ID, but panics if an error occurs.
  494. func (u *IdentityAdoptionDecisionUpsertOne) IDX(ctx context.Context) int64 {
  495. id, err := u.ID(ctx)
  496. if err != nil {
  497. panic(err)
  498. }
  499. return id
  500. }
  501. // IdentityAdoptionDecisionCreateBulk is the builder for creating many IdentityAdoptionDecision entities in bulk.
  502. type IdentityAdoptionDecisionCreateBulk struct {
  503. config
  504. err error
  505. builders []*IdentityAdoptionDecisionCreate
  506. conflict []sql.ConflictOption
  507. }
  508. // Save creates the IdentityAdoptionDecision entities in the database.
  509. func (_c *IdentityAdoptionDecisionCreateBulk) Save(ctx context.Context) ([]*IdentityAdoptionDecision, error) {
  510. if _c.err != nil {
  511. return nil, _c.err
  512. }
  513. specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
  514. nodes := make([]*IdentityAdoptionDecision, len(_c.builders))
  515. mutators := make([]Mutator, len(_c.builders))
  516. for i := range _c.builders {
  517. func(i int, root context.Context) {
  518. builder := _c.builders[i]
  519. builder.defaults()
  520. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  521. mutation, ok := m.(*IdentityAdoptionDecisionMutation)
  522. if !ok {
  523. return nil, fmt.Errorf("unexpected mutation type %T", m)
  524. }
  525. if err := builder.check(); err != nil {
  526. return nil, err
  527. }
  528. builder.mutation = mutation
  529. var err error
  530. nodes[i], specs[i] = builder.createSpec()
  531. if i < len(mutators)-1 {
  532. _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
  533. } else {
  534. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  535. spec.OnConflict = _c.conflict
  536. // Invoke the actual operation on the latest mutation in the chain.
  537. if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
  538. if sqlgraph.IsConstraintError(err) {
  539. err = &ConstraintError{msg: err.Error(), wrap: err}
  540. }
  541. }
  542. }
  543. if err != nil {
  544. return nil, err
  545. }
  546. mutation.id = &nodes[i].ID
  547. if specs[i].ID.Value != nil {
  548. id := specs[i].ID.Value.(int64)
  549. nodes[i].ID = int64(id)
  550. }
  551. mutation.done = true
  552. return nodes[i], nil
  553. })
  554. for i := len(builder.hooks) - 1; i >= 0; i-- {
  555. mut = builder.hooks[i](mut)
  556. }
  557. mutators[i] = mut
  558. }(i, ctx)
  559. }
  560. if len(mutators) > 0 {
  561. if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
  562. return nil, err
  563. }
  564. }
  565. return nodes, nil
  566. }
  567. // SaveX is like Save, but panics if an error occurs.
  568. func (_c *IdentityAdoptionDecisionCreateBulk) SaveX(ctx context.Context) []*IdentityAdoptionDecision {
  569. v, err := _c.Save(ctx)
  570. if err != nil {
  571. panic(err)
  572. }
  573. return v
  574. }
  575. // Exec executes the query.
  576. func (_c *IdentityAdoptionDecisionCreateBulk) Exec(ctx context.Context) error {
  577. _, err := _c.Save(ctx)
  578. return err
  579. }
  580. // ExecX is like Exec, but panics if an error occurs.
  581. func (_c *IdentityAdoptionDecisionCreateBulk) ExecX(ctx context.Context) {
  582. if err := _c.Exec(ctx); err != nil {
  583. panic(err)
  584. }
  585. }
  586. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  587. // of the `INSERT` statement. For example:
  588. //
  589. // client.IdentityAdoptionDecision.CreateBulk(builders...).
  590. // OnConflict(
  591. // // Update the row with the new values
  592. // // the was proposed for insertion.
  593. // sql.ResolveWithNewValues(),
  594. // ).
  595. // // Override some of the fields with custom
  596. // // update values.
  597. // Update(func(u *ent.IdentityAdoptionDecisionUpsert) {
  598. // SetCreatedAt(v+v).
  599. // }).
  600. // Exec(ctx)
  601. func (_c *IdentityAdoptionDecisionCreateBulk) OnConflict(opts ...sql.ConflictOption) *IdentityAdoptionDecisionUpsertBulk {
  602. _c.conflict = opts
  603. return &IdentityAdoptionDecisionUpsertBulk{
  604. create: _c,
  605. }
  606. }
  607. // OnConflictColumns calls `OnConflict` and configures the columns
  608. // as conflict target. Using this option is equivalent to using:
  609. //
  610. // client.IdentityAdoptionDecision.Create().
  611. // OnConflict(sql.ConflictColumns(columns...)).
  612. // Exec(ctx)
  613. func (_c *IdentityAdoptionDecisionCreateBulk) OnConflictColumns(columns ...string) *IdentityAdoptionDecisionUpsertBulk {
  614. _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
  615. return &IdentityAdoptionDecisionUpsertBulk{
  616. create: _c,
  617. }
  618. }
  619. // IdentityAdoptionDecisionUpsertBulk is the builder for "upsert"-ing
  620. // a bulk of IdentityAdoptionDecision nodes.
  621. type IdentityAdoptionDecisionUpsertBulk struct {
  622. create *IdentityAdoptionDecisionCreateBulk
  623. }
  624. // UpdateNewValues updates the mutable fields using the new values that
  625. // were set on create. Using this option is equivalent to using:
  626. //
  627. // client.IdentityAdoptionDecision.Create().
  628. // OnConflict(
  629. // sql.ResolveWithNewValues(),
  630. // ).
  631. // Exec(ctx)
  632. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateNewValues() *IdentityAdoptionDecisionUpsertBulk {
  633. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  634. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  635. for _, b := range u.create.builders {
  636. if _, exists := b.mutation.CreatedAt(); exists {
  637. s.SetIgnore(identityadoptiondecision.FieldCreatedAt)
  638. }
  639. if _, exists := b.mutation.DecidedAt(); exists {
  640. s.SetIgnore(identityadoptiondecision.FieldDecidedAt)
  641. }
  642. }
  643. }))
  644. return u
  645. }
  646. // Ignore sets each column to itself in case of conflict.
  647. // Using this option is equivalent to using:
  648. //
  649. // client.IdentityAdoptionDecision.Create().
  650. // OnConflict(sql.ResolveWithIgnore()).
  651. // Exec(ctx)
  652. func (u *IdentityAdoptionDecisionUpsertBulk) Ignore() *IdentityAdoptionDecisionUpsertBulk {
  653. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  654. return u
  655. }
  656. // DoNothing configures the conflict_action to `DO NOTHING`.
  657. // Supported only by SQLite and PostgreSQL.
  658. func (u *IdentityAdoptionDecisionUpsertBulk) DoNothing() *IdentityAdoptionDecisionUpsertBulk {
  659. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  660. return u
  661. }
  662. // Update allows overriding fields `UPDATE` values. See the IdentityAdoptionDecisionCreateBulk.OnConflict
  663. // documentation for more info.
  664. func (u *IdentityAdoptionDecisionUpsertBulk) Update(set func(*IdentityAdoptionDecisionUpsert)) *IdentityAdoptionDecisionUpsertBulk {
  665. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  666. set(&IdentityAdoptionDecisionUpsert{UpdateSet: update})
  667. }))
  668. return u
  669. }
  670. // SetUpdatedAt sets the "updated_at" field.
  671. func (u *IdentityAdoptionDecisionUpsertBulk) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpsertBulk {
  672. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  673. s.SetUpdatedAt(v)
  674. })
  675. }
  676. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  677. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateUpdatedAt() *IdentityAdoptionDecisionUpsertBulk {
  678. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  679. s.UpdateUpdatedAt()
  680. })
  681. }
  682. // SetPendingAuthSessionID sets the "pending_auth_session_id" field.
  683. func (u *IdentityAdoptionDecisionUpsertBulk) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpsertBulk {
  684. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  685. s.SetPendingAuthSessionID(v)
  686. })
  687. }
  688. // UpdatePendingAuthSessionID sets the "pending_auth_session_id" field to the value that was provided on create.
  689. func (u *IdentityAdoptionDecisionUpsertBulk) UpdatePendingAuthSessionID() *IdentityAdoptionDecisionUpsertBulk {
  690. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  691. s.UpdatePendingAuthSessionID()
  692. })
  693. }
  694. // SetIdentityID sets the "identity_id" field.
  695. func (u *IdentityAdoptionDecisionUpsertBulk) SetIdentityID(v int64) *IdentityAdoptionDecisionUpsertBulk {
  696. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  697. s.SetIdentityID(v)
  698. })
  699. }
  700. // UpdateIdentityID sets the "identity_id" field to the value that was provided on create.
  701. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateIdentityID() *IdentityAdoptionDecisionUpsertBulk {
  702. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  703. s.UpdateIdentityID()
  704. })
  705. }
  706. // ClearIdentityID clears the value of the "identity_id" field.
  707. func (u *IdentityAdoptionDecisionUpsertBulk) ClearIdentityID() *IdentityAdoptionDecisionUpsertBulk {
  708. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  709. s.ClearIdentityID()
  710. })
  711. }
  712. // SetAdoptDisplayName sets the "adopt_display_name" field.
  713. func (u *IdentityAdoptionDecisionUpsertBulk) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpsertBulk {
  714. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  715. s.SetAdoptDisplayName(v)
  716. })
  717. }
  718. // UpdateAdoptDisplayName sets the "adopt_display_name" field to the value that was provided on create.
  719. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateAdoptDisplayName() *IdentityAdoptionDecisionUpsertBulk {
  720. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  721. s.UpdateAdoptDisplayName()
  722. })
  723. }
  724. // SetAdoptAvatar sets the "adopt_avatar" field.
  725. func (u *IdentityAdoptionDecisionUpsertBulk) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpsertBulk {
  726. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  727. s.SetAdoptAvatar(v)
  728. })
  729. }
  730. // UpdateAdoptAvatar sets the "adopt_avatar" field to the value that was provided on create.
  731. func (u *IdentityAdoptionDecisionUpsertBulk) UpdateAdoptAvatar() *IdentityAdoptionDecisionUpsertBulk {
  732. return u.Update(func(s *IdentityAdoptionDecisionUpsert) {
  733. s.UpdateAdoptAvatar()
  734. })
  735. }
  736. // Exec executes the query.
  737. func (u *IdentityAdoptionDecisionUpsertBulk) Exec(ctx context.Context) error {
  738. if u.create.err != nil {
  739. return u.create.err
  740. }
  741. for i, b := range u.create.builders {
  742. if len(b.conflict) != 0 {
  743. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the IdentityAdoptionDecisionCreateBulk instead", i)
  744. }
  745. }
  746. if len(u.create.conflict) == 0 {
  747. return errors.New("ent: missing options for IdentityAdoptionDecisionCreateBulk.OnConflict")
  748. }
  749. return u.create.Exec(ctx)
  750. }
  751. // ExecX is like Exec, but panics if an error occurs.
  752. func (u *IdentityAdoptionDecisionUpsertBulk) ExecX(ctx context.Context) {
  753. if err := u.create.Exec(ctx); err != nil {
  754. panic(err)
  755. }
  756. }