| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349 |
- // 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/group"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- "github.com/Wei-Shaw/sub2api/ent/usagelog"
- "github.com/Wei-Shaw/sub2api/ent/user"
- "github.com/Wei-Shaw/sub2api/ent/usersubscription"
- )
- // UserSubscriptionUpdate is the builder for updating UserSubscription entities.
- type UserSubscriptionUpdate struct {
- config
- hooks []Hook
- mutation *UserSubscriptionMutation
- }
- // Where appends a list predicates to the UserSubscriptionUpdate builder.
- func (_u *UserSubscriptionUpdate) Where(ps ...predicate.UserSubscription) *UserSubscriptionUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *UserSubscriptionUpdate) SetUpdatedAt(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_u *UserSubscriptionUpdate) SetDeletedAt(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetDeletedAt(v)
- return _u
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableDeletedAt(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetDeletedAt(*v)
- }
- return _u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (_u *UserSubscriptionUpdate) ClearDeletedAt() *UserSubscriptionUpdate {
- _u.mutation.ClearDeletedAt()
- return _u
- }
- // SetUserID sets the "user_id" field.
- func (_u *UserSubscriptionUpdate) SetUserID(v int64) *UserSubscriptionUpdate {
- _u.mutation.SetUserID(v)
- return _u
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableUserID(v *int64) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetUserID(*v)
- }
- return _u
- }
- // SetGroupID sets the "group_id" field.
- func (_u *UserSubscriptionUpdate) SetGroupID(v int64) *UserSubscriptionUpdate {
- _u.mutation.SetGroupID(v)
- return _u
- }
- // SetNillableGroupID sets the "group_id" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableGroupID(v *int64) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetGroupID(*v)
- }
- return _u
- }
- // SetStartsAt sets the "starts_at" field.
- func (_u *UserSubscriptionUpdate) SetStartsAt(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetStartsAt(v)
- return _u
- }
- // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableStartsAt(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetStartsAt(*v)
- }
- return _u
- }
- // SetExpiresAt sets the "expires_at" field.
- func (_u *UserSubscriptionUpdate) SetExpiresAt(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetExpiresAt(v)
- return _u
- }
- // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableExpiresAt(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetExpiresAt(*v)
- }
- return _u
- }
- // SetStatus sets the "status" field.
- func (_u *UserSubscriptionUpdate) SetStatus(v string) *UserSubscriptionUpdate {
- _u.mutation.SetStatus(v)
- return _u
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableStatus(v *string) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetStatus(*v)
- }
- return _u
- }
- // SetDailyWindowStart sets the "daily_window_start" field.
- func (_u *UserSubscriptionUpdate) SetDailyWindowStart(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetDailyWindowStart(v)
- return _u
- }
- // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableDailyWindowStart(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetDailyWindowStart(*v)
- }
- return _u
- }
- // ClearDailyWindowStart clears the value of the "daily_window_start" field.
- func (_u *UserSubscriptionUpdate) ClearDailyWindowStart() *UserSubscriptionUpdate {
- _u.mutation.ClearDailyWindowStart()
- return _u
- }
- // SetWeeklyWindowStart sets the "weekly_window_start" field.
- func (_u *UserSubscriptionUpdate) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetWeeklyWindowStart(v)
- return _u
- }
- // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableWeeklyWindowStart(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetWeeklyWindowStart(*v)
- }
- return _u
- }
- // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
- func (_u *UserSubscriptionUpdate) ClearWeeklyWindowStart() *UserSubscriptionUpdate {
- _u.mutation.ClearWeeklyWindowStart()
- return _u
- }
- // SetMonthlyWindowStart sets the "monthly_window_start" field.
- func (_u *UserSubscriptionUpdate) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetMonthlyWindowStart(v)
- return _u
- }
- // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableMonthlyWindowStart(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetMonthlyWindowStart(*v)
- }
- return _u
- }
- // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
- func (_u *UserSubscriptionUpdate) ClearMonthlyWindowStart() *UserSubscriptionUpdate {
- _u.mutation.ClearMonthlyWindowStart()
- return _u
- }
- // SetDailyUsageUsd sets the "daily_usage_usd" field.
- func (_u *UserSubscriptionUpdate) SetDailyUsageUsd(v float64) *UserSubscriptionUpdate {
- _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 *UserSubscriptionUpdate) SetNillableDailyUsageUsd(v *float64) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetDailyUsageUsd(*v)
- }
- return _u
- }
- // AddDailyUsageUsd adds value to the "daily_usage_usd" field.
- func (_u *UserSubscriptionUpdate) AddDailyUsageUsd(v float64) *UserSubscriptionUpdate {
- _u.mutation.AddDailyUsageUsd(v)
- return _u
- }
- // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
- func (_u *UserSubscriptionUpdate) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpdate {
- _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 *UserSubscriptionUpdate) SetNillableWeeklyUsageUsd(v *float64) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetWeeklyUsageUsd(*v)
- }
- return _u
- }
- // AddWeeklyUsageUsd adds value to the "weekly_usage_usd" field.
- func (_u *UserSubscriptionUpdate) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpdate {
- _u.mutation.AddWeeklyUsageUsd(v)
- return _u
- }
- // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
- func (_u *UserSubscriptionUpdate) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpdate {
- _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 *UserSubscriptionUpdate) SetNillableMonthlyUsageUsd(v *float64) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetMonthlyUsageUsd(*v)
- }
- return _u
- }
- // AddMonthlyUsageUsd adds value to the "monthly_usage_usd" field.
- func (_u *UserSubscriptionUpdate) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpdate {
- _u.mutation.AddMonthlyUsageUsd(v)
- return _u
- }
- // SetAssignedBy sets the "assigned_by" field.
- func (_u *UserSubscriptionUpdate) SetAssignedBy(v int64) *UserSubscriptionUpdate {
- _u.mutation.SetAssignedBy(v)
- return _u
- }
- // SetNillableAssignedBy sets the "assigned_by" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableAssignedBy(v *int64) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetAssignedBy(*v)
- }
- return _u
- }
- // ClearAssignedBy clears the value of the "assigned_by" field.
- func (_u *UserSubscriptionUpdate) ClearAssignedBy() *UserSubscriptionUpdate {
- _u.mutation.ClearAssignedBy()
- return _u
- }
- // SetAssignedAt sets the "assigned_at" field.
- func (_u *UserSubscriptionUpdate) SetAssignedAt(v time.Time) *UserSubscriptionUpdate {
- _u.mutation.SetAssignedAt(v)
- return _u
- }
- // SetNillableAssignedAt sets the "assigned_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableAssignedAt(v *time.Time) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetAssignedAt(*v)
- }
- return _u
- }
- // SetNotes sets the "notes" field.
- func (_u *UserSubscriptionUpdate) SetNotes(v string) *UserSubscriptionUpdate {
- _u.mutation.SetNotes(v)
- return _u
- }
- // SetNillableNotes sets the "notes" field if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableNotes(v *string) *UserSubscriptionUpdate {
- if v != nil {
- _u.SetNotes(*v)
- }
- return _u
- }
- // ClearNotes clears the value of the "notes" field.
- func (_u *UserSubscriptionUpdate) ClearNotes() *UserSubscriptionUpdate {
- _u.mutation.ClearNotes()
- return _u
- }
- // SetUser sets the "user" edge to the User entity.
- func (_u *UserSubscriptionUpdate) SetUser(v *User) *UserSubscriptionUpdate {
- return _u.SetUserID(v.ID)
- }
- // SetGroup sets the "group" edge to the Group entity.
- func (_u *UserSubscriptionUpdate) SetGroup(v *Group) *UserSubscriptionUpdate {
- return _u.SetGroupID(v.ID)
- }
- // SetAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID.
- func (_u *UserSubscriptionUpdate) SetAssignedByUserID(id int64) *UserSubscriptionUpdate {
- _u.mutation.SetAssignedByUserID(id)
- return _u
- }
- // SetNillableAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID if the given value is not nil.
- func (_u *UserSubscriptionUpdate) SetNillableAssignedByUserID(id *int64) *UserSubscriptionUpdate {
- if id != nil {
- _u = _u.SetAssignedByUserID(*id)
- }
- return _u
- }
- // SetAssignedByUser sets the "assigned_by_user" edge to the User entity.
- func (_u *UserSubscriptionUpdate) SetAssignedByUser(v *User) *UserSubscriptionUpdate {
- return _u.SetAssignedByUserID(v.ID)
- }
- // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
- func (_u *UserSubscriptionUpdate) AddUsageLogIDs(ids ...int64) *UserSubscriptionUpdate {
- _u.mutation.AddUsageLogIDs(ids...)
- return _u
- }
- // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
- func (_u *UserSubscriptionUpdate) AddUsageLogs(v ...*UsageLog) *UserSubscriptionUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddUsageLogIDs(ids...)
- }
- // Mutation returns the UserSubscriptionMutation object of the builder.
- func (_u *UserSubscriptionUpdate) Mutation() *UserSubscriptionMutation {
- return _u.mutation
- }
- // ClearUser clears the "user" edge to the User entity.
- func (_u *UserSubscriptionUpdate) ClearUser() *UserSubscriptionUpdate {
- _u.mutation.ClearUser()
- return _u
- }
- // ClearGroup clears the "group" edge to the Group entity.
- func (_u *UserSubscriptionUpdate) ClearGroup() *UserSubscriptionUpdate {
- _u.mutation.ClearGroup()
- return _u
- }
- // ClearAssignedByUser clears the "assigned_by_user" edge to the User entity.
- func (_u *UserSubscriptionUpdate) ClearAssignedByUser() *UserSubscriptionUpdate {
- _u.mutation.ClearAssignedByUser()
- return _u
- }
- // ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
- func (_u *UserSubscriptionUpdate) ClearUsageLogs() *UserSubscriptionUpdate {
- _u.mutation.ClearUsageLogs()
- return _u
- }
- // RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
- func (_u *UserSubscriptionUpdate) RemoveUsageLogIDs(ids ...int64) *UserSubscriptionUpdate {
- _u.mutation.RemoveUsageLogIDs(ids...)
- return _u
- }
- // RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
- func (_u *UserSubscriptionUpdate) RemoveUsageLogs(v ...*UsageLog) *UserSubscriptionUpdate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveUsageLogIDs(ids...)
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *UserSubscriptionUpdate) 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 *UserSubscriptionUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *UserSubscriptionUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *UserSubscriptionUpdate) 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 *UserSubscriptionUpdate) defaults() error {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- if usersubscription.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized usersubscription.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := usersubscription.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *UserSubscriptionUpdate) check() error {
- if v, ok := _u.mutation.Status(); ok {
- if err := usersubscription.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UserSubscription.status": %w`, err)}
- }
- }
- if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "UserSubscription.user"`)
- }
- if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "UserSubscription.group"`)
- }
- return nil
- }
- func (_u *UserSubscriptionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(usersubscription.Table, usersubscription.Columns, sqlgraph.NewFieldSpec(usersubscription.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(usersubscription.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.DeletedAt(); ok {
- _spec.SetField(usersubscription.FieldDeletedAt, field.TypeTime, value)
- }
- if _u.mutation.DeletedAtCleared() {
- _spec.ClearField(usersubscription.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.StartsAt(); ok {
- _spec.SetField(usersubscription.FieldStartsAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.ExpiresAt(); ok {
- _spec.SetField(usersubscription.FieldExpiresAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Status(); ok {
- _spec.SetField(usersubscription.FieldStatus, field.TypeString, value)
- }
- if value, ok := _u.mutation.DailyWindowStart(); ok {
- _spec.SetField(usersubscription.FieldDailyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.DailyWindowStartCleared() {
- _spec.ClearField(usersubscription.FieldDailyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.WeeklyWindowStart(); ok {
- _spec.SetField(usersubscription.FieldWeeklyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.WeeklyWindowStartCleared() {
- _spec.ClearField(usersubscription.FieldWeeklyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.MonthlyWindowStart(); ok {
- _spec.SetField(usersubscription.FieldMonthlyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.MonthlyWindowStartCleared() {
- _spec.ClearField(usersubscription.FieldMonthlyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.DailyUsageUsd(); ok {
- _spec.SetField(usersubscription.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedDailyUsageUsd(); ok {
- _spec.AddField(usersubscription.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.WeeklyUsageUsd(); ok {
- _spec.SetField(usersubscription.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedWeeklyUsageUsd(); ok {
- _spec.AddField(usersubscription.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.MonthlyUsageUsd(); ok {
- _spec.SetField(usersubscription.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedMonthlyUsageUsd(); ok {
- _spec.AddField(usersubscription.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AssignedAt(); ok {
- _spec.SetField(usersubscription.FieldAssignedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Notes(); ok {
- _spec.SetField(usersubscription.FieldNotes, field.TypeString, value)
- }
- if _u.mutation.NotesCleared() {
- _spec.ClearField(usersubscription.FieldNotes, field.TypeString)
- }
- if _u.mutation.UserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.UserTable,
- Columns: []string{usersubscription.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: usersubscription.UserTable,
- Columns: []string{usersubscription.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 _u.mutation.GroupCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.GroupTable,
- Columns: []string{usersubscription.GroupColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.GroupTable,
- Columns: []string{usersubscription.GroupColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.AssignedByUserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.AssignedByUserTable,
- Columns: []string{usersubscription.AssignedByUserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.AssignedByUserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.AssignedByUserTable,
- Columns: []string{usersubscription.AssignedByUserColumn},
- 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 _u.mutation.UsageLogsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: usersubscription.UsageLogsTable,
- Columns: []string{usersubscription.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: usersubscription.UsageLogsTable,
- Columns: []string{usersubscription.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: usersubscription.UsageLogsTable,
- Columns: []string{usersubscription.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.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{usersubscription.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // UserSubscriptionUpdateOne is the builder for updating a single UserSubscription entity.
- type UserSubscriptionUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *UserSubscriptionMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *UserSubscriptionUpdateOne) SetUpdatedAt(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (_u *UserSubscriptionUpdateOne) SetDeletedAt(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetDeletedAt(v)
- return _u
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableDeletedAt(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetDeletedAt(*v)
- }
- return _u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (_u *UserSubscriptionUpdateOne) ClearDeletedAt() *UserSubscriptionUpdateOne {
- _u.mutation.ClearDeletedAt()
- return _u
- }
- // SetUserID sets the "user_id" field.
- func (_u *UserSubscriptionUpdateOne) SetUserID(v int64) *UserSubscriptionUpdateOne {
- _u.mutation.SetUserID(v)
- return _u
- }
- // SetNillableUserID sets the "user_id" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableUserID(v *int64) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetUserID(*v)
- }
- return _u
- }
- // SetGroupID sets the "group_id" field.
- func (_u *UserSubscriptionUpdateOne) SetGroupID(v int64) *UserSubscriptionUpdateOne {
- _u.mutation.SetGroupID(v)
- return _u
- }
- // SetNillableGroupID sets the "group_id" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableGroupID(v *int64) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetGroupID(*v)
- }
- return _u
- }
- // SetStartsAt sets the "starts_at" field.
- func (_u *UserSubscriptionUpdateOne) SetStartsAt(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetStartsAt(v)
- return _u
- }
- // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableStartsAt(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetStartsAt(*v)
- }
- return _u
- }
- // SetExpiresAt sets the "expires_at" field.
- func (_u *UserSubscriptionUpdateOne) SetExpiresAt(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetExpiresAt(v)
- return _u
- }
- // SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableExpiresAt(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetExpiresAt(*v)
- }
- return _u
- }
- // SetStatus sets the "status" field.
- func (_u *UserSubscriptionUpdateOne) SetStatus(v string) *UserSubscriptionUpdateOne {
- _u.mutation.SetStatus(v)
- return _u
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableStatus(v *string) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetStatus(*v)
- }
- return _u
- }
- // SetDailyWindowStart sets the "daily_window_start" field.
- func (_u *UserSubscriptionUpdateOne) SetDailyWindowStart(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetDailyWindowStart(v)
- return _u
- }
- // SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableDailyWindowStart(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetDailyWindowStart(*v)
- }
- return _u
- }
- // ClearDailyWindowStart clears the value of the "daily_window_start" field.
- func (_u *UserSubscriptionUpdateOne) ClearDailyWindowStart() *UserSubscriptionUpdateOne {
- _u.mutation.ClearDailyWindowStart()
- return _u
- }
- // SetWeeklyWindowStart sets the "weekly_window_start" field.
- func (_u *UserSubscriptionUpdateOne) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetWeeklyWindowStart(v)
- return _u
- }
- // SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableWeeklyWindowStart(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetWeeklyWindowStart(*v)
- }
- return _u
- }
- // ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
- func (_u *UserSubscriptionUpdateOne) ClearWeeklyWindowStart() *UserSubscriptionUpdateOne {
- _u.mutation.ClearWeeklyWindowStart()
- return _u
- }
- // SetMonthlyWindowStart sets the "monthly_window_start" field.
- func (_u *UserSubscriptionUpdateOne) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetMonthlyWindowStart(v)
- return _u
- }
- // SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableMonthlyWindowStart(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetMonthlyWindowStart(*v)
- }
- return _u
- }
- // ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
- func (_u *UserSubscriptionUpdateOne) ClearMonthlyWindowStart() *UserSubscriptionUpdateOne {
- _u.mutation.ClearMonthlyWindowStart()
- return _u
- }
- // SetDailyUsageUsd sets the "daily_usage_usd" field.
- func (_u *UserSubscriptionUpdateOne) SetDailyUsageUsd(v float64) *UserSubscriptionUpdateOne {
- _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 *UserSubscriptionUpdateOne) SetNillableDailyUsageUsd(v *float64) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetDailyUsageUsd(*v)
- }
- return _u
- }
- // AddDailyUsageUsd adds value to the "daily_usage_usd" field.
- func (_u *UserSubscriptionUpdateOne) AddDailyUsageUsd(v float64) *UserSubscriptionUpdateOne {
- _u.mutation.AddDailyUsageUsd(v)
- return _u
- }
- // SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
- func (_u *UserSubscriptionUpdateOne) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpdateOne {
- _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 *UserSubscriptionUpdateOne) SetNillableWeeklyUsageUsd(v *float64) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetWeeklyUsageUsd(*v)
- }
- return _u
- }
- // AddWeeklyUsageUsd adds value to the "weekly_usage_usd" field.
- func (_u *UserSubscriptionUpdateOne) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpdateOne {
- _u.mutation.AddWeeklyUsageUsd(v)
- return _u
- }
- // SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
- func (_u *UserSubscriptionUpdateOne) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpdateOne {
- _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 *UserSubscriptionUpdateOne) SetNillableMonthlyUsageUsd(v *float64) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetMonthlyUsageUsd(*v)
- }
- return _u
- }
- // AddMonthlyUsageUsd adds value to the "monthly_usage_usd" field.
- func (_u *UserSubscriptionUpdateOne) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpdateOne {
- _u.mutation.AddMonthlyUsageUsd(v)
- return _u
- }
- // SetAssignedBy sets the "assigned_by" field.
- func (_u *UserSubscriptionUpdateOne) SetAssignedBy(v int64) *UserSubscriptionUpdateOne {
- _u.mutation.SetAssignedBy(v)
- return _u
- }
- // SetNillableAssignedBy sets the "assigned_by" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableAssignedBy(v *int64) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetAssignedBy(*v)
- }
- return _u
- }
- // ClearAssignedBy clears the value of the "assigned_by" field.
- func (_u *UserSubscriptionUpdateOne) ClearAssignedBy() *UserSubscriptionUpdateOne {
- _u.mutation.ClearAssignedBy()
- return _u
- }
- // SetAssignedAt sets the "assigned_at" field.
- func (_u *UserSubscriptionUpdateOne) SetAssignedAt(v time.Time) *UserSubscriptionUpdateOne {
- _u.mutation.SetAssignedAt(v)
- return _u
- }
- // SetNillableAssignedAt sets the "assigned_at" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableAssignedAt(v *time.Time) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetAssignedAt(*v)
- }
- return _u
- }
- // SetNotes sets the "notes" field.
- func (_u *UserSubscriptionUpdateOne) SetNotes(v string) *UserSubscriptionUpdateOne {
- _u.mutation.SetNotes(v)
- return _u
- }
- // SetNillableNotes sets the "notes" field if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableNotes(v *string) *UserSubscriptionUpdateOne {
- if v != nil {
- _u.SetNotes(*v)
- }
- return _u
- }
- // ClearNotes clears the value of the "notes" field.
- func (_u *UserSubscriptionUpdateOne) ClearNotes() *UserSubscriptionUpdateOne {
- _u.mutation.ClearNotes()
- return _u
- }
- // SetUser sets the "user" edge to the User entity.
- func (_u *UserSubscriptionUpdateOne) SetUser(v *User) *UserSubscriptionUpdateOne {
- return _u.SetUserID(v.ID)
- }
- // SetGroup sets the "group" edge to the Group entity.
- func (_u *UserSubscriptionUpdateOne) SetGroup(v *Group) *UserSubscriptionUpdateOne {
- return _u.SetGroupID(v.ID)
- }
- // SetAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID.
- func (_u *UserSubscriptionUpdateOne) SetAssignedByUserID(id int64) *UserSubscriptionUpdateOne {
- _u.mutation.SetAssignedByUserID(id)
- return _u
- }
- // SetNillableAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID if the given value is not nil.
- func (_u *UserSubscriptionUpdateOne) SetNillableAssignedByUserID(id *int64) *UserSubscriptionUpdateOne {
- if id != nil {
- _u = _u.SetAssignedByUserID(*id)
- }
- return _u
- }
- // SetAssignedByUser sets the "assigned_by_user" edge to the User entity.
- func (_u *UserSubscriptionUpdateOne) SetAssignedByUser(v *User) *UserSubscriptionUpdateOne {
- return _u.SetAssignedByUserID(v.ID)
- }
- // AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
- func (_u *UserSubscriptionUpdateOne) AddUsageLogIDs(ids ...int64) *UserSubscriptionUpdateOne {
- _u.mutation.AddUsageLogIDs(ids...)
- return _u
- }
- // AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
- func (_u *UserSubscriptionUpdateOne) AddUsageLogs(v ...*UsageLog) *UserSubscriptionUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.AddUsageLogIDs(ids...)
- }
- // Mutation returns the UserSubscriptionMutation object of the builder.
- func (_u *UserSubscriptionUpdateOne) Mutation() *UserSubscriptionMutation {
- return _u.mutation
- }
- // ClearUser clears the "user" edge to the User entity.
- func (_u *UserSubscriptionUpdateOne) ClearUser() *UserSubscriptionUpdateOne {
- _u.mutation.ClearUser()
- return _u
- }
- // ClearGroup clears the "group" edge to the Group entity.
- func (_u *UserSubscriptionUpdateOne) ClearGroup() *UserSubscriptionUpdateOne {
- _u.mutation.ClearGroup()
- return _u
- }
- // ClearAssignedByUser clears the "assigned_by_user" edge to the User entity.
- func (_u *UserSubscriptionUpdateOne) ClearAssignedByUser() *UserSubscriptionUpdateOne {
- _u.mutation.ClearAssignedByUser()
- return _u
- }
- // ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
- func (_u *UserSubscriptionUpdateOne) ClearUsageLogs() *UserSubscriptionUpdateOne {
- _u.mutation.ClearUsageLogs()
- return _u
- }
- // RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
- func (_u *UserSubscriptionUpdateOne) RemoveUsageLogIDs(ids ...int64) *UserSubscriptionUpdateOne {
- _u.mutation.RemoveUsageLogIDs(ids...)
- return _u
- }
- // RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
- func (_u *UserSubscriptionUpdateOne) RemoveUsageLogs(v ...*UsageLog) *UserSubscriptionUpdateOne {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _u.RemoveUsageLogIDs(ids...)
- }
- // Where appends a list predicates to the UserSubscriptionUpdate builder.
- func (_u *UserSubscriptionUpdateOne) Where(ps ...predicate.UserSubscription) *UserSubscriptionUpdateOne {
- _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 *UserSubscriptionUpdateOne) Select(field string, fields ...string) *UserSubscriptionUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated UserSubscription entity.
- func (_u *UserSubscriptionUpdateOne) Save(ctx context.Context) (*UserSubscription, 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 *UserSubscriptionUpdateOne) SaveX(ctx context.Context) *UserSubscription {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *UserSubscriptionUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *UserSubscriptionUpdateOne) 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 *UserSubscriptionUpdateOne) defaults() error {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- if usersubscription.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized usersubscription.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := usersubscription.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *UserSubscriptionUpdateOne) check() error {
- if v, ok := _u.mutation.Status(); ok {
- if err := usersubscription.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UserSubscription.status": %w`, err)}
- }
- }
- if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "UserSubscription.user"`)
- }
- if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "UserSubscription.group"`)
- }
- return nil
- }
- func (_u *UserSubscriptionUpdateOne) sqlSave(ctx context.Context) (_node *UserSubscription, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(usersubscription.Table, usersubscription.Columns, sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserSubscription.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, usersubscription.FieldID)
- for _, f := range fields {
- if !usersubscription.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != usersubscription.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(usersubscription.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.DeletedAt(); ok {
- _spec.SetField(usersubscription.FieldDeletedAt, field.TypeTime, value)
- }
- if _u.mutation.DeletedAtCleared() {
- _spec.ClearField(usersubscription.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := _u.mutation.StartsAt(); ok {
- _spec.SetField(usersubscription.FieldStartsAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.ExpiresAt(); ok {
- _spec.SetField(usersubscription.FieldExpiresAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Status(); ok {
- _spec.SetField(usersubscription.FieldStatus, field.TypeString, value)
- }
- if value, ok := _u.mutation.DailyWindowStart(); ok {
- _spec.SetField(usersubscription.FieldDailyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.DailyWindowStartCleared() {
- _spec.ClearField(usersubscription.FieldDailyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.WeeklyWindowStart(); ok {
- _spec.SetField(usersubscription.FieldWeeklyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.WeeklyWindowStartCleared() {
- _spec.ClearField(usersubscription.FieldWeeklyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.MonthlyWindowStart(); ok {
- _spec.SetField(usersubscription.FieldMonthlyWindowStart, field.TypeTime, value)
- }
- if _u.mutation.MonthlyWindowStartCleared() {
- _spec.ClearField(usersubscription.FieldMonthlyWindowStart, field.TypeTime)
- }
- if value, ok := _u.mutation.DailyUsageUsd(); ok {
- _spec.SetField(usersubscription.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedDailyUsageUsd(); ok {
- _spec.AddField(usersubscription.FieldDailyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.WeeklyUsageUsd(); ok {
- _spec.SetField(usersubscription.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedWeeklyUsageUsd(); ok {
- _spec.AddField(usersubscription.FieldWeeklyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.MonthlyUsageUsd(); ok {
- _spec.SetField(usersubscription.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AddedMonthlyUsageUsd(); ok {
- _spec.AddField(usersubscription.FieldMonthlyUsageUsd, field.TypeFloat64, value)
- }
- if value, ok := _u.mutation.AssignedAt(); ok {
- _spec.SetField(usersubscription.FieldAssignedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.Notes(); ok {
- _spec.SetField(usersubscription.FieldNotes, field.TypeString, value)
- }
- if _u.mutation.NotesCleared() {
- _spec.ClearField(usersubscription.FieldNotes, field.TypeString)
- }
- if _u.mutation.UserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.UserTable,
- Columns: []string{usersubscription.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: usersubscription.UserTable,
- Columns: []string{usersubscription.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 _u.mutation.GroupCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.GroupTable,
- Columns: []string{usersubscription.GroupColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.GroupTable,
- Columns: []string{usersubscription.GroupColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.AssignedByUserCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.AssignedByUserTable,
- Columns: []string{usersubscription.AssignedByUserColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.AssignedByUserIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: usersubscription.AssignedByUserTable,
- Columns: []string{usersubscription.AssignedByUserColumn},
- 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 _u.mutation.UsageLogsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: usersubscription.UsageLogsTable,
- Columns: []string{usersubscription.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.RemovedUsageLogsIDs(); len(nodes) > 0 && !_u.mutation.UsageLogsCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: usersubscription.UsageLogsTable,
- Columns: []string{usersubscription.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.UsageLogsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: usersubscription.UsageLogsTable,
- Columns: []string{usersubscription.UsageLogsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &UserSubscription{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{usersubscription.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|