| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- "github.com/Wei-Shaw/sub2api/ent/user"
- "github.com/Wei-Shaw/sub2api/ent/userplatformquota"
- )
- // UserPlatformQuotaUpdate is the builder for updating UserPlatformQuota entities.
- type UserPlatformQuotaUpdate struct {
- config
- hooks []Hook
- mutation *UserPlatformQuotaMutation
- }
- // Where appends a list predicates to the UserPlatformQuotaUpdate builder.
- func (_u *UserPlatformQuotaUpdate) Where(ps ...predicate.UserPlatformQuota) *UserPlatformQuotaUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *UserPlatformQuotaUpdate) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_u *UserPlatformQuotaUpdate) SetDeletedAt(v time.Time) *UserPlatformQuotaUpdate {
- _u.mutation.SetDeletedAt(v)
- return _u
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableDeletedAt(v *time.Time) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetDeletedAt(*v)
- }
- return _u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (_u *UserPlatformQuotaUpdate) ClearDeletedAt() *UserPlatformQuotaUpdate {
- _u.mutation.ClearDeletedAt()
- return _u
- }
- // SetUserID sets the "user_id" field.
- func (_u *UserPlatformQuotaUpdate) SetUserID(v int64) *UserPlatformQuotaUpdate {
- _u.mutation.SetUserID(v)
- return _u
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableUserID(v *int64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetUserID(*v)
- }
- return _u
- }
- // SetPlatform sets the "platform" field.
- func (_u *UserPlatformQuotaUpdate) SetPlatform(v string) *UserPlatformQuotaUpdate {
- _u.mutation.SetPlatform(v)
- return _u
- }
- // SetNillablePlatform sets the "platform" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillablePlatform(v *string) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetPlatform(*v)
- }
- return _u
- }
- // SetDailyLimitUsd sets the "daily_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.ResetDailyLimitUsd()
- _u.mutation.SetDailyLimitUsd(v)
- return _u
- }
- // SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableDailyLimitUsd(v *float64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetDailyLimitUsd(*v)
- }
- return _u
- }
- // AddDailyLimitUsd adds value to the "daily_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.AddDailyLimitUsd(v)
- return _u
- }
- // ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) ClearDailyLimitUsd() *UserPlatformQuotaUpdate {
- _u.mutation.ClearDailyLimitUsd()
- return _u
- }
- // SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.ResetWeeklyLimitUsd()
- _u.mutation.SetWeeklyLimitUsd(v)
- return _u
- }
- // SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableWeeklyLimitUsd(v *float64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetWeeklyLimitUsd(*v)
- }
- return _u
- }
- // AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.AddWeeklyLimitUsd(v)
- return _u
- }
- // ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) ClearWeeklyLimitUsd() *UserPlatformQuotaUpdate {
- _u.mutation.ClearWeeklyLimitUsd()
- return _u
- }
- // SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.ResetMonthlyLimitUsd()
- _u.mutation.SetMonthlyLimitUsd(v)
- return _u
- }
- // SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableMonthlyLimitUsd(v *float64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetMonthlyLimitUsd(*v)
- }
- return _u
- }
- // AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.AddMonthlyLimitUsd(v)
- return _u
- }
- // ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdate) ClearMonthlyLimitUsd() *UserPlatformQuotaUpdate {
- _u.mutation.ClearMonthlyLimitUsd()
- return _u
- }
- // SetDailyUsageUsd sets the "daily_usage_usd" field.
- func (_u *UserPlatformQuotaUpdate) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.ResetDailyUsageUsd()
- _u.mutation.SetDailyUsageUsd(v)
- return _u
- }
- // SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableDailyUsageUsd(v *float64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetDailyUsageUsd(*v)
- }
- return _u
- }
- // AddDailyUsageUsd adds value to the "daily_usage_usd" field.
- func (_u *UserPlatformQuotaUpdate) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.AddDailyUsageUsd(v)
- return _u
- }
- // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdate) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.ResetWeeklyUsageUsd()
- _u.mutation.SetWeeklyUsageUsd(v)
- return _u
- }
- // SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableWeeklyUsageUsd(v *float64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetWeeklyUsageUsd(*v)
- }
- return _u
- }
- // AddWeeklyUsageUsd adds value to the "weekly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdate) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.AddWeeklyUsageUsd(v)
- return _u
- }
- // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdate) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.ResetMonthlyUsageUsd()
- _u.mutation.SetMonthlyUsageUsd(v)
- return _u
- }
- // SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableMonthlyUsageUsd(v *float64) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetMonthlyUsageUsd(*v)
- }
- return _u
- }
- // AddMonthlyUsageUsd adds value to the "monthly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdate) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdate {
- _u.mutation.AddMonthlyUsageUsd(v)
- return _u
- }
- // SetDailyWindowStart sets the "daily_window_start" field.
- func (_u *UserPlatformQuotaUpdate) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpdate {
- _u.mutation.SetDailyWindowStart(v)
- return _u
- }
- // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableDailyWindowStart(v *time.Time) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetDailyWindowStart(*v)
- }
- return _u
- }
- // ClearDailyWindowStart clears the value of the "daily_window_start" field.
- func (_u *UserPlatformQuotaUpdate) ClearDailyWindowStart() *UserPlatformQuotaUpdate {
- _u.mutation.ClearDailyWindowStart()
- return _u
- }
- // SetWeeklyWindowStart sets the "weekly_window_start" field.
- func (_u *UserPlatformQuotaUpdate) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpdate {
- _u.mutation.SetWeeklyWindowStart(v)
- return _u
- }
- // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableWeeklyWindowStart(v *time.Time) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetWeeklyWindowStart(*v)
- }
- return _u
- }
- // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
- func (_u *UserPlatformQuotaUpdate) ClearWeeklyWindowStart() *UserPlatformQuotaUpdate {
- _u.mutation.ClearWeeklyWindowStart()
- return _u
- }
- // SetMonthlyWindowStart sets the "monthly_window_start" field.
- func (_u *UserPlatformQuotaUpdate) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpdate {
- _u.mutation.SetMonthlyWindowStart(v)
- return _u
- }
- // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdate) SetNillableMonthlyWindowStart(v *time.Time) *UserPlatformQuotaUpdate {
- if v != nil {
- _u.SetMonthlyWindowStart(*v)
- }
- return _u
- }
- // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
- func (_u *UserPlatformQuotaUpdate) ClearMonthlyWindowStart() *UserPlatformQuotaUpdate {
- _u.mutation.ClearMonthlyWindowStart()
- return _u
- }
- // SetUser sets the "user" edge to the User entity.
- func (_u *UserPlatformQuotaUpdate) SetUser(v *User) *UserPlatformQuotaUpdate {
- return _u.SetUserID(v.ID)
- }
- // Mutation returns the UserPlatformQuotaMutation object of the builder.
- func (_u *UserPlatformQuotaUpdate) Mutation() *UserPlatformQuotaMutation {
- return _u.mutation
- }
- // ClearUser clears the "user" edge to the User entity.
- func (_u *UserPlatformQuotaUpdate) ClearUser() *UserPlatformQuotaUpdate {
- _u.mutation.ClearUser()
- return _u
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *UserPlatformQuotaUpdate) Save(ctx context.Context) (int, error) {
- if err := _u.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *UserPlatformQuotaUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *UserPlatformQuotaUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *UserPlatformQuotaUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *UserPlatformQuotaUpdate) defaults() error {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- if userplatformquota.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized userplatformquota.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := userplatformquota.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *UserPlatformQuotaUpdate) check() error {
- if v, ok := _u.mutation.Platform(); ok {
- if err := userplatformquota.PlatformValidator(v); err != nil {
- return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "UserPlatformQuota.platform": %w`, err)}
- }
- }
- if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "UserPlatformQuota.user"`)
- }
- return nil
- }
- func (_u *UserPlatformQuotaUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(userplatformquota.Table, userplatformquota.Columns, sqlgraph.NewFieldSpec(userplatformquota.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(userplatformquota.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.DeletedAt(); ok {
- _spec.SetField(userplatformquota.FieldDeletedAt, field.TypeTime, value)
- }
- if _u.mutation.DeletedAtCleared() {
- _spec.ClearField(userplatformquota.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.Platform(); ok {
- _spec.SetField(userplatformquota.FieldPlatform, field.TypeString, value)
- }
- if value, ok := _u.mutation.DailyLimitUsd(); ok {
- _spec.SetField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
- _spec.AddField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
- }
- if _u.mutation.DailyLimitUsdCleared() {
- _spec.ClearField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64)
- }
- if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
- _spec.SetField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
- _spec.AddField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
- }
- if _u.mutation.WeeklyLimitUsdCleared() {
- _spec.ClearField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64)
- }
- if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
- _spec.SetField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
- _spec.AddField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
- }
- if _u.mutation.MonthlyLimitUsdCleared() {
- _spec.ClearField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64)
- }
- if value, ok := _u.mutation.DailyUsageUsd(); ok {
- _spec.SetField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedDailyUsageUsd(); ok {
- _spec.AddField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.WeeklyUsageUsd(); ok {
- _spec.SetField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedWeeklyUsageUsd(); ok {
- _spec.AddField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.MonthlyUsageUsd(); ok {
- _spec.SetField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedMonthlyUsageUsd(); ok {
- _spec.AddField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.DailyWindowStart(); ok {
- _spec.SetField(userplatformquota.FieldDailyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.DailyWindowStartCleared() {
- _spec.ClearField(userplatformquota.FieldDailyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.WeeklyWindowStart(); ok {
- _spec.SetField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.WeeklyWindowStartCleared() {
- _spec.ClearField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.MonthlyWindowStart(); ok {
- _spec.SetField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.MonthlyWindowStartCleared() {
- _spec.ClearField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime)
- }
- if _u.mutation.UserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: userplatformquota.UserTable,
- Columns: []string{userplatformquota.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: userplatformquota.UserTable,
- Columns: []string{userplatformquota.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{userplatformquota.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // UserPlatformQuotaUpdateOne is the builder for updating a single UserPlatformQuota entity.
- type UserPlatformQuotaUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *UserPlatformQuotaMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *UserPlatformQuotaUpdateOne) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_u *UserPlatformQuotaUpdateOne) SetDeletedAt(v time.Time) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetDeletedAt(v)
- return _u
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableDeletedAt(v *time.Time) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetDeletedAt(*v)
- }
- return _u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearDeletedAt() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearDeletedAt()
- return _u
- }
- // SetUserID sets the "user_id" field.
- func (_u *UserPlatformQuotaUpdateOne) SetUserID(v int64) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetUserID(v)
- return _u
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableUserID(v *int64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetUserID(*v)
- }
- return _u
- }
- // SetPlatform sets the "platform" field.
- func (_u *UserPlatformQuotaUpdateOne) SetPlatform(v string) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetPlatform(v)
- return _u
- }
- // SetNillablePlatform sets the "platform" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillablePlatform(v *string) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetPlatform(*v)
- }
- return _u
- }
- // SetDailyLimitUsd sets the "daily_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.ResetDailyLimitUsd()
- _u.mutation.SetDailyLimitUsd(v)
- return _u
- }
- // SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableDailyLimitUsd(v *float64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetDailyLimitUsd(*v)
- }
- return _u
- }
- // AddDailyLimitUsd adds value to the "daily_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.AddDailyLimitUsd(v)
- return _u
- }
- // ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearDailyLimitUsd() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearDailyLimitUsd()
- return _u
- }
- // SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.ResetWeeklyLimitUsd()
- _u.mutation.SetWeeklyLimitUsd(v)
- return _u
- }
- // SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableWeeklyLimitUsd(v *float64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetWeeklyLimitUsd(*v)
- }
- return _u
- }
- // AddWeeklyLimitUsd adds value to the "weekly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.AddWeeklyLimitUsd(v)
- return _u
- }
- // ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearWeeklyLimitUsd() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearWeeklyLimitUsd()
- return _u
- }
- // SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.ResetMonthlyLimitUsd()
- _u.mutation.SetMonthlyLimitUsd(v)
- return _u
- }
- // SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableMonthlyLimitUsd(v *float64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetMonthlyLimitUsd(*v)
- }
- return _u
- }
- // AddMonthlyLimitUsd adds value to the "monthly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.AddMonthlyLimitUsd(v)
- return _u
- }
- // ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearMonthlyLimitUsd() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearMonthlyLimitUsd()
- return _u
- }
- // SetDailyUsageUsd sets the "daily_usage_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.ResetDailyUsageUsd()
- _u.mutation.SetDailyUsageUsd(v)
- return _u
- }
- // SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableDailyUsageUsd(v *float64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetDailyUsageUsd(*v)
- }
- return _u
- }
- // AddDailyUsageUsd adds value to the "daily_usage_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.AddDailyUsageUsd(v)
- return _u
- }
- // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.ResetWeeklyUsageUsd()
- _u.mutation.SetWeeklyUsageUsd(v)
- return _u
- }
- // SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableWeeklyUsageUsd(v *float64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetWeeklyUsageUsd(*v)
- }
- return _u
- }
- // AddWeeklyUsageUsd adds value to the "weekly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.AddWeeklyUsageUsd(v)
- return _u
- }
- // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.ResetMonthlyUsageUsd()
- _u.mutation.SetMonthlyUsageUsd(v)
- return _u
- }
- // SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableMonthlyUsageUsd(v *float64) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetMonthlyUsageUsd(*v)
- }
- return _u
- }
- // AddMonthlyUsageUsd adds value to the "monthly_usage_usd" field.
- func (_u *UserPlatformQuotaUpdateOne) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpdateOne {
- _u.mutation.AddMonthlyUsageUsd(v)
- return _u
- }
- // SetDailyWindowStart sets the "daily_window_start" field.
- func (_u *UserPlatformQuotaUpdateOne) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetDailyWindowStart(v)
- return _u
- }
- // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableDailyWindowStart(v *time.Time) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetDailyWindowStart(*v)
- }
- return _u
- }
- // ClearDailyWindowStart clears the value of the "daily_window_start" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearDailyWindowStart() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearDailyWindowStart()
- return _u
- }
- // SetWeeklyWindowStart sets the "weekly_window_start" field.
- func (_u *UserPlatformQuotaUpdateOne) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetWeeklyWindowStart(v)
- return _u
- }
- // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableWeeklyWindowStart(v *time.Time) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetWeeklyWindowStart(*v)
- }
- return _u
- }
- // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearWeeklyWindowStart() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearWeeklyWindowStart()
- return _u
- }
- // SetMonthlyWindowStart sets the "monthly_window_start" field.
- func (_u *UserPlatformQuotaUpdateOne) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpdateOne {
- _u.mutation.SetMonthlyWindowStart(v)
- return _u
- }
- // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
- func (_u *UserPlatformQuotaUpdateOne) SetNillableMonthlyWindowStart(v *time.Time) *UserPlatformQuotaUpdateOne {
- if v != nil {
- _u.SetMonthlyWindowStart(*v)
- }
- return _u
- }
- // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
- func (_u *UserPlatformQuotaUpdateOne) ClearMonthlyWindowStart() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearMonthlyWindowStart()
- return _u
- }
- // SetUser sets the "user" edge to the User entity.
- func (_u *UserPlatformQuotaUpdateOne) SetUser(v *User) *UserPlatformQuotaUpdateOne {
- return _u.SetUserID(v.ID)
- }
- // Mutation returns the UserPlatformQuotaMutation object of the builder.
- func (_u *UserPlatformQuotaUpdateOne) Mutation() *UserPlatformQuotaMutation {
- return _u.mutation
- }
- // ClearUser clears the "user" edge to the User entity.
- func (_u *UserPlatformQuotaUpdateOne) ClearUser() *UserPlatformQuotaUpdateOne {
- _u.mutation.ClearUser()
- return _u
- }
- // Where appends a list predicates to the UserPlatformQuotaUpdate builder.
- func (_u *UserPlatformQuotaUpdateOne) Where(ps ...predicate.UserPlatformQuota) *UserPlatformQuotaUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *UserPlatformQuotaUpdateOne) Select(field string, fields ...string) *UserPlatformQuotaUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated UserPlatformQuota entity.
- func (_u *UserPlatformQuotaUpdateOne) Save(ctx context.Context) (*UserPlatformQuota, error) {
- if err := _u.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *UserPlatformQuotaUpdateOne) SaveX(ctx context.Context) *UserPlatformQuota {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *UserPlatformQuotaUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *UserPlatformQuotaUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *UserPlatformQuotaUpdateOne) defaults() error {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- if userplatformquota.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized userplatformquota.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := userplatformquota.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *UserPlatformQuotaUpdateOne) check() error {
- if v, ok := _u.mutation.Platform(); ok {
- if err := userplatformquota.PlatformValidator(v); err != nil {
- return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "UserPlatformQuota.platform": %w`, err)}
- }
- }
- if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "UserPlatformQuota.user"`)
- }
- return nil
- }
- func (_u *UserPlatformQuotaUpdateOne) sqlSave(ctx context.Context) (_node *UserPlatformQuota, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(userplatformquota.Table, userplatformquota.Columns, sqlgraph.NewFieldSpec(userplatformquota.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserPlatformQuota.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, userplatformquota.FieldID)
- for _, f := range fields {
- if !userplatformquota.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != userplatformquota.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(userplatformquota.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.DeletedAt(); ok {
- _spec.SetField(userplatformquota.FieldDeletedAt, field.TypeTime, value)
- }
- if _u.mutation.DeletedAtCleared() {
- _spec.ClearField(userplatformquota.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.Platform(); ok {
- _spec.SetField(userplatformquota.FieldPlatform, field.TypeString, value)
- }
- if value, ok := _u.mutation.DailyLimitUsd(); ok {
- _spec.SetField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedDailyLimitUsd(); ok {
- _spec.AddField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
- }
- if _u.mutation.DailyLimitUsdCleared() {
- _spec.ClearField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64)
- }
- if value, ok := _u.mutation.WeeklyLimitUsd(); ok {
- _spec.SetField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedWeeklyLimitUsd(); ok {
- _spec.AddField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
- }
- if _u.mutation.WeeklyLimitUsdCleared() {
- _spec.ClearField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64)
- }
- if value, ok := _u.mutation.MonthlyLimitUsd(); ok {
- _spec.SetField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedMonthlyLimitUsd(); ok {
- _spec.AddField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
- }
- if _u.mutation.MonthlyLimitUsdCleared() {
- _spec.ClearField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64)
- }
- if value, ok := _u.mutation.DailyUsageUsd(); ok {
- _spec.SetField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedDailyUsageUsd(); ok {
- _spec.AddField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.WeeklyUsageUsd(); ok {
- _spec.SetField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedWeeklyUsageUsd(); ok {
- _spec.AddField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.MonthlyUsageUsd(); ok {
- _spec.SetField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedMonthlyUsageUsd(); ok {
- _spec.AddField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.DailyWindowStart(); ok {
- _spec.SetField(userplatformquota.FieldDailyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.DailyWindowStartCleared() {
- _spec.ClearField(userplatformquota.FieldDailyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.WeeklyWindowStart(); ok {
- _spec.SetField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.WeeklyWindowStartCleared() {
- _spec.ClearField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.MonthlyWindowStart(); ok {
- _spec.SetField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.MonthlyWindowStartCleared() {
- _spec.ClearField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime)
- }
- if _u.mutation.UserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: userplatformquota.UserTable,
- Columns: []string{userplatformquota.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: userplatformquota.UserTable,
- Columns: []string{userplatformquota.UserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &UserPlatformQuota{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{userplatformquota.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|