authidentitychannel_create.go 31 KB

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