creditusage_create.go 48 KB

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