usagedetail_create.go 47 KB

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