creditusage_create.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/creditusage"
  9. "entgo.io/ent/dialect/sql"
  10. "entgo.io/ent/dialect/sql/sqlgraph"
  11. "entgo.io/ent/schema/field"
  12. )
  13. // CreditUsageCreate is the builder for creating a CreditUsage entity.
  14. type CreditUsageCreate struct {
  15. config
  16. mutation *CreditUsageMutation
  17. hooks []Hook
  18. conflict []sql.ConflictOption
  19. }
  20. // SetCreatedAt sets the "created_at" field.
  21. func (cuc *CreditUsageCreate) SetCreatedAt(t time.Time) *CreditUsageCreate {
  22. cuc.mutation.SetCreatedAt(t)
  23. return cuc
  24. }
  25. // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
  26. func (cuc *CreditUsageCreate) SetNillableCreatedAt(t *time.Time) *CreditUsageCreate {
  27. if t != nil {
  28. cuc.SetCreatedAt(*t)
  29. }
  30. return cuc
  31. }
  32. // SetUpdatedAt sets the "updated_at" field.
  33. func (cuc *CreditUsageCreate) SetUpdatedAt(t time.Time) *CreditUsageCreate {
  34. cuc.mutation.SetUpdatedAt(t)
  35. return cuc
  36. }
  37. // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
  38. func (cuc *CreditUsageCreate) SetNillableUpdatedAt(t *time.Time) *CreditUsageCreate {
  39. if t != nil {
  40. cuc.SetUpdatedAt(*t)
  41. }
  42. return cuc
  43. }
  44. // SetDeletedAt sets the "deleted_at" field.
  45. func (cuc *CreditUsageCreate) SetDeletedAt(t time.Time) *CreditUsageCreate {
  46. cuc.mutation.SetDeletedAt(t)
  47. return cuc
  48. }
  49. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  50. func (cuc *CreditUsageCreate) SetNillableDeletedAt(t *time.Time) *CreditUsageCreate {
  51. if t != nil {
  52. cuc.SetDeletedAt(*t)
  53. }
  54. return cuc
  55. }
  56. // SetUserID sets the "user_id" field.
  57. func (cuc *CreditUsageCreate) SetUserID(s string) *CreditUsageCreate {
  58. cuc.mutation.SetUserID(s)
  59. return cuc
  60. }
  61. // SetNumber sets the "number" field.
  62. func (cuc *CreditUsageCreate) SetNumber(f float32) *CreditUsageCreate {
  63. cuc.mutation.SetNumber(f)
  64. return cuc
  65. }
  66. // SetStatus sets the "status" field.
  67. func (cuc *CreditUsageCreate) SetStatus(i int) *CreditUsageCreate {
  68. cuc.mutation.SetStatus(i)
  69. return cuc
  70. }
  71. // SetNillableStatus sets the "status" field if the given value is not nil.
  72. func (cuc *CreditUsageCreate) SetNillableStatus(i *int) *CreditUsageCreate {
  73. if i != nil {
  74. cuc.SetStatus(*i)
  75. }
  76. return cuc
  77. }
  78. // SetNtype sets the "ntype" field.
  79. func (cuc *CreditUsageCreate) SetNtype(i int) *CreditUsageCreate {
  80. cuc.mutation.SetNtype(i)
  81. return cuc
  82. }
  83. // SetNillableNtype sets the "ntype" field if the given value is not nil.
  84. func (cuc *CreditUsageCreate) SetNillableNtype(i *int) *CreditUsageCreate {
  85. if i != nil {
  86. cuc.SetNtype(*i)
  87. }
  88. return cuc
  89. }
  90. // SetTable sets the "table" field.
  91. func (cuc *CreditUsageCreate) SetTable(s string) *CreditUsageCreate {
  92. cuc.mutation.SetTable(s)
  93. return cuc
  94. }
  95. // SetNillableTable sets the "table" field if the given value is not nil.
  96. func (cuc *CreditUsageCreate) SetNillableTable(s *string) *CreditUsageCreate {
  97. if s != nil {
  98. cuc.SetTable(*s)
  99. }
  100. return cuc
  101. }
  102. // SetOrganizationID sets the "organization_id" field.
  103. func (cuc *CreditUsageCreate) SetOrganizationID(u uint64) *CreditUsageCreate {
  104. cuc.mutation.SetOrganizationID(u)
  105. return cuc
  106. }
  107. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  108. func (cuc *CreditUsageCreate) SetNillableOrganizationID(u *uint64) *CreditUsageCreate {
  109. if u != nil {
  110. cuc.SetOrganizationID(*u)
  111. }
  112. return cuc
  113. }
  114. // SetNid sets the "nid" field.
  115. func (cuc *CreditUsageCreate) SetNid(u uint64) *CreditUsageCreate {
  116. cuc.mutation.SetNid(u)
  117. return cuc
  118. }
  119. // SetNillableNid sets the "nid" field if the given value is not nil.
  120. func (cuc *CreditUsageCreate) SetNillableNid(u *uint64) *CreditUsageCreate {
  121. if u != nil {
  122. cuc.SetNid(*u)
  123. }
  124. return cuc
  125. }
  126. // SetReason sets the "reason" field.
  127. func (cuc *CreditUsageCreate) SetReason(s string) *CreditUsageCreate {
  128. cuc.mutation.SetReason(s)
  129. return cuc
  130. }
  131. // SetNillableReason sets the "reason" field if the given value is not nil.
  132. func (cuc *CreditUsageCreate) SetNillableReason(s *string) *CreditUsageCreate {
  133. if s != nil {
  134. cuc.SetReason(*s)
  135. }
  136. return cuc
  137. }
  138. // SetOperator sets the "operator" field.
  139. func (cuc *CreditUsageCreate) SetOperator(s string) *CreditUsageCreate {
  140. cuc.mutation.SetOperator(s)
  141. return cuc
  142. }
  143. // SetNillableOperator sets the "operator" field if the given value is not nil.
  144. func (cuc *CreditUsageCreate) SetNillableOperator(s *string) *CreditUsageCreate {
  145. if s != nil {
  146. cuc.SetOperator(*s)
  147. }
  148. return cuc
  149. }
  150. // SetID sets the "id" field.
  151. func (cuc *CreditUsageCreate) SetID(u uint64) *CreditUsageCreate {
  152. cuc.mutation.SetID(u)
  153. return cuc
  154. }
  155. // Mutation returns the CreditUsageMutation object of the builder.
  156. func (cuc *CreditUsageCreate) Mutation() *CreditUsageMutation {
  157. return cuc.mutation
  158. }
  159. // Save creates the CreditUsage in the database.
  160. func (cuc *CreditUsageCreate) Save(ctx context.Context) (*CreditUsage, error) {
  161. if err := cuc.defaults(); err != nil {
  162. return nil, err
  163. }
  164. return withHooks(ctx, cuc.sqlSave, cuc.mutation, cuc.hooks)
  165. }
  166. // SaveX calls Save and panics if Save returns an error.
  167. func (cuc *CreditUsageCreate) SaveX(ctx context.Context) *CreditUsage {
  168. v, err := cuc.Save(ctx)
  169. if err != nil {
  170. panic(err)
  171. }
  172. return v
  173. }
  174. // Exec executes the query.
  175. func (cuc *CreditUsageCreate) Exec(ctx context.Context) error {
  176. _, err := cuc.Save(ctx)
  177. return err
  178. }
  179. // ExecX is like Exec, but panics if an error occurs.
  180. func (cuc *CreditUsageCreate) ExecX(ctx context.Context) {
  181. if err := cuc.Exec(ctx); err != nil {
  182. panic(err)
  183. }
  184. }
  185. // defaults sets the default values of the builder before save.
  186. func (cuc *CreditUsageCreate) defaults() error {
  187. if _, ok := cuc.mutation.CreatedAt(); !ok {
  188. if creditusage.DefaultCreatedAt == nil {
  189. return fmt.Errorf("ent: uninitialized creditusage.DefaultCreatedAt (forgotten import ent/runtime?)")
  190. }
  191. v := creditusage.DefaultCreatedAt()
  192. cuc.mutation.SetCreatedAt(v)
  193. }
  194. if _, ok := cuc.mutation.UpdatedAt(); !ok {
  195. if creditusage.DefaultUpdatedAt == nil {
  196. return fmt.Errorf("ent: uninitialized creditusage.DefaultUpdatedAt (forgotten import ent/runtime?)")
  197. }
  198. v := creditusage.DefaultUpdatedAt()
  199. cuc.mutation.SetUpdatedAt(v)
  200. }
  201. if _, ok := cuc.mutation.Status(); !ok {
  202. v := creditusage.DefaultStatus
  203. cuc.mutation.SetStatus(v)
  204. }
  205. if _, ok := cuc.mutation.Ntype(); !ok {
  206. v := creditusage.DefaultNtype
  207. cuc.mutation.SetNtype(v)
  208. }
  209. if _, ok := cuc.mutation.Table(); !ok {
  210. v := creditusage.DefaultTable
  211. cuc.mutation.SetTable(v)
  212. }
  213. if _, ok := cuc.mutation.Nid(); !ok {
  214. v := creditusage.DefaultNid
  215. cuc.mutation.SetNid(v)
  216. }
  217. if _, ok := cuc.mutation.Reason(); !ok {
  218. v := creditusage.DefaultReason
  219. cuc.mutation.SetReason(v)
  220. }
  221. if _, ok := cuc.mutation.Operator(); !ok {
  222. v := creditusage.DefaultOperator
  223. cuc.mutation.SetOperator(v)
  224. }
  225. return nil
  226. }
  227. // check runs all checks and user-defined validators on the builder.
  228. func (cuc *CreditUsageCreate) check() error {
  229. if _, ok := cuc.mutation.CreatedAt(); !ok {
  230. return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "CreditUsage.created_at"`)}
  231. }
  232. if _, ok := cuc.mutation.UpdatedAt(); !ok {
  233. return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "CreditUsage.updated_at"`)}
  234. }
  235. if _, ok := cuc.mutation.UserID(); !ok {
  236. return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "CreditUsage.user_id"`)}
  237. }
  238. if v, ok := cuc.mutation.UserID(); ok {
  239. if err := creditusage.UserIDValidator(v); err != nil {
  240. return &ValidationError{Name: "user_id", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.user_id": %w`, err)}
  241. }
  242. }
  243. if _, ok := cuc.mutation.Number(); !ok {
  244. return &ValidationError{Name: "number", err: errors.New(`ent: missing required field "CreditUsage.number"`)}
  245. }
  246. if v, ok := cuc.mutation.Status(); ok {
  247. if err := creditusage.StatusValidator(v); err != nil {
  248. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.status": %w`, err)}
  249. }
  250. }
  251. if _, ok := cuc.mutation.Ntype(); !ok {
  252. return &ValidationError{Name: "ntype", err: errors.New(`ent: missing required field "CreditUsage.ntype"`)}
  253. }
  254. if _, ok := cuc.mutation.Table(); !ok {
  255. return &ValidationError{Name: "table", err: errors.New(`ent: missing required field "CreditUsage.table"`)}
  256. }
  257. if _, ok := cuc.mutation.Nid(); !ok {
  258. return &ValidationError{Name: "nid", err: errors.New(`ent: missing required field "CreditUsage.nid"`)}
  259. }
  260. if _, ok := cuc.mutation.Reason(); !ok {
  261. return &ValidationError{Name: "reason", err: errors.New(`ent: missing required field "CreditUsage.reason"`)}
  262. }
  263. if v, ok := cuc.mutation.Reason(); ok {
  264. if err := creditusage.ReasonValidator(v); err != nil {
  265. return &ValidationError{Name: "reason", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.reason": %w`, err)}
  266. }
  267. }
  268. if _, ok := cuc.mutation.Operator(); !ok {
  269. return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "CreditUsage.operator"`)}
  270. }
  271. if v, ok := cuc.mutation.Operator(); ok {
  272. if err := creditusage.OperatorValidator(v); err != nil {
  273. return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "CreditUsage.operator": %w`, err)}
  274. }
  275. }
  276. return nil
  277. }
  278. func (cuc *CreditUsageCreate) sqlSave(ctx context.Context) (*CreditUsage, error) {
  279. if err := cuc.check(); err != nil {
  280. return nil, err
  281. }
  282. _node, _spec := cuc.createSpec()
  283. if err := sqlgraph.CreateNode(ctx, cuc.driver, _spec); err != nil {
  284. if sqlgraph.IsConstraintError(err) {
  285. err = &ConstraintError{msg: err.Error(), wrap: err}
  286. }
  287. return nil, err
  288. }
  289. if _spec.ID.Value != _node.ID {
  290. id := _spec.ID.Value.(int64)
  291. _node.ID = uint64(id)
  292. }
  293. cuc.mutation.id = &_node.ID
  294. cuc.mutation.done = true
  295. return _node, nil
  296. }
  297. func (cuc *CreditUsageCreate) createSpec() (*CreditUsage, *sqlgraph.CreateSpec) {
  298. var (
  299. _node = &CreditUsage{config: cuc.config}
  300. _spec = sqlgraph.NewCreateSpec(creditusage.Table, sqlgraph.NewFieldSpec(creditusage.FieldID, field.TypeUint64))
  301. )
  302. _spec.OnConflict = cuc.conflict
  303. if id, ok := cuc.mutation.ID(); ok {
  304. _node.ID = id
  305. _spec.ID.Value = id
  306. }
  307. if value, ok := cuc.mutation.CreatedAt(); ok {
  308. _spec.SetField(creditusage.FieldCreatedAt, field.TypeTime, value)
  309. _node.CreatedAt = value
  310. }
  311. if value, ok := cuc.mutation.UpdatedAt(); ok {
  312. _spec.SetField(creditusage.FieldUpdatedAt, field.TypeTime, value)
  313. _node.UpdatedAt = value
  314. }
  315. if value, ok := cuc.mutation.DeletedAt(); ok {
  316. _spec.SetField(creditusage.FieldDeletedAt, field.TypeTime, value)
  317. _node.DeletedAt = value
  318. }
  319. if value, ok := cuc.mutation.UserID(); ok {
  320. _spec.SetField(creditusage.FieldUserID, field.TypeString, value)
  321. _node.UserID = value
  322. }
  323. if value, ok := cuc.mutation.Number(); ok {
  324. _spec.SetField(creditusage.FieldNumber, field.TypeFloat32, value)
  325. _node.Number = value
  326. }
  327. if value, ok := cuc.mutation.Status(); ok {
  328. _spec.SetField(creditusage.FieldStatus, field.TypeInt, value)
  329. _node.Status = value
  330. }
  331. if value, ok := cuc.mutation.Ntype(); ok {
  332. _spec.SetField(creditusage.FieldNtype, field.TypeInt, value)
  333. _node.Ntype = value
  334. }
  335. if value, ok := cuc.mutation.Table(); ok {
  336. _spec.SetField(creditusage.FieldTable, field.TypeString, value)
  337. _node.Table = value
  338. }
  339. if value, ok := cuc.mutation.OrganizationID(); ok {
  340. _spec.SetField(creditusage.FieldOrganizationID, field.TypeUint64, value)
  341. _node.OrganizationID = value
  342. }
  343. if value, ok := cuc.mutation.Nid(); ok {
  344. _spec.SetField(creditusage.FieldNid, field.TypeUint64, value)
  345. _node.Nid = value
  346. }
  347. if value, ok := cuc.mutation.Reason(); ok {
  348. _spec.SetField(creditusage.FieldReason, field.TypeString, value)
  349. _node.Reason = value
  350. }
  351. if value, ok := cuc.mutation.Operator(); ok {
  352. _spec.SetField(creditusage.FieldOperator, field.TypeString, value)
  353. _node.Operator = value
  354. }
  355. return _node, _spec
  356. }
  357. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  358. // of the `INSERT` statement. For example:
  359. //
  360. // client.CreditUsage.Create().
  361. // SetCreatedAt(v).
  362. // OnConflict(
  363. // // Update the row with the new values
  364. // // the was proposed for insertion.
  365. // sql.ResolveWithNewValues(),
  366. // ).
  367. // // Override some of the fields with custom
  368. // // update values.
  369. // Update(func(u *ent.CreditUsageUpsert) {
  370. // SetCreatedAt(v+v).
  371. // }).
  372. // Exec(ctx)
  373. func (cuc *CreditUsageCreate) OnConflict(opts ...sql.ConflictOption) *CreditUsageUpsertOne {
  374. cuc.conflict = opts
  375. return &CreditUsageUpsertOne{
  376. create: cuc,
  377. }
  378. }
  379. // OnConflictColumns calls `OnConflict` and configures the columns
  380. // as conflict target. Using this option is equivalent to using:
  381. //
  382. // client.CreditUsage.Create().
  383. // OnConflict(sql.ConflictColumns(columns...)).
  384. // Exec(ctx)
  385. func (cuc *CreditUsageCreate) OnConflictColumns(columns ...string) *CreditUsageUpsertOne {
  386. cuc.conflict = append(cuc.conflict, sql.ConflictColumns(columns...))
  387. return &CreditUsageUpsertOne{
  388. create: cuc,
  389. }
  390. }
  391. type (
  392. // CreditUsageUpsertOne is the builder for "upsert"-ing
  393. // one CreditUsage node.
  394. CreditUsageUpsertOne struct {
  395. create *CreditUsageCreate
  396. }
  397. // CreditUsageUpsert is the "OnConflict" setter.
  398. CreditUsageUpsert struct {
  399. *sql.UpdateSet
  400. }
  401. )
  402. // SetUpdatedAt sets the "updated_at" field.
  403. func (u *CreditUsageUpsert) SetUpdatedAt(v time.Time) *CreditUsageUpsert {
  404. u.Set(creditusage.FieldUpdatedAt, v)
  405. return u
  406. }
  407. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  408. func (u *CreditUsageUpsert) UpdateUpdatedAt() *CreditUsageUpsert {
  409. u.SetExcluded(creditusage.FieldUpdatedAt)
  410. return u
  411. }
  412. // SetDeletedAt sets the "deleted_at" field.
  413. func (u *CreditUsageUpsert) SetDeletedAt(v time.Time) *CreditUsageUpsert {
  414. u.Set(creditusage.FieldDeletedAt, v)
  415. return u
  416. }
  417. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  418. func (u *CreditUsageUpsert) UpdateDeletedAt() *CreditUsageUpsert {
  419. u.SetExcluded(creditusage.FieldDeletedAt)
  420. return u
  421. }
  422. // ClearDeletedAt clears the value of the "deleted_at" field.
  423. func (u *CreditUsageUpsert) ClearDeletedAt() *CreditUsageUpsert {
  424. u.SetNull(creditusage.FieldDeletedAt)
  425. return u
  426. }
  427. // SetUserID sets the "user_id" field.
  428. func (u *CreditUsageUpsert) SetUserID(v string) *CreditUsageUpsert {
  429. u.Set(creditusage.FieldUserID, v)
  430. return u
  431. }
  432. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  433. func (u *CreditUsageUpsert) UpdateUserID() *CreditUsageUpsert {
  434. u.SetExcluded(creditusage.FieldUserID)
  435. return u
  436. }
  437. // SetNumber sets the "number" field.
  438. func (u *CreditUsageUpsert) SetNumber(v float32) *CreditUsageUpsert {
  439. u.Set(creditusage.FieldNumber, v)
  440. return u
  441. }
  442. // UpdateNumber sets the "number" field to the value that was provided on create.
  443. func (u *CreditUsageUpsert) UpdateNumber() *CreditUsageUpsert {
  444. u.SetExcluded(creditusage.FieldNumber)
  445. return u
  446. }
  447. // AddNumber adds v to the "number" field.
  448. func (u *CreditUsageUpsert) AddNumber(v float32) *CreditUsageUpsert {
  449. u.Add(creditusage.FieldNumber, v)
  450. return u
  451. }
  452. // SetStatus sets the "status" field.
  453. func (u *CreditUsageUpsert) SetStatus(v int) *CreditUsageUpsert {
  454. u.Set(creditusage.FieldStatus, v)
  455. return u
  456. }
  457. // UpdateStatus sets the "status" field to the value that was provided on create.
  458. func (u *CreditUsageUpsert) UpdateStatus() *CreditUsageUpsert {
  459. u.SetExcluded(creditusage.FieldStatus)
  460. return u
  461. }
  462. // AddStatus adds v to the "status" field.
  463. func (u *CreditUsageUpsert) AddStatus(v int) *CreditUsageUpsert {
  464. u.Add(creditusage.FieldStatus, v)
  465. return u
  466. }
  467. // ClearStatus clears the value of the "status" field.
  468. func (u *CreditUsageUpsert) ClearStatus() *CreditUsageUpsert {
  469. u.SetNull(creditusage.FieldStatus)
  470. return u
  471. }
  472. // SetNtype sets the "ntype" field.
  473. func (u *CreditUsageUpsert) SetNtype(v int) *CreditUsageUpsert {
  474. u.Set(creditusage.FieldNtype, v)
  475. return u
  476. }
  477. // UpdateNtype sets the "ntype" field to the value that was provided on create.
  478. func (u *CreditUsageUpsert) UpdateNtype() *CreditUsageUpsert {
  479. u.SetExcluded(creditusage.FieldNtype)
  480. return u
  481. }
  482. // AddNtype adds v to the "ntype" field.
  483. func (u *CreditUsageUpsert) AddNtype(v int) *CreditUsageUpsert {
  484. u.Add(creditusage.FieldNtype, v)
  485. return u
  486. }
  487. // SetTable sets the "table" field.
  488. func (u *CreditUsageUpsert) SetTable(v string) *CreditUsageUpsert {
  489. u.Set(creditusage.FieldTable, v)
  490. return u
  491. }
  492. // UpdateTable sets the "table" field to the value that was provided on create.
  493. func (u *CreditUsageUpsert) UpdateTable() *CreditUsageUpsert {
  494. u.SetExcluded(creditusage.FieldTable)
  495. return u
  496. }
  497. // SetOrganizationID sets the "organization_id" field.
  498. func (u *CreditUsageUpsert) SetOrganizationID(v uint64) *CreditUsageUpsert {
  499. u.Set(creditusage.FieldOrganizationID, v)
  500. return u
  501. }
  502. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  503. func (u *CreditUsageUpsert) UpdateOrganizationID() *CreditUsageUpsert {
  504. u.SetExcluded(creditusage.FieldOrganizationID)
  505. return u
  506. }
  507. // AddOrganizationID adds v to the "organization_id" field.
  508. func (u *CreditUsageUpsert) AddOrganizationID(v uint64) *CreditUsageUpsert {
  509. u.Add(creditusage.FieldOrganizationID, v)
  510. return u
  511. }
  512. // ClearOrganizationID clears the value of the "organization_id" field.
  513. func (u *CreditUsageUpsert) ClearOrganizationID() *CreditUsageUpsert {
  514. u.SetNull(creditusage.FieldOrganizationID)
  515. return u
  516. }
  517. // SetNid sets the "nid" field.
  518. func (u *CreditUsageUpsert) SetNid(v uint64) *CreditUsageUpsert {
  519. u.Set(creditusage.FieldNid, v)
  520. return u
  521. }
  522. // UpdateNid sets the "nid" field to the value that was provided on create.
  523. func (u *CreditUsageUpsert) UpdateNid() *CreditUsageUpsert {
  524. u.SetExcluded(creditusage.FieldNid)
  525. return u
  526. }
  527. // AddNid adds v to the "nid" field.
  528. func (u *CreditUsageUpsert) AddNid(v uint64) *CreditUsageUpsert {
  529. u.Add(creditusage.FieldNid, v)
  530. return u
  531. }
  532. // SetReason sets the "reason" field.
  533. func (u *CreditUsageUpsert) SetReason(v string) *CreditUsageUpsert {
  534. u.Set(creditusage.FieldReason, v)
  535. return u
  536. }
  537. // UpdateReason sets the "reason" field to the value that was provided on create.
  538. func (u *CreditUsageUpsert) UpdateReason() *CreditUsageUpsert {
  539. u.SetExcluded(creditusage.FieldReason)
  540. return u
  541. }
  542. // SetOperator sets the "operator" field.
  543. func (u *CreditUsageUpsert) SetOperator(v string) *CreditUsageUpsert {
  544. u.Set(creditusage.FieldOperator, v)
  545. return u
  546. }
  547. // UpdateOperator sets the "operator" field to the value that was provided on create.
  548. func (u *CreditUsageUpsert) UpdateOperator() *CreditUsageUpsert {
  549. u.SetExcluded(creditusage.FieldOperator)
  550. return u
  551. }
  552. // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
  553. // Using this option is equivalent to using:
  554. //
  555. // client.CreditUsage.Create().
  556. // OnConflict(
  557. // sql.ResolveWithNewValues(),
  558. // sql.ResolveWith(func(u *sql.UpdateSet) {
  559. // u.SetIgnore(creditusage.FieldID)
  560. // }),
  561. // ).
  562. // Exec(ctx)
  563. func (u *CreditUsageUpsertOne) UpdateNewValues() *CreditUsageUpsertOne {
  564. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  565. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  566. if _, exists := u.create.mutation.ID(); exists {
  567. s.SetIgnore(creditusage.FieldID)
  568. }
  569. if _, exists := u.create.mutation.CreatedAt(); exists {
  570. s.SetIgnore(creditusage.FieldCreatedAt)
  571. }
  572. }))
  573. return u
  574. }
  575. // Ignore sets each column to itself in case of conflict.
  576. // Using this option is equivalent to using:
  577. //
  578. // client.CreditUsage.Create().
  579. // OnConflict(sql.ResolveWithIgnore()).
  580. // Exec(ctx)
  581. func (u *CreditUsageUpsertOne) Ignore() *CreditUsageUpsertOne {
  582. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  583. return u
  584. }
  585. // DoNothing configures the conflict_action to `DO NOTHING`.
  586. // Supported only by SQLite and PostgreSQL.
  587. func (u *CreditUsageUpsertOne) DoNothing() *CreditUsageUpsertOne {
  588. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  589. return u
  590. }
  591. // Update allows overriding fields `UPDATE` values. See the CreditUsageCreate.OnConflict
  592. // documentation for more info.
  593. func (u *CreditUsageUpsertOne) Update(set func(*CreditUsageUpsert)) *CreditUsageUpsertOne {
  594. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  595. set(&CreditUsageUpsert{UpdateSet: update})
  596. }))
  597. return u
  598. }
  599. // SetUpdatedAt sets the "updated_at" field.
  600. func (u *CreditUsageUpsertOne) SetUpdatedAt(v time.Time) *CreditUsageUpsertOne {
  601. return u.Update(func(s *CreditUsageUpsert) {
  602. s.SetUpdatedAt(v)
  603. })
  604. }
  605. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  606. func (u *CreditUsageUpsertOne) UpdateUpdatedAt() *CreditUsageUpsertOne {
  607. return u.Update(func(s *CreditUsageUpsert) {
  608. s.UpdateUpdatedAt()
  609. })
  610. }
  611. // SetDeletedAt sets the "deleted_at" field.
  612. func (u *CreditUsageUpsertOne) SetDeletedAt(v time.Time) *CreditUsageUpsertOne {
  613. return u.Update(func(s *CreditUsageUpsert) {
  614. s.SetDeletedAt(v)
  615. })
  616. }
  617. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  618. func (u *CreditUsageUpsertOne) UpdateDeletedAt() *CreditUsageUpsertOne {
  619. return u.Update(func(s *CreditUsageUpsert) {
  620. s.UpdateDeletedAt()
  621. })
  622. }
  623. // ClearDeletedAt clears the value of the "deleted_at" field.
  624. func (u *CreditUsageUpsertOne) ClearDeletedAt() *CreditUsageUpsertOne {
  625. return u.Update(func(s *CreditUsageUpsert) {
  626. s.ClearDeletedAt()
  627. })
  628. }
  629. // SetUserID sets the "user_id" field.
  630. func (u *CreditUsageUpsertOne) SetUserID(v string) *CreditUsageUpsertOne {
  631. return u.Update(func(s *CreditUsageUpsert) {
  632. s.SetUserID(v)
  633. })
  634. }
  635. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  636. func (u *CreditUsageUpsertOne) UpdateUserID() *CreditUsageUpsertOne {
  637. return u.Update(func(s *CreditUsageUpsert) {
  638. s.UpdateUserID()
  639. })
  640. }
  641. // SetNumber sets the "number" field.
  642. func (u *CreditUsageUpsertOne) SetNumber(v float32) *CreditUsageUpsertOne {
  643. return u.Update(func(s *CreditUsageUpsert) {
  644. s.SetNumber(v)
  645. })
  646. }
  647. // AddNumber adds v to the "number" field.
  648. func (u *CreditUsageUpsertOne) AddNumber(v float32) *CreditUsageUpsertOne {
  649. return u.Update(func(s *CreditUsageUpsert) {
  650. s.AddNumber(v)
  651. })
  652. }
  653. // UpdateNumber sets the "number" field to the value that was provided on create.
  654. func (u *CreditUsageUpsertOne) UpdateNumber() *CreditUsageUpsertOne {
  655. return u.Update(func(s *CreditUsageUpsert) {
  656. s.UpdateNumber()
  657. })
  658. }
  659. // SetStatus sets the "status" field.
  660. func (u *CreditUsageUpsertOne) SetStatus(v int) *CreditUsageUpsertOne {
  661. return u.Update(func(s *CreditUsageUpsert) {
  662. s.SetStatus(v)
  663. })
  664. }
  665. // AddStatus adds v to the "status" field.
  666. func (u *CreditUsageUpsertOne) AddStatus(v int) *CreditUsageUpsertOne {
  667. return u.Update(func(s *CreditUsageUpsert) {
  668. s.AddStatus(v)
  669. })
  670. }
  671. // UpdateStatus sets the "status" field to the value that was provided on create.
  672. func (u *CreditUsageUpsertOne) UpdateStatus() *CreditUsageUpsertOne {
  673. return u.Update(func(s *CreditUsageUpsert) {
  674. s.UpdateStatus()
  675. })
  676. }
  677. // ClearStatus clears the value of the "status" field.
  678. func (u *CreditUsageUpsertOne) ClearStatus() *CreditUsageUpsertOne {
  679. return u.Update(func(s *CreditUsageUpsert) {
  680. s.ClearStatus()
  681. })
  682. }
  683. // SetNtype sets the "ntype" field.
  684. func (u *CreditUsageUpsertOne) SetNtype(v int) *CreditUsageUpsertOne {
  685. return u.Update(func(s *CreditUsageUpsert) {
  686. s.SetNtype(v)
  687. })
  688. }
  689. // AddNtype adds v to the "ntype" field.
  690. func (u *CreditUsageUpsertOne) AddNtype(v int) *CreditUsageUpsertOne {
  691. return u.Update(func(s *CreditUsageUpsert) {
  692. s.AddNtype(v)
  693. })
  694. }
  695. // UpdateNtype sets the "ntype" field to the value that was provided on create.
  696. func (u *CreditUsageUpsertOne) UpdateNtype() *CreditUsageUpsertOne {
  697. return u.Update(func(s *CreditUsageUpsert) {
  698. s.UpdateNtype()
  699. })
  700. }
  701. // SetTable sets the "table" field.
  702. func (u *CreditUsageUpsertOne) SetTable(v string) *CreditUsageUpsertOne {
  703. return u.Update(func(s *CreditUsageUpsert) {
  704. s.SetTable(v)
  705. })
  706. }
  707. // UpdateTable sets the "table" field to the value that was provided on create.
  708. func (u *CreditUsageUpsertOne) UpdateTable() *CreditUsageUpsertOne {
  709. return u.Update(func(s *CreditUsageUpsert) {
  710. s.UpdateTable()
  711. })
  712. }
  713. // SetOrganizationID sets the "organization_id" field.
  714. func (u *CreditUsageUpsertOne) SetOrganizationID(v uint64) *CreditUsageUpsertOne {
  715. return u.Update(func(s *CreditUsageUpsert) {
  716. s.SetOrganizationID(v)
  717. })
  718. }
  719. // AddOrganizationID adds v to the "organization_id" field.
  720. func (u *CreditUsageUpsertOne) AddOrganizationID(v uint64) *CreditUsageUpsertOne {
  721. return u.Update(func(s *CreditUsageUpsert) {
  722. s.AddOrganizationID(v)
  723. })
  724. }
  725. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  726. func (u *CreditUsageUpsertOne) UpdateOrganizationID() *CreditUsageUpsertOne {
  727. return u.Update(func(s *CreditUsageUpsert) {
  728. s.UpdateOrganizationID()
  729. })
  730. }
  731. // ClearOrganizationID clears the value of the "organization_id" field.
  732. func (u *CreditUsageUpsertOne) ClearOrganizationID() *CreditUsageUpsertOne {
  733. return u.Update(func(s *CreditUsageUpsert) {
  734. s.ClearOrganizationID()
  735. })
  736. }
  737. // SetNid sets the "nid" field.
  738. func (u *CreditUsageUpsertOne) SetNid(v uint64) *CreditUsageUpsertOne {
  739. return u.Update(func(s *CreditUsageUpsert) {
  740. s.SetNid(v)
  741. })
  742. }
  743. // AddNid adds v to the "nid" field.
  744. func (u *CreditUsageUpsertOne) AddNid(v uint64) *CreditUsageUpsertOne {
  745. return u.Update(func(s *CreditUsageUpsert) {
  746. s.AddNid(v)
  747. })
  748. }
  749. // UpdateNid sets the "nid" field to the value that was provided on create.
  750. func (u *CreditUsageUpsertOne) UpdateNid() *CreditUsageUpsertOne {
  751. return u.Update(func(s *CreditUsageUpsert) {
  752. s.UpdateNid()
  753. })
  754. }
  755. // SetReason sets the "reason" field.
  756. func (u *CreditUsageUpsertOne) SetReason(v string) *CreditUsageUpsertOne {
  757. return u.Update(func(s *CreditUsageUpsert) {
  758. s.SetReason(v)
  759. })
  760. }
  761. // UpdateReason sets the "reason" field to the value that was provided on create.
  762. func (u *CreditUsageUpsertOne) UpdateReason() *CreditUsageUpsertOne {
  763. return u.Update(func(s *CreditUsageUpsert) {
  764. s.UpdateReason()
  765. })
  766. }
  767. // SetOperator sets the "operator" field.
  768. func (u *CreditUsageUpsertOne) SetOperator(v string) *CreditUsageUpsertOne {
  769. return u.Update(func(s *CreditUsageUpsert) {
  770. s.SetOperator(v)
  771. })
  772. }
  773. // UpdateOperator sets the "operator" field to the value that was provided on create.
  774. func (u *CreditUsageUpsertOne) UpdateOperator() *CreditUsageUpsertOne {
  775. return u.Update(func(s *CreditUsageUpsert) {
  776. s.UpdateOperator()
  777. })
  778. }
  779. // Exec executes the query.
  780. func (u *CreditUsageUpsertOne) Exec(ctx context.Context) error {
  781. if len(u.create.conflict) == 0 {
  782. return errors.New("ent: missing options for CreditUsageCreate.OnConflict")
  783. }
  784. return u.create.Exec(ctx)
  785. }
  786. // ExecX is like Exec, but panics if an error occurs.
  787. func (u *CreditUsageUpsertOne) ExecX(ctx context.Context) {
  788. if err := u.create.Exec(ctx); err != nil {
  789. panic(err)
  790. }
  791. }
  792. // Exec executes the UPSERT query and returns the inserted/updated ID.
  793. func (u *CreditUsageUpsertOne) ID(ctx context.Context) (id uint64, err error) {
  794. node, err := u.create.Save(ctx)
  795. if err != nil {
  796. return id, err
  797. }
  798. return node.ID, nil
  799. }
  800. // IDX is like ID, but panics if an error occurs.
  801. func (u *CreditUsageUpsertOne) IDX(ctx context.Context) uint64 {
  802. id, err := u.ID(ctx)
  803. if err != nil {
  804. panic(err)
  805. }
  806. return id
  807. }
  808. // CreditUsageCreateBulk is the builder for creating many CreditUsage entities in bulk.
  809. type CreditUsageCreateBulk struct {
  810. config
  811. err error
  812. builders []*CreditUsageCreate
  813. conflict []sql.ConflictOption
  814. }
  815. // Save creates the CreditUsage entities in the database.
  816. func (cucb *CreditUsageCreateBulk) Save(ctx context.Context) ([]*CreditUsage, error) {
  817. if cucb.err != nil {
  818. return nil, cucb.err
  819. }
  820. specs := make([]*sqlgraph.CreateSpec, len(cucb.builders))
  821. nodes := make([]*CreditUsage, len(cucb.builders))
  822. mutators := make([]Mutator, len(cucb.builders))
  823. for i := range cucb.builders {
  824. func(i int, root context.Context) {
  825. builder := cucb.builders[i]
  826. builder.defaults()
  827. var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
  828. mutation, ok := m.(*CreditUsageMutation)
  829. if !ok {
  830. return nil, fmt.Errorf("unexpected mutation type %T", m)
  831. }
  832. if err := builder.check(); err != nil {
  833. return nil, err
  834. }
  835. builder.mutation = mutation
  836. var err error
  837. nodes[i], specs[i] = builder.createSpec()
  838. if i < len(mutators)-1 {
  839. _, err = mutators[i+1].Mutate(root, cucb.builders[i+1].mutation)
  840. } else {
  841. spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
  842. spec.OnConflict = cucb.conflict
  843. // Invoke the actual operation on the latest mutation in the chain.
  844. if err = sqlgraph.BatchCreate(ctx, cucb.driver, spec); err != nil {
  845. if sqlgraph.IsConstraintError(err) {
  846. err = &ConstraintError{msg: err.Error(), wrap: err}
  847. }
  848. }
  849. }
  850. if err != nil {
  851. return nil, err
  852. }
  853. mutation.id = &nodes[i].ID
  854. if specs[i].ID.Value != nil && nodes[i].ID == 0 {
  855. id := specs[i].ID.Value.(int64)
  856. nodes[i].ID = uint64(id)
  857. }
  858. mutation.done = true
  859. return nodes[i], nil
  860. })
  861. for i := len(builder.hooks) - 1; i >= 0; i-- {
  862. mut = builder.hooks[i](mut)
  863. }
  864. mutators[i] = mut
  865. }(i, ctx)
  866. }
  867. if len(mutators) > 0 {
  868. if _, err := mutators[0].Mutate(ctx, cucb.builders[0].mutation); err != nil {
  869. return nil, err
  870. }
  871. }
  872. return nodes, nil
  873. }
  874. // SaveX is like Save, but panics if an error occurs.
  875. func (cucb *CreditUsageCreateBulk) SaveX(ctx context.Context) []*CreditUsage {
  876. v, err := cucb.Save(ctx)
  877. if err != nil {
  878. panic(err)
  879. }
  880. return v
  881. }
  882. // Exec executes the query.
  883. func (cucb *CreditUsageCreateBulk) Exec(ctx context.Context) error {
  884. _, err := cucb.Save(ctx)
  885. return err
  886. }
  887. // ExecX is like Exec, but panics if an error occurs.
  888. func (cucb *CreditUsageCreateBulk) ExecX(ctx context.Context) {
  889. if err := cucb.Exec(ctx); err != nil {
  890. panic(err)
  891. }
  892. }
  893. // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
  894. // of the `INSERT` statement. For example:
  895. //
  896. // client.CreditUsage.CreateBulk(builders...).
  897. // OnConflict(
  898. // // Update the row with the new values
  899. // // the was proposed for insertion.
  900. // sql.ResolveWithNewValues(),
  901. // ).
  902. // // Override some of the fields with custom
  903. // // update values.
  904. // Update(func(u *ent.CreditUsageUpsert) {
  905. // SetCreatedAt(v+v).
  906. // }).
  907. // Exec(ctx)
  908. func (cucb *CreditUsageCreateBulk) OnConflict(opts ...sql.ConflictOption) *CreditUsageUpsertBulk {
  909. cucb.conflict = opts
  910. return &CreditUsageUpsertBulk{
  911. create: cucb,
  912. }
  913. }
  914. // OnConflictColumns calls `OnConflict` and configures the columns
  915. // as conflict target. Using this option is equivalent to using:
  916. //
  917. // client.CreditUsage.Create().
  918. // OnConflict(sql.ConflictColumns(columns...)).
  919. // Exec(ctx)
  920. func (cucb *CreditUsageCreateBulk) OnConflictColumns(columns ...string) *CreditUsageUpsertBulk {
  921. cucb.conflict = append(cucb.conflict, sql.ConflictColumns(columns...))
  922. return &CreditUsageUpsertBulk{
  923. create: cucb,
  924. }
  925. }
  926. // CreditUsageUpsertBulk is the builder for "upsert"-ing
  927. // a bulk of CreditUsage nodes.
  928. type CreditUsageUpsertBulk struct {
  929. create *CreditUsageCreateBulk
  930. }
  931. // UpdateNewValues updates the mutable fields using the new values that
  932. // were set on create. Using this option is equivalent to using:
  933. //
  934. // client.CreditUsage.Create().
  935. // OnConflict(
  936. // sql.ResolveWithNewValues(),
  937. // sql.ResolveWith(func(u *sql.UpdateSet) {
  938. // u.SetIgnore(creditusage.FieldID)
  939. // }),
  940. // ).
  941. // Exec(ctx)
  942. func (u *CreditUsageUpsertBulk) UpdateNewValues() *CreditUsageUpsertBulk {
  943. u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
  944. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
  945. for _, b := range u.create.builders {
  946. if _, exists := b.mutation.ID(); exists {
  947. s.SetIgnore(creditusage.FieldID)
  948. }
  949. if _, exists := b.mutation.CreatedAt(); exists {
  950. s.SetIgnore(creditusage.FieldCreatedAt)
  951. }
  952. }
  953. }))
  954. return u
  955. }
  956. // Ignore sets each column to itself in case of conflict.
  957. // Using this option is equivalent to using:
  958. //
  959. // client.CreditUsage.Create().
  960. // OnConflict(sql.ResolveWithIgnore()).
  961. // Exec(ctx)
  962. func (u *CreditUsageUpsertBulk) Ignore() *CreditUsageUpsertBulk {
  963. u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
  964. return u
  965. }
  966. // DoNothing configures the conflict_action to `DO NOTHING`.
  967. // Supported only by SQLite and PostgreSQL.
  968. func (u *CreditUsageUpsertBulk) DoNothing() *CreditUsageUpsertBulk {
  969. u.create.conflict = append(u.create.conflict, sql.DoNothing())
  970. return u
  971. }
  972. // Update allows overriding fields `UPDATE` values. See the CreditUsageCreateBulk.OnConflict
  973. // documentation for more info.
  974. func (u *CreditUsageUpsertBulk) Update(set func(*CreditUsageUpsert)) *CreditUsageUpsertBulk {
  975. u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
  976. set(&CreditUsageUpsert{UpdateSet: update})
  977. }))
  978. return u
  979. }
  980. // SetUpdatedAt sets the "updated_at" field.
  981. func (u *CreditUsageUpsertBulk) SetUpdatedAt(v time.Time) *CreditUsageUpsertBulk {
  982. return u.Update(func(s *CreditUsageUpsert) {
  983. s.SetUpdatedAt(v)
  984. })
  985. }
  986. // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
  987. func (u *CreditUsageUpsertBulk) UpdateUpdatedAt() *CreditUsageUpsertBulk {
  988. return u.Update(func(s *CreditUsageUpsert) {
  989. s.UpdateUpdatedAt()
  990. })
  991. }
  992. // SetDeletedAt sets the "deleted_at" field.
  993. func (u *CreditUsageUpsertBulk) SetDeletedAt(v time.Time) *CreditUsageUpsertBulk {
  994. return u.Update(func(s *CreditUsageUpsert) {
  995. s.SetDeletedAt(v)
  996. })
  997. }
  998. // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
  999. func (u *CreditUsageUpsertBulk) UpdateDeletedAt() *CreditUsageUpsertBulk {
  1000. return u.Update(func(s *CreditUsageUpsert) {
  1001. s.UpdateDeletedAt()
  1002. })
  1003. }
  1004. // ClearDeletedAt clears the value of the "deleted_at" field.
  1005. func (u *CreditUsageUpsertBulk) ClearDeletedAt() *CreditUsageUpsertBulk {
  1006. return u.Update(func(s *CreditUsageUpsert) {
  1007. s.ClearDeletedAt()
  1008. })
  1009. }
  1010. // SetUserID sets the "user_id" field.
  1011. func (u *CreditUsageUpsertBulk) SetUserID(v string) *CreditUsageUpsertBulk {
  1012. return u.Update(func(s *CreditUsageUpsert) {
  1013. s.SetUserID(v)
  1014. })
  1015. }
  1016. // UpdateUserID sets the "user_id" field to the value that was provided on create.
  1017. func (u *CreditUsageUpsertBulk) UpdateUserID() *CreditUsageUpsertBulk {
  1018. return u.Update(func(s *CreditUsageUpsert) {
  1019. s.UpdateUserID()
  1020. })
  1021. }
  1022. // SetNumber sets the "number" field.
  1023. func (u *CreditUsageUpsertBulk) SetNumber(v float32) *CreditUsageUpsertBulk {
  1024. return u.Update(func(s *CreditUsageUpsert) {
  1025. s.SetNumber(v)
  1026. })
  1027. }
  1028. // AddNumber adds v to the "number" field.
  1029. func (u *CreditUsageUpsertBulk) AddNumber(v float32) *CreditUsageUpsertBulk {
  1030. return u.Update(func(s *CreditUsageUpsert) {
  1031. s.AddNumber(v)
  1032. })
  1033. }
  1034. // UpdateNumber sets the "number" field to the value that was provided on create.
  1035. func (u *CreditUsageUpsertBulk) UpdateNumber() *CreditUsageUpsertBulk {
  1036. return u.Update(func(s *CreditUsageUpsert) {
  1037. s.UpdateNumber()
  1038. })
  1039. }
  1040. // SetStatus sets the "status" field.
  1041. func (u *CreditUsageUpsertBulk) SetStatus(v int) *CreditUsageUpsertBulk {
  1042. return u.Update(func(s *CreditUsageUpsert) {
  1043. s.SetStatus(v)
  1044. })
  1045. }
  1046. // AddStatus adds v to the "status" field.
  1047. func (u *CreditUsageUpsertBulk) AddStatus(v int) *CreditUsageUpsertBulk {
  1048. return u.Update(func(s *CreditUsageUpsert) {
  1049. s.AddStatus(v)
  1050. })
  1051. }
  1052. // UpdateStatus sets the "status" field to the value that was provided on create.
  1053. func (u *CreditUsageUpsertBulk) UpdateStatus() *CreditUsageUpsertBulk {
  1054. return u.Update(func(s *CreditUsageUpsert) {
  1055. s.UpdateStatus()
  1056. })
  1057. }
  1058. // ClearStatus clears the value of the "status" field.
  1059. func (u *CreditUsageUpsertBulk) ClearStatus() *CreditUsageUpsertBulk {
  1060. return u.Update(func(s *CreditUsageUpsert) {
  1061. s.ClearStatus()
  1062. })
  1063. }
  1064. // SetNtype sets the "ntype" field.
  1065. func (u *CreditUsageUpsertBulk) SetNtype(v int) *CreditUsageUpsertBulk {
  1066. return u.Update(func(s *CreditUsageUpsert) {
  1067. s.SetNtype(v)
  1068. })
  1069. }
  1070. // AddNtype adds v to the "ntype" field.
  1071. func (u *CreditUsageUpsertBulk) AddNtype(v int) *CreditUsageUpsertBulk {
  1072. return u.Update(func(s *CreditUsageUpsert) {
  1073. s.AddNtype(v)
  1074. })
  1075. }
  1076. // UpdateNtype sets the "ntype" field to the value that was provided on create.
  1077. func (u *CreditUsageUpsertBulk) UpdateNtype() *CreditUsageUpsertBulk {
  1078. return u.Update(func(s *CreditUsageUpsert) {
  1079. s.UpdateNtype()
  1080. })
  1081. }
  1082. // SetTable sets the "table" field.
  1083. func (u *CreditUsageUpsertBulk) SetTable(v string) *CreditUsageUpsertBulk {
  1084. return u.Update(func(s *CreditUsageUpsert) {
  1085. s.SetTable(v)
  1086. })
  1087. }
  1088. // UpdateTable sets the "table" field to the value that was provided on create.
  1089. func (u *CreditUsageUpsertBulk) UpdateTable() *CreditUsageUpsertBulk {
  1090. return u.Update(func(s *CreditUsageUpsert) {
  1091. s.UpdateTable()
  1092. })
  1093. }
  1094. // SetOrganizationID sets the "organization_id" field.
  1095. func (u *CreditUsageUpsertBulk) SetOrganizationID(v uint64) *CreditUsageUpsertBulk {
  1096. return u.Update(func(s *CreditUsageUpsert) {
  1097. s.SetOrganizationID(v)
  1098. })
  1099. }
  1100. // AddOrganizationID adds v to the "organization_id" field.
  1101. func (u *CreditUsageUpsertBulk) AddOrganizationID(v uint64) *CreditUsageUpsertBulk {
  1102. return u.Update(func(s *CreditUsageUpsert) {
  1103. s.AddOrganizationID(v)
  1104. })
  1105. }
  1106. // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
  1107. func (u *CreditUsageUpsertBulk) UpdateOrganizationID() *CreditUsageUpsertBulk {
  1108. return u.Update(func(s *CreditUsageUpsert) {
  1109. s.UpdateOrganizationID()
  1110. })
  1111. }
  1112. // ClearOrganizationID clears the value of the "organization_id" field.
  1113. func (u *CreditUsageUpsertBulk) ClearOrganizationID() *CreditUsageUpsertBulk {
  1114. return u.Update(func(s *CreditUsageUpsert) {
  1115. s.ClearOrganizationID()
  1116. })
  1117. }
  1118. // SetNid sets the "nid" field.
  1119. func (u *CreditUsageUpsertBulk) SetNid(v uint64) *CreditUsageUpsertBulk {
  1120. return u.Update(func(s *CreditUsageUpsert) {
  1121. s.SetNid(v)
  1122. })
  1123. }
  1124. // AddNid adds v to the "nid" field.
  1125. func (u *CreditUsageUpsertBulk) AddNid(v uint64) *CreditUsageUpsertBulk {
  1126. return u.Update(func(s *CreditUsageUpsert) {
  1127. s.AddNid(v)
  1128. })
  1129. }
  1130. // UpdateNid sets the "nid" field to the value that was provided on create.
  1131. func (u *CreditUsageUpsertBulk) UpdateNid() *CreditUsageUpsertBulk {
  1132. return u.Update(func(s *CreditUsageUpsert) {
  1133. s.UpdateNid()
  1134. })
  1135. }
  1136. // SetReason sets the "reason" field.
  1137. func (u *CreditUsageUpsertBulk) SetReason(v string) *CreditUsageUpsertBulk {
  1138. return u.Update(func(s *CreditUsageUpsert) {
  1139. s.SetReason(v)
  1140. })
  1141. }
  1142. // UpdateReason sets the "reason" field to the value that was provided on create.
  1143. func (u *CreditUsageUpsertBulk) UpdateReason() *CreditUsageUpsertBulk {
  1144. return u.Update(func(s *CreditUsageUpsert) {
  1145. s.UpdateReason()
  1146. })
  1147. }
  1148. // SetOperator sets the "operator" field.
  1149. func (u *CreditUsageUpsertBulk) SetOperator(v string) *CreditUsageUpsertBulk {
  1150. return u.Update(func(s *CreditUsageUpsert) {
  1151. s.SetOperator(v)
  1152. })
  1153. }
  1154. // UpdateOperator sets the "operator" field to the value that was provided on create.
  1155. func (u *CreditUsageUpsertBulk) UpdateOperator() *CreditUsageUpsertBulk {
  1156. return u.Update(func(s *CreditUsageUpsert) {
  1157. s.UpdateOperator()
  1158. })
  1159. }
  1160. // Exec executes the query.
  1161. func (u *CreditUsageUpsertBulk) Exec(ctx context.Context) error {
  1162. if u.create.err != nil {
  1163. return u.create.err
  1164. }
  1165. for i, b := range u.create.builders {
  1166. if len(b.conflict) != 0 {
  1167. return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the CreditUsageCreateBulk instead", i)
  1168. }
  1169. }
  1170. if len(u.create.conflict) == 0 {
  1171. return errors.New("ent: missing options for CreditUsageCreateBulk.OnConflict")
  1172. }
  1173. return u.create.Exec(ctx)
  1174. }
  1175. // ExecX is like Exec, but panics if an error occurs.
  1176. func (u *CreditUsageUpsertBulk) ExecX(ctx context.Context) {
  1177. if err := u.create.Exec(ctx); err != nil {
  1178. panic(err)
  1179. }
  1180. }