usagetotal_create.go 38 KB

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