12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/usagetotal"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // UsageTotalCreate is the builder for creating a UsageTotal entity.
- type UsageTotalCreate struct {
- config
- mutation *UsageTotalMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (utc *UsageTotalCreate) SetCreatedAt(t time.Time) *UsageTotalCreate {
- utc.mutation.SetCreatedAt(t)
- return utc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableCreatedAt(t *time.Time) *UsageTotalCreate {
- if t != nil {
- utc.SetCreatedAt(*t)
- }
- return utc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (utc *UsageTotalCreate) SetUpdatedAt(t time.Time) *UsageTotalCreate {
- utc.mutation.SetUpdatedAt(t)
- return utc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableUpdatedAt(t *time.Time) *UsageTotalCreate {
- if t != nil {
- utc.SetUpdatedAt(*t)
- }
- return utc
- }
- // SetStatus sets the "status" field.
- func (utc *UsageTotalCreate) SetStatus(u uint8) *UsageTotalCreate {
- utc.mutation.SetStatus(u)
- return utc
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableStatus(u *uint8) *UsageTotalCreate {
- if u != nil {
- utc.SetStatus(*u)
- }
- return utc
- }
- // SetType sets the "type" field.
- func (utc *UsageTotalCreate) SetType(i int) *UsageTotalCreate {
- utc.mutation.SetType(i)
- return utc
- }
- // SetNillableType sets the "type" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableType(i *int) *UsageTotalCreate {
- if i != nil {
- utc.SetType(*i)
- }
- return utc
- }
- // SetBotID sets the "bot_id" field.
- func (utc *UsageTotalCreate) SetBotID(s string) *UsageTotalCreate {
- utc.mutation.SetBotID(s)
- return utc
- }
- // SetNillableBotID sets the "bot_id" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableBotID(s *string) *UsageTotalCreate {
- if s != nil {
- utc.SetBotID(*s)
- }
- return utc
- }
- // SetTotalTokens sets the "total_tokens" field.
- func (utc *UsageTotalCreate) SetTotalTokens(u uint64) *UsageTotalCreate {
- utc.mutation.SetTotalTokens(u)
- return utc
- }
- // SetNillableTotalTokens sets the "total_tokens" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableTotalTokens(u *uint64) *UsageTotalCreate {
- if u != nil {
- utc.SetTotalTokens(*u)
- }
- return utc
- }
- // SetStartIndex sets the "start_index" field.
- func (utc *UsageTotalCreate) SetStartIndex(u uint64) *UsageTotalCreate {
- utc.mutation.SetStartIndex(u)
- return utc
- }
- // SetNillableStartIndex sets the "start_index" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableStartIndex(u *uint64) *UsageTotalCreate {
- if u != nil {
- utc.SetStartIndex(*u)
- }
- return utc
- }
- // SetEndIndex sets the "end_index" field.
- func (utc *UsageTotalCreate) SetEndIndex(u uint64) *UsageTotalCreate {
- utc.mutation.SetEndIndex(u)
- return utc
- }
- // SetNillableEndIndex sets the "end_index" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableEndIndex(u *uint64) *UsageTotalCreate {
- if u != nil {
- utc.SetEndIndex(*u)
- }
- return utc
- }
- // SetOrganizationID sets the "organization_id" field.
- func (utc *UsageTotalCreate) SetOrganizationID(u uint64) *UsageTotalCreate {
- utc.mutation.SetOrganizationID(u)
- return utc
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (utc *UsageTotalCreate) SetNillableOrganizationID(u *uint64) *UsageTotalCreate {
- if u != nil {
- utc.SetOrganizationID(*u)
- }
- return utc
- }
- // SetID sets the "id" field.
- func (utc *UsageTotalCreate) SetID(u uint64) *UsageTotalCreate {
- utc.mutation.SetID(u)
- return utc
- }
- // Mutation returns the UsageTotalMutation object of the builder.
- func (utc *UsageTotalCreate) Mutation() *UsageTotalMutation {
- return utc.mutation
- }
- // Save creates the UsageTotal in the database.
- func (utc *UsageTotalCreate) Save(ctx context.Context) (*UsageTotal, error) {
- utc.defaults()
- return withHooks(ctx, utc.sqlSave, utc.mutation, utc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (utc *UsageTotalCreate) SaveX(ctx context.Context) *UsageTotal {
- v, err := utc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (utc *UsageTotalCreate) Exec(ctx context.Context) error {
- _, err := utc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (utc *UsageTotalCreate) ExecX(ctx context.Context) {
- if err := utc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (utc *UsageTotalCreate) defaults() {
- if _, ok := utc.mutation.CreatedAt(); !ok {
- v := usagetotal.DefaultCreatedAt()
- utc.mutation.SetCreatedAt(v)
- }
- if _, ok := utc.mutation.UpdatedAt(); !ok {
- v := usagetotal.DefaultUpdatedAt()
- utc.mutation.SetUpdatedAt(v)
- }
- if _, ok := utc.mutation.Status(); !ok {
- v := usagetotal.DefaultStatus
- utc.mutation.SetStatus(v)
- }
- if _, ok := utc.mutation.GetType(); !ok {
- v := usagetotal.DefaultType
- utc.mutation.SetType(v)
- }
- if _, ok := utc.mutation.BotID(); !ok {
- v := usagetotal.DefaultBotID
- utc.mutation.SetBotID(v)
- }
- if _, ok := utc.mutation.TotalTokens(); !ok {
- v := usagetotal.DefaultTotalTokens
- utc.mutation.SetTotalTokens(v)
- }
- if _, ok := utc.mutation.StartIndex(); !ok {
- v := usagetotal.DefaultStartIndex
- utc.mutation.SetStartIndex(v)
- }
- if _, ok := utc.mutation.EndIndex(); !ok {
- v := usagetotal.DefaultEndIndex
- utc.mutation.SetEndIndex(v)
- }
- if _, ok := utc.mutation.OrganizationID(); !ok {
- v := usagetotal.DefaultOrganizationID
- utc.mutation.SetOrganizationID(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (utc *UsageTotalCreate) check() error {
- if _, ok := utc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UsageTotal.created_at"`)}
- }
- if _, ok := utc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UsageTotal.updated_at"`)}
- }
- if _, ok := utc.mutation.BotID(); !ok {
- return &ValidationError{Name: "bot_id", err: errors.New(`ent: missing required field "UsageTotal.bot_id"`)}
- }
- return nil
- }
- func (utc *UsageTotalCreate) sqlSave(ctx context.Context) (*UsageTotal, error) {
- if err := utc.check(); err != nil {
- return nil, err
- }
- _node, _spec := utc.createSpec()
- if err := sqlgraph.CreateNode(ctx, utc.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- if _spec.ID.Value != _node.ID {
- id := _spec.ID.Value.(int64)
- _node.ID = uint64(id)
- }
- utc.mutation.id = &_node.ID
- utc.mutation.done = true
- return _node, nil
- }
- func (utc *UsageTotalCreate) createSpec() (*UsageTotal, *sqlgraph.CreateSpec) {
- var (
- _node = &UsageTotal{config: utc.config}
- _spec = sqlgraph.NewCreateSpec(usagetotal.Table, sqlgraph.NewFieldSpec(usagetotal.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = utc.conflict
- if id, ok := utc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := utc.mutation.CreatedAt(); ok {
- _spec.SetField(usagetotal.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := utc.mutation.UpdatedAt(); ok {
- _spec.SetField(usagetotal.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := utc.mutation.Status(); ok {
- _spec.SetField(usagetotal.FieldStatus, field.TypeUint8, value)
- _node.Status = value
- }
- if value, ok := utc.mutation.GetType(); ok {
- _spec.SetField(usagetotal.FieldType, field.TypeInt, value)
- _node.Type = value
- }
- if value, ok := utc.mutation.BotID(); ok {
- _spec.SetField(usagetotal.FieldBotID, field.TypeString, value)
- _node.BotID = value
- }
- if value, ok := utc.mutation.TotalTokens(); ok {
- _spec.SetField(usagetotal.FieldTotalTokens, field.TypeUint64, value)
- _node.TotalTokens = value
- }
- if value, ok := utc.mutation.StartIndex(); ok {
- _spec.SetField(usagetotal.FieldStartIndex, field.TypeUint64, value)
- _node.StartIndex = value
- }
- if value, ok := utc.mutation.EndIndex(); ok {
- _spec.SetField(usagetotal.FieldEndIndex, field.TypeUint64, value)
- _node.EndIndex = value
- }
- if value, ok := utc.mutation.OrganizationID(); ok {
- _spec.SetField(usagetotal.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- return _node, _spec
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.UsageTotal.Create().
- // SetCreatedAt(v).
- // OnConflict(
- // // Update the row with the new values
- // // the was proposed for insertion.
- // sql.ResolveWithNewValues(),
- // ).
- // // Override some of the fields with custom
- // // update values.
- // Update(func(u *ent.UsageTotalUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (utc *UsageTotalCreate) OnConflict(opts ...sql.ConflictOption) *UsageTotalUpsertOne {
- utc.conflict = opts
- return &UsageTotalUpsertOne{
- create: utc,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.UsageTotal.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (utc *UsageTotalCreate) OnConflictColumns(columns ...string) *UsageTotalUpsertOne {
- utc.conflict = append(utc.conflict, sql.ConflictColumns(columns...))
- return &UsageTotalUpsertOne{
- create: utc,
- }
- }
- type (
- // UsageTotalUpsertOne is the builder for "upsert"-ing
- // one UsageTotal node.
- UsageTotalUpsertOne struct {
- create *UsageTotalCreate
- }
- // UsageTotalUpsert is the "OnConflict" setter.
- UsageTotalUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *UsageTotalUpsert) SetUpdatedAt(v time.Time) *UsageTotalUpsert {
- u.Set(usagetotal.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateUpdatedAt() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldUpdatedAt)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *UsageTotalUpsert) SetStatus(v uint8) *UsageTotalUpsert {
- u.Set(usagetotal.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateStatus() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldStatus)
- return u
- }
- // AddStatus adds v to the "status" field.
- func (u *UsageTotalUpsert) AddStatus(v uint8) *UsageTotalUpsert {
- u.Add(usagetotal.FieldStatus, v)
- return u
- }
- // ClearStatus clears the value of the "status" field.
- func (u *UsageTotalUpsert) ClearStatus() *UsageTotalUpsert {
- u.SetNull(usagetotal.FieldStatus)
- return u
- }
- // SetType sets the "type" field.
- func (u *UsageTotalUpsert) SetType(v int) *UsageTotalUpsert {
- u.Set(usagetotal.FieldType, v)
- return u
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateType() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldType)
- return u
- }
- // AddType adds v to the "type" field.
- func (u *UsageTotalUpsert) AddType(v int) *UsageTotalUpsert {
- u.Add(usagetotal.FieldType, v)
- return u
- }
- // ClearType clears the value of the "type" field.
- func (u *UsageTotalUpsert) ClearType() *UsageTotalUpsert {
- u.SetNull(usagetotal.FieldType)
- return u
- }
- // SetBotID sets the "bot_id" field.
- func (u *UsageTotalUpsert) SetBotID(v string) *UsageTotalUpsert {
- u.Set(usagetotal.FieldBotID, v)
- return u
- }
- // UpdateBotID sets the "bot_id" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateBotID() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldBotID)
- return u
- }
- // SetTotalTokens sets the "total_tokens" field.
- func (u *UsageTotalUpsert) SetTotalTokens(v uint64) *UsageTotalUpsert {
- u.Set(usagetotal.FieldTotalTokens, v)
- return u
- }
- // UpdateTotalTokens sets the "total_tokens" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateTotalTokens() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldTotalTokens)
- return u
- }
- // AddTotalTokens adds v to the "total_tokens" field.
- func (u *UsageTotalUpsert) AddTotalTokens(v uint64) *UsageTotalUpsert {
- u.Add(usagetotal.FieldTotalTokens, v)
- return u
- }
- // ClearTotalTokens clears the value of the "total_tokens" field.
- func (u *UsageTotalUpsert) ClearTotalTokens() *UsageTotalUpsert {
- u.SetNull(usagetotal.FieldTotalTokens)
- return u
- }
- // SetStartIndex sets the "start_index" field.
- func (u *UsageTotalUpsert) SetStartIndex(v uint64) *UsageTotalUpsert {
- u.Set(usagetotal.FieldStartIndex, v)
- return u
- }
- // UpdateStartIndex sets the "start_index" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateStartIndex() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldStartIndex)
- return u
- }
- // AddStartIndex adds v to the "start_index" field.
- func (u *UsageTotalUpsert) AddStartIndex(v uint64) *UsageTotalUpsert {
- u.Add(usagetotal.FieldStartIndex, v)
- return u
- }
- // ClearStartIndex clears the value of the "start_index" field.
- func (u *UsageTotalUpsert) ClearStartIndex() *UsageTotalUpsert {
- u.SetNull(usagetotal.FieldStartIndex)
- return u
- }
- // SetEndIndex sets the "end_index" field.
- func (u *UsageTotalUpsert) SetEndIndex(v uint64) *UsageTotalUpsert {
- u.Set(usagetotal.FieldEndIndex, v)
- return u
- }
- // UpdateEndIndex sets the "end_index" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateEndIndex() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldEndIndex)
- return u
- }
- // AddEndIndex adds v to the "end_index" field.
- func (u *UsageTotalUpsert) AddEndIndex(v uint64) *UsageTotalUpsert {
- u.Add(usagetotal.FieldEndIndex, v)
- return u
- }
- // ClearEndIndex clears the value of the "end_index" field.
- func (u *UsageTotalUpsert) ClearEndIndex() *UsageTotalUpsert {
- u.SetNull(usagetotal.FieldEndIndex)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *UsageTotalUpsert) SetOrganizationID(v uint64) *UsageTotalUpsert {
- u.Set(usagetotal.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *UsageTotalUpsert) UpdateOrganizationID() *UsageTotalUpsert {
- u.SetExcluded(usagetotal.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *UsageTotalUpsert) AddOrganizationID(v uint64) *UsageTotalUpsert {
- u.Add(usagetotal.FieldOrganizationID, v)
- return u
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *UsageTotalUpsert) ClearOrganizationID() *UsageTotalUpsert {
- u.SetNull(usagetotal.FieldOrganizationID)
- return u
- }
- // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
- // Using this option is equivalent to using:
- //
- // client.UsageTotal.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(usagetotal.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *UsageTotalUpsertOne) UpdateNewValues() *UsageTotalUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
- if _, exists := u.create.mutation.ID(); exists {
- s.SetIgnore(usagetotal.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(usagetotal.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.UsageTotal.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *UsageTotalUpsertOne) Ignore() *UsageTotalUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
- return u
- }
- // DoNothing configures the conflict_action to `DO NOTHING`.
- // Supported only by SQLite and PostgreSQL.
- func (u *UsageTotalUpsertOne) DoNothing() *UsageTotalUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the UsageTotalCreate.OnConflict
- // documentation for more info.
- func (u *UsageTotalUpsertOne) Update(set func(*UsageTotalUpsert)) *UsageTotalUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&UsageTotalUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *UsageTotalUpsertOne) SetUpdatedAt(v time.Time) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateUpdatedAt() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *UsageTotalUpsertOne) SetStatus(v uint8) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *UsageTotalUpsertOne) AddStatus(v uint8) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateStatus() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *UsageTotalUpsertOne) ClearStatus() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearStatus()
- })
- }
- // SetType sets the "type" field.
- func (u *UsageTotalUpsertOne) SetType(v int) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetType(v)
- })
- }
- // AddType adds v to the "type" field.
- func (u *UsageTotalUpsertOne) AddType(v int) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddType(v)
- })
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateType() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateType()
- })
- }
- // ClearType clears the value of the "type" field.
- func (u *UsageTotalUpsertOne) ClearType() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearType()
- })
- }
- // SetBotID sets the "bot_id" field.
- func (u *UsageTotalUpsertOne) SetBotID(v string) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetBotID(v)
- })
- }
- // UpdateBotID sets the "bot_id" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateBotID() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateBotID()
- })
- }
- // SetTotalTokens sets the "total_tokens" field.
- func (u *UsageTotalUpsertOne) SetTotalTokens(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetTotalTokens(v)
- })
- }
- // AddTotalTokens adds v to the "total_tokens" field.
- func (u *UsageTotalUpsertOne) AddTotalTokens(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddTotalTokens(v)
- })
- }
- // UpdateTotalTokens sets the "total_tokens" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateTotalTokens() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateTotalTokens()
- })
- }
- // ClearTotalTokens clears the value of the "total_tokens" field.
- func (u *UsageTotalUpsertOne) ClearTotalTokens() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearTotalTokens()
- })
- }
- // SetStartIndex sets the "start_index" field.
- func (u *UsageTotalUpsertOne) SetStartIndex(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetStartIndex(v)
- })
- }
- // AddStartIndex adds v to the "start_index" field.
- func (u *UsageTotalUpsertOne) AddStartIndex(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddStartIndex(v)
- })
- }
- // UpdateStartIndex sets the "start_index" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateStartIndex() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateStartIndex()
- })
- }
- // ClearStartIndex clears the value of the "start_index" field.
- func (u *UsageTotalUpsertOne) ClearStartIndex() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearStartIndex()
- })
- }
- // SetEndIndex sets the "end_index" field.
- func (u *UsageTotalUpsertOne) SetEndIndex(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetEndIndex(v)
- })
- }
- // AddEndIndex adds v to the "end_index" field.
- func (u *UsageTotalUpsertOne) AddEndIndex(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddEndIndex(v)
- })
- }
- // UpdateEndIndex sets the "end_index" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateEndIndex() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateEndIndex()
- })
- }
- // ClearEndIndex clears the value of the "end_index" field.
- func (u *UsageTotalUpsertOne) ClearEndIndex() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearEndIndex()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *UsageTotalUpsertOne) SetOrganizationID(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *UsageTotalUpsertOne) AddOrganizationID(v uint64) *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *UsageTotalUpsertOne) UpdateOrganizationID() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *UsageTotalUpsertOne) ClearOrganizationID() *UsageTotalUpsertOne {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *UsageTotalUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for UsageTotalCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *UsageTotalUpsertOne) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // Exec executes the UPSERT query and returns the inserted/updated ID.
- func (u *UsageTotalUpsertOne) ID(ctx context.Context) (id uint64, err error) {
- node, err := u.create.Save(ctx)
- if err != nil {
- return id, err
- }
- return node.ID, nil
- }
- // IDX is like ID, but panics if an error occurs.
- func (u *UsageTotalUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // UsageTotalCreateBulk is the builder for creating many UsageTotal entities in bulk.
- type UsageTotalCreateBulk struct {
- config
- err error
- builders []*UsageTotalCreate
- conflict []sql.ConflictOption
- }
- // Save creates the UsageTotal entities in the database.
- func (utcb *UsageTotalCreateBulk) Save(ctx context.Context) ([]*UsageTotal, error) {
- if utcb.err != nil {
- return nil, utcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(utcb.builders))
- nodes := make([]*UsageTotal, len(utcb.builders))
- mutators := make([]Mutator, len(utcb.builders))
- for i := range utcb.builders {
- func(i int, root context.Context) {
- builder := utcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*UsageTotalMutation)
- if !ok {
- return nil, fmt.Errorf("unexpected mutation type %T", m)
- }
- if err := builder.check(); err != nil {
- return nil, err
- }
- builder.mutation = mutation
- var err error
- nodes[i], specs[i] = builder.createSpec()
- if i < len(mutators)-1 {
- _, err = mutators[i+1].Mutate(root, utcb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = utcb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, utcb.driver, spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- }
- }
- if err != nil {
- return nil, err
- }
- mutation.id = &nodes[i].ID
- if specs[i].ID.Value != nil && nodes[i].ID == 0 {
- id := specs[i].ID.Value.(int64)
- nodes[i].ID = uint64(id)
- }
- mutation.done = true
- return nodes[i], nil
- })
- for i := len(builder.hooks) - 1; i >= 0; i-- {
- mut = builder.hooks[i](mut)
- }
- mutators[i] = mut
- }(i, ctx)
- }
- if len(mutators) > 0 {
- if _, err := mutators[0].Mutate(ctx, utcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (utcb *UsageTotalCreateBulk) SaveX(ctx context.Context) []*UsageTotal {
- v, err := utcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (utcb *UsageTotalCreateBulk) Exec(ctx context.Context) error {
- _, err := utcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (utcb *UsageTotalCreateBulk) ExecX(ctx context.Context) {
- if err := utcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.UsageTotal.CreateBulk(builders...).
- // OnConflict(
- // // Update the row with the new values
- // // the was proposed for insertion.
- // sql.ResolveWithNewValues(),
- // ).
- // // Override some of the fields with custom
- // // update values.
- // Update(func(u *ent.UsageTotalUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (utcb *UsageTotalCreateBulk) OnConflict(opts ...sql.ConflictOption) *UsageTotalUpsertBulk {
- utcb.conflict = opts
- return &UsageTotalUpsertBulk{
- create: utcb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.UsageTotal.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (utcb *UsageTotalCreateBulk) OnConflictColumns(columns ...string) *UsageTotalUpsertBulk {
- utcb.conflict = append(utcb.conflict, sql.ConflictColumns(columns...))
- return &UsageTotalUpsertBulk{
- create: utcb,
- }
- }
- // UsageTotalUpsertBulk is the builder for "upsert"-ing
- // a bulk of UsageTotal nodes.
- type UsageTotalUpsertBulk struct {
- create *UsageTotalCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.UsageTotal.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(usagetotal.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *UsageTotalUpsertBulk) UpdateNewValues() *UsageTotalUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
- for _, b := range u.create.builders {
- if _, exists := b.mutation.ID(); exists {
- s.SetIgnore(usagetotal.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(usagetotal.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.UsageTotal.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *UsageTotalUpsertBulk) Ignore() *UsageTotalUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
- return u
- }
- // DoNothing configures the conflict_action to `DO NOTHING`.
- // Supported only by SQLite and PostgreSQL.
- func (u *UsageTotalUpsertBulk) DoNothing() *UsageTotalUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the UsageTotalCreateBulk.OnConflict
- // documentation for more info.
- func (u *UsageTotalUpsertBulk) Update(set func(*UsageTotalUpsert)) *UsageTotalUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&UsageTotalUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *UsageTotalUpsertBulk) SetUpdatedAt(v time.Time) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateUpdatedAt() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetStatus sets the "status" field.
- func (u *UsageTotalUpsertBulk) SetStatus(v uint8) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetStatus(v)
- })
- }
- // AddStatus adds v to the "status" field.
- func (u *UsageTotalUpsertBulk) AddStatus(v uint8) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateStatus() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateStatus()
- })
- }
- // ClearStatus clears the value of the "status" field.
- func (u *UsageTotalUpsertBulk) ClearStatus() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearStatus()
- })
- }
- // SetType sets the "type" field.
- func (u *UsageTotalUpsertBulk) SetType(v int) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetType(v)
- })
- }
- // AddType adds v to the "type" field.
- func (u *UsageTotalUpsertBulk) AddType(v int) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddType(v)
- })
- }
- // UpdateType sets the "type" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateType() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateType()
- })
- }
- // ClearType clears the value of the "type" field.
- func (u *UsageTotalUpsertBulk) ClearType() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearType()
- })
- }
- // SetBotID sets the "bot_id" field.
- func (u *UsageTotalUpsertBulk) SetBotID(v string) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetBotID(v)
- })
- }
- // UpdateBotID sets the "bot_id" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateBotID() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateBotID()
- })
- }
- // SetTotalTokens sets the "total_tokens" field.
- func (u *UsageTotalUpsertBulk) SetTotalTokens(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetTotalTokens(v)
- })
- }
- // AddTotalTokens adds v to the "total_tokens" field.
- func (u *UsageTotalUpsertBulk) AddTotalTokens(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddTotalTokens(v)
- })
- }
- // UpdateTotalTokens sets the "total_tokens" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateTotalTokens() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateTotalTokens()
- })
- }
- // ClearTotalTokens clears the value of the "total_tokens" field.
- func (u *UsageTotalUpsertBulk) ClearTotalTokens() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearTotalTokens()
- })
- }
- // SetStartIndex sets the "start_index" field.
- func (u *UsageTotalUpsertBulk) SetStartIndex(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetStartIndex(v)
- })
- }
- // AddStartIndex adds v to the "start_index" field.
- func (u *UsageTotalUpsertBulk) AddStartIndex(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddStartIndex(v)
- })
- }
- // UpdateStartIndex sets the "start_index" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateStartIndex() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateStartIndex()
- })
- }
- // ClearStartIndex clears the value of the "start_index" field.
- func (u *UsageTotalUpsertBulk) ClearStartIndex() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearStartIndex()
- })
- }
- // SetEndIndex sets the "end_index" field.
- func (u *UsageTotalUpsertBulk) SetEndIndex(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetEndIndex(v)
- })
- }
- // AddEndIndex adds v to the "end_index" field.
- func (u *UsageTotalUpsertBulk) AddEndIndex(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddEndIndex(v)
- })
- }
- // UpdateEndIndex sets the "end_index" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateEndIndex() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateEndIndex()
- })
- }
- // ClearEndIndex clears the value of the "end_index" field.
- func (u *UsageTotalUpsertBulk) ClearEndIndex() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearEndIndex()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *UsageTotalUpsertBulk) SetOrganizationID(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *UsageTotalUpsertBulk) AddOrganizationID(v uint64) *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *UsageTotalUpsertBulk) UpdateOrganizationID() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (u *UsageTotalUpsertBulk) ClearOrganizationID() *UsageTotalUpsertBulk {
- return u.Update(func(s *UsageTotalUpsert) {
- s.ClearOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *UsageTotalUpsertBulk) Exec(ctx context.Context) error {
- if u.create.err != nil {
- return u.create.err
- }
- for i, b := range u.create.builders {
- if len(b.conflict) != 0 {
- return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the UsageTotalCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for UsageTotalCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *UsageTotalUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|