creditusage_create.go 51 KB

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