creditusage_create.go 40 KB

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