securitypolicykeyword_create.go 29 KB

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