Commit 7331220e authored by Edric Li's avatar Edric Li
Browse files

Merge remote-tracking branch 'upstream/main'

# Conflicts:
#	frontend/src/components/account/CreateAccountModal.vue
parents fb86002e 4f13c8de
......@@ -41,12 +41,16 @@ const (
FieldWeeklyLimitUsd = "weekly_limit_usd"
// FieldMonthlyLimitUsd holds the string denoting the monthly_limit_usd field in the database.
FieldMonthlyLimitUsd = "monthly_limit_usd"
// FieldDefaultValidityDays holds the string denoting the default_validity_days field in the database.
FieldDefaultValidityDays = "default_validity_days"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys = "api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
EdgeRedeemCodes = "redeem_codes"
// EdgeSubscriptions holds the string denoting the subscriptions edge name in mutations.
EdgeSubscriptions = "subscriptions"
// EdgeUsageLogs holds the string denoting the usage_logs edge name in mutations.
EdgeUsageLogs = "usage_logs"
// EdgeAccounts holds the string denoting the accounts edge name in mutations.
EdgeAccounts = "accounts"
// EdgeAllowedUsers holds the string denoting the allowed_users edge name in mutations.
......@@ -78,6 +82,13 @@ const (
SubscriptionsInverseTable = "user_subscriptions"
// SubscriptionsColumn is the table column denoting the subscriptions relation/edge.
SubscriptionsColumn = "group_id"
// UsageLogsTable is the table that holds the usage_logs relation/edge.
UsageLogsTable = "usage_logs"
// UsageLogsInverseTable is the table name for the UsageLog entity.
// It exists in this package in order to avoid circular dependency with the "usagelog" package.
UsageLogsInverseTable = "usage_logs"
// UsageLogsColumn is the table column denoting the usage_logs relation/edge.
UsageLogsColumn = "group_id"
// AccountsTable is the table that holds the accounts relation/edge. The primary key declared below.
AccountsTable = "account_groups"
// AccountsInverseTable is the table name for the Account entity.
......@@ -120,6 +131,7 @@ var Columns = []string{
FieldDailyLimitUsd,
FieldWeeklyLimitUsd,
FieldMonthlyLimitUsd,
FieldDefaultValidityDays,
}
var (
......@@ -173,6 +185,8 @@ var (
DefaultSubscriptionType string
// SubscriptionTypeValidator is a validator for the "subscription_type" field. It is called by the builders before save.
SubscriptionTypeValidator func(string) error
// DefaultDefaultValidityDays holds the default value on creation for the "default_validity_days" field.
DefaultDefaultValidityDays int
)
// OrderOption defines the ordering options for the Group queries.
......@@ -248,6 +262,11 @@ func ByMonthlyLimitUsd(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMonthlyLimitUsd, opts...).ToFunc()
}
// ByDefaultValidityDays orders the results by the default_validity_days field.
func ByDefaultValidityDays(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDefaultValidityDays, opts...).ToFunc()
}
// ByAPIKeysCount orders the results by api_keys count.
func ByAPIKeysCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
......@@ -290,6 +309,20 @@ func BySubscriptions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
}
}
// ByUsageLogsCount orders the results by usage_logs count.
func ByUsageLogsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newUsageLogsStep(), opts...)
}
}
// ByUsageLogs orders the results by usage_logs terms.
func ByUsageLogs(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUsageLogsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
// ByAccountsCount orders the results by accounts count.
func ByAccountsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
......@@ -366,6 +399,13 @@ func newSubscriptionsStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.O2M, false, SubscriptionsTable, SubscriptionsColumn),
)
}
func newUsageLogsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UsageLogsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
)
}
func newAccountsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
......
......@@ -120,6 +120,11 @@ func MonthlyLimitUsd(v float64) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldMonthlyLimitUsd, v))
}
// DefaultValidityDays applies equality check predicate on the "default_validity_days" field. It's identical to DefaultValidityDaysEQ.
func DefaultValidityDays(v int) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldDefaultValidityDays, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldCreatedAt, v))
......@@ -785,6 +790,46 @@ func MonthlyLimitUsdNotNil() predicate.Group {
return predicate.Group(sql.FieldNotNull(FieldMonthlyLimitUsd))
}
// DefaultValidityDaysEQ applies the EQ predicate on the "default_validity_days" field.
func DefaultValidityDaysEQ(v int) predicate.Group {
return predicate.Group(sql.FieldEQ(FieldDefaultValidityDays, v))
}
// DefaultValidityDaysNEQ applies the NEQ predicate on the "default_validity_days" field.
func DefaultValidityDaysNEQ(v int) predicate.Group {
return predicate.Group(sql.FieldNEQ(FieldDefaultValidityDays, v))
}
// DefaultValidityDaysIn applies the In predicate on the "default_validity_days" field.
func DefaultValidityDaysIn(vs ...int) predicate.Group {
return predicate.Group(sql.FieldIn(FieldDefaultValidityDays, vs...))
}
// DefaultValidityDaysNotIn applies the NotIn predicate on the "default_validity_days" field.
func DefaultValidityDaysNotIn(vs ...int) predicate.Group {
return predicate.Group(sql.FieldNotIn(FieldDefaultValidityDays, vs...))
}
// DefaultValidityDaysGT applies the GT predicate on the "default_validity_days" field.
func DefaultValidityDaysGT(v int) predicate.Group {
return predicate.Group(sql.FieldGT(FieldDefaultValidityDays, v))
}
// DefaultValidityDaysGTE applies the GTE predicate on the "default_validity_days" field.
func DefaultValidityDaysGTE(v int) predicate.Group {
return predicate.Group(sql.FieldGTE(FieldDefaultValidityDays, v))
}
// DefaultValidityDaysLT applies the LT predicate on the "default_validity_days" field.
func DefaultValidityDaysLT(v int) predicate.Group {
return predicate.Group(sql.FieldLT(FieldDefaultValidityDays, v))
}
// DefaultValidityDaysLTE applies the LTE predicate on the "default_validity_days" field.
func DefaultValidityDaysLTE(v int) predicate.Group {
return predicate.Group(sql.FieldLTE(FieldDefaultValidityDays, v))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func HasAPIKeys() predicate.Group {
return predicate.Group(func(s *sql.Selector) {
......@@ -854,6 +899,29 @@ func HasSubscriptionsWith(preds ...predicate.UserSubscription) predicate.Group {
})
}
// HasUsageLogs applies the HasEdge predicate on the "usage_logs" edge.
func HasUsageLogs() predicate.Group {
return predicate.Group(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasUsageLogsWith applies the HasEdge predicate on the "usage_logs" edge with a given conditions (other predicates).
func HasUsageLogsWith(preds ...predicate.UsageLog) predicate.Group {
return predicate.Group(func(s *sql.Selector) {
step := newUsageLogsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasAccounts applies the HasEdge predicate on the "accounts" edge.
func HasAccounts() predicate.Group {
return predicate.Group(func(s *sql.Selector) {
......
......@@ -15,6 +15,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
......@@ -201,6 +202,20 @@ func (_c *GroupCreate) SetNillableMonthlyLimitUsd(v *float64) *GroupCreate {
return _c
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (_c *GroupCreate) SetDefaultValidityDays(v int) *GroupCreate {
_c.mutation.SetDefaultValidityDays(v)
return _c
}
// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
func (_c *GroupCreate) SetNillableDefaultValidityDays(v *int) *GroupCreate {
if v != nil {
_c.SetDefaultValidityDays(*v)
}
return _c
}
// AddAPIKeyIDs adds the "api_keys" edge to the ApiKey entity by IDs.
func (_c *GroupCreate) AddAPIKeyIDs(ids ...int64) *GroupCreate {
_c.mutation.AddAPIKeyIDs(ids...)
......@@ -246,6 +261,21 @@ func (_c *GroupCreate) AddSubscriptions(v ...*UserSubscription) *GroupCreate {
return _c.AddSubscriptionIDs(ids...)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_c *GroupCreate) AddUsageLogIDs(ids ...int64) *GroupCreate {
_c.mutation.AddUsageLogIDs(ids...)
return _c
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_c *GroupCreate) AddUsageLogs(v ...*UsageLog) *GroupCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddUsageLogIDs(ids...)
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_c *GroupCreate) AddAccountIDs(ids ...int64) *GroupCreate {
_c.mutation.AddAccountIDs(ids...)
......@@ -347,6 +377,10 @@ func (_c *GroupCreate) defaults() error {
v := group.DefaultSubscriptionType
_c.mutation.SetSubscriptionType(v)
}
if _, ok := _c.mutation.DefaultValidityDays(); !ok {
v := group.DefaultDefaultValidityDays
_c.mutation.SetDefaultValidityDays(v)
}
return nil
}
......@@ -396,6 +430,9 @@ func (_c *GroupCreate) check() error {
return &ValidationError{Name: "subscription_type", err: fmt.Errorf(`ent: validator failed for field "Group.subscription_type": %w`, err)}
}
}
if _, ok := _c.mutation.DefaultValidityDays(); !ok {
return &ValidationError{Name: "default_validity_days", err: errors.New(`ent: missing required field "Group.default_validity_days"`)}
}
return nil
}
......@@ -475,6 +512,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec.SetField(group.FieldMonthlyLimitUsd, field.TypeFloat64, value)
_node.MonthlyLimitUsd = &value
}
if value, ok := _c.mutation.DefaultValidityDays(); ok {
_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
_node.DefaultValidityDays = value
}
if nodes := _c.mutation.APIKeysIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
......@@ -523,6 +564,22 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: group.UsageLogsTable,
Columns: []string{group.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 = append(_spec.Edges, edge)
}
if nodes := _c.mutation.AccountsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
......@@ -813,6 +870,24 @@ func (u *GroupUpsert) ClearMonthlyLimitUsd() *GroupUpsert {
return u
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (u *GroupUpsert) SetDefaultValidityDays(v int) *GroupUpsert {
u.Set(group.FieldDefaultValidityDays, v)
return u
}
// UpdateDefaultValidityDays sets the "default_validity_days" field to the value that was provided on create.
func (u *GroupUpsert) UpdateDefaultValidityDays() *GroupUpsert {
u.SetExcluded(group.FieldDefaultValidityDays)
return u
}
// AddDefaultValidityDays adds v to the "default_validity_days" field.
func (u *GroupUpsert) AddDefaultValidityDays(v int) *GroupUpsert {
u.Add(group.FieldDefaultValidityDays, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
......@@ -1089,6 +1164,27 @@ func (u *GroupUpsertOne) ClearMonthlyLimitUsd() *GroupUpsertOne {
})
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (u *GroupUpsertOne) SetDefaultValidityDays(v int) *GroupUpsertOne {
return u.Update(func(s *GroupUpsert) {
s.SetDefaultValidityDays(v)
})
}
// AddDefaultValidityDays adds v to the "default_validity_days" field.
func (u *GroupUpsertOne) AddDefaultValidityDays(v int) *GroupUpsertOne {
return u.Update(func(s *GroupUpsert) {
s.AddDefaultValidityDays(v)
})
}
// UpdateDefaultValidityDays sets the "default_validity_days" field to the value that was provided on create.
func (u *GroupUpsertOne) UpdateDefaultValidityDays() *GroupUpsertOne {
return u.Update(func(s *GroupUpsert) {
s.UpdateDefaultValidityDays()
})
}
// Exec executes the query.
func (u *GroupUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
......@@ -1531,6 +1627,27 @@ func (u *GroupUpsertBulk) ClearMonthlyLimitUsd() *GroupUpsertBulk {
})
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (u *GroupUpsertBulk) SetDefaultValidityDays(v int) *GroupUpsertBulk {
return u.Update(func(s *GroupUpsert) {
s.SetDefaultValidityDays(v)
})
}
// AddDefaultValidityDays adds v to the "default_validity_days" field.
func (u *GroupUpsertBulk) AddDefaultValidityDays(v int) *GroupUpsertBulk {
return u.Update(func(s *GroupUpsert) {
s.AddDefaultValidityDays(v)
})
}
// UpdateDefaultValidityDays sets the "default_validity_days" field to the value that was provided on create.
func (u *GroupUpsertBulk) UpdateDefaultValidityDays() *GroupUpsertBulk {
return u.Update(func(s *GroupUpsert) {
s.UpdateDefaultValidityDays()
})
}
// Exec executes the query.
func (u *GroupUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
......
......@@ -18,6 +18,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
......@@ -33,6 +34,7 @@ type GroupQuery struct {
withAPIKeys *ApiKeyQuery
withRedeemCodes *RedeemCodeQuery
withSubscriptions *UserSubscriptionQuery
withUsageLogs *UsageLogQuery
withAccounts *AccountQuery
withAllowedUsers *UserQuery
withAccountGroups *AccountGroupQuery
......@@ -139,6 +141,28 @@ func (_q *GroupQuery) QuerySubscriptions() *UserSubscriptionQuery {
return query
}
// QueryUsageLogs chains the current query on the "usage_logs" edge.
func (_q *GroupQuery) QueryUsageLogs() *UsageLogQuery {
query := (&UsageLogClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(group.Table, group.FieldID, selector),
sqlgraph.To(usagelog.Table, usagelog.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, group.UsageLogsTable, group.UsageLogsColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryAccounts chains the current query on the "accounts" edge.
func (_q *GroupQuery) QueryAccounts() *AccountQuery {
query := (&AccountClient{config: _q.config}).Query()
......@@ -422,6 +446,7 @@ func (_q *GroupQuery) Clone() *GroupQuery {
withAPIKeys: _q.withAPIKeys.Clone(),
withRedeemCodes: _q.withRedeemCodes.Clone(),
withSubscriptions: _q.withSubscriptions.Clone(),
withUsageLogs: _q.withUsageLogs.Clone(),
withAccounts: _q.withAccounts.Clone(),
withAllowedUsers: _q.withAllowedUsers.Clone(),
withAccountGroups: _q.withAccountGroups.Clone(),
......@@ -465,6 +490,17 @@ func (_q *GroupQuery) WithSubscriptions(opts ...func(*UserSubscriptionQuery)) *G
return _q
}
// WithUsageLogs tells the query-builder to eager-load the nodes that are connected to
// the "usage_logs" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *GroupQuery) WithUsageLogs(opts ...func(*UsageLogQuery)) *GroupQuery {
query := (&UsageLogClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withUsageLogs = query
return _q
}
// WithAccounts tells the query-builder to eager-load the nodes that are connected to
// the "accounts" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *GroupQuery) WithAccounts(opts ...func(*AccountQuery)) *GroupQuery {
......@@ -587,10 +623,11 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
var (
nodes = []*Group{}
_spec = _q.querySpec()
loadedTypes = [7]bool{
loadedTypes = [8]bool{
_q.withAPIKeys != nil,
_q.withRedeemCodes != nil,
_q.withSubscriptions != nil,
_q.withUsageLogs != nil,
_q.withAccounts != nil,
_q.withAllowedUsers != nil,
_q.withAccountGroups != nil,
......@@ -636,6 +673,13 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
return nil, err
}
}
if query := _q.withUsageLogs; query != nil {
if err := _q.loadUsageLogs(ctx, query, nodes,
func(n *Group) { n.Edges.UsageLogs = []*UsageLog{} },
func(n *Group, e *UsageLog) { n.Edges.UsageLogs = append(n.Edges.UsageLogs, e) }); err != nil {
return nil, err
}
}
if query := _q.withAccounts; query != nil {
if err := _q.loadAccounts(ctx, query, nodes,
func(n *Group) { n.Edges.Accounts = []*Account{} },
......@@ -763,6 +807,39 @@ func (_q *GroupQuery) loadSubscriptions(ctx context.Context, query *UserSubscrip
}
return nil
}
func (_q *GroupQuery) loadUsageLogs(ctx context.Context, query *UsageLogQuery, nodes []*Group, init func(*Group), assign func(*Group, *UsageLog)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*Group)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
if len(query.ctx.Fields) > 0 {
query.ctx.AppendFieldOnce(usagelog.FieldGroupID)
}
query.Where(predicate.UsageLog(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(group.UsageLogsColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.GroupID
if fk == nil {
return fmt.Errorf(`foreign-key "group_id" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "group_id" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *GroupQuery) loadAccounts(ctx context.Context, query *AccountQuery, nodes []*Group, init func(*Group), assign func(*Group, *Account)) error {
edgeIDs := make([]driver.Value, len(nodes))
byID := make(map[int64]*Group)
......
......@@ -16,6 +16,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
......@@ -251,6 +252,27 @@ func (_u *GroupUpdate) ClearMonthlyLimitUsd() *GroupUpdate {
return _u
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (_u *GroupUpdate) SetDefaultValidityDays(v int) *GroupUpdate {
_u.mutation.ResetDefaultValidityDays()
_u.mutation.SetDefaultValidityDays(v)
return _u
}
// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
func (_u *GroupUpdate) SetNillableDefaultValidityDays(v *int) *GroupUpdate {
if v != nil {
_u.SetDefaultValidityDays(*v)
}
return _u
}
// AddDefaultValidityDays adds value to the "default_validity_days" field.
func (_u *GroupUpdate) AddDefaultValidityDays(v int) *GroupUpdate {
_u.mutation.AddDefaultValidityDays(v)
return _u
}
// AddAPIKeyIDs adds the "api_keys" edge to the ApiKey entity by IDs.
func (_u *GroupUpdate) AddAPIKeyIDs(ids ...int64) *GroupUpdate {
_u.mutation.AddAPIKeyIDs(ids...)
......@@ -296,6 +318,21 @@ func (_u *GroupUpdate) AddSubscriptions(v ...*UserSubscription) *GroupUpdate {
return _u.AddSubscriptionIDs(ids...)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *GroupUpdate) AddUsageLogIDs(ids ...int64) *GroupUpdate {
_u.mutation.AddUsageLogIDs(ids...)
return _u
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdate) AddUsageLogs(v ...*UsageLog) *GroupUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddUsageLogIDs(ids...)
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *GroupUpdate) AddAccountIDs(ids ...int64) *GroupUpdate {
_u.mutation.AddAccountIDs(ids...)
......@@ -394,6 +431,27 @@ func (_u *GroupUpdate) RemoveSubscriptions(v ...*UserSubscription) *GroupUpdate
return _u.RemoveSubscriptionIDs(ids...)
}
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdate) ClearUsageLogs() *GroupUpdate {
_u.mutation.ClearUsageLogs()
return _u
}
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *GroupUpdate) RemoveUsageLogIDs(ids ...int64) *GroupUpdate {
_u.mutation.RemoveUsageLogIDs(ids...)
return _u
}
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *GroupUpdate) RemoveUsageLogs(v ...*UsageLog) *GroupUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveUsageLogIDs(ids...)
}
// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *GroupUpdate) ClearAccounts() *GroupUpdate {
_u.mutation.ClearAccounts()
......@@ -578,6 +636,12 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if _u.mutation.MonthlyLimitUsdCleared() {
_spec.ClearField(group.FieldMonthlyLimitUsd, field.TypeFloat64)
}
if value, ok := _u.mutation.DefaultValidityDays(); ok {
_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedDefaultValidityDays(); ok {
_spec.AddField(group.FieldDefaultValidityDays, field.TypeInt, value)
}
if _u.mutation.APIKeysCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
......@@ -713,6 +777,51 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.UsageLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: group.UsageLogsTable,
Columns: []string{group.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: group.UsageLogsTable,
Columns: []string{group.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: group.UsageLogsTable,
Columns: []string{group.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 _u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
......@@ -1065,6 +1174,27 @@ func (_u *GroupUpdateOne) ClearMonthlyLimitUsd() *GroupUpdateOne {
return _u
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (_u *GroupUpdateOne) SetDefaultValidityDays(v int) *GroupUpdateOne {
_u.mutation.ResetDefaultValidityDays()
_u.mutation.SetDefaultValidityDays(v)
return _u
}
// SetNillableDefaultValidityDays sets the "default_validity_days" field if the given value is not nil.
func (_u *GroupUpdateOne) SetNillableDefaultValidityDays(v *int) *GroupUpdateOne {
if v != nil {
_u.SetDefaultValidityDays(*v)
}
return _u
}
// AddDefaultValidityDays adds value to the "default_validity_days" field.
func (_u *GroupUpdateOne) AddDefaultValidityDays(v int) *GroupUpdateOne {
_u.mutation.AddDefaultValidityDays(v)
return _u
}
// AddAPIKeyIDs adds the "api_keys" edge to the ApiKey entity by IDs.
func (_u *GroupUpdateOne) AddAPIKeyIDs(ids ...int64) *GroupUpdateOne {
_u.mutation.AddAPIKeyIDs(ids...)
......@@ -1110,6 +1240,21 @@ func (_u *GroupUpdateOne) AddSubscriptions(v ...*UserSubscription) *GroupUpdateO
return _u.AddSubscriptionIDs(ids...)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *GroupUpdateOne) AddUsageLogIDs(ids ...int64) *GroupUpdateOne {
_u.mutation.AddUsageLogIDs(ids...)
return _u
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdateOne) AddUsageLogs(v ...*UsageLog) *GroupUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddUsageLogIDs(ids...)
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *GroupUpdateOne) AddAccountIDs(ids ...int64) *GroupUpdateOne {
_u.mutation.AddAccountIDs(ids...)
......@@ -1208,6 +1353,27 @@ func (_u *GroupUpdateOne) RemoveSubscriptions(v ...*UserSubscription) *GroupUpda
return _u.RemoveSubscriptionIDs(ids...)
}
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *GroupUpdateOne) ClearUsageLogs() *GroupUpdateOne {
_u.mutation.ClearUsageLogs()
return _u
}
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *GroupUpdateOne) RemoveUsageLogIDs(ids ...int64) *GroupUpdateOne {
_u.mutation.RemoveUsageLogIDs(ids...)
return _u
}
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *GroupUpdateOne) RemoveUsageLogs(v ...*UsageLog) *GroupUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveUsageLogIDs(ids...)
}
// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *GroupUpdateOne) ClearAccounts() *GroupUpdateOne {
_u.mutation.ClearAccounts()
......@@ -1422,6 +1588,12 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if _u.mutation.MonthlyLimitUsdCleared() {
_spec.ClearField(group.FieldMonthlyLimitUsd, field.TypeFloat64)
}
if value, ok := _u.mutation.DefaultValidityDays(); ok {
_spec.SetField(group.FieldDefaultValidityDays, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedDefaultValidityDays(); ok {
_spec.AddField(group.FieldDefaultValidityDays, field.TypeInt, value)
}
if _u.mutation.APIKeysCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
......@@ -1557,6 +1729,51 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.UsageLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: group.UsageLogsTable,
Columns: []string{group.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: group.UsageLogsTable,
Columns: []string{group.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: group.UsageLogsTable,
Columns: []string{group.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 _u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2M,
......
......@@ -93,6 +93,18 @@ func (f SettingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SettingMutation", m)
}
// The UsageLogFunc type is an adapter to allow the use of ordinary
// function as UsageLog mutator.
type UsageLogFunc func(context.Context, *ent.UsageLogMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UsageLogFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UsageLogMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageLogMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
......
......@@ -16,6 +16,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
......@@ -266,6 +267,33 @@ func (f TraverseSetting) Traverse(ctx context.Context, q ent.Query) error {
return fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q)
}
// The UsageLogFunc type is an adapter to allow the use of ordinary function as a Querier.
type UsageLogFunc func(context.Context, *ent.UsageLogQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UsageLogFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UsageLogQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UsageLogQuery", q)
}
// The TraverseUsageLog type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUsageLog func(context.Context, *ent.UsageLogQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUsageLog) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUsageLog) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UsageLogQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UsageLogQuery", q)
}
// The UserFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserFunc func(context.Context, *ent.UserQuery) (ent.Value, error)
......@@ -364,6 +392,8 @@ func NewQuery(q ent.Query) (Query, error) {
return &query[*ent.RedeemCodeQuery, predicate.RedeemCode, redeemcode.OrderOption]{typ: ent.TypeRedeemCode, tq: q}, nil
case *ent.SettingQuery:
return &query[*ent.SettingQuery, predicate.Setting, setting.OrderOption]{typ: ent.TypeSetting, tq: q}, nil
case *ent.UsageLogQuery:
return &query[*ent.UsageLogQuery, predicate.UsageLog, usagelog.OrderOption]{typ: ent.TypeUsageLog, tq: q}, nil
case *ent.UserQuery:
return &query[*ent.UserQuery, predicate.User, user.OrderOption]{typ: ent.TypeUser, tq: q}, nil
case *ent.UserAllowedGroupQuery:
......
......@@ -20,7 +20,6 @@ var (
{Name: "type", Type: field.TypeString, Size: 20},
{Name: "credentials", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
{Name: "extra", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
{Name: "proxy_id", Type: field.TypeInt64, Nullable: true},
{Name: "concurrency", Type: field.TypeInt, Default: 3},
{Name: "priority", Type: field.TypeInt, Default: 50},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
......@@ -33,12 +32,21 @@ var (
{Name: "session_window_start", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "session_window_end", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "session_window_status", Type: field.TypeString, Nullable: true, Size: 20},
{Name: "proxy_id", Type: field.TypeInt64, Nullable: true},
}
// AccountsTable holds the schema information for the "accounts" table.
AccountsTable = &schema.Table{
Name: "accounts",
Columns: AccountsColumns,
PrimaryKey: []*schema.Column{AccountsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "accounts_proxies_proxy",
Columns: []*schema.Column{AccountsColumns[21]},
RefColumns: []*schema.Column{ProxiesColumns[0]},
OnDelete: schema.SetNull,
},
},
Indexes: []*schema.Index{
{
Name: "account_platform",
......@@ -53,42 +61,42 @@ var (
{
Name: "account_status",
Unique: false,
Columns: []*schema.Column{AccountsColumns[12]},
Columns: []*schema.Column{AccountsColumns[11]},
},
{
Name: "account_proxy_id",
Unique: false,
Columns: []*schema.Column{AccountsColumns[9]},
Columns: []*schema.Column{AccountsColumns[21]},
},
{
Name: "account_priority",
Unique: false,
Columns: []*schema.Column{AccountsColumns[11]},
Columns: []*schema.Column{AccountsColumns[10]},
},
{
Name: "account_last_used_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[14]},
Columns: []*schema.Column{AccountsColumns[13]},
},
{
Name: "account_schedulable",
Unique: false,
Columns: []*schema.Column{AccountsColumns[15]},
Columns: []*schema.Column{AccountsColumns[14]},
},
{
Name: "account_rate_limited_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[16]},
Columns: []*schema.Column{AccountsColumns[15]},
},
{
Name: "account_rate_limit_reset_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[17]},
Columns: []*schema.Column{AccountsColumns[16]},
},
{
Name: "account_overload_until",
Unique: false,
Columns: []*schema.Column{AccountsColumns[18]},
Columns: []*schema.Column{AccountsColumns[17]},
},
{
Name: "account_deleted_at",
......@@ -100,7 +108,7 @@ var (
// AccountGroupsColumns holds the columns for the "account_groups" table.
AccountGroupsColumns = []*schema.Column{
{Name: "priority", Type: field.TypeInt, Default: 50},
{Name: "created_at", Type: field.TypeTime},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "account_id", Type: field.TypeInt64},
{Name: "group_id", Type: field.TypeInt64},
}
......@@ -168,11 +176,6 @@ var (
},
},
Indexes: []*schema.Index{
{
Name: "apikey_key",
Unique: true,
Columns: []*schema.Column{APIKeysColumns[4]},
},
{
Name: "apikey_user_id",
Unique: false,
......@@ -201,7 +204,7 @@ var (
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "name", Type: field.TypeString, Unique: true, Size: 100},
{Name: "name", Type: field.TypeString, Size: 100},
{Name: "description", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
{Name: "rate_multiplier", Type: field.TypeFloat64, Default: 1, SchemaType: map[string]string{"postgres": "decimal(10,4)"}},
{Name: "is_exclusive", Type: field.TypeBool, Default: false},
......@@ -211,6 +214,7 @@ var (
{Name: "daily_limit_usd", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "weekly_limit_usd", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "monthly_limit_usd", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "default_validity_days", Type: field.TypeInt, Default: 30},
}
// GroupsTable holds the schema information for the "groups" table.
GroupsTable = &schema.Table{
......@@ -218,11 +222,6 @@ var (
Columns: GroupsColumns,
PrimaryKey: []*schema.Column{GroupsColumns[0]},
Indexes: []*schema.Index{
{
Name: "group_name",
Unique: true,
Columns: []*schema.Column{GroupsColumns[4]},
},
{
Name: "group_status",
Unique: false,
......@@ -316,11 +315,6 @@ var (
},
},
Indexes: []*schema.Index{
{
Name: "redeemcode_code",
Unique: true,
Columns: []*schema.Column{RedeemCodesColumns[1]},
},
{
Name: "redeemcode_status",
Unique: false,
......@@ -350,11 +344,123 @@ var (
Name: "settings",
Columns: SettingsColumns,
PrimaryKey: []*schema.Column{SettingsColumns[0]},
}
// UsageLogsColumns holds the columns for the "usage_logs" table.
UsageLogsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "request_id", Type: field.TypeString, Size: 64},
{Name: "model", Type: field.TypeString, Size: 100},
{Name: "input_tokens", Type: field.TypeInt, Default: 0},
{Name: "output_tokens", Type: field.TypeInt, Default: 0},
{Name: "cache_creation_tokens", Type: field.TypeInt, Default: 0},
{Name: "cache_read_tokens", Type: field.TypeInt, Default: 0},
{Name: "cache_creation_5m_tokens", Type: field.TypeInt, Default: 0},
{Name: "cache_creation_1h_tokens", Type: field.TypeInt, Default: 0},
{Name: "input_cost", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "output_cost", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "cache_creation_cost", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "cache_read_cost", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "total_cost", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "actual_cost", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "rate_multiplier", Type: field.TypeFloat64, Default: 1, SchemaType: map[string]string{"postgres": "decimal(10,4)"}},
{Name: "billing_type", Type: field.TypeInt8, Default: 0},
{Name: "stream", Type: field.TypeBool, Default: false},
{Name: "duration_ms", Type: field.TypeInt, Nullable: true},
{Name: "first_token_ms", Type: field.TypeInt, Nullable: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "account_id", Type: field.TypeInt64},
{Name: "api_key_id", Type: field.TypeInt64},
{Name: "group_id", Type: field.TypeInt64, Nullable: true},
{Name: "user_id", Type: field.TypeInt64},
{Name: "subscription_id", Type: field.TypeInt64, Nullable: true},
}
// UsageLogsTable holds the schema information for the "usage_logs" table.
UsageLogsTable = &schema.Table{
Name: "usage_logs",
Columns: UsageLogsColumns,
PrimaryKey: []*schema.Column{UsageLogsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "usage_logs_accounts_usage_logs",
Columns: []*schema.Column{UsageLogsColumns[21]},
RefColumns: []*schema.Column{AccountsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "usage_logs_api_keys_usage_logs",
Columns: []*schema.Column{UsageLogsColumns[22]},
RefColumns: []*schema.Column{APIKeysColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "usage_logs_groups_usage_logs",
Columns: []*schema.Column{UsageLogsColumns[23]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull,
},
{
Symbol: "usage_logs_users_usage_logs",
Columns: []*schema.Column{UsageLogsColumns[24]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "usage_logs_user_subscriptions_usage_logs",
Columns: []*schema.Column{UsageLogsColumns[25]},
RefColumns: []*schema.Column{UserSubscriptionsColumns[0]},
OnDelete: schema.SetNull,
},
},
Indexes: []*schema.Index{
{
Name: "setting_key",
Unique: true,
Columns: []*schema.Column{SettingsColumns[1]},
Name: "usagelog_user_id",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[24]},
},
{
Name: "usagelog_api_key_id",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[22]},
},
{
Name: "usagelog_account_id",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[21]},
},
{
Name: "usagelog_group_id",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[23]},
},
{
Name: "usagelog_subscription_id",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[25]},
},
{
Name: "usagelog_created_at",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[20]},
},
{
Name: "usagelog_model",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[2]},
},
{
Name: "usagelog_request_id",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[1]},
},
{
Name: "usagelog_user_id_created_at",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[24], UsageLogsColumns[20]},
},
{
Name: "usagelog_api_key_id_created_at",
Unique: false,
Columns: []*schema.Column{UsageLogsColumns[22], UsageLogsColumns[20]},
},
},
}
......@@ -364,7 +470,7 @@ var (
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "email", Type: field.TypeString, Unique: true, Size: 255},
{Name: "email", Type: field.TypeString, Size: 255},
{Name: "password_hash", Type: field.TypeString, Size: 255},
{Name: "role", Type: field.TypeString, Size: 20, Default: "user"},
{Name: "balance", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
......@@ -380,11 +486,6 @@ var (
Columns: UsersColumns,
PrimaryKey: []*schema.Column{UsersColumns[0]},
Indexes: []*schema.Index{
{
Name: "user_email",
Unique: true,
Columns: []*schema.Column{UsersColumns[4]},
},
{
Name: "user_status",
Unique: false,
......@@ -399,7 +500,7 @@ var (
}
// UserAllowedGroupsColumns holds the columns for the "user_allowed_groups" table.
UserAllowedGroupsColumns = []*schema.Column{
{Name: "created_at", Type: field.TypeTime},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "user_id", Type: field.TypeInt64},
{Name: "group_id", Type: field.TypeInt64},
}
......@@ -435,6 +536,7 @@ var (
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "starts_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "expires_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
......@@ -458,19 +560,19 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "user_subscriptions_groups_subscriptions",
Columns: []*schema.Column{UserSubscriptionsColumns[14]},
Columns: []*schema.Column{UserSubscriptionsColumns[15]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "user_subscriptions_users_subscriptions",
Columns: []*schema.Column{UserSubscriptionsColumns[15]},
Columns: []*schema.Column{UserSubscriptionsColumns[16]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "user_subscriptions_users_assigned_subscriptions",
Columns: []*schema.Column{UserSubscriptionsColumns[16]},
Columns: []*schema.Column{UserSubscriptionsColumns[17]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.SetNull,
},
......@@ -479,32 +581,37 @@ var (
{
Name: "usersubscription_user_id",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[15]},
Columns: []*schema.Column{UserSubscriptionsColumns[16]},
},
{
Name: "usersubscription_group_id",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[14]},
Columns: []*schema.Column{UserSubscriptionsColumns[15]},
},
{
Name: "usersubscription_status",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[5]},
Columns: []*schema.Column{UserSubscriptionsColumns[6]},
},
{
Name: "usersubscription_expires_at",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[4]},
Columns: []*schema.Column{UserSubscriptionsColumns[5]},
},
{
Name: "usersubscription_assigned_by",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[16]},
Columns: []*schema.Column{UserSubscriptionsColumns[17]},
},
{
Name: "usersubscription_user_id_group_id",
Unique: true,
Columns: []*schema.Column{UserSubscriptionsColumns[15], UserSubscriptionsColumns[14]},
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[16], UserSubscriptionsColumns[15]},
},
{
Name: "usersubscription_deleted_at",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[3]},
},
},
}
......@@ -517,6 +624,7 @@ var (
ProxiesTable,
RedeemCodesTable,
SettingsTable,
UsageLogsTable,
UsersTable,
UserAllowedGroupsTable,
UserSubscriptionsTable,
......@@ -524,6 +632,7 @@ var (
)
func init() {
AccountsTable.ForeignKeys[0].RefTable = ProxiesTable
AccountsTable.Annotation = &entsql.Annotation{
Table: "accounts",
}
......@@ -551,6 +660,14 @@ func init() {
SettingsTable.Annotation = &entsql.Annotation{
Table: "settings",
}
UsageLogsTable.ForeignKeys[0].RefTable = AccountsTable
UsageLogsTable.ForeignKeys[1].RefTable = APIKeysTable
UsageLogsTable.ForeignKeys[2].RefTable = GroupsTable
UsageLogsTable.ForeignKeys[3].RefTable = UsersTable
UsageLogsTable.ForeignKeys[4].RefTable = UserSubscriptionsTable
UsageLogsTable.Annotation = &entsql.Annotation{
Table: "usage_logs",
}
UsersTable.Annotation = &entsql.Annotation{
Table: "users",
}
......
......@@ -19,6 +19,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
......@@ -40,6 +41,7 @@ const (
TypeProxy = "Proxy"
TypeRedeemCode = "RedeemCode"
TypeSetting = "Setting"
TypeUsageLog = "UsageLog"
TypeUser = "User"
TypeUserAllowedGroup = "UserAllowedGroup"
TypeUserSubscription = "UserSubscription"
......@@ -59,8 +61,6 @@ type AccountMutation struct {
_type *string
credentials *map[string]interface{}
extra *map[string]interface{}
proxy_id *int64
addproxy_id *int64
concurrency *int
addconcurrency *int
priority *int
......@@ -79,6 +79,11 @@ type AccountMutation struct {
groups map[int64]struct{}
removedgroups map[int64]struct{}
clearedgroups bool
proxy *int64
clearedproxy bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
done bool
oldValue func(context.Context) (*Account, error)
predicates []predicate.Account
......@@ -485,13 +490,12 @@ func (m *AccountMutation) ResetExtra() {
// SetProxyID sets the "proxy_id" field.
func (m *AccountMutation) SetProxyID(i int64) {
m.proxy_id = &i
m.addproxy_id = nil
m.proxy = &i
}
// ProxyID returns the value of the "proxy_id" field in the mutation.
func (m *AccountMutation) ProxyID() (r int64, exists bool) {
v := m.proxy_id
v := m.proxy
if v == nil {
return
}
......@@ -515,28 +519,9 @@ func (m *AccountMutation) OldProxyID(ctx context.Context) (v *int64, err error)
return oldValue.ProxyID, nil
}
// AddProxyID adds i to the "proxy_id" field.
func (m *AccountMutation) AddProxyID(i int64) {
if m.addproxy_id != nil {
*m.addproxy_id += i
} else {
m.addproxy_id = &i
}
}
// AddedProxyID returns the value that was added to the "proxy_id" field in this mutation.
func (m *AccountMutation) AddedProxyID() (r int64, exists bool) {
v := m.addproxy_id
if v == nil {
return
}
return *v, true
}
// ClearProxyID clears the value of the "proxy_id" field.
func (m *AccountMutation) ClearProxyID() {
m.proxy_id = nil
m.addproxy_id = nil
m.proxy = nil
m.clearedFields[account.FieldProxyID] = struct{}{}
}
......@@ -548,8 +533,7 @@ func (m *AccountMutation) ProxyIDCleared() bool {
// ResetProxyID resets all changes to the "proxy_id" field.
func (m *AccountMutation) ResetProxyID() {
m.proxy_id = nil
m.addproxy_id = nil
m.proxy = nil
delete(m.clearedFields, account.FieldProxyID)
}
......@@ -1183,6 +1167,87 @@ func (m *AccountMutation) ResetGroups() {
m.removedgroups = nil
}
// ClearProxy clears the "proxy" edge to the Proxy entity.
func (m *AccountMutation) ClearProxy() {
m.clearedproxy = true
m.clearedFields[account.FieldProxyID] = struct{}{}
}
// ProxyCleared reports if the "proxy" edge to the Proxy entity was cleared.
func (m *AccountMutation) ProxyCleared() bool {
return m.ProxyIDCleared() || m.clearedproxy
}
// ProxyIDs returns the "proxy" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// ProxyID instead. It exists only for internal usage by the builders.
func (m *AccountMutation) ProxyIDs() (ids []int64) {
if id := m.proxy; id != nil {
ids = append(ids, *id)
}
return
}
// ResetProxy resets all changes to the "proxy" edge.
func (m *AccountMutation) ResetProxy() {
m.proxy = nil
m.clearedproxy = false
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *AccountMutation) AddUsageLogIDs(ids ...int64) {
if m.usage_logs == nil {
m.usage_logs = make(map[int64]struct{})
}
for i := range ids {
m.usage_logs[ids[i]] = struct{}{}
}
}
// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *AccountMutation) ClearUsageLogs() {
m.clearedusage_logs = true
}
// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *AccountMutation) UsageLogsCleared() bool {
return m.clearedusage_logs
}
// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *AccountMutation) RemoveUsageLogIDs(ids ...int64) {
if m.removedusage_logs == nil {
m.removedusage_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_logs, ids[i])
m.removedusage_logs[ids[i]] = struct{}{}
}
}
// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *AccountMutation) RemovedUsageLogsIDs() (ids []int64) {
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return
}
// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *AccountMutation) UsageLogsIDs() (ids []int64) {
for id := range m.usage_logs {
ids = append(ids, id)
}
return
}
// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *AccountMutation) ResetUsageLogs() {
m.usage_logs = nil
m.clearedusage_logs = false
m.removedusage_logs = nil
}
// Where appends a list predicates to the AccountMutation builder.
func (m *AccountMutation) Where(ps ...predicate.Account) {
m.predicates = append(m.predicates, ps...)
......@@ -1242,7 +1307,7 @@ func (m *AccountMutation) Fields() []string {
if m.extra != nil {
fields = append(fields, account.FieldExtra)
}
if m.proxy_id != nil {
if m.proxy != nil {
fields = append(fields, account.FieldProxyID)
}
if m.concurrency != nil {
......@@ -1546,9 +1611,6 @@ func (m *AccountMutation) SetField(name string, value ent.Value) error {
// this mutation.
func (m *AccountMutation) AddedFields() []string {
var fields []string
if m.addproxy_id != nil {
fields = append(fields, account.FieldProxyID)
}
if m.addconcurrency != nil {
fields = append(fields, account.FieldConcurrency)
}
......@@ -1563,8 +1625,6 @@ func (m *AccountMutation) AddedFields() []string {
// was not set, or was not defined in the schema.
func (m *AccountMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case account.FieldProxyID:
return m.AddedProxyID()
case account.FieldConcurrency:
return m.AddedConcurrency()
case account.FieldPriority:
......@@ -1578,13 +1638,6 @@ func (m *AccountMutation) AddedField(name string) (ent.Value, bool) {
// type.
func (m *AccountMutation) AddField(name string, value ent.Value) error {
switch name {
case account.FieldProxyID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddProxyID(v)
return nil
case account.FieldConcurrency:
v, ok := value.(int)
if !ok {
......@@ -1758,10 +1811,16 @@ func (m *AccountMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AccountMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
edges := make([]string, 0, 3)
if m.groups != nil {
edges = append(edges, account.EdgeGroups)
}
if m.proxy != nil {
edges = append(edges, account.EdgeProxy)
}
if m.usage_logs != nil {
edges = append(edges, account.EdgeUsageLogs)
}
return edges
}
......@@ -1775,16 +1834,29 @@ func (m *AccountMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case account.EdgeProxy:
if id := m.proxy; id != nil {
return []ent.Value{*id}
}
case account.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AccountMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
edges := make([]string, 0, 3)
if m.removedgroups != nil {
edges = append(edges, account.EdgeGroups)
}
if m.removedusage_logs != nil {
edges = append(edges, account.EdgeUsageLogs)
}
return edges
}
......@@ -1798,16 +1870,28 @@ func (m *AccountMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case account.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AccountMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
edges := make([]string, 0, 3)
if m.clearedgroups {
edges = append(edges, account.EdgeGroups)
}
if m.clearedproxy {
edges = append(edges, account.EdgeProxy)
}
if m.clearedusage_logs {
edges = append(edges, account.EdgeUsageLogs)
}
return edges
}
......@@ -1817,6 +1901,10 @@ func (m *AccountMutation) EdgeCleared(name string) bool {
switch name {
case account.EdgeGroups:
return m.clearedgroups
case account.EdgeProxy:
return m.clearedproxy
case account.EdgeUsageLogs:
return m.clearedusage_logs
}
return false
}
......@@ -1825,6 +1913,9 @@ func (m *AccountMutation) EdgeCleared(name string) bool {
// if that edge is not defined in the schema.
func (m *AccountMutation) ClearEdge(name string) error {
switch name {
case account.EdgeProxy:
m.ClearProxy()
return nil
}
return fmt.Errorf("unknown Account unique edge %s", name)
}
......@@ -1836,6 +1927,12 @@ func (m *AccountMutation) ResetEdge(name string) error {
case account.EdgeGroups:
m.ResetGroups()
return nil
case account.EdgeProxy:
m.ResetProxy()
return nil
case account.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
}
return fmt.Errorf("unknown Account edge %s", name)
}
......@@ -2342,6 +2439,9 @@ type ApiKeyMutation struct {
cleareduser bool
group *int64
clearedgroup bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
done bool
oldValue func(context.Context) (*ApiKey, error)
predicates []predicate.ApiKey
......@@ -2813,6 +2913,60 @@ func (m *ApiKeyMutation) ResetGroup() {
m.clearedgroup = false
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *ApiKeyMutation) AddUsageLogIDs(ids ...int64) {
if m.usage_logs == nil {
m.usage_logs = make(map[int64]struct{})
}
for i := range ids {
m.usage_logs[ids[i]] = struct{}{}
}
}
// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *ApiKeyMutation) ClearUsageLogs() {
m.clearedusage_logs = true
}
// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *ApiKeyMutation) UsageLogsCleared() bool {
return m.clearedusage_logs
}
// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *ApiKeyMutation) RemoveUsageLogIDs(ids ...int64) {
if m.removedusage_logs == nil {
m.removedusage_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_logs, ids[i])
m.removedusage_logs[ids[i]] = struct{}{}
}
}
// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *ApiKeyMutation) RemovedUsageLogsIDs() (ids []int64) {
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return
}
// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *ApiKeyMutation) UsageLogsIDs() (ids []int64) {
for id := range m.usage_logs {
ids = append(ids, id)
}
return
}
// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *ApiKeyMutation) ResetUsageLogs() {
m.usage_logs = nil
m.clearedusage_logs = false
m.removedusage_logs = nil
}
// Where appends a list predicates to the ApiKeyMutation builder.
func (m *ApiKeyMutation) Where(ps ...predicate.ApiKey) {
m.predicates = append(m.predicates, ps...)
......@@ -3083,13 +3237,16 @@ func (m *ApiKeyMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ApiKeyMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
edges := make([]string, 0, 3)
if m.user != nil {
edges = append(edges, apikey.EdgeUser)
}
if m.group != nil {
edges = append(edges, apikey.EdgeGroup)
}
if m.usage_logs != nil {
edges = append(edges, apikey.EdgeUsageLogs)
}
return edges
}
......@@ -3105,31 +3262,51 @@ func (m *ApiKeyMutation) AddedIDs(name string) []ent.Value {
if id := m.group; id != nil {
return []ent.Value{*id}
}
case apikey.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ApiKeyMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
edges := make([]string, 0, 3)
if m.removedusage_logs != nil {
edges = append(edges, apikey.EdgeUsageLogs)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ApiKeyMutation) RemovedIDs(name string) []ent.Value {
switch name {
case apikey.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ApiKeyMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
edges := make([]string, 0, 3)
if m.cleareduser {
edges = append(edges, apikey.EdgeUser)
}
if m.clearedgroup {
edges = append(edges, apikey.EdgeGroup)
}
if m.clearedusage_logs {
edges = append(edges, apikey.EdgeUsageLogs)
}
return edges
}
......@@ -3141,6 +3318,8 @@ func (m *ApiKeyMutation) EdgeCleared(name string) bool {
return m.cleareduser
case apikey.EdgeGroup:
return m.clearedgroup
case apikey.EdgeUsageLogs:
return m.clearedusage_logs
}
return false
}
......@@ -3169,6 +3348,9 @@ func (m *ApiKeyMutation) ResetEdge(name string) error {
case apikey.EdgeGroup:
m.ResetGroup()
return nil
case apikey.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
}
return fmt.Errorf("unknown ApiKey edge %s", name)
}
......@@ -3196,6 +3378,8 @@ type GroupMutation struct {
addweekly_limit_usd *float64
monthly_limit_usd *float64
addmonthly_limit_usd *float64
default_validity_days *int
adddefault_validity_days *int
clearedFields map[string]struct{}
api_keys map[int64]struct{}
removedapi_keys map[int64]struct{}
......@@ -3206,6 +3390,9 @@ type GroupMutation struct {
subscriptions map[int64]struct{}
removedsubscriptions map[int64]struct{}
clearedsubscriptions bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
accounts map[int64]struct{}
removedaccounts map[int64]struct{}
clearedaccounts bool
......@@ -3931,6 +4118,62 @@ func (m *GroupMutation) ResetMonthlyLimitUsd() {
delete(m.clearedFields, group.FieldMonthlyLimitUsd)
}
// SetDefaultValidityDays sets the "default_validity_days" field.
func (m *GroupMutation) SetDefaultValidityDays(i int) {
m.default_validity_days = &i
m.adddefault_validity_days = nil
}
// DefaultValidityDays returns the value of the "default_validity_days" field in the mutation.
func (m *GroupMutation) DefaultValidityDays() (r int, exists bool) {
v := m.default_validity_days
if v == nil {
return
}
return *v, true
}
// OldDefaultValidityDays returns the old "default_validity_days" field's value of the Group entity.
// If the Group object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GroupMutation) OldDefaultValidityDays(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDefaultValidityDays is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDefaultValidityDays requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDefaultValidityDays: %w", err)
}
return oldValue.DefaultValidityDays, nil
}
// AddDefaultValidityDays adds i to the "default_validity_days" field.
func (m *GroupMutation) AddDefaultValidityDays(i int) {
if m.adddefault_validity_days != nil {
*m.adddefault_validity_days += i
} else {
m.adddefault_validity_days = &i
}
}
// AddedDefaultValidityDays returns the value that was added to the "default_validity_days" field in this mutation.
func (m *GroupMutation) AddedDefaultValidityDays() (r int, exists bool) {
v := m.adddefault_validity_days
if v == nil {
return
}
return *v, true
}
// ResetDefaultValidityDays resets all changes to the "default_validity_days" field.
func (m *GroupMutation) ResetDefaultValidityDays() {
m.default_validity_days = nil
m.adddefault_validity_days = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the ApiKey entity by ids.
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil {
......@@ -4093,6 +4336,60 @@ func (m *GroupMutation) ResetSubscriptions() {
m.removedsubscriptions = nil
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *GroupMutation) AddUsageLogIDs(ids ...int64) {
if m.usage_logs == nil {
m.usage_logs = make(map[int64]struct{})
}
for i := range ids {
m.usage_logs[ids[i]] = struct{}{}
}
}
// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *GroupMutation) ClearUsageLogs() {
m.clearedusage_logs = true
}
// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *GroupMutation) UsageLogsCleared() bool {
return m.clearedusage_logs
}
// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *GroupMutation) RemoveUsageLogIDs(ids ...int64) {
if m.removedusage_logs == nil {
m.removedusage_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_logs, ids[i])
m.removedusage_logs[ids[i]] = struct{}{}
}
}
// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *GroupMutation) RemovedUsageLogsIDs() (ids []int64) {
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return
}
// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *GroupMutation) UsageLogsIDs() (ids []int64) {
for id := range m.usage_logs {
ids = append(ids, id)
}
return
}
// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *GroupMutation) ResetUsageLogs() {
m.usage_logs = nil
m.clearedusage_logs = false
m.removedusage_logs = nil
}
// AddAccountIDs adds the "accounts" edge to the Account entity by ids.
func (m *GroupMutation) AddAccountIDs(ids ...int64) {
if m.accounts == nil {
......@@ -4235,7 +4532,7 @@ func (m *GroupMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *GroupMutation) Fields() []string {
fields := make([]string, 0, 13)
fields := make([]string, 0, 14)
if m.created_at != nil {
fields = append(fields, group.FieldCreatedAt)
}
......@@ -4275,6 +4572,9 @@ func (m *GroupMutation) Fields() []string {
if m.monthly_limit_usd != nil {
fields = append(fields, group.FieldMonthlyLimitUsd)
}
if m.default_validity_days != nil {
fields = append(fields, group.FieldDefaultValidityDays)
}
return fields
}
......@@ -4309,6 +4609,8 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
return m.WeeklyLimitUsd()
case group.FieldMonthlyLimitUsd:
return m.MonthlyLimitUsd()
case group.FieldDefaultValidityDays:
return m.DefaultValidityDays()
}
return nil, false
}
......@@ -4344,6 +4646,8 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
return m.OldWeeklyLimitUsd(ctx)
case group.FieldMonthlyLimitUsd:
return m.OldMonthlyLimitUsd(ctx)
case group.FieldDefaultValidityDays:
return m.OldDefaultValidityDays(ctx)
}
return nil, fmt.Errorf("unknown Group field %s", name)
}
......@@ -4444,6 +4748,13 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
}
m.SetMonthlyLimitUsd(v)
return nil
case group.FieldDefaultValidityDays:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDefaultValidityDays(v)
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
......@@ -4464,6 +4775,9 @@ func (m *GroupMutation) AddedFields() []string {
if m.addmonthly_limit_usd != nil {
fields = append(fields, group.FieldMonthlyLimitUsd)
}
if m.adddefault_validity_days != nil {
fields = append(fields, group.FieldDefaultValidityDays)
}
return fields
}
......@@ -4480,6 +4794,8 @@ func (m *GroupMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedWeeklyLimitUsd()
case group.FieldMonthlyLimitUsd:
return m.AddedMonthlyLimitUsd()
case group.FieldDefaultValidityDays:
return m.AddedDefaultValidityDays()
}
return nil, false
}
......@@ -4517,6 +4833,13 @@ func (m *GroupMutation) AddField(name string, value ent.Value) error {
}
m.AddMonthlyLimitUsd(v)
return nil
case group.FieldDefaultValidityDays:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddDefaultValidityDays(v)
return nil
}
return fmt.Errorf("unknown Group numeric field %s", name)
}
......@@ -4616,13 +4939,16 @@ func (m *GroupMutation) ResetField(name string) error {
case group.FieldMonthlyLimitUsd:
m.ResetMonthlyLimitUsd()
return nil
case group.FieldDefaultValidityDays:
m.ResetDefaultValidityDays()
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GroupMutation) AddedEdges() []string {
edges := make([]string, 0, 5)
edges := make([]string, 0, 6)
if m.api_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
......@@ -4632,6 +4958,9 @@ func (m *GroupMutation) AddedEdges() []string {
if m.subscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.usage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.accounts != nil {
edges = append(edges, group.EdgeAccounts)
}
......@@ -4663,6 +4992,12 @@ func (m *GroupMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.accounts))
for id := range m.accounts {
......@@ -4681,7 +5016,7 @@ func (m *GroupMutation) AddedIDs(name string) []ent.Value {
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GroupMutation) RemovedEdges() []string {
edges := make([]string, 0, 5)
edges := make([]string, 0, 6)
if m.removedapi_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
......@@ -4691,6 +5026,9 @@ func (m *GroupMutation) RemovedEdges() []string {
if m.removedsubscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.removedusage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.removedaccounts != nil {
edges = append(edges, group.EdgeAccounts)
}
......@@ -4722,6 +5060,12 @@ func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
......@@ -4740,7 +5084,7 @@ func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
edges := make([]string, 0, 5)
edges := make([]string, 0, 6)
if m.clearedapi_keys {
edges = append(edges, group.EdgeAPIKeys)
}
......@@ -4750,6 +5094,9 @@ func (m *GroupMutation) ClearedEdges() []string {
if m.clearedsubscriptions {
edges = append(edges, group.EdgeSubscriptions)
}
if m.clearedusage_logs {
edges = append(edges, group.EdgeUsageLogs)
}
if m.clearedaccounts {
edges = append(edges, group.EdgeAccounts)
}
......@@ -4769,6 +5116,8 @@ func (m *GroupMutation) EdgeCleared(name string) bool {
return m.clearedredeem_codes
case group.EdgeSubscriptions:
return m.clearedsubscriptions
case group.EdgeUsageLogs:
return m.clearedusage_logs
case group.EdgeAccounts:
return m.clearedaccounts
case group.EdgeAllowedUsers:
......@@ -4798,6 +5147,9 @@ func (m *GroupMutation) ResetEdge(name string) error {
case group.EdgeSubscriptions:
m.ResetSubscriptions()
return nil
case group.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
case group.EdgeAccounts:
m.ResetAccounts()
return nil
......@@ -4826,6 +5178,9 @@ type ProxyMutation struct {
password *string
status *string
clearedFields map[string]struct{}
accounts map[int64]struct{}
removedaccounts map[int64]struct{}
clearedaccounts bool
done bool
oldValue func(context.Context) (*Proxy, error)
predicates []predicate.Proxy
......@@ -5348,38 +5703,92 @@ func (m *ProxyMutation) ResetStatus() {
m.status = nil
}
// Where appends a list predicates to the ProxyMutation builder.
func (m *ProxyMutation) Where(ps ...predicate.Proxy) {
m.predicates = append(m.predicates, ps...)
// AddAccountIDs adds the "accounts" edge to the Account entity by ids.
func (m *ProxyMutation) AddAccountIDs(ids ...int64) {
if m.accounts == nil {
m.accounts = make(map[int64]struct{})
}
for i := range ids {
m.accounts[ids[i]] = struct{}{}
}
}
// WhereP appends storage-level predicates to the ProxyMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ProxyMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Proxy, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
// ClearAccounts clears the "accounts" edge to the Account entity.
func (m *ProxyMutation) ClearAccounts() {
m.clearedaccounts = true
}
// Op returns the operation name.
func (m *ProxyMutation) Op() Op {
return m.op
// AccountsCleared reports if the "accounts" edge to the Account entity was cleared.
func (m *ProxyMutation) AccountsCleared() bool {
return m.clearedaccounts
}
// SetOp allows setting the mutation operation.
func (m *ProxyMutation) SetOp(op Op) {
m.op = op
// RemoveAccountIDs removes the "accounts" edge to the Account entity by IDs.
func (m *ProxyMutation) RemoveAccountIDs(ids ...int64) {
if m.removedaccounts == nil {
m.removedaccounts = make(map[int64]struct{})
}
for i := range ids {
delete(m.accounts, ids[i])
m.removedaccounts[ids[i]] = struct{}{}
}
}
// Type returns the node type of this mutation (Proxy).
func (m *ProxyMutation) Type() string {
return m.typ
// RemovedAccounts returns the removed IDs of the "accounts" edge to the Account entity.
func (m *ProxyMutation) RemovedAccountsIDs() (ids []int64) {
for id := range m.removedaccounts {
ids = append(ids, id)
}
return
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AccountsIDs returns the "accounts" edge IDs in the mutation.
func (m *ProxyMutation) AccountsIDs() (ids []int64) {
for id := range m.accounts {
ids = append(ids, id)
}
return
}
// ResetAccounts resets all changes to the "accounts" edge.
func (m *ProxyMutation) ResetAccounts() {
m.accounts = nil
m.clearedaccounts = false
m.removedaccounts = nil
}
// Where appends a list predicates to the ProxyMutation builder.
func (m *ProxyMutation) Where(ps ...predicate.Proxy) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the ProxyMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ProxyMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Proxy, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *ProxyMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *ProxyMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Proxy).
func (m *ProxyMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *ProxyMutation) Fields() []string {
fields := make([]string, 0, 10)
......@@ -5670,49 +6079,85 @@ func (m *ProxyMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ProxyMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
edges := make([]string, 0, 1)
if m.accounts != nil {
edges = append(edges, proxy.EdgeAccounts)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ProxyMutation) AddedIDs(name string) []ent.Value {
switch name {
case proxy.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.accounts))
for id := range m.accounts {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ProxyMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
edges := make([]string, 0, 1)
if m.removedaccounts != nil {
edges = append(edges, proxy.EdgeAccounts)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ProxyMutation) RemovedIDs(name string) []ent.Value {
switch name {
case proxy.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ProxyMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
edges := make([]string, 0, 1)
if m.clearedaccounts {
edges = append(edges, proxy.EdgeAccounts)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ProxyMutation) EdgeCleared(name string) bool {
switch name {
case proxy.EdgeAccounts:
return m.clearedaccounts
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *ProxyMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown Proxy unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *ProxyMutation) ResetEdge(name string) error {
switch name {
case proxy.EdgeAccounts:
m.ResetAccounts()
return nil
}
return fmt.Errorf("unknown Proxy edge %s", name)
}
......@@ -7147,80 +7592,2552 @@ func (m *SettingMutation) ClearedFields() []string {
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *SettingMutation) FieldCleared(name string) bool {
func (m *SettingMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *SettingMutation) ClearField(name string) error {
return fmt.Errorf("unknown Setting nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *SettingMutation) ResetField(name string) error {
switch name {
case setting.FieldKey:
m.ResetKey()
return nil
case setting.FieldValue:
m.ResetValue()
return nil
case setting.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
}
return fmt.Errorf("unknown Setting field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SettingMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SettingMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SettingMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SettingMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SettingMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SettingMutation) EdgeCleared(name string) bool {
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *SettingMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Setting unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *SettingMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Setting edge %s", name)
}
// UsageLogMutation represents an operation that mutates the UsageLog nodes in the graph.
type UsageLogMutation struct {
config
op Op
typ string
id *int64
request_id *string
model *string
input_tokens *int
addinput_tokens *int
output_tokens *int
addoutput_tokens *int
cache_creation_tokens *int
addcache_creation_tokens *int
cache_read_tokens *int
addcache_read_tokens *int
cache_creation_5m_tokens *int
addcache_creation_5m_tokens *int
cache_creation_1h_tokens *int
addcache_creation_1h_tokens *int
input_cost *float64
addinput_cost *float64
output_cost *float64
addoutput_cost *float64
cache_creation_cost *float64
addcache_creation_cost *float64
cache_read_cost *float64
addcache_read_cost *float64
total_cost *float64
addtotal_cost *float64
actual_cost *float64
addactual_cost *float64
rate_multiplier *float64
addrate_multiplier *float64
billing_type *int8
addbilling_type *int8
stream *bool
duration_ms *int
addduration_ms *int
first_token_ms *int
addfirst_token_ms *int
created_at *time.Time
clearedFields map[string]struct{}
user *int64
cleareduser bool
api_key *int64
clearedapi_key bool
account *int64
clearedaccount bool
group *int64
clearedgroup bool
subscription *int64
clearedsubscription bool
done bool
oldValue func(context.Context) (*UsageLog, error)
predicates []predicate.UsageLog
}
var _ ent.Mutation = (*UsageLogMutation)(nil)
// usagelogOption allows management of the mutation configuration using functional options.
type usagelogOption func(*UsageLogMutation)
// newUsageLogMutation creates new mutation for the UsageLog entity.
func newUsageLogMutation(c config, op Op, opts ...usagelogOption) *UsageLogMutation {
m := &UsageLogMutation{
config: c,
op: op,
typ: TypeUsageLog,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUsageLogID sets the ID field of the mutation.
func withUsageLogID(id int64) usagelogOption {
return func(m *UsageLogMutation) {
var (
err error
once sync.Once
value *UsageLog
)
m.oldValue = func(ctx context.Context) (*UsageLog, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UsageLog.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUsageLog sets the old UsageLog of the mutation.
func withUsageLog(node *UsageLog) usagelogOption {
return func(m *UsageLogMutation) {
m.oldValue = func(context.Context) (*UsageLog, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m UsageLogMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m UsageLogMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *UsageLogMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UsageLogMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().UsageLog.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUserID sets the "user_id" field.
func (m *UsageLogMutation) SetUserID(i int64) {
m.user = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *UsageLogMutation) UserID() (r int64, exists bool) {
v := m.user
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// ResetUserID resets all changes to the "user_id" field.
func (m *UsageLogMutation) ResetUserID() {
m.user = nil
}
// SetAPIKeyID sets the "api_key_id" field.
func (m *UsageLogMutation) SetAPIKeyID(i int64) {
m.api_key = &i
}
// APIKeyID returns the value of the "api_key_id" field in the mutation.
func (m *UsageLogMutation) APIKeyID() (r int64, exists bool) {
v := m.api_key
if v == nil {
return
}
return *v, true
}
// OldAPIKeyID returns the old "api_key_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldAPIKeyID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAPIKeyID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAPIKeyID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAPIKeyID: %w", err)
}
return oldValue.APIKeyID, nil
}
// ResetAPIKeyID resets all changes to the "api_key_id" field.
func (m *UsageLogMutation) ResetAPIKeyID() {
m.api_key = nil
}
// SetAccountID sets the "account_id" field.
func (m *UsageLogMutation) SetAccountID(i int64) {
m.account = &i
}
// AccountID returns the value of the "account_id" field in the mutation.
func (m *UsageLogMutation) AccountID() (r int64, exists bool) {
v := m.account
if v == nil {
return
}
return *v, true
}
// OldAccountID returns the old "account_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldAccountID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAccountID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAccountID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAccountID: %w", err)
}
return oldValue.AccountID, nil
}
// ResetAccountID resets all changes to the "account_id" field.
func (m *UsageLogMutation) ResetAccountID() {
m.account = nil
}
// SetRequestID sets the "request_id" field.
func (m *UsageLogMutation) SetRequestID(s string) {
m.request_id = &s
}
// RequestID returns the value of the "request_id" field in the mutation.
func (m *UsageLogMutation) RequestID() (r string, exists bool) {
v := m.request_id
if v == nil {
return
}
return *v, true
}
// OldRequestID returns the old "request_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldRequestID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRequestID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRequestID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRequestID: %w", err)
}
return oldValue.RequestID, nil
}
// ResetRequestID resets all changes to the "request_id" field.
func (m *UsageLogMutation) ResetRequestID() {
m.request_id = nil
}
// SetModel sets the "model" field.
func (m *UsageLogMutation) SetModel(s string) {
m.model = &s
}
// Model returns the value of the "model" field in the mutation.
func (m *UsageLogMutation) Model() (r string, exists bool) {
v := m.model
if v == nil {
return
}
return *v, true
}
// OldModel returns the old "model" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldModel(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModel: %w", err)
}
return oldValue.Model, nil
}
// ResetModel resets all changes to the "model" field.
func (m *UsageLogMutation) ResetModel() {
m.model = nil
}
// SetGroupID sets the "group_id" field.
func (m *UsageLogMutation) SetGroupID(i int64) {
m.group = &i
}
// GroupID returns the value of the "group_id" field in the mutation.
func (m *UsageLogMutation) GroupID() (r int64, exists bool) {
v := m.group
if v == nil {
return
}
return *v, true
}
// OldGroupID returns the old "group_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldGroupID(ctx context.Context) (v *int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldGroupID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldGroupID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldGroupID: %w", err)
}
return oldValue.GroupID, nil
}
// ClearGroupID clears the value of the "group_id" field.
func (m *UsageLogMutation) ClearGroupID() {
m.group = nil
m.clearedFields[usagelog.FieldGroupID] = struct{}{}
}
// GroupIDCleared returns if the "group_id" field was cleared in this mutation.
func (m *UsageLogMutation) GroupIDCleared() bool {
_, ok := m.clearedFields[usagelog.FieldGroupID]
return ok
}
// ResetGroupID resets all changes to the "group_id" field.
func (m *UsageLogMutation) ResetGroupID() {
m.group = nil
delete(m.clearedFields, usagelog.FieldGroupID)
}
// SetSubscriptionID sets the "subscription_id" field.
func (m *UsageLogMutation) SetSubscriptionID(i int64) {
m.subscription = &i
}
// SubscriptionID returns the value of the "subscription_id" field in the mutation.
func (m *UsageLogMutation) SubscriptionID() (r int64, exists bool) {
v := m.subscription
if v == nil {
return
}
return *v, true
}
// OldSubscriptionID returns the old "subscription_id" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldSubscriptionID(ctx context.Context) (v *int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSubscriptionID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSubscriptionID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSubscriptionID: %w", err)
}
return oldValue.SubscriptionID, nil
}
// ClearSubscriptionID clears the value of the "subscription_id" field.
func (m *UsageLogMutation) ClearSubscriptionID() {
m.subscription = nil
m.clearedFields[usagelog.FieldSubscriptionID] = struct{}{}
}
// SubscriptionIDCleared returns if the "subscription_id" field was cleared in this mutation.
func (m *UsageLogMutation) SubscriptionIDCleared() bool {
_, ok := m.clearedFields[usagelog.FieldSubscriptionID]
return ok
}
// ResetSubscriptionID resets all changes to the "subscription_id" field.
func (m *UsageLogMutation) ResetSubscriptionID() {
m.subscription = nil
delete(m.clearedFields, usagelog.FieldSubscriptionID)
}
// SetInputTokens sets the "input_tokens" field.
func (m *UsageLogMutation) SetInputTokens(i int) {
m.input_tokens = &i
m.addinput_tokens = nil
}
// InputTokens returns the value of the "input_tokens" field in the mutation.
func (m *UsageLogMutation) InputTokens() (r int, exists bool) {
v := m.input_tokens
if v == nil {
return
}
return *v, true
}
// OldInputTokens returns the old "input_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldInputTokens(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldInputTokens is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldInputTokens requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldInputTokens: %w", err)
}
return oldValue.InputTokens, nil
}
// AddInputTokens adds i to the "input_tokens" field.
func (m *UsageLogMutation) AddInputTokens(i int) {
if m.addinput_tokens != nil {
*m.addinput_tokens += i
} else {
m.addinput_tokens = &i
}
}
// AddedInputTokens returns the value that was added to the "input_tokens" field in this mutation.
func (m *UsageLogMutation) AddedInputTokens() (r int, exists bool) {
v := m.addinput_tokens
if v == nil {
return
}
return *v, true
}
// ResetInputTokens resets all changes to the "input_tokens" field.
func (m *UsageLogMutation) ResetInputTokens() {
m.input_tokens = nil
m.addinput_tokens = nil
}
// SetOutputTokens sets the "output_tokens" field.
func (m *UsageLogMutation) SetOutputTokens(i int) {
m.output_tokens = &i
m.addoutput_tokens = nil
}
// OutputTokens returns the value of the "output_tokens" field in the mutation.
func (m *UsageLogMutation) OutputTokens() (r int, exists bool) {
v := m.output_tokens
if v == nil {
return
}
return *v, true
}
// OldOutputTokens returns the old "output_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldOutputTokens(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOutputTokens is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOutputTokens requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOutputTokens: %w", err)
}
return oldValue.OutputTokens, nil
}
// AddOutputTokens adds i to the "output_tokens" field.
func (m *UsageLogMutation) AddOutputTokens(i int) {
if m.addoutput_tokens != nil {
*m.addoutput_tokens += i
} else {
m.addoutput_tokens = &i
}
}
// AddedOutputTokens returns the value that was added to the "output_tokens" field in this mutation.
func (m *UsageLogMutation) AddedOutputTokens() (r int, exists bool) {
v := m.addoutput_tokens
if v == nil {
return
}
return *v, true
}
// ResetOutputTokens resets all changes to the "output_tokens" field.
func (m *UsageLogMutation) ResetOutputTokens() {
m.output_tokens = nil
m.addoutput_tokens = nil
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (m *UsageLogMutation) SetCacheCreationTokens(i int) {
m.cache_creation_tokens = &i
m.addcache_creation_tokens = nil
}
// CacheCreationTokens returns the value of the "cache_creation_tokens" field in the mutation.
func (m *UsageLogMutation) CacheCreationTokens() (r int, exists bool) {
v := m.cache_creation_tokens
if v == nil {
return
}
return *v, true
}
// OldCacheCreationTokens returns the old "cache_creation_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreationTokens(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCacheCreationTokens is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCacheCreationTokens requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCacheCreationTokens: %w", err)
}
return oldValue.CacheCreationTokens, nil
}
// AddCacheCreationTokens adds i to the "cache_creation_tokens" field.
func (m *UsageLogMutation) AddCacheCreationTokens(i int) {
if m.addcache_creation_tokens != nil {
*m.addcache_creation_tokens += i
} else {
m.addcache_creation_tokens = &i
}
}
// AddedCacheCreationTokens returns the value that was added to the "cache_creation_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreationTokens() (r int, exists bool) {
v := m.addcache_creation_tokens
if v == nil {
return
}
return *v, true
}
// ResetCacheCreationTokens resets all changes to the "cache_creation_tokens" field.
func (m *UsageLogMutation) ResetCacheCreationTokens() {
m.cache_creation_tokens = nil
m.addcache_creation_tokens = nil
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (m *UsageLogMutation) SetCacheReadTokens(i int) {
m.cache_read_tokens = &i
m.addcache_read_tokens = nil
}
// CacheReadTokens returns the value of the "cache_read_tokens" field in the mutation.
func (m *UsageLogMutation) CacheReadTokens() (r int, exists bool) {
v := m.cache_read_tokens
if v == nil {
return
}
return *v, true
}
// OldCacheReadTokens returns the old "cache_read_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheReadTokens(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCacheReadTokens is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCacheReadTokens requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCacheReadTokens: %w", err)
}
return oldValue.CacheReadTokens, nil
}
// AddCacheReadTokens adds i to the "cache_read_tokens" field.
func (m *UsageLogMutation) AddCacheReadTokens(i int) {
if m.addcache_read_tokens != nil {
*m.addcache_read_tokens += i
} else {
m.addcache_read_tokens = &i
}
}
// AddedCacheReadTokens returns the value that was added to the "cache_read_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheReadTokens() (r int, exists bool) {
v := m.addcache_read_tokens
if v == nil {
return
}
return *v, true
}
// ResetCacheReadTokens resets all changes to the "cache_read_tokens" field.
func (m *UsageLogMutation) ResetCacheReadTokens() {
m.cache_read_tokens = nil
m.addcache_read_tokens = nil
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (m *UsageLogMutation) SetCacheCreation5mTokens(i int) {
m.cache_creation_5m_tokens = &i
m.addcache_creation_5m_tokens = nil
}
// CacheCreation5mTokens returns the value of the "cache_creation_5m_tokens" field in the mutation.
func (m *UsageLogMutation) CacheCreation5mTokens() (r int, exists bool) {
v := m.cache_creation_5m_tokens
if v == nil {
return
}
return *v, true
}
// OldCacheCreation5mTokens returns the old "cache_creation_5m_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreation5mTokens(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCacheCreation5mTokens is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCacheCreation5mTokens requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCacheCreation5mTokens: %w", err)
}
return oldValue.CacheCreation5mTokens, nil
}
// AddCacheCreation5mTokens adds i to the "cache_creation_5m_tokens" field.
func (m *UsageLogMutation) AddCacheCreation5mTokens(i int) {
if m.addcache_creation_5m_tokens != nil {
*m.addcache_creation_5m_tokens += i
} else {
m.addcache_creation_5m_tokens = &i
}
}
// AddedCacheCreation5mTokens returns the value that was added to the "cache_creation_5m_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreation5mTokens() (r int, exists bool) {
v := m.addcache_creation_5m_tokens
if v == nil {
return
}
return *v, true
}
// ResetCacheCreation5mTokens resets all changes to the "cache_creation_5m_tokens" field.
func (m *UsageLogMutation) ResetCacheCreation5mTokens() {
m.cache_creation_5m_tokens = nil
m.addcache_creation_5m_tokens = nil
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (m *UsageLogMutation) SetCacheCreation1hTokens(i int) {
m.cache_creation_1h_tokens = &i
m.addcache_creation_1h_tokens = nil
}
// CacheCreation1hTokens returns the value of the "cache_creation_1h_tokens" field in the mutation.
func (m *UsageLogMutation) CacheCreation1hTokens() (r int, exists bool) {
v := m.cache_creation_1h_tokens
if v == nil {
return
}
return *v, true
}
// OldCacheCreation1hTokens returns the old "cache_creation_1h_tokens" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreation1hTokens(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCacheCreation1hTokens is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCacheCreation1hTokens requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCacheCreation1hTokens: %w", err)
}
return oldValue.CacheCreation1hTokens, nil
}
// AddCacheCreation1hTokens adds i to the "cache_creation_1h_tokens" field.
func (m *UsageLogMutation) AddCacheCreation1hTokens(i int) {
if m.addcache_creation_1h_tokens != nil {
*m.addcache_creation_1h_tokens += i
} else {
m.addcache_creation_1h_tokens = &i
}
}
// AddedCacheCreation1hTokens returns the value that was added to the "cache_creation_1h_tokens" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreation1hTokens() (r int, exists bool) {
v := m.addcache_creation_1h_tokens
if v == nil {
return
}
return *v, true
}
// ResetCacheCreation1hTokens resets all changes to the "cache_creation_1h_tokens" field.
func (m *UsageLogMutation) ResetCacheCreation1hTokens() {
m.cache_creation_1h_tokens = nil
m.addcache_creation_1h_tokens = nil
}
// SetInputCost sets the "input_cost" field.
func (m *UsageLogMutation) SetInputCost(f float64) {
m.input_cost = &f
m.addinput_cost = nil
}
// InputCost returns the value of the "input_cost" field in the mutation.
func (m *UsageLogMutation) InputCost() (r float64, exists bool) {
v := m.input_cost
if v == nil {
return
}
return *v, true
}
// OldInputCost returns the old "input_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldInputCost(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldInputCost is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldInputCost requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldInputCost: %w", err)
}
return oldValue.InputCost, nil
}
// AddInputCost adds f to the "input_cost" field.
func (m *UsageLogMutation) AddInputCost(f float64) {
if m.addinput_cost != nil {
*m.addinput_cost += f
} else {
m.addinput_cost = &f
}
}
// AddedInputCost returns the value that was added to the "input_cost" field in this mutation.
func (m *UsageLogMutation) AddedInputCost() (r float64, exists bool) {
v := m.addinput_cost
if v == nil {
return
}
return *v, true
}
// ResetInputCost resets all changes to the "input_cost" field.
func (m *UsageLogMutation) ResetInputCost() {
m.input_cost = nil
m.addinput_cost = nil
}
// SetOutputCost sets the "output_cost" field.
func (m *UsageLogMutation) SetOutputCost(f float64) {
m.output_cost = &f
m.addoutput_cost = nil
}
// OutputCost returns the value of the "output_cost" field in the mutation.
func (m *UsageLogMutation) OutputCost() (r float64, exists bool) {
v := m.output_cost
if v == nil {
return
}
return *v, true
}
// OldOutputCost returns the old "output_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldOutputCost(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOutputCost is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOutputCost requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOutputCost: %w", err)
}
return oldValue.OutputCost, nil
}
// AddOutputCost adds f to the "output_cost" field.
func (m *UsageLogMutation) AddOutputCost(f float64) {
if m.addoutput_cost != nil {
*m.addoutput_cost += f
} else {
m.addoutput_cost = &f
}
}
// AddedOutputCost returns the value that was added to the "output_cost" field in this mutation.
func (m *UsageLogMutation) AddedOutputCost() (r float64, exists bool) {
v := m.addoutput_cost
if v == nil {
return
}
return *v, true
}
// ResetOutputCost resets all changes to the "output_cost" field.
func (m *UsageLogMutation) ResetOutputCost() {
m.output_cost = nil
m.addoutput_cost = nil
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (m *UsageLogMutation) SetCacheCreationCost(f float64) {
m.cache_creation_cost = &f
m.addcache_creation_cost = nil
}
// CacheCreationCost returns the value of the "cache_creation_cost" field in the mutation.
func (m *UsageLogMutation) CacheCreationCost() (r float64, exists bool) {
v := m.cache_creation_cost
if v == nil {
return
}
return *v, true
}
// OldCacheCreationCost returns the old "cache_creation_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheCreationCost(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCacheCreationCost is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCacheCreationCost requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCacheCreationCost: %w", err)
}
return oldValue.CacheCreationCost, nil
}
// AddCacheCreationCost adds f to the "cache_creation_cost" field.
func (m *UsageLogMutation) AddCacheCreationCost(f float64) {
if m.addcache_creation_cost != nil {
*m.addcache_creation_cost += f
} else {
m.addcache_creation_cost = &f
}
}
// AddedCacheCreationCost returns the value that was added to the "cache_creation_cost" field in this mutation.
func (m *UsageLogMutation) AddedCacheCreationCost() (r float64, exists bool) {
v := m.addcache_creation_cost
if v == nil {
return
}
return *v, true
}
// ResetCacheCreationCost resets all changes to the "cache_creation_cost" field.
func (m *UsageLogMutation) ResetCacheCreationCost() {
m.cache_creation_cost = nil
m.addcache_creation_cost = nil
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (m *UsageLogMutation) SetCacheReadCost(f float64) {
m.cache_read_cost = &f
m.addcache_read_cost = nil
}
// CacheReadCost returns the value of the "cache_read_cost" field in the mutation.
func (m *UsageLogMutation) CacheReadCost() (r float64, exists bool) {
v := m.cache_read_cost
if v == nil {
return
}
return *v, true
}
// OldCacheReadCost returns the old "cache_read_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCacheReadCost(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCacheReadCost is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCacheReadCost requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCacheReadCost: %w", err)
}
return oldValue.CacheReadCost, nil
}
// AddCacheReadCost adds f to the "cache_read_cost" field.
func (m *UsageLogMutation) AddCacheReadCost(f float64) {
if m.addcache_read_cost != nil {
*m.addcache_read_cost += f
} else {
m.addcache_read_cost = &f
}
}
// AddedCacheReadCost returns the value that was added to the "cache_read_cost" field in this mutation.
func (m *UsageLogMutation) AddedCacheReadCost() (r float64, exists bool) {
v := m.addcache_read_cost
if v == nil {
return
}
return *v, true
}
// ResetCacheReadCost resets all changes to the "cache_read_cost" field.
func (m *UsageLogMutation) ResetCacheReadCost() {
m.cache_read_cost = nil
m.addcache_read_cost = nil
}
// SetTotalCost sets the "total_cost" field.
func (m *UsageLogMutation) SetTotalCost(f float64) {
m.total_cost = &f
m.addtotal_cost = nil
}
// TotalCost returns the value of the "total_cost" field in the mutation.
func (m *UsageLogMutation) TotalCost() (r float64, exists bool) {
v := m.total_cost
if v == nil {
return
}
return *v, true
}
// OldTotalCost returns the old "total_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldTotalCost(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTotalCost is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTotalCost requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTotalCost: %w", err)
}
return oldValue.TotalCost, nil
}
// AddTotalCost adds f to the "total_cost" field.
func (m *UsageLogMutation) AddTotalCost(f float64) {
if m.addtotal_cost != nil {
*m.addtotal_cost += f
} else {
m.addtotal_cost = &f
}
}
// AddedTotalCost returns the value that was added to the "total_cost" field in this mutation.
func (m *UsageLogMutation) AddedTotalCost() (r float64, exists bool) {
v := m.addtotal_cost
if v == nil {
return
}
return *v, true
}
// ResetTotalCost resets all changes to the "total_cost" field.
func (m *UsageLogMutation) ResetTotalCost() {
m.total_cost = nil
m.addtotal_cost = nil
}
// SetActualCost sets the "actual_cost" field.
func (m *UsageLogMutation) SetActualCost(f float64) {
m.actual_cost = &f
m.addactual_cost = nil
}
// ActualCost returns the value of the "actual_cost" field in the mutation.
func (m *UsageLogMutation) ActualCost() (r float64, exists bool) {
v := m.actual_cost
if v == nil {
return
}
return *v, true
}
// OldActualCost returns the old "actual_cost" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldActualCost(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActualCost is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActualCost requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActualCost: %w", err)
}
return oldValue.ActualCost, nil
}
// AddActualCost adds f to the "actual_cost" field.
func (m *UsageLogMutation) AddActualCost(f float64) {
if m.addactual_cost != nil {
*m.addactual_cost += f
} else {
m.addactual_cost = &f
}
}
// AddedActualCost returns the value that was added to the "actual_cost" field in this mutation.
func (m *UsageLogMutation) AddedActualCost() (r float64, exists bool) {
v := m.addactual_cost
if v == nil {
return
}
return *v, true
}
// ResetActualCost resets all changes to the "actual_cost" field.
func (m *UsageLogMutation) ResetActualCost() {
m.actual_cost = nil
m.addactual_cost = nil
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (m *UsageLogMutation) SetRateMultiplier(f float64) {
m.rate_multiplier = &f
m.addrate_multiplier = nil
}
// RateMultiplier returns the value of the "rate_multiplier" field in the mutation.
func (m *UsageLogMutation) RateMultiplier() (r float64, exists bool) {
v := m.rate_multiplier
if v == nil {
return
}
return *v, true
}
// OldRateMultiplier returns the old "rate_multiplier" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldRateMultiplier(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRateMultiplier is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRateMultiplier requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRateMultiplier: %w", err)
}
return oldValue.RateMultiplier, nil
}
// AddRateMultiplier adds f to the "rate_multiplier" field.
func (m *UsageLogMutation) AddRateMultiplier(f float64) {
if m.addrate_multiplier != nil {
*m.addrate_multiplier += f
} else {
m.addrate_multiplier = &f
}
}
// AddedRateMultiplier returns the value that was added to the "rate_multiplier" field in this mutation.
func (m *UsageLogMutation) AddedRateMultiplier() (r float64, exists bool) {
v := m.addrate_multiplier
if v == nil {
return
}
return *v, true
}
// ResetRateMultiplier resets all changes to the "rate_multiplier" field.
func (m *UsageLogMutation) ResetRateMultiplier() {
m.rate_multiplier = nil
m.addrate_multiplier = nil
}
// SetBillingType sets the "billing_type" field.
func (m *UsageLogMutation) SetBillingType(i int8) {
m.billing_type = &i
m.addbilling_type = nil
}
// BillingType returns the value of the "billing_type" field in the mutation.
func (m *UsageLogMutation) BillingType() (r int8, exists bool) {
v := m.billing_type
if v == nil {
return
}
return *v, true
}
// OldBillingType returns the old "billing_type" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldBillingType(ctx context.Context) (v int8, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBillingType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBillingType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBillingType: %w", err)
}
return oldValue.BillingType, nil
}
// AddBillingType adds i to the "billing_type" field.
func (m *UsageLogMutation) AddBillingType(i int8) {
if m.addbilling_type != nil {
*m.addbilling_type += i
} else {
m.addbilling_type = &i
}
}
// AddedBillingType returns the value that was added to the "billing_type" field in this mutation.
func (m *UsageLogMutation) AddedBillingType() (r int8, exists bool) {
v := m.addbilling_type
if v == nil {
return
}
return *v, true
}
// ResetBillingType resets all changes to the "billing_type" field.
func (m *UsageLogMutation) ResetBillingType() {
m.billing_type = nil
m.addbilling_type = nil
}
// SetStream sets the "stream" field.
func (m *UsageLogMutation) SetStream(b bool) {
m.stream = &b
}
// Stream returns the value of the "stream" field in the mutation.
func (m *UsageLogMutation) Stream() (r bool, exists bool) {
v := m.stream
if v == nil {
return
}
return *v, true
}
// OldStream returns the old "stream" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldStream(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStream is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStream requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStream: %w", err)
}
return oldValue.Stream, nil
}
// ResetStream resets all changes to the "stream" field.
func (m *UsageLogMutation) ResetStream() {
m.stream = nil
}
// SetDurationMs sets the "duration_ms" field.
func (m *UsageLogMutation) SetDurationMs(i int) {
m.duration_ms = &i
m.addduration_ms = nil
}
// DurationMs returns the value of the "duration_ms" field in the mutation.
func (m *UsageLogMutation) DurationMs() (r int, exists bool) {
v := m.duration_ms
if v == nil {
return
}
return *v, true
}
// OldDurationMs returns the old "duration_ms" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldDurationMs(ctx context.Context) (v *int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDurationMs is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDurationMs requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDurationMs: %w", err)
}
return oldValue.DurationMs, nil
}
// AddDurationMs adds i to the "duration_ms" field.
func (m *UsageLogMutation) AddDurationMs(i int) {
if m.addduration_ms != nil {
*m.addduration_ms += i
} else {
m.addduration_ms = &i
}
}
// AddedDurationMs returns the value that was added to the "duration_ms" field in this mutation.
func (m *UsageLogMutation) AddedDurationMs() (r int, exists bool) {
v := m.addduration_ms
if v == nil {
return
}
return *v, true
}
// ClearDurationMs clears the value of the "duration_ms" field.
func (m *UsageLogMutation) ClearDurationMs() {
m.duration_ms = nil
m.addduration_ms = nil
m.clearedFields[usagelog.FieldDurationMs] = struct{}{}
}
// DurationMsCleared returns if the "duration_ms" field was cleared in this mutation.
func (m *UsageLogMutation) DurationMsCleared() bool {
_, ok := m.clearedFields[usagelog.FieldDurationMs]
return ok
}
// ResetDurationMs resets all changes to the "duration_ms" field.
func (m *UsageLogMutation) ResetDurationMs() {
m.duration_ms = nil
m.addduration_ms = nil
delete(m.clearedFields, usagelog.FieldDurationMs)
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (m *UsageLogMutation) SetFirstTokenMs(i int) {
m.first_token_ms = &i
m.addfirst_token_ms = nil
}
// FirstTokenMs returns the value of the "first_token_ms" field in the mutation.
func (m *UsageLogMutation) FirstTokenMs() (r int, exists bool) {
v := m.first_token_ms
if v == nil {
return
}
return *v, true
}
// OldFirstTokenMs returns the old "first_token_ms" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldFirstTokenMs(ctx context.Context) (v *int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFirstTokenMs is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFirstTokenMs requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFirstTokenMs: %w", err)
}
return oldValue.FirstTokenMs, nil
}
// AddFirstTokenMs adds i to the "first_token_ms" field.
func (m *UsageLogMutation) AddFirstTokenMs(i int) {
if m.addfirst_token_ms != nil {
*m.addfirst_token_ms += i
} else {
m.addfirst_token_ms = &i
}
}
// AddedFirstTokenMs returns the value that was added to the "first_token_ms" field in this mutation.
func (m *UsageLogMutation) AddedFirstTokenMs() (r int, exists bool) {
v := m.addfirst_token_ms
if v == nil {
return
}
return *v, true
}
// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (m *UsageLogMutation) ClearFirstTokenMs() {
m.first_token_ms = nil
m.addfirst_token_ms = nil
m.clearedFields[usagelog.FieldFirstTokenMs] = struct{}{}
}
// FirstTokenMsCleared returns if the "first_token_ms" field was cleared in this mutation.
func (m *UsageLogMutation) FirstTokenMsCleared() bool {
_, ok := m.clearedFields[usagelog.FieldFirstTokenMs]
return ok
}
// ResetFirstTokenMs resets all changes to the "first_token_ms" field.
func (m *UsageLogMutation) ResetFirstTokenMs() {
m.first_token_ms = nil
m.addfirst_token_ms = nil
delete(m.clearedFields, usagelog.FieldFirstTokenMs)
}
// SetCreatedAt sets the "created_at" field.
func (m *UsageLogMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UsageLogMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *UsageLogMutation) ResetCreatedAt() {
m.created_at = nil
}
// ClearUser clears the "user" edge to the User entity.
func (m *UsageLogMutation) ClearUser() {
m.cleareduser = true
m.clearedFields[usagelog.FieldUserID] = struct{}{}
}
// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UsageLogMutation) UserCleared() bool {
return m.cleareduser
}
// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) UserIDs() (ids []int64) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *UsageLogMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// ClearAPIKey clears the "api_key" edge to the ApiKey entity.
func (m *UsageLogMutation) ClearAPIKey() {
m.clearedapi_key = true
m.clearedFields[usagelog.FieldAPIKeyID] = struct{}{}
}
// APIKeyCleared reports if the "api_key" edge to the ApiKey entity was cleared.
func (m *UsageLogMutation) APIKeyCleared() bool {
return m.clearedapi_key
}
// APIKeyIDs returns the "api_key" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// APIKeyID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) APIKeyIDs() (ids []int64) {
if id := m.api_key; id != nil {
ids = append(ids, *id)
}
return
}
// ResetAPIKey resets all changes to the "api_key" edge.
func (m *UsageLogMutation) ResetAPIKey() {
m.api_key = nil
m.clearedapi_key = false
}
// ClearAccount clears the "account" edge to the Account entity.
func (m *UsageLogMutation) ClearAccount() {
m.clearedaccount = true
m.clearedFields[usagelog.FieldAccountID] = struct{}{}
}
// AccountCleared reports if the "account" edge to the Account entity was cleared.
func (m *UsageLogMutation) AccountCleared() bool {
return m.clearedaccount
}
// AccountIDs returns the "account" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AccountID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) AccountIDs() (ids []int64) {
if id := m.account; id != nil {
ids = append(ids, *id)
}
return
}
// ResetAccount resets all changes to the "account" edge.
func (m *UsageLogMutation) ResetAccount() {
m.account = nil
m.clearedaccount = false
}
// ClearGroup clears the "group" edge to the Group entity.
func (m *UsageLogMutation) ClearGroup() {
m.clearedgroup = true
m.clearedFields[usagelog.FieldGroupID] = struct{}{}
}
// GroupCleared reports if the "group" edge to the Group entity was cleared.
func (m *UsageLogMutation) GroupCleared() bool {
return m.GroupIDCleared() || m.clearedgroup
}
// GroupIDs returns the "group" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GroupID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) GroupIDs() (ids []int64) {
if id := m.group; id != nil {
ids = append(ids, *id)
}
return
}
// ResetGroup resets all changes to the "group" edge.
func (m *UsageLogMutation) ResetGroup() {
m.group = nil
m.clearedgroup = false
}
// ClearSubscription clears the "subscription" edge to the UserSubscription entity.
func (m *UsageLogMutation) ClearSubscription() {
m.clearedsubscription = true
m.clearedFields[usagelog.FieldSubscriptionID] = struct{}{}
}
// SubscriptionCleared reports if the "subscription" edge to the UserSubscription entity was cleared.
func (m *UsageLogMutation) SubscriptionCleared() bool {
return m.SubscriptionIDCleared() || m.clearedsubscription
}
// SubscriptionIDs returns the "subscription" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// SubscriptionID instead. It exists only for internal usage by the builders.
func (m *UsageLogMutation) SubscriptionIDs() (ids []int64) {
if id := m.subscription; id != nil {
ids = append(ids, *id)
}
return
}
// ResetSubscription resets all changes to the "subscription" edge.
func (m *UsageLogMutation) ResetSubscription() {
m.subscription = nil
m.clearedsubscription = false
}
// Where appends a list predicates to the UsageLogMutation builder.
func (m *UsageLogMutation) Where(ps ...predicate.UsageLog) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UsageLogMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UsageLogMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UsageLog, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UsageLogMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UsageLogMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UsageLog).
func (m *UsageLogMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UsageLogMutation) Fields() []string {
fields := make([]string, 0, 25)
if m.user != nil {
fields = append(fields, usagelog.FieldUserID)
}
if m.api_key != nil {
fields = append(fields, usagelog.FieldAPIKeyID)
}
if m.account != nil {
fields = append(fields, usagelog.FieldAccountID)
}
if m.request_id != nil {
fields = append(fields, usagelog.FieldRequestID)
}
if m.model != nil {
fields = append(fields, usagelog.FieldModel)
}
if m.group != nil {
fields = append(fields, usagelog.FieldGroupID)
}
if m.subscription != nil {
fields = append(fields, usagelog.FieldSubscriptionID)
}
if m.input_tokens != nil {
fields = append(fields, usagelog.FieldInputTokens)
}
if m.output_tokens != nil {
fields = append(fields, usagelog.FieldOutputTokens)
}
if m.cache_creation_tokens != nil {
fields = append(fields, usagelog.FieldCacheCreationTokens)
}
if m.cache_read_tokens != nil {
fields = append(fields, usagelog.FieldCacheReadTokens)
}
if m.cache_creation_5m_tokens != nil {
fields = append(fields, usagelog.FieldCacheCreation5mTokens)
}
if m.cache_creation_1h_tokens != nil {
fields = append(fields, usagelog.FieldCacheCreation1hTokens)
}
if m.input_cost != nil {
fields = append(fields, usagelog.FieldInputCost)
}
if m.output_cost != nil {
fields = append(fields, usagelog.FieldOutputCost)
}
if m.cache_creation_cost != nil {
fields = append(fields, usagelog.FieldCacheCreationCost)
}
if m.cache_read_cost != nil {
fields = append(fields, usagelog.FieldCacheReadCost)
}
if m.total_cost != nil {
fields = append(fields, usagelog.FieldTotalCost)
}
if m.actual_cost != nil {
fields = append(fields, usagelog.FieldActualCost)
}
if m.rate_multiplier != nil {
fields = append(fields, usagelog.FieldRateMultiplier)
}
if m.billing_type != nil {
fields = append(fields, usagelog.FieldBillingType)
}
if m.stream != nil {
fields = append(fields, usagelog.FieldStream)
}
if m.duration_ms != nil {
fields = append(fields, usagelog.FieldDurationMs)
}
if m.first_token_ms != nil {
fields = append(fields, usagelog.FieldFirstTokenMs)
}
if m.created_at != nil {
fields = append(fields, usagelog.FieldCreatedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *UsageLogMutation) Field(name string) (ent.Value, bool) {
switch name {
case usagelog.FieldUserID:
return m.UserID()
case usagelog.FieldAPIKeyID:
return m.APIKeyID()
case usagelog.FieldAccountID:
return m.AccountID()
case usagelog.FieldRequestID:
return m.RequestID()
case usagelog.FieldModel:
return m.Model()
case usagelog.FieldGroupID:
return m.GroupID()
case usagelog.FieldSubscriptionID:
return m.SubscriptionID()
case usagelog.FieldInputTokens:
return m.InputTokens()
case usagelog.FieldOutputTokens:
return m.OutputTokens()
case usagelog.FieldCacheCreationTokens:
return m.CacheCreationTokens()
case usagelog.FieldCacheReadTokens:
return m.CacheReadTokens()
case usagelog.FieldCacheCreation5mTokens:
return m.CacheCreation5mTokens()
case usagelog.FieldCacheCreation1hTokens:
return m.CacheCreation1hTokens()
case usagelog.FieldInputCost:
return m.InputCost()
case usagelog.FieldOutputCost:
return m.OutputCost()
case usagelog.FieldCacheCreationCost:
return m.CacheCreationCost()
case usagelog.FieldCacheReadCost:
return m.CacheReadCost()
case usagelog.FieldTotalCost:
return m.TotalCost()
case usagelog.FieldActualCost:
return m.ActualCost()
case usagelog.FieldRateMultiplier:
return m.RateMultiplier()
case usagelog.FieldBillingType:
return m.BillingType()
case usagelog.FieldStream:
return m.Stream()
case usagelog.FieldDurationMs:
return m.DurationMs()
case usagelog.FieldFirstTokenMs:
return m.FirstTokenMs()
case usagelog.FieldCreatedAt:
return m.CreatedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case usagelog.FieldUserID:
return m.OldUserID(ctx)
case usagelog.FieldAPIKeyID:
return m.OldAPIKeyID(ctx)
case usagelog.FieldAccountID:
return m.OldAccountID(ctx)
case usagelog.FieldRequestID:
return m.OldRequestID(ctx)
case usagelog.FieldModel:
return m.OldModel(ctx)
case usagelog.FieldGroupID:
return m.OldGroupID(ctx)
case usagelog.FieldSubscriptionID:
return m.OldSubscriptionID(ctx)
case usagelog.FieldInputTokens:
return m.OldInputTokens(ctx)
case usagelog.FieldOutputTokens:
return m.OldOutputTokens(ctx)
case usagelog.FieldCacheCreationTokens:
return m.OldCacheCreationTokens(ctx)
case usagelog.FieldCacheReadTokens:
return m.OldCacheReadTokens(ctx)
case usagelog.FieldCacheCreation5mTokens:
return m.OldCacheCreation5mTokens(ctx)
case usagelog.FieldCacheCreation1hTokens:
return m.OldCacheCreation1hTokens(ctx)
case usagelog.FieldInputCost:
return m.OldInputCost(ctx)
case usagelog.FieldOutputCost:
return m.OldOutputCost(ctx)
case usagelog.FieldCacheCreationCost:
return m.OldCacheCreationCost(ctx)
case usagelog.FieldCacheReadCost:
return m.OldCacheReadCost(ctx)
case usagelog.FieldTotalCost:
return m.OldTotalCost(ctx)
case usagelog.FieldActualCost:
return m.OldActualCost(ctx)
case usagelog.FieldRateMultiplier:
return m.OldRateMultiplier(ctx)
case usagelog.FieldBillingType:
return m.OldBillingType(ctx)
case usagelog.FieldStream:
return m.OldStream(ctx)
case usagelog.FieldDurationMs:
return m.OldDurationMs(ctx)
case usagelog.FieldFirstTokenMs:
return m.OldFirstTokenMs(ctx)
case usagelog.FieldCreatedAt:
return m.OldCreatedAt(ctx)
}
return nil, fmt.Errorf("unknown UsageLog field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UsageLogMutation) SetField(name string, value ent.Value) error {
switch name {
case usagelog.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case usagelog.FieldAPIKeyID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAPIKeyID(v)
return nil
case usagelog.FieldAccountID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAccountID(v)
return nil
case usagelog.FieldRequestID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRequestID(v)
return nil
case usagelog.FieldModel:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModel(v)
return nil
case usagelog.FieldGroupID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetGroupID(v)
return nil
case usagelog.FieldSubscriptionID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSubscriptionID(v)
return nil
case usagelog.FieldInputTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetInputTokens(v)
return nil
case usagelog.FieldOutputTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOutputTokens(v)
return nil
case usagelog.FieldCacheCreationTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCacheCreationTokens(v)
return nil
case usagelog.FieldCacheReadTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCacheReadTokens(v)
return nil
case usagelog.FieldCacheCreation5mTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCacheCreation5mTokens(v)
return nil
case usagelog.FieldCacheCreation1hTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCacheCreation1hTokens(v)
return nil
case usagelog.FieldInputCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetInputCost(v)
return nil
case usagelog.FieldOutputCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOutputCost(v)
return nil
case usagelog.FieldCacheCreationCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCacheCreationCost(v)
return nil
case usagelog.FieldCacheReadCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCacheReadCost(v)
return nil
case usagelog.FieldTotalCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTotalCost(v)
return nil
case usagelog.FieldActualCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActualCost(v)
return nil
case usagelog.FieldRateMultiplier:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRateMultiplier(v)
return nil
case usagelog.FieldBillingType:
v, ok := value.(int8)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBillingType(v)
return nil
case usagelog.FieldStream:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStream(v)
return nil
case usagelog.FieldDurationMs:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDurationMs(v)
return nil
case usagelog.FieldFirstTokenMs:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFirstTokenMs(v)
return nil
case usagelog.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
}
return fmt.Errorf("unknown UsageLog field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UsageLogMutation) AddedFields() []string {
var fields []string
if m.addinput_tokens != nil {
fields = append(fields, usagelog.FieldInputTokens)
}
if m.addoutput_tokens != nil {
fields = append(fields, usagelog.FieldOutputTokens)
}
if m.addcache_creation_tokens != nil {
fields = append(fields, usagelog.FieldCacheCreationTokens)
}
if m.addcache_read_tokens != nil {
fields = append(fields, usagelog.FieldCacheReadTokens)
}
if m.addcache_creation_5m_tokens != nil {
fields = append(fields, usagelog.FieldCacheCreation5mTokens)
}
if m.addcache_creation_1h_tokens != nil {
fields = append(fields, usagelog.FieldCacheCreation1hTokens)
}
if m.addinput_cost != nil {
fields = append(fields, usagelog.FieldInputCost)
}
if m.addoutput_cost != nil {
fields = append(fields, usagelog.FieldOutputCost)
}
if m.addcache_creation_cost != nil {
fields = append(fields, usagelog.FieldCacheCreationCost)
}
if m.addcache_read_cost != nil {
fields = append(fields, usagelog.FieldCacheReadCost)
}
if m.addtotal_cost != nil {
fields = append(fields, usagelog.FieldTotalCost)
}
if m.addactual_cost != nil {
fields = append(fields, usagelog.FieldActualCost)
}
if m.addrate_multiplier != nil {
fields = append(fields, usagelog.FieldRateMultiplier)
}
if m.addbilling_type != nil {
fields = append(fields, usagelog.FieldBillingType)
}
if m.addduration_ms != nil {
fields = append(fields, usagelog.FieldDurationMs)
}
if m.addfirst_token_ms != nil {
fields = append(fields, usagelog.FieldFirstTokenMs)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UsageLogMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case usagelog.FieldInputTokens:
return m.AddedInputTokens()
case usagelog.FieldOutputTokens:
return m.AddedOutputTokens()
case usagelog.FieldCacheCreationTokens:
return m.AddedCacheCreationTokens()
case usagelog.FieldCacheReadTokens:
return m.AddedCacheReadTokens()
case usagelog.FieldCacheCreation5mTokens:
return m.AddedCacheCreation5mTokens()
case usagelog.FieldCacheCreation1hTokens:
return m.AddedCacheCreation1hTokens()
case usagelog.FieldInputCost:
return m.AddedInputCost()
case usagelog.FieldOutputCost:
return m.AddedOutputCost()
case usagelog.FieldCacheCreationCost:
return m.AddedCacheCreationCost()
case usagelog.FieldCacheReadCost:
return m.AddedCacheReadCost()
case usagelog.FieldTotalCost:
return m.AddedTotalCost()
case usagelog.FieldActualCost:
return m.AddedActualCost()
case usagelog.FieldRateMultiplier:
return m.AddedRateMultiplier()
case usagelog.FieldBillingType:
return m.AddedBillingType()
case usagelog.FieldDurationMs:
return m.AddedDurationMs()
case usagelog.FieldFirstTokenMs:
return m.AddedFirstTokenMs()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UsageLogMutation) AddField(name string, value ent.Value) error {
switch name {
case usagelog.FieldInputTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddInputTokens(v)
return nil
case usagelog.FieldOutputTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddOutputTokens(v)
return nil
case usagelog.FieldCacheCreationTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCacheCreationTokens(v)
return nil
case usagelog.FieldCacheReadTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCacheReadTokens(v)
return nil
case usagelog.FieldCacheCreation5mTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCacheCreation5mTokens(v)
return nil
case usagelog.FieldCacheCreation1hTokens:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCacheCreation1hTokens(v)
return nil
case usagelog.FieldInputCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddInputCost(v)
return nil
case usagelog.FieldOutputCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddOutputCost(v)
return nil
case usagelog.FieldCacheCreationCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCacheCreationCost(v)
return nil
case usagelog.FieldCacheReadCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCacheReadCost(v)
return nil
case usagelog.FieldTotalCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddTotalCost(v)
return nil
case usagelog.FieldActualCost:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddActualCost(v)
return nil
case usagelog.FieldRateMultiplier:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRateMultiplier(v)
return nil
case usagelog.FieldBillingType:
v, ok := value.(int8)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddBillingType(v)
return nil
case usagelog.FieldDurationMs:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddDurationMs(v)
return nil
case usagelog.FieldFirstTokenMs:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddFirstTokenMs(v)
return nil
}
return fmt.Errorf("unknown UsageLog numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UsageLogMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(usagelog.FieldGroupID) {
fields = append(fields, usagelog.FieldGroupID)
}
if m.FieldCleared(usagelog.FieldSubscriptionID) {
fields = append(fields, usagelog.FieldSubscriptionID)
}
if m.FieldCleared(usagelog.FieldDurationMs) {
fields = append(fields, usagelog.FieldDurationMs)
}
if m.FieldCleared(usagelog.FieldFirstTokenMs) {
fields = append(fields, usagelog.FieldFirstTokenMs)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UsageLogMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *SettingMutation) ClearField(name string) error {
return fmt.Errorf("unknown Setting nullable field %s", name)
func (m *UsageLogMutation) ClearField(name string) error {
switch name {
case usagelog.FieldGroupID:
m.ClearGroupID()
return nil
case usagelog.FieldSubscriptionID:
m.ClearSubscriptionID()
return nil
case usagelog.FieldDurationMs:
m.ClearDurationMs()
return nil
case usagelog.FieldFirstTokenMs:
m.ClearFirstTokenMs()
return nil
}
return fmt.Errorf("unknown UsageLog nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *SettingMutation) ResetField(name string) error {
func (m *UsageLogMutation) ResetField(name string) error {
switch name {
case setting.FieldKey:
m.ResetKey()
case usagelog.FieldUserID:
m.ResetUserID()
return nil
case setting.FieldValue:
m.ResetValue()
case usagelog.FieldAPIKeyID:
m.ResetAPIKeyID()
return nil
case setting.FieldUpdatedAt:
m.ResetUpdatedAt()
case usagelog.FieldAccountID:
m.ResetAccountID()
return nil
case usagelog.FieldRequestID:
m.ResetRequestID()
return nil
case usagelog.FieldModel:
m.ResetModel()
return nil
case usagelog.FieldGroupID:
m.ResetGroupID()
return nil
case usagelog.FieldSubscriptionID:
m.ResetSubscriptionID()
return nil
case usagelog.FieldInputTokens:
m.ResetInputTokens()
return nil
case usagelog.FieldOutputTokens:
m.ResetOutputTokens()
return nil
case usagelog.FieldCacheCreationTokens:
m.ResetCacheCreationTokens()
return nil
case usagelog.FieldCacheReadTokens:
m.ResetCacheReadTokens()
return nil
case usagelog.FieldCacheCreation5mTokens:
m.ResetCacheCreation5mTokens()
return nil
case usagelog.FieldCacheCreation1hTokens:
m.ResetCacheCreation1hTokens()
return nil
case usagelog.FieldInputCost:
m.ResetInputCost()
return nil
case usagelog.FieldOutputCost:
m.ResetOutputCost()
return nil
case usagelog.FieldCacheCreationCost:
m.ResetCacheCreationCost()
return nil
case usagelog.FieldCacheReadCost:
m.ResetCacheReadCost()
return nil
case usagelog.FieldTotalCost:
m.ResetTotalCost()
return nil
case usagelog.FieldActualCost:
m.ResetActualCost()
return nil
case usagelog.FieldRateMultiplier:
m.ResetRateMultiplier()
return nil
case usagelog.FieldBillingType:
m.ResetBillingType()
return nil
case usagelog.FieldStream:
m.ResetStream()
return nil
case usagelog.FieldDurationMs:
m.ResetDurationMs()
return nil
case usagelog.FieldFirstTokenMs:
m.ResetFirstTokenMs()
return nil
case usagelog.FieldCreatedAt:
m.ResetCreatedAt()
return nil
}
return fmt.Errorf("unknown Setting field %s", name)
return fmt.Errorf("unknown UsageLog field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *SettingMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
func (m *UsageLogMutation) AddedEdges() []string {
edges := make([]string, 0, 5)
if m.user != nil {
edges = append(edges, usagelog.EdgeUser)
}
if m.api_key != nil {
edges = append(edges, usagelog.EdgeAPIKey)
}
if m.account != nil {
edges = append(edges, usagelog.EdgeAccount)
}
if m.group != nil {
edges = append(edges, usagelog.EdgeGroup)
}
if m.subscription != nil {
edges = append(edges, usagelog.EdgeSubscription)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *SettingMutation) AddedIDs(name string) []ent.Value {
func (m *UsageLogMutation) AddedIDs(name string) []ent.Value {
switch name {
case usagelog.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
case usagelog.EdgeAPIKey:
if id := m.api_key; id != nil {
return []ent.Value{*id}
}
case usagelog.EdgeAccount:
if id := m.account; id != nil {
return []ent.Value{*id}
}
case usagelog.EdgeGroup:
if id := m.group; id != nil {
return []ent.Value{*id}
}
case usagelog.EdgeSubscription:
if id := m.subscription; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *SettingMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
func (m *UsageLogMutation) RemovedEdges() []string {
edges := make([]string, 0, 5)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *SettingMutation) RemovedIDs(name string) []ent.Value {
func (m *UsageLogMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *SettingMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
func (m *UsageLogMutation) ClearedEdges() []string {
edges := make([]string, 0, 5)
if m.cleareduser {
edges = append(edges, usagelog.EdgeUser)
}
if m.clearedapi_key {
edges = append(edges, usagelog.EdgeAPIKey)
}
if m.clearedaccount {
edges = append(edges, usagelog.EdgeAccount)
}
if m.clearedgroup {
edges = append(edges, usagelog.EdgeGroup)
}
if m.clearedsubscription {
edges = append(edges, usagelog.EdgeSubscription)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *SettingMutation) EdgeCleared(name string) bool {
func (m *UsageLogMutation) EdgeCleared(name string) bool {
switch name {
case usagelog.EdgeUser:
return m.cleareduser
case usagelog.EdgeAPIKey:
return m.clearedapi_key
case usagelog.EdgeAccount:
return m.clearedaccount
case usagelog.EdgeGroup:
return m.clearedgroup
case usagelog.EdgeSubscription:
return m.clearedsubscription
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *SettingMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Setting unique edge %s", name)
func (m *UsageLogMutation) ClearEdge(name string) error {
switch name {
case usagelog.EdgeUser:
m.ClearUser()
return nil
case usagelog.EdgeAPIKey:
m.ClearAPIKey()
return nil
case usagelog.EdgeAccount:
m.ClearAccount()
return nil
case usagelog.EdgeGroup:
m.ClearGroup()
return nil
case usagelog.EdgeSubscription:
m.ClearSubscription()
return nil
}
return fmt.Errorf("unknown UsageLog unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *SettingMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Setting edge %s", name)
func (m *UsageLogMutation) ResetEdge(name string) error {
switch name {
case usagelog.EdgeUser:
m.ResetUser()
return nil
case usagelog.EdgeAPIKey:
m.ResetAPIKey()
return nil
case usagelog.EdgeAccount:
m.ResetAccount()
return nil
case usagelog.EdgeGroup:
m.ResetGroup()
return nil
case usagelog.EdgeSubscription:
m.ResetSubscription()
return nil
}
return fmt.Errorf("unknown UsageLog edge %s", name)
}
// UserMutation represents an operation that mutates the User nodes in the graph.
......@@ -7259,6 +10176,9 @@ type UserMutation struct {
allowed_groups map[int64]struct{}
removedallowed_groups map[int64]struct{}
clearedallowed_groups bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
......@@ -8117,6 +11037,60 @@ func (m *UserMutation) ResetAllowedGroups() {
m.removedallowed_groups = nil
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *UserMutation) AddUsageLogIDs(ids ...int64) {
if m.usage_logs == nil {
m.usage_logs = make(map[int64]struct{})
}
for i := range ids {
m.usage_logs[ids[i]] = struct{}{}
}
}
// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *UserMutation) ClearUsageLogs() {
m.clearedusage_logs = true
}
// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *UserMutation) UsageLogsCleared() bool {
return m.clearedusage_logs
}
// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *UserMutation) RemoveUsageLogIDs(ids ...int64) {
if m.removedusage_logs == nil {
m.removedusage_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_logs, ids[i])
m.removedusage_logs[ids[i]] = struct{}{}
}
}
// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *UserMutation) RemovedUsageLogsIDs() (ids []int64) {
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return
}
// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *UserMutation) UsageLogsIDs() (ids []int64) {
for id := range m.usage_logs {
ids = append(ids, id)
}
return
}
// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *UserMutation) ResetUsageLogs() {
m.usage_logs = nil
m.clearedusage_logs = false
m.removedusage_logs = nil
}
// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
m.predicates = append(m.predicates, ps...)
......@@ -8473,7 +11447,7 @@ func (m *UserMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
edges := make([]string, 0, 5)
edges := make([]string, 0, 6)
if m.api_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
}
......@@ -8489,6 +11463,9 @@ func (m *UserMutation) AddedEdges() []string {
if m.allowed_groups != nil {
edges = append(edges, user.EdgeAllowedGroups)
}
if m.usage_logs != nil {
edges = append(edges, user.EdgeUsageLogs)
}
return edges
}
......@@ -8526,13 +11503,19 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case user.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0, 5)
edges := make([]string, 0, 6)
if m.removedapi_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
}
......@@ -8548,6 +11531,9 @@ func (m *UserMutation) RemovedEdges() []string {
if m.removedallowed_groups != nil {
edges = append(edges, user.EdgeAllowedGroups)
}
if m.removedusage_logs != nil {
edges = append(edges, user.EdgeUsageLogs)
}
return edges
}
......@@ -8585,13 +11571,19 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case user.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
edges := make([]string, 0, 5)
edges := make([]string, 0, 6)
if m.clearedapi_keys {
edges = append(edges, user.EdgeAPIKeys)
}
......@@ -8607,6 +11599,9 @@ func (m *UserMutation) ClearedEdges() []string {
if m.clearedallowed_groups {
edges = append(edges, user.EdgeAllowedGroups)
}
if m.clearedusage_logs {
edges = append(edges, user.EdgeUsageLogs)
}
return edges
}
......@@ -8624,6 +11619,8 @@ func (m *UserMutation) EdgeCleared(name string) bool {
return m.clearedassigned_subscriptions
case user.EdgeAllowedGroups:
return m.clearedallowed_groups
case user.EdgeUsageLogs:
return m.clearedusage_logs
}
return false
}
......@@ -8655,6 +11652,9 @@ func (m *UserMutation) ResetEdge(name string) error {
case user.EdgeAllowedGroups:
m.ResetAllowedGroups()
return nil
case user.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
}
return fmt.Errorf("unknown User edge %s", name)
}
......@@ -9084,6 +12084,7 @@ type UserSubscriptionMutation struct {
id *int64
created_at *time.Time
updated_at *time.Time
deleted_at *time.Time
starts_at *time.Time
expires_at *time.Time
status *string
......@@ -9105,6 +12106,9 @@ type UserSubscriptionMutation struct {
clearedgroup bool
assigned_by_user *int64
clearedassigned_by_user bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
done bool
oldValue func(context.Context) (*UserSubscription, error)
predicates []predicate.UserSubscription
......@@ -9280,6 +12284,55 @@ func (m *UserSubscriptionMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *UserSubscriptionMutation) SetDeletedAt(t time.Time) {
m.deleted_at = &t
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *UserSubscriptionMutation) DeletedAt() (r time.Time, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the UserSubscription entity.
// If the UserSubscription object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserSubscriptionMutation) OldDeletedAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *UserSubscriptionMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[usersubscription.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *UserSubscriptionMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[usersubscription.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *UserSubscriptionMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, usersubscription.FieldDeletedAt)
}
// SetUserID sets the "user_id" field.
func (m *UserSubscriptionMutation) SetUserID(i int64) {
m.user = &i
......@@ -10003,6 +13056,60 @@ func (m *UserSubscriptionMutation) ResetAssignedByUser() {
m.clearedassigned_by_user = false
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by ids.
func (m *UserSubscriptionMutation) AddUsageLogIDs(ids ...int64) {
if m.usage_logs == nil {
m.usage_logs = make(map[int64]struct{})
}
for i := range ids {
m.usage_logs[ids[i]] = struct{}{}
}
}
// ClearUsageLogs clears the "usage_logs" edge to the UsageLog entity.
func (m *UserSubscriptionMutation) ClearUsageLogs() {
m.clearedusage_logs = true
}
// UsageLogsCleared reports if the "usage_logs" edge to the UsageLog entity was cleared.
func (m *UserSubscriptionMutation) UsageLogsCleared() bool {
return m.clearedusage_logs
}
// RemoveUsageLogIDs removes the "usage_logs" edge to the UsageLog entity by IDs.
func (m *UserSubscriptionMutation) RemoveUsageLogIDs(ids ...int64) {
if m.removedusage_logs == nil {
m.removedusage_logs = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_logs, ids[i])
m.removedusage_logs[ids[i]] = struct{}{}
}
}
// RemovedUsageLogs returns the removed IDs of the "usage_logs" edge to the UsageLog entity.
func (m *UserSubscriptionMutation) RemovedUsageLogsIDs() (ids []int64) {
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return
}
// UsageLogsIDs returns the "usage_logs" edge IDs in the mutation.
func (m *UserSubscriptionMutation) UsageLogsIDs() (ids []int64) {
for id := range m.usage_logs {
ids = append(ids, id)
}
return
}
// ResetUsageLogs resets all changes to the "usage_logs" edge.
func (m *UserSubscriptionMutation) ResetUsageLogs() {
m.usage_logs = nil
m.clearedusage_logs = false
m.removedusage_logs = nil
}
// Where appends a list predicates to the UserSubscriptionMutation builder.
func (m *UserSubscriptionMutation) Where(ps ...predicate.UserSubscription) {
m.predicates = append(m.predicates, ps...)
......@@ -10037,13 +13144,16 @@ func (m *UserSubscriptionMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserSubscriptionMutation) Fields() []string {
fields := make([]string, 0, 16)
fields := make([]string, 0, 17)
if m.created_at != nil {
fields = append(fields, usersubscription.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, usersubscription.FieldUpdatedAt)
}
if m.deleted_at != nil {
fields = append(fields, usersubscription.FieldDeletedAt)
}
if m.user != nil {
fields = append(fields, usersubscription.FieldUserID)
}
......@@ -10098,6 +13208,8 @@ func (m *UserSubscriptionMutation) Field(name string) (ent.Value, bool) {
return m.CreatedAt()
case usersubscription.FieldUpdatedAt:
return m.UpdatedAt()
case usersubscription.FieldDeletedAt:
return m.DeletedAt()
case usersubscription.FieldUserID:
return m.UserID()
case usersubscription.FieldGroupID:
......@@ -10139,6 +13251,8 @@ func (m *UserSubscriptionMutation) OldField(ctx context.Context, name string) (e
return m.OldCreatedAt(ctx)
case usersubscription.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case usersubscription.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case usersubscription.FieldUserID:
return m.OldUserID(ctx)
case usersubscription.FieldGroupID:
......@@ -10190,6 +13304,13 @@ func (m *UserSubscriptionMutation) SetField(name string, value ent.Value) error
}
m.SetUpdatedAt(v)
return nil
case usersubscription.FieldDeletedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case usersubscription.FieldUserID:
v, ok := value.(int64)
if !ok {
......@@ -10357,6 +13478,9 @@ func (m *UserSubscriptionMutation) AddField(name string, value ent.Value) error
// mutation.
func (m *UserSubscriptionMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(usersubscription.FieldDeletedAt) {
fields = append(fields, usersubscription.FieldDeletedAt)
}
if m.FieldCleared(usersubscription.FieldDailyWindowStart) {
fields = append(fields, usersubscription.FieldDailyWindowStart)
}
......@@ -10386,6 +13510,9 @@ func (m *UserSubscriptionMutation) FieldCleared(name string) bool {
// error if the field is not defined in the schema.
func (m *UserSubscriptionMutation) ClearField(name string) error {
switch name {
case usersubscription.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case usersubscription.FieldDailyWindowStart:
m.ClearDailyWindowStart()
return nil
......@@ -10415,6 +13542,9 @@ func (m *UserSubscriptionMutation) ResetField(name string) error {
case usersubscription.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case usersubscription.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case usersubscription.FieldUserID:
m.ResetUserID()
return nil
......@@ -10463,7 +13593,7 @@ func (m *UserSubscriptionMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserSubscriptionMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
edges := make([]string, 0, 4)
if m.user != nil {
edges = append(edges, usersubscription.EdgeUser)
}
......@@ -10473,6 +13603,9 @@ func (m *UserSubscriptionMutation) AddedEdges() []string {
if m.assigned_by_user != nil {
edges = append(edges, usersubscription.EdgeAssignedByUser)
}
if m.usage_logs != nil {
edges = append(edges, usersubscription.EdgeUsageLogs)
}
return edges
}
......@@ -10492,25 +13625,42 @@ func (m *UserSubscriptionMutation) AddedIDs(name string) []ent.Value {
if id := m.assigned_by_user; id != nil {
return []ent.Value{*id}
}
case usersubscription.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserSubscriptionMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
edges := make([]string, 0, 4)
if m.removedusage_logs != nil {
edges = append(edges, usersubscription.EdgeUsageLogs)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserSubscriptionMutation) RemovedIDs(name string) []ent.Value {
switch name {
case usersubscription.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserSubscriptionMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
edges := make([]string, 0, 4)
if m.cleareduser {
edges = append(edges, usersubscription.EdgeUser)
}
......@@ -10520,6 +13670,9 @@ func (m *UserSubscriptionMutation) ClearedEdges() []string {
if m.clearedassigned_by_user {
edges = append(edges, usersubscription.EdgeAssignedByUser)
}
if m.clearedusage_logs {
edges = append(edges, usersubscription.EdgeUsageLogs)
}
return edges
}
......@@ -10533,6 +13686,8 @@ func (m *UserSubscriptionMutation) EdgeCleared(name string) bool {
return m.clearedgroup
case usersubscription.EdgeAssignedByUser:
return m.clearedassigned_by_user
case usersubscription.EdgeUsageLogs:
return m.clearedusage_logs
}
return false
}
......@@ -10567,6 +13722,9 @@ func (m *UserSubscriptionMutation) ResetEdge(name string) error {
case usersubscription.EdgeAssignedByUser:
m.ResetAssignedByUser()
return nil
case usersubscription.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
}
return fmt.Errorf("unknown UserSubscription edge %s", name)
}
......@@ -27,6 +27,9 @@ type RedeemCode func(*sql.Selector)
// Setting is the predicate function for setting builders.
type Setting func(*sql.Selector)
// UsageLog is the predicate function for usagelog builders.
type UsageLog func(*sql.Selector)
// User is the predicate function for user builders.
type User func(*sql.Selector)
......
......@@ -37,9 +37,30 @@ type Proxy struct {
Password *string `json:"password,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the ProxyQuery when eager-loading is set.
Edges ProxyEdges `json:"edges"`
selectValues sql.SelectValues
}
// ProxyEdges holds the relations/edges for other nodes in the graph.
type ProxyEdges struct {
// Accounts holds the value of the accounts edge.
Accounts []*Account `json:"accounts,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// AccountsOrErr returns the Accounts value or an error if the edge
// was not loaded in eager-loading.
func (e ProxyEdges) AccountsOrErr() ([]*Account, error) {
if e.loadedTypes[0] {
return e.Accounts, nil
}
return nil, &NotLoadedError{edge: "accounts"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Proxy) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
......@@ -148,6 +169,11 @@ func (_m *Proxy) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryAccounts queries the "accounts" edge of the Proxy entity.
func (_m *Proxy) QueryAccounts() *AccountQuery {
return NewProxyClient(_m.config).QueryAccounts(_m)
}
// Update returns a builder for updating this Proxy.
// Note that you need to call Proxy.Unwrap() before calling this method if this Proxy
// was returned from a transaction, and the transaction was committed or rolled back.
......
......@@ -7,6 +7,7 @@ import (
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
......@@ -34,8 +35,17 @@ const (
FieldPassword = "password"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// EdgeAccounts holds the string denoting the accounts edge name in mutations.
EdgeAccounts = "accounts"
// Table holds the table name of the proxy in the database.
Table = "proxies"
// AccountsTable is the table that holds the accounts relation/edge.
AccountsTable = "accounts"
// AccountsInverseTable is the table name for the Account entity.
// It exists in this package in order to avoid circular dependency with the "account" package.
AccountsInverseTable = "accounts"
// AccountsColumn is the table column denoting the accounts relation/edge.
AccountsColumn = "proxy_id"
)
// Columns holds all SQL columns for proxy fields.
......@@ -150,3 +160,24 @@ func ByPassword(opts ...sql.OrderTermOption) OrderOption {
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByAccountsCount orders the results by accounts count.
func ByAccountsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborsCount(s, newAccountsStep(), opts...)
}
}
// ByAccounts orders the results by accounts terms.
func ByAccounts(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newAccountsStep(), append([]sql.OrderTerm{term}, terms...)...)
}
}
func newAccountsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(AccountsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, AccountsTable, AccountsColumn),
)
}
......@@ -6,6 +6,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
......@@ -684,6 +685,29 @@ func StatusContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldStatus, v))
}
// HasAccounts applies the HasEdge predicate on the "accounts" edge.
func HasAccounts() predicate.Proxy {
return predicate.Proxy(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, AccountsTable, AccountsColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasAccountsWith applies the HasEdge predicate on the "accounts" edge with a given conditions (other predicates).
func HasAccountsWith(preds ...predicate.Account) predicate.Proxy {
return predicate.Proxy(func(s *sql.Selector) {
step := newAccountsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.AndPredicates(predicates...))
......
......@@ -11,6 +11,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
......@@ -130,6 +131,21 @@ func (_c *ProxyCreate) SetNillableStatus(v *string) *ProxyCreate {
return _c
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_c *ProxyCreate) AddAccountIDs(ids ...int64) *ProxyCreate {
_c.mutation.AddAccountIDs(ids...)
return _c
}
// AddAccounts adds the "accounts" edges to the Account entity.
func (_c *ProxyCreate) AddAccounts(v ...*Account) *ProxyCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddAccountIDs(ids...)
}
// Mutation returns the ProxyMutation object of the builder.
func (_c *ProxyCreate) Mutation() *ProxyMutation {
return _c.mutation
......@@ -308,6 +324,22 @@ func (_c *ProxyCreate) createSpec() (*Proxy, *sqlgraph.CreateSpec) {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
_node.Status = value
}
if nodes := _c.mutation.AccountsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
......
......@@ -4,6 +4,7 @@ package ent
import (
"context"
"database/sql/driver"
"fmt"
"math"
......@@ -11,6 +12,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
......@@ -22,6 +24,7 @@ type ProxyQuery struct {
order []proxy.OrderOption
inters []Interceptor
predicates []predicate.Proxy
withAccounts *AccountQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
......@@ -58,6 +61,28 @@ func (_q *ProxyQuery) Order(o ...proxy.OrderOption) *ProxyQuery {
return _q
}
// QueryAccounts chains the current query on the "accounts" edge.
func (_q *ProxyQuery) QueryAccounts() *AccountQuery {
query := (&AccountClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(proxy.Table, proxy.FieldID, selector),
sqlgraph.To(account.Table, account.FieldID),
sqlgraph.Edge(sqlgraph.O2M, true, proxy.AccountsTable, proxy.AccountsColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first Proxy entity from the query.
// Returns a *NotFoundError when no Proxy was found.
func (_q *ProxyQuery) First(ctx context.Context) (*Proxy, error) {
......@@ -250,12 +275,24 @@ func (_q *ProxyQuery) Clone() *ProxyQuery {
order: append([]proxy.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.Proxy{}, _q.predicates...),
withAccounts: _q.withAccounts.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// WithAccounts tells the query-builder to eager-load the nodes that are connected to
// the "accounts" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *ProxyQuery) WithAccounts(opts ...func(*AccountQuery)) *ProxyQuery {
query := (&AccountClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withAccounts = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
......@@ -334,6 +371,9 @@ func (_q *ProxyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Proxy,
var (
nodes = []*Proxy{}
_spec = _q.querySpec()
loadedTypes = [1]bool{
_q.withAccounts != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Proxy).scanValues(nil, columns)
......@@ -341,6 +381,7 @@ func (_q *ProxyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Proxy,
_spec.Assign = func(columns []string, values []any) error {
node := &Proxy{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
......@@ -352,9 +393,50 @@ func (_q *ProxyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Proxy,
if len(nodes) == 0 {
return nodes, nil
}
if query := _q.withAccounts; query != nil {
if err := _q.loadAccounts(ctx, query, nodes,
func(n *Proxy) { n.Edges.Accounts = []*Account{} },
func(n *Proxy, e *Account) { n.Edges.Accounts = append(n.Edges.Accounts, e) }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *ProxyQuery) loadAccounts(ctx context.Context, query *AccountQuery, nodes []*Proxy, init func(*Proxy), assign func(*Proxy, *Account)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*Proxy)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
if init != nil {
init(nodes[i])
}
}
if len(query.ctx.Fields) > 0 {
query.ctx.AppendFieldOnce(account.FieldProxyID)
}
query.Where(predicate.Account(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(proxy.AccountsColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.ProxyID
if fk == nil {
return fmt.Errorf(`foreign-key "proxy_id" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "proxy_id" returned %v for node %v`, *fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *ProxyQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
......
......@@ -11,6 +11,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
......@@ -171,11 +172,47 @@ func (_u *ProxyUpdate) SetNillableStatus(v *string) *ProxyUpdate {
return _u
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *ProxyUpdate) AddAccountIDs(ids ...int64) *ProxyUpdate {
_u.mutation.AddAccountIDs(ids...)
return _u
}
// AddAccounts adds the "accounts" edges to the Account entity.
func (_u *ProxyUpdate) AddAccounts(v ...*Account) *ProxyUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddAccountIDs(ids...)
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdate) Mutation() *ProxyMutation {
return _u.mutation
}
// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *ProxyUpdate) ClearAccounts() *ProxyUpdate {
_u.mutation.ClearAccounts()
return _u
}
// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
func (_u *ProxyUpdate) RemoveAccountIDs(ids ...int64) *ProxyUpdate {
_u.mutation.RemoveAccountIDs(ids...)
return _u
}
// RemoveAccounts removes "accounts" edges to Account entities.
func (_u *ProxyUpdate) RemoveAccounts(v ...*Account) *ProxyUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveAccountIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ProxyUpdate) Save(ctx context.Context) (int, error) {
if err := _u.defaults(); err != nil {
......@@ -304,6 +341,51 @@ func (_u *ProxyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if _u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.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.AccountsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.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{proxy.Label}
......@@ -467,11 +549,47 @@ func (_u *ProxyUpdateOne) SetNillableStatus(v *string) *ProxyUpdateOne {
return _u
}
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
func (_u *ProxyUpdateOne) AddAccountIDs(ids ...int64) *ProxyUpdateOne {
_u.mutation.AddAccountIDs(ids...)
return _u
}
// AddAccounts adds the "accounts" edges to the Account entity.
func (_u *ProxyUpdateOne) AddAccounts(v ...*Account) *ProxyUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddAccountIDs(ids...)
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdateOne) Mutation() *ProxyMutation {
return _u.mutation
}
// ClearAccounts clears all "accounts" edges to the Account entity.
func (_u *ProxyUpdateOne) ClearAccounts() *ProxyUpdateOne {
_u.mutation.ClearAccounts()
return _u
}
// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs.
func (_u *ProxyUpdateOne) RemoveAccountIDs(ids ...int64) *ProxyUpdateOne {
_u.mutation.RemoveAccountIDs(ids...)
return _u
}
// RemoveAccounts removes "accounts" edges to Account entities.
func (_u *ProxyUpdateOne) RemoveAccounts(v ...*Account) *ProxyUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveAccountIDs(ids...)
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdateOne) Where(ps ...predicate.Proxy) *ProxyUpdateOne {
_u.mutation.Where(ps...)
......@@ -630,6 +748,51 @@ func (_u *ProxyUpdateOne) sqlSave(ctx context.Context) (_node *Proxy, err error)
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if _u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !_u.mutation.AccountsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.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.AccountsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: true,
Table: proxy.AccountsTable,
Columns: []string{proxy.AccountsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &Proxy{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
......
......@@ -13,6 +13,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/schema"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
......@@ -259,6 +260,10 @@ func init() {
group.DefaultSubscriptionType = groupDescSubscriptionType.Default.(string)
// group.SubscriptionTypeValidator is a validator for the "subscription_type" field. It is called by the builders before save.
group.SubscriptionTypeValidator = groupDescSubscriptionType.Validators[0].(func(string) error)
// groupDescDefaultValidityDays is the schema descriptor for default_validity_days field.
groupDescDefaultValidityDays := groupFields[10].Descriptor()
// group.DefaultDefaultValidityDays holds the default value on creation for the default_validity_days field.
group.DefaultDefaultValidityDays = groupDescDefaultValidityDays.Default.(int)
proxyMixin := schema.Proxy{}.Mixin()
proxyMixinHooks1 := proxyMixin[1].Hooks()
proxy.Hooks[0] = proxyMixinHooks1[0]
......@@ -410,16 +415,114 @@ func init() {
return nil
}
}()
// settingDescValue is the schema descriptor for value field.
settingDescValue := settingFields[1].Descriptor()
// setting.ValueValidator is a validator for the "value" field. It is called by the builders before save.
setting.ValueValidator = settingDescValue.Validators[0].(func(string) error)
// settingDescUpdatedAt is the schema descriptor for updated_at field.
settingDescUpdatedAt := settingFields[2].Descriptor()
// setting.DefaultUpdatedAt holds the default value on creation for the updated_at field.
setting.DefaultUpdatedAt = settingDescUpdatedAt.Default.(func() time.Time)
// setting.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
setting.UpdateDefaultUpdatedAt = settingDescUpdatedAt.UpdateDefault.(func() time.Time)
usagelogFields := schema.UsageLog{}.Fields()
_ = usagelogFields
// usagelogDescRequestID is the schema descriptor for request_id field.
usagelogDescRequestID := usagelogFields[3].Descriptor()
// usagelog.RequestIDValidator is a validator for the "request_id" field. It is called by the builders before save.
usagelog.RequestIDValidator = func() func(string) error {
validators := usagelogDescRequestID.Validators
fns := [...]func(string) error{
validators[0].(func(string) error),
validators[1].(func(string) error),
}
return func(request_id string) error {
for _, fn := range fns {
if err := fn(request_id); err != nil {
return err
}
}
return nil
}
}()
// usagelogDescModel is the schema descriptor for model field.
usagelogDescModel := usagelogFields[4].Descriptor()
// usagelog.ModelValidator is a validator for the "model" field. It is called by the builders before save.
usagelog.ModelValidator = func() func(string) error {
validators := usagelogDescModel.Validators
fns := [...]func(string) error{
validators[0].(func(string) error),
validators[1].(func(string) error),
}
return func(model string) error {
for _, fn := range fns {
if err := fn(model); err != nil {
return err
}
}
return nil
}
}()
// usagelogDescInputTokens is the schema descriptor for input_tokens field.
usagelogDescInputTokens := usagelogFields[7].Descriptor()
// usagelog.DefaultInputTokens holds the default value on creation for the input_tokens field.
usagelog.DefaultInputTokens = usagelogDescInputTokens.Default.(int)
// usagelogDescOutputTokens is the schema descriptor for output_tokens field.
usagelogDescOutputTokens := usagelogFields[8].Descriptor()
// usagelog.DefaultOutputTokens holds the default value on creation for the output_tokens field.
usagelog.DefaultOutputTokens = usagelogDescOutputTokens.Default.(int)
// usagelogDescCacheCreationTokens is the schema descriptor for cache_creation_tokens field.
usagelogDescCacheCreationTokens := usagelogFields[9].Descriptor()
// usagelog.DefaultCacheCreationTokens holds the default value on creation for the cache_creation_tokens field.
usagelog.DefaultCacheCreationTokens = usagelogDescCacheCreationTokens.Default.(int)
// usagelogDescCacheReadTokens is the schema descriptor for cache_read_tokens field.
usagelogDescCacheReadTokens := usagelogFields[10].Descriptor()
// usagelog.DefaultCacheReadTokens holds the default value on creation for the cache_read_tokens field.
usagelog.DefaultCacheReadTokens = usagelogDescCacheReadTokens.Default.(int)
// usagelogDescCacheCreation5mTokens is the schema descriptor for cache_creation_5m_tokens field.
usagelogDescCacheCreation5mTokens := usagelogFields[11].Descriptor()
// usagelog.DefaultCacheCreation5mTokens holds the default value on creation for the cache_creation_5m_tokens field.
usagelog.DefaultCacheCreation5mTokens = usagelogDescCacheCreation5mTokens.Default.(int)
// usagelogDescCacheCreation1hTokens is the schema descriptor for cache_creation_1h_tokens field.
usagelogDescCacheCreation1hTokens := usagelogFields[12].Descriptor()
// usagelog.DefaultCacheCreation1hTokens holds the default value on creation for the cache_creation_1h_tokens field.
usagelog.DefaultCacheCreation1hTokens = usagelogDescCacheCreation1hTokens.Default.(int)
// usagelogDescInputCost is the schema descriptor for input_cost field.
usagelogDescInputCost := usagelogFields[13].Descriptor()
// usagelog.DefaultInputCost holds the default value on creation for the input_cost field.
usagelog.DefaultInputCost = usagelogDescInputCost.Default.(float64)
// usagelogDescOutputCost is the schema descriptor for output_cost field.
usagelogDescOutputCost := usagelogFields[14].Descriptor()
// usagelog.DefaultOutputCost holds the default value on creation for the output_cost field.
usagelog.DefaultOutputCost = usagelogDescOutputCost.Default.(float64)
// usagelogDescCacheCreationCost is the schema descriptor for cache_creation_cost field.
usagelogDescCacheCreationCost := usagelogFields[15].Descriptor()
// usagelog.DefaultCacheCreationCost holds the default value on creation for the cache_creation_cost field.
usagelog.DefaultCacheCreationCost = usagelogDescCacheCreationCost.Default.(float64)
// usagelogDescCacheReadCost is the schema descriptor for cache_read_cost field.
usagelogDescCacheReadCost := usagelogFields[16].Descriptor()
// usagelog.DefaultCacheReadCost holds the default value on creation for the cache_read_cost field.
usagelog.DefaultCacheReadCost = usagelogDescCacheReadCost.Default.(float64)
// usagelogDescTotalCost is the schema descriptor for total_cost field.
usagelogDescTotalCost := usagelogFields[17].Descriptor()
// usagelog.DefaultTotalCost holds the default value on creation for the total_cost field.
usagelog.DefaultTotalCost = usagelogDescTotalCost.Default.(float64)
// usagelogDescActualCost is the schema descriptor for actual_cost field.
usagelogDescActualCost := usagelogFields[18].Descriptor()
// usagelog.DefaultActualCost holds the default value on creation for the actual_cost field.
usagelog.DefaultActualCost = usagelogDescActualCost.Default.(float64)
// usagelogDescRateMultiplier is the schema descriptor for rate_multiplier field.
usagelogDescRateMultiplier := usagelogFields[19].Descriptor()
// usagelog.DefaultRateMultiplier holds the default value on creation for the rate_multiplier field.
usagelog.DefaultRateMultiplier = usagelogDescRateMultiplier.Default.(float64)
// usagelogDescBillingType is the schema descriptor for billing_type field.
usagelogDescBillingType := usagelogFields[20].Descriptor()
// usagelog.DefaultBillingType holds the default value on creation for the billing_type field.
usagelog.DefaultBillingType = usagelogDescBillingType.Default.(int8)
// usagelogDescStream is the schema descriptor for stream field.
usagelogDescStream := usagelogFields[21].Descriptor()
// usagelog.DefaultStream holds the default value on creation for the stream field.
usagelog.DefaultStream = usagelogDescStream.Default.(bool)
// usagelogDescCreatedAt is the schema descriptor for created_at field.
usagelogDescCreatedAt := usagelogFields[24].Descriptor()
// usagelog.DefaultCreatedAt holds the default value on creation for the created_at field.
usagelog.DefaultCreatedAt = usagelogDescCreatedAt.Default.(func() time.Time)
userMixin := schema.User{}.Mixin()
userMixinHooks1 := userMixin[1].Hooks()
user.Hooks[0] = userMixinHooks1[0]
......@@ -518,6 +621,10 @@ func init() {
// userallowedgroup.DefaultCreatedAt holds the default value on creation for the created_at field.
userallowedgroup.DefaultCreatedAt = userallowedgroupDescCreatedAt.Default.(func() time.Time)
usersubscriptionMixin := schema.UserSubscription{}.Mixin()
usersubscriptionMixinHooks1 := usersubscriptionMixin[1].Hooks()
usersubscription.Hooks[0] = usersubscriptionMixinHooks1[0]
usersubscriptionMixinInters1 := usersubscriptionMixin[1].Interceptors()
usersubscription.Interceptors[0] = usersubscriptionMixinInters1[0]
usersubscriptionMixinFields0 := usersubscriptionMixin[0].Fields()
_ = usersubscriptionMixinFields0
usersubscriptionFields := schema.UserSubscription{}.Fields()
......
......@@ -168,6 +168,13 @@ func (Account) Edges() []ent.Edge {
// 一个账户可以属于多个分组,一个分组可以包含多个账户
edge.To("groups", Group.Type).
Through("account_groups", AccountGroup.Type),
// proxy: 账户使用的代理配置(可选的一对一关系)
// 使用已有的 proxy_id 外键字段
edge.To("proxy", Proxy.Type).
Field("proxy_id").
Unique(),
// usage_logs: 该账户的使用日志
edge.To("usage_logs", UsageLog.Type),
}
}
......
......@@ -4,6 +4,7 @@ import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
......@@ -33,7 +34,8 @@ func (AccountGroup) Fields() []ent.Field {
Default(50),
field.Time("created_at").
Immutable().
Default(time.Now),
Default(time.Now).
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
}
}
......
......@@ -60,12 +60,13 @@ func (ApiKey) Edges() []ent.Edge {
Ref("api_keys").
Field("group_id").
Unique(),
edge.To("usage_logs", UsageLog.Type),
}
}
func (ApiKey) Indexes() []ent.Index {
return []ent.Index{
index.Fields("key").Unique(),
// key 字段已在 Fields() 中声明 Unique(),无需重复索引
index.Fields("user_id"),
index.Fields("group_id"),
index.Fields("status"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment