usagetotal_create.go 35 KB

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