Commit 5906f9ab authored by yangjianbo's avatar yangjianbo
Browse files

fix(数据层): 修复数据完整性与仓储一致性问题

## 数据完整性修复 (fix-critical-data-integrity)
- 添加 error_translate.go 统一错误转换层
- 修复 nil 输入和 NotFound 错误处理
- 增强仓储层错误一致性

## 仓储一致性修复 (fix-high-repository-consistency)
- Group schema 添加 default_validity_days 字段
- Account schema 添加 proxy edge 关联
- 新增 UsageLog ent schema 定义
- 修复 UpdateBalance/UpdateConcurrency 受影响行数校验

## 数据卫生修复 (fix-medium-data-hygiene)
- UserSubscription 添加软删除支持 (SoftDeleteMixin)
- RedeemCode/Setting 添加硬删除策略文档
- account_groups/user_allowed_groups 的 created_at 声明 timestamptz
- 停止写入 legacy users.allowed_groups 列
- 新增迁移: 011-014 (索引优化、软删除、孤立数据审计、列清理)

## 测试补充
- 添加 UserSubscription 软删除测试
- 添加迁移回归测试
- 添加 NotFound 错误测试

🤖 Generated with [Claude Code](https://claude.com/claude-code

)
Co-Authored-By: default avatarClaude Opus 4.5 <noreply@anthropic.com>
parent 820bb16c
......@@ -8,10 +8,17 @@ import (
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Setting holds the schema definition for the Setting entity.
//
// 删除策略:硬删除
// Setting 使用硬删除而非软删除,原因如下:
// - 系统设置是简单的键值对,删除即意味着恢复默认值
// - 设置变更通常通过应用日志追踪,无需在数据库层面保留历史
// - 保持表结构简洁,避免无效数据积累
//
// 如需设置变更审计,建议在更新/删除前将变更记录写入审计日志表。
type Setting struct {
ent.Schema
}
......@@ -43,7 +50,6 @@ func (Setting) Fields() []ent.Field {
}
func (Setting) Indexes() []ent.Index {
return []ent.Index{
index.Fields("key").Unique(),
}
// key 字段已在 Fields() 中声明 Unique(),无需额外索引
return nil
}
// Package schema 定义 Ent ORM 的数据库 schema。
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// UsageLog 定义使用日志实体的 schema。
//
// 使用日志记录每次 API 调用的详细信息,包括 token 使用量、成本计算等。
// 这是一个只追加的表,不支持更新和删除。
type UsageLog struct {
ent.Schema
}
// Annotations 返回 schema 的注解配置。
func (UsageLog) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "usage_logs"},
}
}
// Fields 定义使用日志实体的所有字段。
func (UsageLog) Fields() []ent.Field {
return []ent.Field{
// 关联字段
field.Int64("user_id"),
field.Int64("api_key_id"),
field.Int64("account_id"),
field.String("request_id").
MaxLen(64).
NotEmpty(),
field.String("model").
MaxLen(100).
NotEmpty(),
field.Int64("group_id").
Optional().
Nillable(),
field.Int64("subscription_id").
Optional().
Nillable(),
// Token 计数字段
field.Int("input_tokens").
Default(0),
field.Int("output_tokens").
Default(0),
field.Int("cache_creation_tokens").
Default(0),
field.Int("cache_read_tokens").
Default(0),
field.Int("cache_creation_5m_tokens").
Default(0),
field.Int("cache_creation_1h_tokens").
Default(0),
// 成本字段
field.Float("input_cost").
Default(0).
SchemaType(map[string]string{dialect.Postgres: "decimal(20,10)"}),
field.Float("output_cost").
Default(0).
SchemaType(map[string]string{dialect.Postgres: "decimal(20,10)"}),
field.Float("cache_creation_cost").
Default(0).
SchemaType(map[string]string{dialect.Postgres: "decimal(20,10)"}),
field.Float("cache_read_cost").
Default(0).
SchemaType(map[string]string{dialect.Postgres: "decimal(20,10)"}),
field.Float("total_cost").
Default(0).
SchemaType(map[string]string{dialect.Postgres: "decimal(20,10)"}),
field.Float("actual_cost").
Default(0).
SchemaType(map[string]string{dialect.Postgres: "decimal(20,10)"}),
field.Float("rate_multiplier").
Default(1).
SchemaType(map[string]string{dialect.Postgres: "decimal(10,4)"}),
// 其他字段
field.Int8("billing_type").
Default(0),
field.Bool("stream").
Default(false),
field.Int("duration_ms").
Optional().
Nillable(),
field.Int("first_token_ms").
Optional().
Nillable(),
// 时间戳(只有 created_at,日志不可修改)
field.Time("created_at").
Default(time.Now).
Immutable().
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
}
}
// Edges 定义使用日志实体的关联关系。
func (UsageLog) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("usage_logs").
Field("user_id").
Required().
Unique(),
edge.From("api_key", ApiKey.Type).
Ref("usage_logs").
Field("api_key_id").
Required().
Unique(),
edge.From("account", Account.Type).
Ref("usage_logs").
Field("account_id").
Required().
Unique(),
edge.From("group", Group.Type).
Ref("usage_logs").
Field("group_id").
Unique(),
edge.From("subscription", UserSubscription.Type).
Ref("usage_logs").
Field("subscription_id").
Unique(),
}
}
// Indexes 定义数据库索引,优化查询性能。
func (UsageLog) Indexes() []ent.Index {
return []ent.Index{
index.Fields("user_id"),
index.Fields("api_key_id"),
index.Fields("account_id"),
index.Fields("group_id"),
index.Fields("subscription_id"),
index.Fields("created_at"),
index.Fields("model"),
index.Fields("request_id"),
// 复合索引用于时间范围查询
index.Fields("user_id", "created_at"),
index.Fields("api_key_id", "created_at"),
}
}
......@@ -73,12 +73,13 @@ func (User) Edges() []ent.Edge {
edge.To("assigned_subscriptions", UserSubscription.Type),
edge.To("allowed_groups", Group.Type).
Through("user_allowed_groups", UserAllowedGroup.Type),
edge.To("usage_logs", UsageLog.Type),
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
index.Fields("email").Unique(),
// email 字段已在 Fields() 中声明 Unique(),无需重复索引
index.Fields("status"),
index.Fields("deleted_at"),
}
......
......@@ -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"
......@@ -31,7 +32,8 @@ func (UserAllowedGroup) Fields() []ent.Field {
field.Int64("group_id"),
field.Time("created_at").
Immutable().
Default(time.Now),
Default(time.Now).
SchemaType(map[string]string{dialect.Postgres: "timestamptz"}),
}
}
......
......@@ -29,6 +29,7 @@ func (UserSubscription) Annotations() []schema.Annotation {
func (UserSubscription) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.TimeMixin{},
mixins.SoftDeleteMixin{},
}
}
......@@ -97,6 +98,7 @@ func (UserSubscription) Edges() []ent.Edge {
Ref("assigned_subscriptions").
Field("assigned_by").
Unique(),
edge.To("usage_logs", UsageLog.Type),
}
}
......@@ -108,5 +110,6 @@ func (UserSubscription) Indexes() []ent.Index {
index.Fields("expires_at"),
index.Fields("assigned_by"),
index.Fields("user_id", "group_id").Unique(),
index.Fields("deleted_at"),
}
}
......@@ -28,6 +28,8 @@ type Tx struct {
RedeemCode *RedeemCodeClient
// Setting is the client for interacting with the Setting builders.
Setting *SettingClient
// UsageLog is the client for interacting with the UsageLog builders.
UsageLog *UsageLogClient
// User is the client for interacting with the User builders.
User *UserClient
// UserAllowedGroup is the client for interacting with the UserAllowedGroup builders.
......@@ -172,6 +174,7 @@ func (tx *Tx) init() {
tx.Proxy = NewProxyClient(tx.config)
tx.RedeemCode = NewRedeemCodeClient(tx.config)
tx.Setting = NewSettingClient(tx.config)
tx.UsageLog = NewUsageLogClient(tx.config)
tx.User = NewUserClient(tx.config)
tx.UserAllowedGroup = NewUserAllowedGroupClient(tx.config)
tx.UserSubscription = NewUserSubscriptionClient(tx.config)
......@@ -238,7 +241,6 @@ func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error
var _ dialect.Driver = (*txDriver)(nil)
// ExecContext 透传到底层事务,用于在 ent 事务中执行原生 SQL(与 ent 写入保持同一事务)。
// ExecContext allows calling the underlying ExecContext method of the transaction if it is supported by it.
// See, database/sql#Tx.ExecContext for more information.
func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) {
......@@ -251,7 +253,6 @@ func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any)
return ex.ExecContext(ctx, query, args...)
}
// QueryContext 透传到底层事务,用于在 ent 事务中执行原生查询并共享锁语义。
// QueryContext allows calling the underlying QueryContext method of the transaction if it is supported by it.
// See, database/sql#Tx.QueryContext for more information.
func (tx *txDriver) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) {
......
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
// UsageLog is the model entity for the UsageLog schema.
type UsageLog struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// UserID holds the value of the "user_id" field.
UserID int64 `json:"user_id,omitempty"`
// APIKeyID holds the value of the "api_key_id" field.
APIKeyID int64 `json:"api_key_id,omitempty"`
// AccountID holds the value of the "account_id" field.
AccountID int64 `json:"account_id,omitempty"`
// RequestID holds the value of the "request_id" field.
RequestID string `json:"request_id,omitempty"`
// Model holds the value of the "model" field.
Model string `json:"model,omitempty"`
// GroupID holds the value of the "group_id" field.
GroupID *int64 `json:"group_id,omitempty"`
// SubscriptionID holds the value of the "subscription_id" field.
SubscriptionID *int64 `json:"subscription_id,omitempty"`
// InputTokens holds the value of the "input_tokens" field.
InputTokens int `json:"input_tokens,omitempty"`
// OutputTokens holds the value of the "output_tokens" field.
OutputTokens int `json:"output_tokens,omitempty"`
// CacheCreationTokens holds the value of the "cache_creation_tokens" field.
CacheCreationTokens int `json:"cache_creation_tokens,omitempty"`
// CacheReadTokens holds the value of the "cache_read_tokens" field.
CacheReadTokens int `json:"cache_read_tokens,omitempty"`
// CacheCreation5mTokens holds the value of the "cache_creation_5m_tokens" field.
CacheCreation5mTokens int `json:"cache_creation_5m_tokens,omitempty"`
// CacheCreation1hTokens holds the value of the "cache_creation_1h_tokens" field.
CacheCreation1hTokens int `json:"cache_creation_1h_tokens,omitempty"`
// InputCost holds the value of the "input_cost" field.
InputCost float64 `json:"input_cost,omitempty"`
// OutputCost holds the value of the "output_cost" field.
OutputCost float64 `json:"output_cost,omitempty"`
// CacheCreationCost holds the value of the "cache_creation_cost" field.
CacheCreationCost float64 `json:"cache_creation_cost,omitempty"`
// CacheReadCost holds the value of the "cache_read_cost" field.
CacheReadCost float64 `json:"cache_read_cost,omitempty"`
// TotalCost holds the value of the "total_cost" field.
TotalCost float64 `json:"total_cost,omitempty"`
// ActualCost holds the value of the "actual_cost" field.
ActualCost float64 `json:"actual_cost,omitempty"`
// RateMultiplier holds the value of the "rate_multiplier" field.
RateMultiplier float64 `json:"rate_multiplier,omitempty"`
// BillingType holds the value of the "billing_type" field.
BillingType int8 `json:"billing_type,omitempty"`
// Stream holds the value of the "stream" field.
Stream bool `json:"stream,omitempty"`
// DurationMs holds the value of the "duration_ms" field.
DurationMs *int `json:"duration_ms,omitempty"`
// FirstTokenMs holds the value of the "first_token_ms" field.
FirstTokenMs *int `json:"first_token_ms,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UsageLogQuery when eager-loading is set.
Edges UsageLogEdges `json:"edges"`
selectValues sql.SelectValues
}
// UsageLogEdges holds the relations/edges for other nodes in the graph.
type UsageLogEdges struct {
// User holds the value of the user edge.
User *User `json:"user,omitempty"`
// APIKey holds the value of the api_key edge.
APIKey *ApiKey `json:"api_key,omitempty"`
// Account holds the value of the account edge.
Account *Account `json:"account,omitempty"`
// Group holds the value of the group edge.
Group *Group `json:"group,omitempty"`
// Subscription holds the value of the subscription edge.
Subscription *UserSubscription `json:"subscription,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [5]bool
}
// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UsageLogEdges) UserOrErr() (*User, error) {
if e.User != nil {
return e.User, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: user.Label}
}
return nil, &NotLoadedError{edge: "user"}
}
// APIKeyOrErr returns the APIKey value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UsageLogEdges) APIKeyOrErr() (*ApiKey, error) {
if e.APIKey != nil {
return e.APIKey, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: apikey.Label}
}
return nil, &NotLoadedError{edge: "api_key"}
}
// AccountOrErr returns the Account value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UsageLogEdges) AccountOrErr() (*Account, error) {
if e.Account != nil {
return e.Account, nil
} else if e.loadedTypes[2] {
return nil, &NotFoundError{label: account.Label}
}
return nil, &NotLoadedError{edge: "account"}
}
// GroupOrErr returns the Group value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UsageLogEdges) GroupOrErr() (*Group, error) {
if e.Group != nil {
return e.Group, nil
} else if e.loadedTypes[3] {
return nil, &NotFoundError{label: group.Label}
}
return nil, &NotLoadedError{edge: "group"}
}
// SubscriptionOrErr returns the Subscription value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UsageLogEdges) SubscriptionOrErr() (*UserSubscription, error) {
if e.Subscription != nil {
return e.Subscription, nil
} else if e.loadedTypes[4] {
return nil, &NotFoundError{label: usersubscription.Label}
}
return nil, &NotLoadedError{edge: "subscription"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*UsageLog) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case usagelog.FieldStream:
values[i] = new(sql.NullBool)
case usagelog.FieldInputCost, usagelog.FieldOutputCost, usagelog.FieldCacheCreationCost, usagelog.FieldCacheReadCost, usagelog.FieldTotalCost, usagelog.FieldActualCost, usagelog.FieldRateMultiplier:
values[i] = new(sql.NullFloat64)
case usagelog.FieldID, usagelog.FieldUserID, usagelog.FieldAPIKeyID, usagelog.FieldAccountID, usagelog.FieldGroupID, usagelog.FieldSubscriptionID, usagelog.FieldInputTokens, usagelog.FieldOutputTokens, usagelog.FieldCacheCreationTokens, usagelog.FieldCacheReadTokens, usagelog.FieldCacheCreation5mTokens, usagelog.FieldCacheCreation1hTokens, usagelog.FieldBillingType, usagelog.FieldDurationMs, usagelog.FieldFirstTokenMs:
values[i] = new(sql.NullInt64)
case usagelog.FieldRequestID, usagelog.FieldModel:
values[i] = new(sql.NullString)
case usagelog.FieldCreatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the UsageLog fields.
func (_m *UsageLog) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case usagelog.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case usagelog.FieldUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
} else if value.Valid {
_m.UserID = value.Int64
}
case usagelog.FieldAPIKeyID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field api_key_id", values[i])
} else if value.Valid {
_m.APIKeyID = value.Int64
}
case usagelog.FieldAccountID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field account_id", values[i])
} else if value.Valid {
_m.AccountID = value.Int64
}
case usagelog.FieldRequestID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field request_id", values[i])
} else if value.Valid {
_m.RequestID = value.String
}
case usagelog.FieldModel:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field model", values[i])
} else if value.Valid {
_m.Model = value.String
}
case usagelog.FieldGroupID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field group_id", values[i])
} else if value.Valid {
_m.GroupID = new(int64)
*_m.GroupID = value.Int64
}
case usagelog.FieldSubscriptionID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field subscription_id", values[i])
} else if value.Valid {
_m.SubscriptionID = new(int64)
*_m.SubscriptionID = value.Int64
}
case usagelog.FieldInputTokens:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field input_tokens", values[i])
} else if value.Valid {
_m.InputTokens = int(value.Int64)
}
case usagelog.FieldOutputTokens:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field output_tokens", values[i])
} else if value.Valid {
_m.OutputTokens = int(value.Int64)
}
case usagelog.FieldCacheCreationTokens:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field cache_creation_tokens", values[i])
} else if value.Valid {
_m.CacheCreationTokens = int(value.Int64)
}
case usagelog.FieldCacheReadTokens:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field cache_read_tokens", values[i])
} else if value.Valid {
_m.CacheReadTokens = int(value.Int64)
}
case usagelog.FieldCacheCreation5mTokens:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field cache_creation_5m_tokens", values[i])
} else if value.Valid {
_m.CacheCreation5mTokens = int(value.Int64)
}
case usagelog.FieldCacheCreation1hTokens:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field cache_creation_1h_tokens", values[i])
} else if value.Valid {
_m.CacheCreation1hTokens = int(value.Int64)
}
case usagelog.FieldInputCost:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field input_cost", values[i])
} else if value.Valid {
_m.InputCost = value.Float64
}
case usagelog.FieldOutputCost:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field output_cost", values[i])
} else if value.Valid {
_m.OutputCost = value.Float64
}
case usagelog.FieldCacheCreationCost:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field cache_creation_cost", values[i])
} else if value.Valid {
_m.CacheCreationCost = value.Float64
}
case usagelog.FieldCacheReadCost:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field cache_read_cost", values[i])
} else if value.Valid {
_m.CacheReadCost = value.Float64
}
case usagelog.FieldTotalCost:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field total_cost", values[i])
} else if value.Valid {
_m.TotalCost = value.Float64
}
case usagelog.FieldActualCost:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field actual_cost", values[i])
} else if value.Valid {
_m.ActualCost = value.Float64
}
case usagelog.FieldRateMultiplier:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field rate_multiplier", values[i])
} else if value.Valid {
_m.RateMultiplier = value.Float64
}
case usagelog.FieldBillingType:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field billing_type", values[i])
} else if value.Valid {
_m.BillingType = int8(value.Int64)
}
case usagelog.FieldStream:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field stream", values[i])
} else if value.Valid {
_m.Stream = value.Bool
}
case usagelog.FieldDurationMs:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field duration_ms", values[i])
} else if value.Valid {
_m.DurationMs = new(int)
*_m.DurationMs = int(value.Int64)
}
case usagelog.FieldFirstTokenMs:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field first_token_ms", values[i])
} else if value.Valid {
_m.FirstTokenMs = new(int)
*_m.FirstTokenMs = int(value.Int64)
}
case usagelog.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the UsageLog.
// This includes values selected through modifiers, order, etc.
func (_m *UsageLog) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryUser queries the "user" edge of the UsageLog entity.
func (_m *UsageLog) QueryUser() *UserQuery {
return NewUsageLogClient(_m.config).QueryUser(_m)
}
// QueryAPIKey queries the "api_key" edge of the UsageLog entity.
func (_m *UsageLog) QueryAPIKey() *ApiKeyQuery {
return NewUsageLogClient(_m.config).QueryAPIKey(_m)
}
// QueryAccount queries the "account" edge of the UsageLog entity.
func (_m *UsageLog) QueryAccount() *AccountQuery {
return NewUsageLogClient(_m.config).QueryAccount(_m)
}
// QueryGroup queries the "group" edge of the UsageLog entity.
func (_m *UsageLog) QueryGroup() *GroupQuery {
return NewUsageLogClient(_m.config).QueryGroup(_m)
}
// QuerySubscription queries the "subscription" edge of the UsageLog entity.
func (_m *UsageLog) QuerySubscription() *UserSubscriptionQuery {
return NewUsageLogClient(_m.config).QuerySubscription(_m)
}
// Update returns a builder for updating this UsageLog.
// Note that you need to call UsageLog.Unwrap() before calling this method if this UsageLog
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *UsageLog) Update() *UsageLogUpdateOne {
return NewUsageLogClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the UsageLog entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *UsageLog) Unwrap() *UsageLog {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: UsageLog is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *UsageLog) String() string {
var builder strings.Builder
builder.WriteString("UsageLog(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
builder.WriteString(", ")
builder.WriteString("api_key_id=")
builder.WriteString(fmt.Sprintf("%v", _m.APIKeyID))
builder.WriteString(", ")
builder.WriteString("account_id=")
builder.WriteString(fmt.Sprintf("%v", _m.AccountID))
builder.WriteString(", ")
builder.WriteString("request_id=")
builder.WriteString(_m.RequestID)
builder.WriteString(", ")
builder.WriteString("model=")
builder.WriteString(_m.Model)
builder.WriteString(", ")
if v := _m.GroupID; v != nil {
builder.WriteString("group_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := _m.SubscriptionID; v != nil {
builder.WriteString("subscription_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("input_tokens=")
builder.WriteString(fmt.Sprintf("%v", _m.InputTokens))
builder.WriteString(", ")
builder.WriteString("output_tokens=")
builder.WriteString(fmt.Sprintf("%v", _m.OutputTokens))
builder.WriteString(", ")
builder.WriteString("cache_creation_tokens=")
builder.WriteString(fmt.Sprintf("%v", _m.CacheCreationTokens))
builder.WriteString(", ")
builder.WriteString("cache_read_tokens=")
builder.WriteString(fmt.Sprintf("%v", _m.CacheReadTokens))
builder.WriteString(", ")
builder.WriteString("cache_creation_5m_tokens=")
builder.WriteString(fmt.Sprintf("%v", _m.CacheCreation5mTokens))
builder.WriteString(", ")
builder.WriteString("cache_creation_1h_tokens=")
builder.WriteString(fmt.Sprintf("%v", _m.CacheCreation1hTokens))
builder.WriteString(", ")
builder.WriteString("input_cost=")
builder.WriteString(fmt.Sprintf("%v", _m.InputCost))
builder.WriteString(", ")
builder.WriteString("output_cost=")
builder.WriteString(fmt.Sprintf("%v", _m.OutputCost))
builder.WriteString(", ")
builder.WriteString("cache_creation_cost=")
builder.WriteString(fmt.Sprintf("%v", _m.CacheCreationCost))
builder.WriteString(", ")
builder.WriteString("cache_read_cost=")
builder.WriteString(fmt.Sprintf("%v", _m.CacheReadCost))
builder.WriteString(", ")
builder.WriteString("total_cost=")
builder.WriteString(fmt.Sprintf("%v", _m.TotalCost))
builder.WriteString(", ")
builder.WriteString("actual_cost=")
builder.WriteString(fmt.Sprintf("%v", _m.ActualCost))
builder.WriteString(", ")
builder.WriteString("rate_multiplier=")
builder.WriteString(fmt.Sprintf("%v", _m.RateMultiplier))
builder.WriteString(", ")
builder.WriteString("billing_type=")
builder.WriteString(fmt.Sprintf("%v", _m.BillingType))
builder.WriteString(", ")
builder.WriteString("stream=")
builder.WriteString(fmt.Sprintf("%v", _m.Stream))
builder.WriteString(", ")
if v := _m.DurationMs; v != nil {
builder.WriteString("duration_ms=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := _m.FirstTokenMs; v != nil {
builder.WriteString("first_token_ms=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// UsageLogs is a parsable slice of UsageLog.
type UsageLogs []*UsageLog
// Code generated by ent, DO NOT EDIT.
package usagelog
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the usagelog type in the database.
Label = "usage_log"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
// FieldAPIKeyID holds the string denoting the api_key_id field in the database.
FieldAPIKeyID = "api_key_id"
// FieldAccountID holds the string denoting the account_id field in the database.
FieldAccountID = "account_id"
// FieldRequestID holds the string denoting the request_id field in the database.
FieldRequestID = "request_id"
// FieldModel holds the string denoting the model field in the database.
FieldModel = "model"
// FieldGroupID holds the string denoting the group_id field in the database.
FieldGroupID = "group_id"
// FieldSubscriptionID holds the string denoting the subscription_id field in the database.
FieldSubscriptionID = "subscription_id"
// FieldInputTokens holds the string denoting the input_tokens field in the database.
FieldInputTokens = "input_tokens"
// FieldOutputTokens holds the string denoting the output_tokens field in the database.
FieldOutputTokens = "output_tokens"
// FieldCacheCreationTokens holds the string denoting the cache_creation_tokens field in the database.
FieldCacheCreationTokens = "cache_creation_tokens"
// FieldCacheReadTokens holds the string denoting the cache_read_tokens field in the database.
FieldCacheReadTokens = "cache_read_tokens"
// FieldCacheCreation5mTokens holds the string denoting the cache_creation_5m_tokens field in the database.
FieldCacheCreation5mTokens = "cache_creation_5m_tokens"
// FieldCacheCreation1hTokens holds the string denoting the cache_creation_1h_tokens field in the database.
FieldCacheCreation1hTokens = "cache_creation_1h_tokens"
// FieldInputCost holds the string denoting the input_cost field in the database.
FieldInputCost = "input_cost"
// FieldOutputCost holds the string denoting the output_cost field in the database.
FieldOutputCost = "output_cost"
// FieldCacheCreationCost holds the string denoting the cache_creation_cost field in the database.
FieldCacheCreationCost = "cache_creation_cost"
// FieldCacheReadCost holds the string denoting the cache_read_cost field in the database.
FieldCacheReadCost = "cache_read_cost"
// FieldTotalCost holds the string denoting the total_cost field in the database.
FieldTotalCost = "total_cost"
// FieldActualCost holds the string denoting the actual_cost field in the database.
FieldActualCost = "actual_cost"
// FieldRateMultiplier holds the string denoting the rate_multiplier field in the database.
FieldRateMultiplier = "rate_multiplier"
// FieldBillingType holds the string denoting the billing_type field in the database.
FieldBillingType = "billing_type"
// FieldStream holds the string denoting the stream field in the database.
FieldStream = "stream"
// FieldDurationMs holds the string denoting the duration_ms field in the database.
FieldDurationMs = "duration_ms"
// FieldFirstTokenMs holds the string denoting the first_token_ms field in the database.
FieldFirstTokenMs = "first_token_ms"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// EdgeUser holds the string denoting the user edge name in mutations.
EdgeUser = "user"
// EdgeAPIKey holds the string denoting the api_key edge name in mutations.
EdgeAPIKey = "api_key"
// EdgeAccount holds the string denoting the account edge name in mutations.
EdgeAccount = "account"
// EdgeGroup holds the string denoting the group edge name in mutations.
EdgeGroup = "group"
// EdgeSubscription holds the string denoting the subscription edge name in mutations.
EdgeSubscription = "subscription"
// Table holds the table name of the usagelog in the database.
Table = "usage_logs"
// UserTable is the table that holds the user relation/edge.
UserTable = "usage_logs"
// UserInverseTable is the table name for the User entity.
// It exists in this package in order to avoid circular dependency with the "user" package.
UserInverseTable = "users"
// UserColumn is the table column denoting the user relation/edge.
UserColumn = "user_id"
// APIKeyTable is the table that holds the api_key relation/edge.
APIKeyTable = "usage_logs"
// APIKeyInverseTable is the table name for the ApiKey entity.
// It exists in this package in order to avoid circular dependency with the "apikey" package.
APIKeyInverseTable = "api_keys"
// APIKeyColumn is the table column denoting the api_key relation/edge.
APIKeyColumn = "api_key_id"
// AccountTable is the table that holds the account relation/edge.
AccountTable = "usage_logs"
// AccountInverseTable is the table name for the Account entity.
// It exists in this package in order to avoid circular dependency with the "account" package.
AccountInverseTable = "accounts"
// AccountColumn is the table column denoting the account relation/edge.
AccountColumn = "account_id"
// GroupTable is the table that holds the group relation/edge.
GroupTable = "usage_logs"
// GroupInverseTable is the table name for the Group entity.
// It exists in this package in order to avoid circular dependency with the "group" package.
GroupInverseTable = "groups"
// GroupColumn is the table column denoting the group relation/edge.
GroupColumn = "group_id"
// SubscriptionTable is the table that holds the subscription relation/edge.
SubscriptionTable = "usage_logs"
// SubscriptionInverseTable is the table name for the UserSubscription entity.
// It exists in this package in order to avoid circular dependency with the "usersubscription" package.
SubscriptionInverseTable = "user_subscriptions"
// SubscriptionColumn is the table column denoting the subscription relation/edge.
SubscriptionColumn = "subscription_id"
)
// Columns holds all SQL columns for usagelog fields.
var Columns = []string{
FieldID,
FieldUserID,
FieldAPIKeyID,
FieldAccountID,
FieldRequestID,
FieldModel,
FieldGroupID,
FieldSubscriptionID,
FieldInputTokens,
FieldOutputTokens,
FieldCacheCreationTokens,
FieldCacheReadTokens,
FieldCacheCreation5mTokens,
FieldCacheCreation1hTokens,
FieldInputCost,
FieldOutputCost,
FieldCacheCreationCost,
FieldCacheReadCost,
FieldTotalCost,
FieldActualCost,
FieldRateMultiplier,
FieldBillingType,
FieldStream,
FieldDurationMs,
FieldFirstTokenMs,
FieldCreatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// RequestIDValidator is a validator for the "request_id" field. It is called by the builders before save.
RequestIDValidator func(string) error
// ModelValidator is a validator for the "model" field. It is called by the builders before save.
ModelValidator func(string) error
// DefaultInputTokens holds the default value on creation for the "input_tokens" field.
DefaultInputTokens int
// DefaultOutputTokens holds the default value on creation for the "output_tokens" field.
DefaultOutputTokens int
// DefaultCacheCreationTokens holds the default value on creation for the "cache_creation_tokens" field.
DefaultCacheCreationTokens int
// DefaultCacheReadTokens holds the default value on creation for the "cache_read_tokens" field.
DefaultCacheReadTokens int
// DefaultCacheCreation5mTokens holds the default value on creation for the "cache_creation_5m_tokens" field.
DefaultCacheCreation5mTokens int
// DefaultCacheCreation1hTokens holds the default value on creation for the "cache_creation_1h_tokens" field.
DefaultCacheCreation1hTokens int
// DefaultInputCost holds the default value on creation for the "input_cost" field.
DefaultInputCost float64
// DefaultOutputCost holds the default value on creation for the "output_cost" field.
DefaultOutputCost float64
// DefaultCacheCreationCost holds the default value on creation for the "cache_creation_cost" field.
DefaultCacheCreationCost float64
// DefaultCacheReadCost holds the default value on creation for the "cache_read_cost" field.
DefaultCacheReadCost float64
// DefaultTotalCost holds the default value on creation for the "total_cost" field.
DefaultTotalCost float64
// DefaultActualCost holds the default value on creation for the "actual_cost" field.
DefaultActualCost float64
// DefaultRateMultiplier holds the default value on creation for the "rate_multiplier" field.
DefaultRateMultiplier float64
// DefaultBillingType holds the default value on creation for the "billing_type" field.
DefaultBillingType int8
// DefaultStream holds the default value on creation for the "stream" field.
DefaultStream bool
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the UsageLog queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByAPIKeyID orders the results by the api_key_id field.
func ByAPIKeyID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAPIKeyID, opts...).ToFunc()
}
// ByAccountID orders the results by the account_id field.
func ByAccountID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAccountID, opts...).ToFunc()
}
// ByRequestID orders the results by the request_id field.
func ByRequestID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRequestID, opts...).ToFunc()
}
// ByModel orders the results by the model field.
func ByModel(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldModel, opts...).ToFunc()
}
// ByGroupID orders the results by the group_id field.
func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldGroupID, opts...).ToFunc()
}
// BySubscriptionID orders the results by the subscription_id field.
func BySubscriptionID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldSubscriptionID, opts...).ToFunc()
}
// ByInputTokens orders the results by the input_tokens field.
func ByInputTokens(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldInputTokens, opts...).ToFunc()
}
// ByOutputTokens orders the results by the output_tokens field.
func ByOutputTokens(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOutputTokens, opts...).ToFunc()
}
// ByCacheCreationTokens orders the results by the cache_creation_tokens field.
func ByCacheCreationTokens(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCacheCreationTokens, opts...).ToFunc()
}
// ByCacheReadTokens orders the results by the cache_read_tokens field.
func ByCacheReadTokens(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCacheReadTokens, opts...).ToFunc()
}
// ByCacheCreation5mTokens orders the results by the cache_creation_5m_tokens field.
func ByCacheCreation5mTokens(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCacheCreation5mTokens, opts...).ToFunc()
}
// ByCacheCreation1hTokens orders the results by the cache_creation_1h_tokens field.
func ByCacheCreation1hTokens(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCacheCreation1hTokens, opts...).ToFunc()
}
// ByInputCost orders the results by the input_cost field.
func ByInputCost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldInputCost, opts...).ToFunc()
}
// ByOutputCost orders the results by the output_cost field.
func ByOutputCost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOutputCost, opts...).ToFunc()
}
// ByCacheCreationCost orders the results by the cache_creation_cost field.
func ByCacheCreationCost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCacheCreationCost, opts...).ToFunc()
}
// ByCacheReadCost orders the results by the cache_read_cost field.
func ByCacheReadCost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCacheReadCost, opts...).ToFunc()
}
// ByTotalCost orders the results by the total_cost field.
func ByTotalCost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTotalCost, opts...).ToFunc()
}
// ByActualCost orders the results by the actual_cost field.
func ByActualCost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldActualCost, opts...).ToFunc()
}
// ByRateMultiplier orders the results by the rate_multiplier field.
func ByRateMultiplier(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRateMultiplier, opts...).ToFunc()
}
// ByBillingType orders the results by the billing_type field.
func ByBillingType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldBillingType, opts...).ToFunc()
}
// ByStream orders the results by the stream field.
func ByStream(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStream, opts...).ToFunc()
}
// ByDurationMs orders the results by the duration_ms field.
func ByDurationMs(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDurationMs, opts...).ToFunc()
}
// ByFirstTokenMs orders the results by the first_token_ms field.
func ByFirstTokenMs(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldFirstTokenMs, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUserField orders the results by user field.
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
}
}
// ByAPIKeyField orders the results by api_key field.
func ByAPIKeyField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newAPIKeyStep(), sql.OrderByField(field, opts...))
}
}
// ByAccountField orders the results by account field.
func ByAccountField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newAccountStep(), sql.OrderByField(field, opts...))
}
}
// ByGroupField orders the results by group field.
func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
}
}
// BySubscriptionField orders the results by subscription field.
func BySubscriptionField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newSubscriptionStep(), sql.OrderByField(field, opts...))
}
}
func newUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UserInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
}
func newAPIKeyStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(APIKeyInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, APIKeyTable, APIKeyColumn),
)
}
func newAccountStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(AccountInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn),
)
}
func newGroupStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(GroupInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
)
}
func newSubscriptionStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(SubscriptionInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionTable, SubscriptionColumn),
)
}
// Code generated by ent, DO NOT EDIT.
package usagelog
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldID, id))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func UserID(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldUserID, v))
}
// APIKeyID applies equality check predicate on the "api_key_id" field. It's identical to APIKeyIDEQ.
func APIKeyID(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldAPIKeyID, v))
}
// AccountID applies equality check predicate on the "account_id" field. It's identical to AccountIDEQ.
func AccountID(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldAccountID, v))
}
// RequestID applies equality check predicate on the "request_id" field. It's identical to RequestIDEQ.
func RequestID(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldRequestID, v))
}
// Model applies equality check predicate on the "model" field. It's identical to ModelEQ.
func Model(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldModel, v))
}
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
func GroupID(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldGroupID, v))
}
// SubscriptionID applies equality check predicate on the "subscription_id" field. It's identical to SubscriptionIDEQ.
func SubscriptionID(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldSubscriptionID, v))
}
// InputTokens applies equality check predicate on the "input_tokens" field. It's identical to InputTokensEQ.
func InputTokens(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldInputTokens, v))
}
// OutputTokens applies equality check predicate on the "output_tokens" field. It's identical to OutputTokensEQ.
func OutputTokens(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldOutputTokens, v))
}
// CacheCreationTokens applies equality check predicate on the "cache_creation_tokens" field. It's identical to CacheCreationTokensEQ.
func CacheCreationTokens(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreationTokens, v))
}
// CacheReadTokens applies equality check predicate on the "cache_read_tokens" field. It's identical to CacheReadTokensEQ.
func CacheReadTokens(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheReadTokens, v))
}
// CacheCreation5mTokens applies equality check predicate on the "cache_creation_5m_tokens" field. It's identical to CacheCreation5mTokensEQ.
func CacheCreation5mTokens(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreation5mTokens, v))
}
// CacheCreation1hTokens applies equality check predicate on the "cache_creation_1h_tokens" field. It's identical to CacheCreation1hTokensEQ.
func CacheCreation1hTokens(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreation1hTokens, v))
}
// InputCost applies equality check predicate on the "input_cost" field. It's identical to InputCostEQ.
func InputCost(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldInputCost, v))
}
// OutputCost applies equality check predicate on the "output_cost" field. It's identical to OutputCostEQ.
func OutputCost(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldOutputCost, v))
}
// CacheCreationCost applies equality check predicate on the "cache_creation_cost" field. It's identical to CacheCreationCostEQ.
func CacheCreationCost(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreationCost, v))
}
// CacheReadCost applies equality check predicate on the "cache_read_cost" field. It's identical to CacheReadCostEQ.
func CacheReadCost(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheReadCost, v))
}
// TotalCost applies equality check predicate on the "total_cost" field. It's identical to TotalCostEQ.
func TotalCost(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldTotalCost, v))
}
// ActualCost applies equality check predicate on the "actual_cost" field. It's identical to ActualCostEQ.
func ActualCost(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldActualCost, v))
}
// RateMultiplier applies equality check predicate on the "rate_multiplier" field. It's identical to RateMultiplierEQ.
func RateMultiplier(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldRateMultiplier, v))
}
// BillingType applies equality check predicate on the "billing_type" field. It's identical to BillingTypeEQ.
func BillingType(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldBillingType, v))
}
// Stream applies equality check predicate on the "stream" field. It's identical to StreamEQ.
func Stream(v bool) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldStream, v))
}
// DurationMs applies equality check predicate on the "duration_ms" field. It's identical to DurationMsEQ.
func DurationMs(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldDurationMs, v))
}
// FirstTokenMs applies equality check predicate on the "first_token_ms" field. It's identical to FirstTokenMsEQ.
func FirstTokenMs(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldFirstTokenMs, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCreatedAt, v))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func UserIDEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldUserID, v))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func UserIDNEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldUserID, v))
}
// UserIDIn applies the In predicate on the "user_id" field.
func UserIDIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldUserID, vs...))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func UserIDNotIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldUserID, vs...))
}
// APIKeyIDEQ applies the EQ predicate on the "api_key_id" field.
func APIKeyIDEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldAPIKeyID, v))
}
// APIKeyIDNEQ applies the NEQ predicate on the "api_key_id" field.
func APIKeyIDNEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldAPIKeyID, v))
}
// APIKeyIDIn applies the In predicate on the "api_key_id" field.
func APIKeyIDIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldAPIKeyID, vs...))
}
// APIKeyIDNotIn applies the NotIn predicate on the "api_key_id" field.
func APIKeyIDNotIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldAPIKeyID, vs...))
}
// AccountIDEQ applies the EQ predicate on the "account_id" field.
func AccountIDEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldAccountID, v))
}
// AccountIDNEQ applies the NEQ predicate on the "account_id" field.
func AccountIDNEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldAccountID, v))
}
// AccountIDIn applies the In predicate on the "account_id" field.
func AccountIDIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldAccountID, vs...))
}
// AccountIDNotIn applies the NotIn predicate on the "account_id" field.
func AccountIDNotIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldAccountID, vs...))
}
// RequestIDEQ applies the EQ predicate on the "request_id" field.
func RequestIDEQ(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldRequestID, v))
}
// RequestIDNEQ applies the NEQ predicate on the "request_id" field.
func RequestIDNEQ(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldRequestID, v))
}
// RequestIDIn applies the In predicate on the "request_id" field.
func RequestIDIn(vs ...string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldRequestID, vs...))
}
// RequestIDNotIn applies the NotIn predicate on the "request_id" field.
func RequestIDNotIn(vs ...string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldRequestID, vs...))
}
// RequestIDGT applies the GT predicate on the "request_id" field.
func RequestIDGT(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldRequestID, v))
}
// RequestIDGTE applies the GTE predicate on the "request_id" field.
func RequestIDGTE(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldRequestID, v))
}
// RequestIDLT applies the LT predicate on the "request_id" field.
func RequestIDLT(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldRequestID, v))
}
// RequestIDLTE applies the LTE predicate on the "request_id" field.
func RequestIDLTE(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldRequestID, v))
}
// RequestIDContains applies the Contains predicate on the "request_id" field.
func RequestIDContains(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldContains(FieldRequestID, v))
}
// RequestIDHasPrefix applies the HasPrefix predicate on the "request_id" field.
func RequestIDHasPrefix(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldHasPrefix(FieldRequestID, v))
}
// RequestIDHasSuffix applies the HasSuffix predicate on the "request_id" field.
func RequestIDHasSuffix(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldHasSuffix(FieldRequestID, v))
}
// RequestIDEqualFold applies the EqualFold predicate on the "request_id" field.
func RequestIDEqualFold(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEqualFold(FieldRequestID, v))
}
// RequestIDContainsFold applies the ContainsFold predicate on the "request_id" field.
func RequestIDContainsFold(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldContainsFold(FieldRequestID, v))
}
// ModelEQ applies the EQ predicate on the "model" field.
func ModelEQ(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldModel, v))
}
// ModelNEQ applies the NEQ predicate on the "model" field.
func ModelNEQ(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldModel, v))
}
// ModelIn applies the In predicate on the "model" field.
func ModelIn(vs ...string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldModel, vs...))
}
// ModelNotIn applies the NotIn predicate on the "model" field.
func ModelNotIn(vs ...string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldModel, vs...))
}
// ModelGT applies the GT predicate on the "model" field.
func ModelGT(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldModel, v))
}
// ModelGTE applies the GTE predicate on the "model" field.
func ModelGTE(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldModel, v))
}
// ModelLT applies the LT predicate on the "model" field.
func ModelLT(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldModel, v))
}
// ModelLTE applies the LTE predicate on the "model" field.
func ModelLTE(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldModel, v))
}
// ModelContains applies the Contains predicate on the "model" field.
func ModelContains(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldContains(FieldModel, v))
}
// ModelHasPrefix applies the HasPrefix predicate on the "model" field.
func ModelHasPrefix(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldHasPrefix(FieldModel, v))
}
// ModelHasSuffix applies the HasSuffix predicate on the "model" field.
func ModelHasSuffix(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldHasSuffix(FieldModel, v))
}
// ModelEqualFold applies the EqualFold predicate on the "model" field.
func ModelEqualFold(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEqualFold(FieldModel, v))
}
// ModelContainsFold applies the ContainsFold predicate on the "model" field.
func ModelContainsFold(v string) predicate.UsageLog {
return predicate.UsageLog(sql.FieldContainsFold(FieldModel, v))
}
// GroupIDEQ applies the EQ predicate on the "group_id" field.
func GroupIDEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldGroupID, v))
}
// GroupIDNEQ applies the NEQ predicate on the "group_id" field.
func GroupIDNEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldGroupID, v))
}
// GroupIDIn applies the In predicate on the "group_id" field.
func GroupIDIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldGroupID, vs...))
}
// GroupIDNotIn applies the NotIn predicate on the "group_id" field.
func GroupIDNotIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldGroupID, vs...))
}
// GroupIDIsNil applies the IsNil predicate on the "group_id" field.
func GroupIDIsNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldIsNull(FieldGroupID))
}
// GroupIDNotNil applies the NotNil predicate on the "group_id" field.
func GroupIDNotNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotNull(FieldGroupID))
}
// SubscriptionIDEQ applies the EQ predicate on the "subscription_id" field.
func SubscriptionIDEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldSubscriptionID, v))
}
// SubscriptionIDNEQ applies the NEQ predicate on the "subscription_id" field.
func SubscriptionIDNEQ(v int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldSubscriptionID, v))
}
// SubscriptionIDIn applies the In predicate on the "subscription_id" field.
func SubscriptionIDIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldSubscriptionID, vs...))
}
// SubscriptionIDNotIn applies the NotIn predicate on the "subscription_id" field.
func SubscriptionIDNotIn(vs ...int64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldSubscriptionID, vs...))
}
// SubscriptionIDIsNil applies the IsNil predicate on the "subscription_id" field.
func SubscriptionIDIsNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldIsNull(FieldSubscriptionID))
}
// SubscriptionIDNotNil applies the NotNil predicate on the "subscription_id" field.
func SubscriptionIDNotNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotNull(FieldSubscriptionID))
}
// InputTokensEQ applies the EQ predicate on the "input_tokens" field.
func InputTokensEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldInputTokens, v))
}
// InputTokensNEQ applies the NEQ predicate on the "input_tokens" field.
func InputTokensNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldInputTokens, v))
}
// InputTokensIn applies the In predicate on the "input_tokens" field.
func InputTokensIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldInputTokens, vs...))
}
// InputTokensNotIn applies the NotIn predicate on the "input_tokens" field.
func InputTokensNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldInputTokens, vs...))
}
// InputTokensGT applies the GT predicate on the "input_tokens" field.
func InputTokensGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldInputTokens, v))
}
// InputTokensGTE applies the GTE predicate on the "input_tokens" field.
func InputTokensGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldInputTokens, v))
}
// InputTokensLT applies the LT predicate on the "input_tokens" field.
func InputTokensLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldInputTokens, v))
}
// InputTokensLTE applies the LTE predicate on the "input_tokens" field.
func InputTokensLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldInputTokens, v))
}
// OutputTokensEQ applies the EQ predicate on the "output_tokens" field.
func OutputTokensEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldOutputTokens, v))
}
// OutputTokensNEQ applies the NEQ predicate on the "output_tokens" field.
func OutputTokensNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldOutputTokens, v))
}
// OutputTokensIn applies the In predicate on the "output_tokens" field.
func OutputTokensIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldOutputTokens, vs...))
}
// OutputTokensNotIn applies the NotIn predicate on the "output_tokens" field.
func OutputTokensNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldOutputTokens, vs...))
}
// OutputTokensGT applies the GT predicate on the "output_tokens" field.
func OutputTokensGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldOutputTokens, v))
}
// OutputTokensGTE applies the GTE predicate on the "output_tokens" field.
func OutputTokensGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldOutputTokens, v))
}
// OutputTokensLT applies the LT predicate on the "output_tokens" field.
func OutputTokensLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldOutputTokens, v))
}
// OutputTokensLTE applies the LTE predicate on the "output_tokens" field.
func OutputTokensLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldOutputTokens, v))
}
// CacheCreationTokensEQ applies the EQ predicate on the "cache_creation_tokens" field.
func CacheCreationTokensEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreationTokens, v))
}
// CacheCreationTokensNEQ applies the NEQ predicate on the "cache_creation_tokens" field.
func CacheCreationTokensNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCacheCreationTokens, v))
}
// CacheCreationTokensIn applies the In predicate on the "cache_creation_tokens" field.
func CacheCreationTokensIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCacheCreationTokens, vs...))
}
// CacheCreationTokensNotIn applies the NotIn predicate on the "cache_creation_tokens" field.
func CacheCreationTokensNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCacheCreationTokens, vs...))
}
// CacheCreationTokensGT applies the GT predicate on the "cache_creation_tokens" field.
func CacheCreationTokensGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCacheCreationTokens, v))
}
// CacheCreationTokensGTE applies the GTE predicate on the "cache_creation_tokens" field.
func CacheCreationTokensGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCacheCreationTokens, v))
}
// CacheCreationTokensLT applies the LT predicate on the "cache_creation_tokens" field.
func CacheCreationTokensLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCacheCreationTokens, v))
}
// CacheCreationTokensLTE applies the LTE predicate on the "cache_creation_tokens" field.
func CacheCreationTokensLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCacheCreationTokens, v))
}
// CacheReadTokensEQ applies the EQ predicate on the "cache_read_tokens" field.
func CacheReadTokensEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheReadTokens, v))
}
// CacheReadTokensNEQ applies the NEQ predicate on the "cache_read_tokens" field.
func CacheReadTokensNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCacheReadTokens, v))
}
// CacheReadTokensIn applies the In predicate on the "cache_read_tokens" field.
func CacheReadTokensIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCacheReadTokens, vs...))
}
// CacheReadTokensNotIn applies the NotIn predicate on the "cache_read_tokens" field.
func CacheReadTokensNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCacheReadTokens, vs...))
}
// CacheReadTokensGT applies the GT predicate on the "cache_read_tokens" field.
func CacheReadTokensGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCacheReadTokens, v))
}
// CacheReadTokensGTE applies the GTE predicate on the "cache_read_tokens" field.
func CacheReadTokensGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCacheReadTokens, v))
}
// CacheReadTokensLT applies the LT predicate on the "cache_read_tokens" field.
func CacheReadTokensLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCacheReadTokens, v))
}
// CacheReadTokensLTE applies the LTE predicate on the "cache_read_tokens" field.
func CacheReadTokensLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCacheReadTokens, v))
}
// CacheCreation5mTokensEQ applies the EQ predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreation5mTokens, v))
}
// CacheCreation5mTokensNEQ applies the NEQ predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCacheCreation5mTokens, v))
}
// CacheCreation5mTokensIn applies the In predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCacheCreation5mTokens, vs...))
}
// CacheCreation5mTokensNotIn applies the NotIn predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCacheCreation5mTokens, vs...))
}
// CacheCreation5mTokensGT applies the GT predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCacheCreation5mTokens, v))
}
// CacheCreation5mTokensGTE applies the GTE predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCacheCreation5mTokens, v))
}
// CacheCreation5mTokensLT applies the LT predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCacheCreation5mTokens, v))
}
// CacheCreation5mTokensLTE applies the LTE predicate on the "cache_creation_5m_tokens" field.
func CacheCreation5mTokensLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCacheCreation5mTokens, v))
}
// CacheCreation1hTokensEQ applies the EQ predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreation1hTokens, v))
}
// CacheCreation1hTokensNEQ applies the NEQ predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCacheCreation1hTokens, v))
}
// CacheCreation1hTokensIn applies the In predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCacheCreation1hTokens, vs...))
}
// CacheCreation1hTokensNotIn applies the NotIn predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCacheCreation1hTokens, vs...))
}
// CacheCreation1hTokensGT applies the GT predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCacheCreation1hTokens, v))
}
// CacheCreation1hTokensGTE applies the GTE predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCacheCreation1hTokens, v))
}
// CacheCreation1hTokensLT applies the LT predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCacheCreation1hTokens, v))
}
// CacheCreation1hTokensLTE applies the LTE predicate on the "cache_creation_1h_tokens" field.
func CacheCreation1hTokensLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCacheCreation1hTokens, v))
}
// InputCostEQ applies the EQ predicate on the "input_cost" field.
func InputCostEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldInputCost, v))
}
// InputCostNEQ applies the NEQ predicate on the "input_cost" field.
func InputCostNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldInputCost, v))
}
// InputCostIn applies the In predicate on the "input_cost" field.
func InputCostIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldInputCost, vs...))
}
// InputCostNotIn applies the NotIn predicate on the "input_cost" field.
func InputCostNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldInputCost, vs...))
}
// InputCostGT applies the GT predicate on the "input_cost" field.
func InputCostGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldInputCost, v))
}
// InputCostGTE applies the GTE predicate on the "input_cost" field.
func InputCostGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldInputCost, v))
}
// InputCostLT applies the LT predicate on the "input_cost" field.
func InputCostLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldInputCost, v))
}
// InputCostLTE applies the LTE predicate on the "input_cost" field.
func InputCostLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldInputCost, v))
}
// OutputCostEQ applies the EQ predicate on the "output_cost" field.
func OutputCostEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldOutputCost, v))
}
// OutputCostNEQ applies the NEQ predicate on the "output_cost" field.
func OutputCostNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldOutputCost, v))
}
// OutputCostIn applies the In predicate on the "output_cost" field.
func OutputCostIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldOutputCost, vs...))
}
// OutputCostNotIn applies the NotIn predicate on the "output_cost" field.
func OutputCostNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldOutputCost, vs...))
}
// OutputCostGT applies the GT predicate on the "output_cost" field.
func OutputCostGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldOutputCost, v))
}
// OutputCostGTE applies the GTE predicate on the "output_cost" field.
func OutputCostGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldOutputCost, v))
}
// OutputCostLT applies the LT predicate on the "output_cost" field.
func OutputCostLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldOutputCost, v))
}
// OutputCostLTE applies the LTE predicate on the "output_cost" field.
func OutputCostLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldOutputCost, v))
}
// CacheCreationCostEQ applies the EQ predicate on the "cache_creation_cost" field.
func CacheCreationCostEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheCreationCost, v))
}
// CacheCreationCostNEQ applies the NEQ predicate on the "cache_creation_cost" field.
func CacheCreationCostNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCacheCreationCost, v))
}
// CacheCreationCostIn applies the In predicate on the "cache_creation_cost" field.
func CacheCreationCostIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCacheCreationCost, vs...))
}
// CacheCreationCostNotIn applies the NotIn predicate on the "cache_creation_cost" field.
func CacheCreationCostNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCacheCreationCost, vs...))
}
// CacheCreationCostGT applies the GT predicate on the "cache_creation_cost" field.
func CacheCreationCostGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCacheCreationCost, v))
}
// CacheCreationCostGTE applies the GTE predicate on the "cache_creation_cost" field.
func CacheCreationCostGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCacheCreationCost, v))
}
// CacheCreationCostLT applies the LT predicate on the "cache_creation_cost" field.
func CacheCreationCostLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCacheCreationCost, v))
}
// CacheCreationCostLTE applies the LTE predicate on the "cache_creation_cost" field.
func CacheCreationCostLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCacheCreationCost, v))
}
// CacheReadCostEQ applies the EQ predicate on the "cache_read_cost" field.
func CacheReadCostEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCacheReadCost, v))
}
// CacheReadCostNEQ applies the NEQ predicate on the "cache_read_cost" field.
func CacheReadCostNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCacheReadCost, v))
}
// CacheReadCostIn applies the In predicate on the "cache_read_cost" field.
func CacheReadCostIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCacheReadCost, vs...))
}
// CacheReadCostNotIn applies the NotIn predicate on the "cache_read_cost" field.
func CacheReadCostNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCacheReadCost, vs...))
}
// CacheReadCostGT applies the GT predicate on the "cache_read_cost" field.
func CacheReadCostGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCacheReadCost, v))
}
// CacheReadCostGTE applies the GTE predicate on the "cache_read_cost" field.
func CacheReadCostGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCacheReadCost, v))
}
// CacheReadCostLT applies the LT predicate on the "cache_read_cost" field.
func CacheReadCostLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCacheReadCost, v))
}
// CacheReadCostLTE applies the LTE predicate on the "cache_read_cost" field.
func CacheReadCostLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCacheReadCost, v))
}
// TotalCostEQ applies the EQ predicate on the "total_cost" field.
func TotalCostEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldTotalCost, v))
}
// TotalCostNEQ applies the NEQ predicate on the "total_cost" field.
func TotalCostNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldTotalCost, v))
}
// TotalCostIn applies the In predicate on the "total_cost" field.
func TotalCostIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldTotalCost, vs...))
}
// TotalCostNotIn applies the NotIn predicate on the "total_cost" field.
func TotalCostNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldTotalCost, vs...))
}
// TotalCostGT applies the GT predicate on the "total_cost" field.
func TotalCostGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldTotalCost, v))
}
// TotalCostGTE applies the GTE predicate on the "total_cost" field.
func TotalCostGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldTotalCost, v))
}
// TotalCostLT applies the LT predicate on the "total_cost" field.
func TotalCostLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldTotalCost, v))
}
// TotalCostLTE applies the LTE predicate on the "total_cost" field.
func TotalCostLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldTotalCost, v))
}
// ActualCostEQ applies the EQ predicate on the "actual_cost" field.
func ActualCostEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldActualCost, v))
}
// ActualCostNEQ applies the NEQ predicate on the "actual_cost" field.
func ActualCostNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldActualCost, v))
}
// ActualCostIn applies the In predicate on the "actual_cost" field.
func ActualCostIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldActualCost, vs...))
}
// ActualCostNotIn applies the NotIn predicate on the "actual_cost" field.
func ActualCostNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldActualCost, vs...))
}
// ActualCostGT applies the GT predicate on the "actual_cost" field.
func ActualCostGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldActualCost, v))
}
// ActualCostGTE applies the GTE predicate on the "actual_cost" field.
func ActualCostGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldActualCost, v))
}
// ActualCostLT applies the LT predicate on the "actual_cost" field.
func ActualCostLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldActualCost, v))
}
// ActualCostLTE applies the LTE predicate on the "actual_cost" field.
func ActualCostLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldActualCost, v))
}
// RateMultiplierEQ applies the EQ predicate on the "rate_multiplier" field.
func RateMultiplierEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldRateMultiplier, v))
}
// RateMultiplierNEQ applies the NEQ predicate on the "rate_multiplier" field.
func RateMultiplierNEQ(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldRateMultiplier, v))
}
// RateMultiplierIn applies the In predicate on the "rate_multiplier" field.
func RateMultiplierIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldRateMultiplier, vs...))
}
// RateMultiplierNotIn applies the NotIn predicate on the "rate_multiplier" field.
func RateMultiplierNotIn(vs ...float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldRateMultiplier, vs...))
}
// RateMultiplierGT applies the GT predicate on the "rate_multiplier" field.
func RateMultiplierGT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldRateMultiplier, v))
}
// RateMultiplierGTE applies the GTE predicate on the "rate_multiplier" field.
func RateMultiplierGTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldRateMultiplier, v))
}
// RateMultiplierLT applies the LT predicate on the "rate_multiplier" field.
func RateMultiplierLT(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldRateMultiplier, v))
}
// RateMultiplierLTE applies the LTE predicate on the "rate_multiplier" field.
func RateMultiplierLTE(v float64) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldRateMultiplier, v))
}
// BillingTypeEQ applies the EQ predicate on the "billing_type" field.
func BillingTypeEQ(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldBillingType, v))
}
// BillingTypeNEQ applies the NEQ predicate on the "billing_type" field.
func BillingTypeNEQ(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldBillingType, v))
}
// BillingTypeIn applies the In predicate on the "billing_type" field.
func BillingTypeIn(vs ...int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldBillingType, vs...))
}
// BillingTypeNotIn applies the NotIn predicate on the "billing_type" field.
func BillingTypeNotIn(vs ...int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldBillingType, vs...))
}
// BillingTypeGT applies the GT predicate on the "billing_type" field.
func BillingTypeGT(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldBillingType, v))
}
// BillingTypeGTE applies the GTE predicate on the "billing_type" field.
func BillingTypeGTE(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldBillingType, v))
}
// BillingTypeLT applies the LT predicate on the "billing_type" field.
func BillingTypeLT(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldBillingType, v))
}
// BillingTypeLTE applies the LTE predicate on the "billing_type" field.
func BillingTypeLTE(v int8) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldBillingType, v))
}
// StreamEQ applies the EQ predicate on the "stream" field.
func StreamEQ(v bool) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldStream, v))
}
// StreamNEQ applies the NEQ predicate on the "stream" field.
func StreamNEQ(v bool) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldStream, v))
}
// DurationMsEQ applies the EQ predicate on the "duration_ms" field.
func DurationMsEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldDurationMs, v))
}
// DurationMsNEQ applies the NEQ predicate on the "duration_ms" field.
func DurationMsNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldDurationMs, v))
}
// DurationMsIn applies the In predicate on the "duration_ms" field.
func DurationMsIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldDurationMs, vs...))
}
// DurationMsNotIn applies the NotIn predicate on the "duration_ms" field.
func DurationMsNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldDurationMs, vs...))
}
// DurationMsGT applies the GT predicate on the "duration_ms" field.
func DurationMsGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldDurationMs, v))
}
// DurationMsGTE applies the GTE predicate on the "duration_ms" field.
func DurationMsGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldDurationMs, v))
}
// DurationMsLT applies the LT predicate on the "duration_ms" field.
func DurationMsLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldDurationMs, v))
}
// DurationMsLTE applies the LTE predicate on the "duration_ms" field.
func DurationMsLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldDurationMs, v))
}
// DurationMsIsNil applies the IsNil predicate on the "duration_ms" field.
func DurationMsIsNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldIsNull(FieldDurationMs))
}
// DurationMsNotNil applies the NotNil predicate on the "duration_ms" field.
func DurationMsNotNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotNull(FieldDurationMs))
}
// FirstTokenMsEQ applies the EQ predicate on the "first_token_ms" field.
func FirstTokenMsEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldFirstTokenMs, v))
}
// FirstTokenMsNEQ applies the NEQ predicate on the "first_token_ms" field.
func FirstTokenMsNEQ(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldFirstTokenMs, v))
}
// FirstTokenMsIn applies the In predicate on the "first_token_ms" field.
func FirstTokenMsIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldFirstTokenMs, vs...))
}
// FirstTokenMsNotIn applies the NotIn predicate on the "first_token_ms" field.
func FirstTokenMsNotIn(vs ...int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldFirstTokenMs, vs...))
}
// FirstTokenMsGT applies the GT predicate on the "first_token_ms" field.
func FirstTokenMsGT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldFirstTokenMs, v))
}
// FirstTokenMsGTE applies the GTE predicate on the "first_token_ms" field.
func FirstTokenMsGTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldFirstTokenMs, v))
}
// FirstTokenMsLT applies the LT predicate on the "first_token_ms" field.
func FirstTokenMsLT(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldFirstTokenMs, v))
}
// FirstTokenMsLTE applies the LTE predicate on the "first_token_ms" field.
func FirstTokenMsLTE(v int) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldFirstTokenMs, v))
}
// FirstTokenMsIsNil applies the IsNil predicate on the "first_token_ms" field.
func FirstTokenMsIsNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldIsNull(FieldFirstTokenMs))
}
// FirstTokenMsNotNil applies the NotNil predicate on the "first_token_ms" field.
func FirstTokenMsNotNil() predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotNull(FieldFirstTokenMs))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.UsageLog {
return predicate.UsageLog(sql.FieldLTE(FieldCreatedAt, v))
}
// HasUser applies the HasEdge predicate on the "user" edge.
func HasUser() predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
func HasUserWith(preds ...predicate.User) predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := newUserStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasAPIKey applies the HasEdge predicate on the "api_key" edge.
func HasAPIKey() predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, APIKeyTable, APIKeyColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasAPIKeyWith applies the HasEdge predicate on the "api_key" edge with a given conditions (other predicates).
func HasAPIKeyWith(preds ...predicate.ApiKey) predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := newAPIKeyStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasAccount applies the HasEdge predicate on the "account" edge.
func HasAccount() predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasAccountWith applies the HasEdge predicate on the "account" edge with a given conditions (other predicates).
func HasAccountWith(preds ...predicate.Account) predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := newAccountStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasGroup applies the HasEdge predicate on the "group" edge.
func HasGroup() predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
func HasGroupWith(preds ...predicate.Group) predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := newGroupStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasSubscription applies the HasEdge predicate on the "subscription" edge.
func HasSubscription() predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, SubscriptionTable, SubscriptionColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasSubscriptionWith applies the HasEdge predicate on the "subscription" edge with a given conditions (other predicates).
func HasSubscriptionWith(preds ...predicate.UserSubscription) predicate.UsageLog {
return predicate.UsageLog(func(s *sql.Selector) {
step := newSubscriptionStep()
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.UsageLog) predicate.UsageLog {
return predicate.UsageLog(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.UsageLog) predicate.UsageLog {
return predicate.UsageLog(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.UsageLog) predicate.UsageLog {
return predicate.UsageLog(sql.NotPredicates(p))
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
// UsageLogCreate is the builder for creating a UsageLog entity.
type UsageLogCreate struct {
config
mutation *UsageLogMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetUserID sets the "user_id" field.
func (_c *UsageLogCreate) SetUserID(v int64) *UsageLogCreate {
_c.mutation.SetUserID(v)
return _c
}
// SetAPIKeyID sets the "api_key_id" field.
func (_c *UsageLogCreate) SetAPIKeyID(v int64) *UsageLogCreate {
_c.mutation.SetAPIKeyID(v)
return _c
}
// SetAccountID sets the "account_id" field.
func (_c *UsageLogCreate) SetAccountID(v int64) *UsageLogCreate {
_c.mutation.SetAccountID(v)
return _c
}
// SetRequestID sets the "request_id" field.
func (_c *UsageLogCreate) SetRequestID(v string) *UsageLogCreate {
_c.mutation.SetRequestID(v)
return _c
}
// SetModel sets the "model" field.
func (_c *UsageLogCreate) SetModel(v string) *UsageLogCreate {
_c.mutation.SetModel(v)
return _c
}
// SetGroupID sets the "group_id" field.
func (_c *UsageLogCreate) SetGroupID(v int64) *UsageLogCreate {
_c.mutation.SetGroupID(v)
return _c
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableGroupID(v *int64) *UsageLogCreate {
if v != nil {
_c.SetGroupID(*v)
}
return _c
}
// SetSubscriptionID sets the "subscription_id" field.
func (_c *UsageLogCreate) SetSubscriptionID(v int64) *UsageLogCreate {
_c.mutation.SetSubscriptionID(v)
return _c
}
// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableSubscriptionID(v *int64) *UsageLogCreate {
if v != nil {
_c.SetSubscriptionID(*v)
}
return _c
}
// SetInputTokens sets the "input_tokens" field.
func (_c *UsageLogCreate) SetInputTokens(v int) *UsageLogCreate {
_c.mutation.SetInputTokens(v)
return _c
}
// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableInputTokens(v *int) *UsageLogCreate {
if v != nil {
_c.SetInputTokens(*v)
}
return _c
}
// SetOutputTokens sets the "output_tokens" field.
func (_c *UsageLogCreate) SetOutputTokens(v int) *UsageLogCreate {
_c.mutation.SetOutputTokens(v)
return _c
}
// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableOutputTokens(v *int) *UsageLogCreate {
if v != nil {
_c.SetOutputTokens(*v)
}
return _c
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (_c *UsageLogCreate) SetCacheCreationTokens(v int) *UsageLogCreate {
_c.mutation.SetCacheCreationTokens(v)
return _c
}
// SetNillableCacheCreationTokens sets the "cache_creation_tokens" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCacheCreationTokens(v *int) *UsageLogCreate {
if v != nil {
_c.SetCacheCreationTokens(*v)
}
return _c
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (_c *UsageLogCreate) SetCacheReadTokens(v int) *UsageLogCreate {
_c.mutation.SetCacheReadTokens(v)
return _c
}
// SetNillableCacheReadTokens sets the "cache_read_tokens" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCacheReadTokens(v *int) *UsageLogCreate {
if v != nil {
_c.SetCacheReadTokens(*v)
}
return _c
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (_c *UsageLogCreate) SetCacheCreation5mTokens(v int) *UsageLogCreate {
_c.mutation.SetCacheCreation5mTokens(v)
return _c
}
// SetNillableCacheCreation5mTokens sets the "cache_creation_5m_tokens" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCacheCreation5mTokens(v *int) *UsageLogCreate {
if v != nil {
_c.SetCacheCreation5mTokens(*v)
}
return _c
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (_c *UsageLogCreate) SetCacheCreation1hTokens(v int) *UsageLogCreate {
_c.mutation.SetCacheCreation1hTokens(v)
return _c
}
// SetNillableCacheCreation1hTokens sets the "cache_creation_1h_tokens" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCacheCreation1hTokens(v *int) *UsageLogCreate {
if v != nil {
_c.SetCacheCreation1hTokens(*v)
}
return _c
}
// SetInputCost sets the "input_cost" field.
func (_c *UsageLogCreate) SetInputCost(v float64) *UsageLogCreate {
_c.mutation.SetInputCost(v)
return _c
}
// SetNillableInputCost sets the "input_cost" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableInputCost(v *float64) *UsageLogCreate {
if v != nil {
_c.SetInputCost(*v)
}
return _c
}
// SetOutputCost sets the "output_cost" field.
func (_c *UsageLogCreate) SetOutputCost(v float64) *UsageLogCreate {
_c.mutation.SetOutputCost(v)
return _c
}
// SetNillableOutputCost sets the "output_cost" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableOutputCost(v *float64) *UsageLogCreate {
if v != nil {
_c.SetOutputCost(*v)
}
return _c
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (_c *UsageLogCreate) SetCacheCreationCost(v float64) *UsageLogCreate {
_c.mutation.SetCacheCreationCost(v)
return _c
}
// SetNillableCacheCreationCost sets the "cache_creation_cost" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCacheCreationCost(v *float64) *UsageLogCreate {
if v != nil {
_c.SetCacheCreationCost(*v)
}
return _c
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (_c *UsageLogCreate) SetCacheReadCost(v float64) *UsageLogCreate {
_c.mutation.SetCacheReadCost(v)
return _c
}
// SetNillableCacheReadCost sets the "cache_read_cost" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCacheReadCost(v *float64) *UsageLogCreate {
if v != nil {
_c.SetCacheReadCost(*v)
}
return _c
}
// SetTotalCost sets the "total_cost" field.
func (_c *UsageLogCreate) SetTotalCost(v float64) *UsageLogCreate {
_c.mutation.SetTotalCost(v)
return _c
}
// SetNillableTotalCost sets the "total_cost" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableTotalCost(v *float64) *UsageLogCreate {
if v != nil {
_c.SetTotalCost(*v)
}
return _c
}
// SetActualCost sets the "actual_cost" field.
func (_c *UsageLogCreate) SetActualCost(v float64) *UsageLogCreate {
_c.mutation.SetActualCost(v)
return _c
}
// SetNillableActualCost sets the "actual_cost" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableActualCost(v *float64) *UsageLogCreate {
if v != nil {
_c.SetActualCost(*v)
}
return _c
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (_c *UsageLogCreate) SetRateMultiplier(v float64) *UsageLogCreate {
_c.mutation.SetRateMultiplier(v)
return _c
}
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableRateMultiplier(v *float64) *UsageLogCreate {
if v != nil {
_c.SetRateMultiplier(*v)
}
return _c
}
// SetBillingType sets the "billing_type" field.
func (_c *UsageLogCreate) SetBillingType(v int8) *UsageLogCreate {
_c.mutation.SetBillingType(v)
return _c
}
// SetNillableBillingType sets the "billing_type" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableBillingType(v *int8) *UsageLogCreate {
if v != nil {
_c.SetBillingType(*v)
}
return _c
}
// SetStream sets the "stream" field.
func (_c *UsageLogCreate) SetStream(v bool) *UsageLogCreate {
_c.mutation.SetStream(v)
return _c
}
// SetNillableStream sets the "stream" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableStream(v *bool) *UsageLogCreate {
if v != nil {
_c.SetStream(*v)
}
return _c
}
// SetDurationMs sets the "duration_ms" field.
func (_c *UsageLogCreate) SetDurationMs(v int) *UsageLogCreate {
_c.mutation.SetDurationMs(v)
return _c
}
// SetNillableDurationMs sets the "duration_ms" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableDurationMs(v *int) *UsageLogCreate {
if v != nil {
_c.SetDurationMs(*v)
}
return _c
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (_c *UsageLogCreate) SetFirstTokenMs(v int) *UsageLogCreate {
_c.mutation.SetFirstTokenMs(v)
return _c
}
// SetNillableFirstTokenMs sets the "first_token_ms" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableFirstTokenMs(v *int) *UsageLogCreate {
if v != nil {
_c.SetFirstTokenMs(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *UsageLogCreate) SetCreatedAt(v time.Time) *UsageLogCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *UsageLogCreate) SetNillableCreatedAt(v *time.Time) *UsageLogCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUser sets the "user" edge to the User entity.
func (_c *UsageLogCreate) SetUser(v *User) *UsageLogCreate {
return _c.SetUserID(v.ID)
}
// SetAPIKey sets the "api_key" edge to the ApiKey entity.
func (_c *UsageLogCreate) SetAPIKey(v *ApiKey) *UsageLogCreate {
return _c.SetAPIKeyID(v.ID)
}
// SetAccount sets the "account" edge to the Account entity.
func (_c *UsageLogCreate) SetAccount(v *Account) *UsageLogCreate {
return _c.SetAccountID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_c *UsageLogCreate) SetGroup(v *Group) *UsageLogCreate {
return _c.SetGroupID(v.ID)
}
// SetSubscription sets the "subscription" edge to the UserSubscription entity.
func (_c *UsageLogCreate) SetSubscription(v *UserSubscription) *UsageLogCreate {
return _c.SetSubscriptionID(v.ID)
}
// Mutation returns the UsageLogMutation object of the builder.
func (_c *UsageLogCreate) Mutation() *UsageLogMutation {
return _c.mutation
}
// Save creates the UsageLog in the database.
func (_c *UsageLogCreate) Save(ctx context.Context) (*UsageLog, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *UsageLogCreate) SaveX(ctx context.Context) *UsageLog {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UsageLogCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UsageLogCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *UsageLogCreate) defaults() {
if _, ok := _c.mutation.InputTokens(); !ok {
v := usagelog.DefaultInputTokens
_c.mutation.SetInputTokens(v)
}
if _, ok := _c.mutation.OutputTokens(); !ok {
v := usagelog.DefaultOutputTokens
_c.mutation.SetOutputTokens(v)
}
if _, ok := _c.mutation.CacheCreationTokens(); !ok {
v := usagelog.DefaultCacheCreationTokens
_c.mutation.SetCacheCreationTokens(v)
}
if _, ok := _c.mutation.CacheReadTokens(); !ok {
v := usagelog.DefaultCacheReadTokens
_c.mutation.SetCacheReadTokens(v)
}
if _, ok := _c.mutation.CacheCreation5mTokens(); !ok {
v := usagelog.DefaultCacheCreation5mTokens
_c.mutation.SetCacheCreation5mTokens(v)
}
if _, ok := _c.mutation.CacheCreation1hTokens(); !ok {
v := usagelog.DefaultCacheCreation1hTokens
_c.mutation.SetCacheCreation1hTokens(v)
}
if _, ok := _c.mutation.InputCost(); !ok {
v := usagelog.DefaultInputCost
_c.mutation.SetInputCost(v)
}
if _, ok := _c.mutation.OutputCost(); !ok {
v := usagelog.DefaultOutputCost
_c.mutation.SetOutputCost(v)
}
if _, ok := _c.mutation.CacheCreationCost(); !ok {
v := usagelog.DefaultCacheCreationCost
_c.mutation.SetCacheCreationCost(v)
}
if _, ok := _c.mutation.CacheReadCost(); !ok {
v := usagelog.DefaultCacheReadCost
_c.mutation.SetCacheReadCost(v)
}
if _, ok := _c.mutation.TotalCost(); !ok {
v := usagelog.DefaultTotalCost
_c.mutation.SetTotalCost(v)
}
if _, ok := _c.mutation.ActualCost(); !ok {
v := usagelog.DefaultActualCost
_c.mutation.SetActualCost(v)
}
if _, ok := _c.mutation.RateMultiplier(); !ok {
v := usagelog.DefaultRateMultiplier
_c.mutation.SetRateMultiplier(v)
}
if _, ok := _c.mutation.BillingType(); !ok {
v := usagelog.DefaultBillingType
_c.mutation.SetBillingType(v)
}
if _, ok := _c.mutation.Stream(); !ok {
v := usagelog.DefaultStream
_c.mutation.SetStream(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := usagelog.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *UsageLogCreate) check() error {
if _, ok := _c.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UsageLog.user_id"`)}
}
if _, ok := _c.mutation.APIKeyID(); !ok {
return &ValidationError{Name: "api_key_id", err: errors.New(`ent: missing required field "UsageLog.api_key_id"`)}
}
if _, ok := _c.mutation.AccountID(); !ok {
return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "UsageLog.account_id"`)}
}
if _, ok := _c.mutation.RequestID(); !ok {
return &ValidationError{Name: "request_id", err: errors.New(`ent: missing required field "UsageLog.request_id"`)}
}
if v, ok := _c.mutation.RequestID(); ok {
if err := usagelog.RequestIDValidator(v); err != nil {
return &ValidationError{Name: "request_id", err: fmt.Errorf(`ent: validator failed for field "UsageLog.request_id": %w`, err)}
}
}
if _, ok := _c.mutation.Model(); !ok {
return &ValidationError{Name: "model", err: errors.New(`ent: missing required field "UsageLog.model"`)}
}
if v, ok := _c.mutation.Model(); ok {
if err := usagelog.ModelValidator(v); err != nil {
return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "UsageLog.model": %w`, err)}
}
}
if _, ok := _c.mutation.InputTokens(); !ok {
return &ValidationError{Name: "input_tokens", err: errors.New(`ent: missing required field "UsageLog.input_tokens"`)}
}
if _, ok := _c.mutation.OutputTokens(); !ok {
return &ValidationError{Name: "output_tokens", err: errors.New(`ent: missing required field "UsageLog.output_tokens"`)}
}
if _, ok := _c.mutation.CacheCreationTokens(); !ok {
return &ValidationError{Name: "cache_creation_tokens", err: errors.New(`ent: missing required field "UsageLog.cache_creation_tokens"`)}
}
if _, ok := _c.mutation.CacheReadTokens(); !ok {
return &ValidationError{Name: "cache_read_tokens", err: errors.New(`ent: missing required field "UsageLog.cache_read_tokens"`)}
}
if _, ok := _c.mutation.CacheCreation5mTokens(); !ok {
return &ValidationError{Name: "cache_creation_5m_tokens", err: errors.New(`ent: missing required field "UsageLog.cache_creation_5m_tokens"`)}
}
if _, ok := _c.mutation.CacheCreation1hTokens(); !ok {
return &ValidationError{Name: "cache_creation_1h_tokens", err: errors.New(`ent: missing required field "UsageLog.cache_creation_1h_tokens"`)}
}
if _, ok := _c.mutation.InputCost(); !ok {
return &ValidationError{Name: "input_cost", err: errors.New(`ent: missing required field "UsageLog.input_cost"`)}
}
if _, ok := _c.mutation.OutputCost(); !ok {
return &ValidationError{Name: "output_cost", err: errors.New(`ent: missing required field "UsageLog.output_cost"`)}
}
if _, ok := _c.mutation.CacheCreationCost(); !ok {
return &ValidationError{Name: "cache_creation_cost", err: errors.New(`ent: missing required field "UsageLog.cache_creation_cost"`)}
}
if _, ok := _c.mutation.CacheReadCost(); !ok {
return &ValidationError{Name: "cache_read_cost", err: errors.New(`ent: missing required field "UsageLog.cache_read_cost"`)}
}
if _, ok := _c.mutation.TotalCost(); !ok {
return &ValidationError{Name: "total_cost", err: errors.New(`ent: missing required field "UsageLog.total_cost"`)}
}
if _, ok := _c.mutation.ActualCost(); !ok {
return &ValidationError{Name: "actual_cost", err: errors.New(`ent: missing required field "UsageLog.actual_cost"`)}
}
if _, ok := _c.mutation.RateMultiplier(); !ok {
return &ValidationError{Name: "rate_multiplier", err: errors.New(`ent: missing required field "UsageLog.rate_multiplier"`)}
}
if _, ok := _c.mutation.BillingType(); !ok {
return &ValidationError{Name: "billing_type", err: errors.New(`ent: missing required field "UsageLog.billing_type"`)}
}
if _, ok := _c.mutation.Stream(); !ok {
return &ValidationError{Name: "stream", err: errors.New(`ent: missing required field "UsageLog.stream"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UsageLog.created_at"`)}
}
if len(_c.mutation.UserIDs()) == 0 {
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UsageLog.user"`)}
}
if len(_c.mutation.APIKeyIDs()) == 0 {
return &ValidationError{Name: "api_key", err: errors.New(`ent: missing required edge "UsageLog.api_key"`)}
}
if len(_c.mutation.AccountIDs()) == 0 {
return &ValidationError{Name: "account", err: errors.New(`ent: missing required edge "UsageLog.account"`)}
}
return nil
}
func (_c *UsageLogCreate) sqlSave(ctx context.Context) (*UsageLog, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *UsageLogCreate) createSpec() (*UsageLog, *sqlgraph.CreateSpec) {
var (
_node = &UsageLog{config: _c.config}
_spec = sqlgraph.NewCreateSpec(usagelog.Table, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.RequestID(); ok {
_spec.SetField(usagelog.FieldRequestID, field.TypeString, value)
_node.RequestID = value
}
if value, ok := _c.mutation.Model(); ok {
_spec.SetField(usagelog.FieldModel, field.TypeString, value)
_node.Model = value
}
if value, ok := _c.mutation.InputTokens(); ok {
_spec.SetField(usagelog.FieldInputTokens, field.TypeInt, value)
_node.InputTokens = value
}
if value, ok := _c.mutation.OutputTokens(); ok {
_spec.SetField(usagelog.FieldOutputTokens, field.TypeInt, value)
_node.OutputTokens = value
}
if value, ok := _c.mutation.CacheCreationTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
_node.CacheCreationTokens = value
}
if value, ok := _c.mutation.CacheReadTokens(); ok {
_spec.SetField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
_node.CacheReadTokens = value
}
if value, ok := _c.mutation.CacheCreation5mTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
_node.CacheCreation5mTokens = value
}
if value, ok := _c.mutation.CacheCreation1hTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
_node.CacheCreation1hTokens = value
}
if value, ok := _c.mutation.InputCost(); ok {
_spec.SetField(usagelog.FieldInputCost, field.TypeFloat64, value)
_node.InputCost = value
}
if value, ok := _c.mutation.OutputCost(); ok {
_spec.SetField(usagelog.FieldOutputCost, field.TypeFloat64, value)
_node.OutputCost = value
}
if value, ok := _c.mutation.CacheCreationCost(); ok {
_spec.SetField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
_node.CacheCreationCost = value
}
if value, ok := _c.mutation.CacheReadCost(); ok {
_spec.SetField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
_node.CacheReadCost = value
}
if value, ok := _c.mutation.TotalCost(); ok {
_spec.SetField(usagelog.FieldTotalCost, field.TypeFloat64, value)
_node.TotalCost = value
}
if value, ok := _c.mutation.ActualCost(); ok {
_spec.SetField(usagelog.FieldActualCost, field.TypeFloat64, value)
_node.ActualCost = value
}
if value, ok := _c.mutation.RateMultiplier(); ok {
_spec.SetField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
_node.RateMultiplier = value
}
if value, ok := _c.mutation.BillingType(); ok {
_spec.SetField(usagelog.FieldBillingType, field.TypeInt8, value)
_node.BillingType = value
}
if value, ok := _c.mutation.Stream(); ok {
_spec.SetField(usagelog.FieldStream, field.TypeBool, value)
_node.Stream = value
}
if value, ok := _c.mutation.DurationMs(); ok {
_spec.SetField(usagelog.FieldDurationMs, field.TypeInt, value)
_node.DurationMs = &value
}
if value, ok := _c.mutation.FirstTokenMs(); ok {
_spec.SetField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
_node.FirstTokenMs = &value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(usagelog.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.UserTable,
Columns: []string{usagelog.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.UserID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.APIKeyIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.APIKeyTable,
Columns: []string{usagelog.APIKeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.APIKeyID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.AccountIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.AccountTable,
Columns: []string{usagelog.AccountColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.AccountID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.GroupTable,
Columns: []string{usagelog.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.GroupID = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.SubscriptionIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.SubscriptionTable,
Columns: []string{usagelog.SubscriptionColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.SubscriptionID = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageLog.Create().
// SetUserID(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageLogUpsert) {
// SetUserID(v+v).
// }).
// Exec(ctx)
func (_c *UsageLogCreate) OnConflict(opts ...sql.ConflictOption) *UsageLogUpsertOne {
_c.conflict = opts
return &UsageLogUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageLog.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *UsageLogCreate) OnConflictColumns(columns ...string) *UsageLogUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &UsageLogUpsertOne{
create: _c,
}
}
type (
// UsageLogUpsertOne is the builder for "upsert"-ing
// one UsageLog node.
UsageLogUpsertOne struct {
create *UsageLogCreate
}
// UsageLogUpsert is the "OnConflict" setter.
UsageLogUpsert struct {
*sql.UpdateSet
}
)
// SetUserID sets the "user_id" field.
func (u *UsageLogUpsert) SetUserID(v int64) *UsageLogUpsert {
u.Set(usagelog.FieldUserID, v)
return u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateUserID() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldUserID)
return u
}
// SetAPIKeyID sets the "api_key_id" field.
func (u *UsageLogUpsert) SetAPIKeyID(v int64) *UsageLogUpsert {
u.Set(usagelog.FieldAPIKeyID, v)
return u
}
// UpdateAPIKeyID sets the "api_key_id" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateAPIKeyID() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldAPIKeyID)
return u
}
// SetAccountID sets the "account_id" field.
func (u *UsageLogUpsert) SetAccountID(v int64) *UsageLogUpsert {
u.Set(usagelog.FieldAccountID, v)
return u
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateAccountID() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldAccountID)
return u
}
// SetRequestID sets the "request_id" field.
func (u *UsageLogUpsert) SetRequestID(v string) *UsageLogUpsert {
u.Set(usagelog.FieldRequestID, v)
return u
}
// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateRequestID() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldRequestID)
return u
}
// SetModel sets the "model" field.
func (u *UsageLogUpsert) SetModel(v string) *UsageLogUpsert {
u.Set(usagelog.FieldModel, v)
return u
}
// UpdateModel sets the "model" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateModel() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldModel)
return u
}
// SetGroupID sets the "group_id" field.
func (u *UsageLogUpsert) SetGroupID(v int64) *UsageLogUpsert {
u.Set(usagelog.FieldGroupID, v)
return u
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateGroupID() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldGroupID)
return u
}
// ClearGroupID clears the value of the "group_id" field.
func (u *UsageLogUpsert) ClearGroupID() *UsageLogUpsert {
u.SetNull(usagelog.FieldGroupID)
return u
}
// SetSubscriptionID sets the "subscription_id" field.
func (u *UsageLogUpsert) SetSubscriptionID(v int64) *UsageLogUpsert {
u.Set(usagelog.FieldSubscriptionID, v)
return u
}
// UpdateSubscriptionID sets the "subscription_id" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateSubscriptionID() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldSubscriptionID)
return u
}
// ClearSubscriptionID clears the value of the "subscription_id" field.
func (u *UsageLogUpsert) ClearSubscriptionID() *UsageLogUpsert {
u.SetNull(usagelog.FieldSubscriptionID)
return u
}
// SetInputTokens sets the "input_tokens" field.
func (u *UsageLogUpsert) SetInputTokens(v int) *UsageLogUpsert {
u.Set(usagelog.FieldInputTokens, v)
return u
}
// UpdateInputTokens sets the "input_tokens" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateInputTokens() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldInputTokens)
return u
}
// AddInputTokens adds v to the "input_tokens" field.
func (u *UsageLogUpsert) AddInputTokens(v int) *UsageLogUpsert {
u.Add(usagelog.FieldInputTokens, v)
return u
}
// SetOutputTokens sets the "output_tokens" field.
func (u *UsageLogUpsert) SetOutputTokens(v int) *UsageLogUpsert {
u.Set(usagelog.FieldOutputTokens, v)
return u
}
// UpdateOutputTokens sets the "output_tokens" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateOutputTokens() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldOutputTokens)
return u
}
// AddOutputTokens adds v to the "output_tokens" field.
func (u *UsageLogUpsert) AddOutputTokens(v int) *UsageLogUpsert {
u.Add(usagelog.FieldOutputTokens, v)
return u
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (u *UsageLogUpsert) SetCacheCreationTokens(v int) *UsageLogUpsert {
u.Set(usagelog.FieldCacheCreationTokens, v)
return u
}
// UpdateCacheCreationTokens sets the "cache_creation_tokens" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateCacheCreationTokens() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldCacheCreationTokens)
return u
}
// AddCacheCreationTokens adds v to the "cache_creation_tokens" field.
func (u *UsageLogUpsert) AddCacheCreationTokens(v int) *UsageLogUpsert {
u.Add(usagelog.FieldCacheCreationTokens, v)
return u
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (u *UsageLogUpsert) SetCacheReadTokens(v int) *UsageLogUpsert {
u.Set(usagelog.FieldCacheReadTokens, v)
return u
}
// UpdateCacheReadTokens sets the "cache_read_tokens" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateCacheReadTokens() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldCacheReadTokens)
return u
}
// AddCacheReadTokens adds v to the "cache_read_tokens" field.
func (u *UsageLogUpsert) AddCacheReadTokens(v int) *UsageLogUpsert {
u.Add(usagelog.FieldCacheReadTokens, v)
return u
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (u *UsageLogUpsert) SetCacheCreation5mTokens(v int) *UsageLogUpsert {
u.Set(usagelog.FieldCacheCreation5mTokens, v)
return u
}
// UpdateCacheCreation5mTokens sets the "cache_creation_5m_tokens" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateCacheCreation5mTokens() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldCacheCreation5mTokens)
return u
}
// AddCacheCreation5mTokens adds v to the "cache_creation_5m_tokens" field.
func (u *UsageLogUpsert) AddCacheCreation5mTokens(v int) *UsageLogUpsert {
u.Add(usagelog.FieldCacheCreation5mTokens, v)
return u
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (u *UsageLogUpsert) SetCacheCreation1hTokens(v int) *UsageLogUpsert {
u.Set(usagelog.FieldCacheCreation1hTokens, v)
return u
}
// UpdateCacheCreation1hTokens sets the "cache_creation_1h_tokens" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateCacheCreation1hTokens() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldCacheCreation1hTokens)
return u
}
// AddCacheCreation1hTokens adds v to the "cache_creation_1h_tokens" field.
func (u *UsageLogUpsert) AddCacheCreation1hTokens(v int) *UsageLogUpsert {
u.Add(usagelog.FieldCacheCreation1hTokens, v)
return u
}
// SetInputCost sets the "input_cost" field.
func (u *UsageLogUpsert) SetInputCost(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldInputCost, v)
return u
}
// UpdateInputCost sets the "input_cost" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateInputCost() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldInputCost)
return u
}
// AddInputCost adds v to the "input_cost" field.
func (u *UsageLogUpsert) AddInputCost(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldInputCost, v)
return u
}
// SetOutputCost sets the "output_cost" field.
func (u *UsageLogUpsert) SetOutputCost(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldOutputCost, v)
return u
}
// UpdateOutputCost sets the "output_cost" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateOutputCost() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldOutputCost)
return u
}
// AddOutputCost adds v to the "output_cost" field.
func (u *UsageLogUpsert) AddOutputCost(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldOutputCost, v)
return u
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (u *UsageLogUpsert) SetCacheCreationCost(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldCacheCreationCost, v)
return u
}
// UpdateCacheCreationCost sets the "cache_creation_cost" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateCacheCreationCost() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldCacheCreationCost)
return u
}
// AddCacheCreationCost adds v to the "cache_creation_cost" field.
func (u *UsageLogUpsert) AddCacheCreationCost(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldCacheCreationCost, v)
return u
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (u *UsageLogUpsert) SetCacheReadCost(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldCacheReadCost, v)
return u
}
// UpdateCacheReadCost sets the "cache_read_cost" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateCacheReadCost() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldCacheReadCost)
return u
}
// AddCacheReadCost adds v to the "cache_read_cost" field.
func (u *UsageLogUpsert) AddCacheReadCost(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldCacheReadCost, v)
return u
}
// SetTotalCost sets the "total_cost" field.
func (u *UsageLogUpsert) SetTotalCost(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldTotalCost, v)
return u
}
// UpdateTotalCost sets the "total_cost" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateTotalCost() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldTotalCost)
return u
}
// AddTotalCost adds v to the "total_cost" field.
func (u *UsageLogUpsert) AddTotalCost(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldTotalCost, v)
return u
}
// SetActualCost sets the "actual_cost" field.
func (u *UsageLogUpsert) SetActualCost(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldActualCost, v)
return u
}
// UpdateActualCost sets the "actual_cost" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateActualCost() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldActualCost)
return u
}
// AddActualCost adds v to the "actual_cost" field.
func (u *UsageLogUpsert) AddActualCost(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldActualCost, v)
return u
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (u *UsageLogUpsert) SetRateMultiplier(v float64) *UsageLogUpsert {
u.Set(usagelog.FieldRateMultiplier, v)
return u
}
// UpdateRateMultiplier sets the "rate_multiplier" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateRateMultiplier() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldRateMultiplier)
return u
}
// AddRateMultiplier adds v to the "rate_multiplier" field.
func (u *UsageLogUpsert) AddRateMultiplier(v float64) *UsageLogUpsert {
u.Add(usagelog.FieldRateMultiplier, v)
return u
}
// SetBillingType sets the "billing_type" field.
func (u *UsageLogUpsert) SetBillingType(v int8) *UsageLogUpsert {
u.Set(usagelog.FieldBillingType, v)
return u
}
// UpdateBillingType sets the "billing_type" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateBillingType() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldBillingType)
return u
}
// AddBillingType adds v to the "billing_type" field.
func (u *UsageLogUpsert) AddBillingType(v int8) *UsageLogUpsert {
u.Add(usagelog.FieldBillingType, v)
return u
}
// SetStream sets the "stream" field.
func (u *UsageLogUpsert) SetStream(v bool) *UsageLogUpsert {
u.Set(usagelog.FieldStream, v)
return u
}
// UpdateStream sets the "stream" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateStream() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldStream)
return u
}
// SetDurationMs sets the "duration_ms" field.
func (u *UsageLogUpsert) SetDurationMs(v int) *UsageLogUpsert {
u.Set(usagelog.FieldDurationMs, v)
return u
}
// UpdateDurationMs sets the "duration_ms" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateDurationMs() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldDurationMs)
return u
}
// AddDurationMs adds v to the "duration_ms" field.
func (u *UsageLogUpsert) AddDurationMs(v int) *UsageLogUpsert {
u.Add(usagelog.FieldDurationMs, v)
return u
}
// ClearDurationMs clears the value of the "duration_ms" field.
func (u *UsageLogUpsert) ClearDurationMs() *UsageLogUpsert {
u.SetNull(usagelog.FieldDurationMs)
return u
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (u *UsageLogUpsert) SetFirstTokenMs(v int) *UsageLogUpsert {
u.Set(usagelog.FieldFirstTokenMs, v)
return u
}
// UpdateFirstTokenMs sets the "first_token_ms" field to the value that was provided on create.
func (u *UsageLogUpsert) UpdateFirstTokenMs() *UsageLogUpsert {
u.SetExcluded(usagelog.FieldFirstTokenMs)
return u
}
// AddFirstTokenMs adds v to the "first_token_ms" field.
func (u *UsageLogUpsert) AddFirstTokenMs(v int) *UsageLogUpsert {
u.Add(usagelog.FieldFirstTokenMs, v)
return u
}
// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (u *UsageLogUpsert) ClearFirstTokenMs() *UsageLogUpsert {
u.SetNull(usagelog.FieldFirstTokenMs)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.UsageLog.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *UsageLogUpsertOne) UpdateNewValues() *UsageLogUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(usagelog.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageLog.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *UsageLogUpsertOne) Ignore() *UsageLogUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *UsageLogUpsertOne) DoNothing() *UsageLogUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the UsageLogCreate.OnConflict
// documentation for more info.
func (u *UsageLogUpsertOne) Update(set func(*UsageLogUpsert)) *UsageLogUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&UsageLogUpsert{UpdateSet: update})
}))
return u
}
// SetUserID sets the "user_id" field.
func (u *UsageLogUpsertOne) SetUserID(v int64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateUserID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateUserID()
})
}
// SetAPIKeyID sets the "api_key_id" field.
func (u *UsageLogUpsertOne) SetAPIKeyID(v int64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetAPIKeyID(v)
})
}
// UpdateAPIKeyID sets the "api_key_id" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateAPIKeyID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateAPIKeyID()
})
}
// SetAccountID sets the "account_id" field.
func (u *UsageLogUpsertOne) SetAccountID(v int64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetAccountID(v)
})
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateAccountID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateAccountID()
})
}
// SetRequestID sets the "request_id" field.
func (u *UsageLogUpsertOne) SetRequestID(v string) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetRequestID(v)
})
}
// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateRequestID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateRequestID()
})
}
// SetModel sets the "model" field.
func (u *UsageLogUpsertOne) SetModel(v string) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetModel(v)
})
}
// UpdateModel sets the "model" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateModel() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateModel()
})
}
// SetGroupID sets the "group_id" field.
func (u *UsageLogUpsertOne) SetGroupID(v int64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateGroupID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateGroupID()
})
}
// ClearGroupID clears the value of the "group_id" field.
func (u *UsageLogUpsertOne) ClearGroupID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.ClearGroupID()
})
}
// SetSubscriptionID sets the "subscription_id" field.
func (u *UsageLogUpsertOne) SetSubscriptionID(v int64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetSubscriptionID(v)
})
}
// UpdateSubscriptionID sets the "subscription_id" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateSubscriptionID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateSubscriptionID()
})
}
// ClearSubscriptionID clears the value of the "subscription_id" field.
func (u *UsageLogUpsertOne) ClearSubscriptionID() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.ClearSubscriptionID()
})
}
// SetInputTokens sets the "input_tokens" field.
func (u *UsageLogUpsertOne) SetInputTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetInputTokens(v)
})
}
// AddInputTokens adds v to the "input_tokens" field.
func (u *UsageLogUpsertOne) AddInputTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddInputTokens(v)
})
}
// UpdateInputTokens sets the "input_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateInputTokens() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateInputTokens()
})
}
// SetOutputTokens sets the "output_tokens" field.
func (u *UsageLogUpsertOne) SetOutputTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetOutputTokens(v)
})
}
// AddOutputTokens adds v to the "output_tokens" field.
func (u *UsageLogUpsertOne) AddOutputTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddOutputTokens(v)
})
}
// UpdateOutputTokens sets the "output_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateOutputTokens() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateOutputTokens()
})
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (u *UsageLogUpsertOne) SetCacheCreationTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreationTokens(v)
})
}
// AddCacheCreationTokens adds v to the "cache_creation_tokens" field.
func (u *UsageLogUpsertOne) AddCacheCreationTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreationTokens(v)
})
}
// UpdateCacheCreationTokens sets the "cache_creation_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateCacheCreationTokens() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreationTokens()
})
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (u *UsageLogUpsertOne) SetCacheReadTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheReadTokens(v)
})
}
// AddCacheReadTokens adds v to the "cache_read_tokens" field.
func (u *UsageLogUpsertOne) AddCacheReadTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheReadTokens(v)
})
}
// UpdateCacheReadTokens sets the "cache_read_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateCacheReadTokens() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheReadTokens()
})
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (u *UsageLogUpsertOne) SetCacheCreation5mTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreation5mTokens(v)
})
}
// AddCacheCreation5mTokens adds v to the "cache_creation_5m_tokens" field.
func (u *UsageLogUpsertOne) AddCacheCreation5mTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreation5mTokens(v)
})
}
// UpdateCacheCreation5mTokens sets the "cache_creation_5m_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateCacheCreation5mTokens() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreation5mTokens()
})
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (u *UsageLogUpsertOne) SetCacheCreation1hTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreation1hTokens(v)
})
}
// AddCacheCreation1hTokens adds v to the "cache_creation_1h_tokens" field.
func (u *UsageLogUpsertOne) AddCacheCreation1hTokens(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreation1hTokens(v)
})
}
// UpdateCacheCreation1hTokens sets the "cache_creation_1h_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateCacheCreation1hTokens() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreation1hTokens()
})
}
// SetInputCost sets the "input_cost" field.
func (u *UsageLogUpsertOne) SetInputCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetInputCost(v)
})
}
// AddInputCost adds v to the "input_cost" field.
func (u *UsageLogUpsertOne) AddInputCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddInputCost(v)
})
}
// UpdateInputCost sets the "input_cost" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateInputCost() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateInputCost()
})
}
// SetOutputCost sets the "output_cost" field.
func (u *UsageLogUpsertOne) SetOutputCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetOutputCost(v)
})
}
// AddOutputCost adds v to the "output_cost" field.
func (u *UsageLogUpsertOne) AddOutputCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddOutputCost(v)
})
}
// UpdateOutputCost sets the "output_cost" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateOutputCost() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateOutputCost()
})
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (u *UsageLogUpsertOne) SetCacheCreationCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreationCost(v)
})
}
// AddCacheCreationCost adds v to the "cache_creation_cost" field.
func (u *UsageLogUpsertOne) AddCacheCreationCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreationCost(v)
})
}
// UpdateCacheCreationCost sets the "cache_creation_cost" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateCacheCreationCost() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreationCost()
})
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (u *UsageLogUpsertOne) SetCacheReadCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheReadCost(v)
})
}
// AddCacheReadCost adds v to the "cache_read_cost" field.
func (u *UsageLogUpsertOne) AddCacheReadCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheReadCost(v)
})
}
// UpdateCacheReadCost sets the "cache_read_cost" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateCacheReadCost() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheReadCost()
})
}
// SetTotalCost sets the "total_cost" field.
func (u *UsageLogUpsertOne) SetTotalCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetTotalCost(v)
})
}
// AddTotalCost adds v to the "total_cost" field.
func (u *UsageLogUpsertOne) AddTotalCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddTotalCost(v)
})
}
// UpdateTotalCost sets the "total_cost" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateTotalCost() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateTotalCost()
})
}
// SetActualCost sets the "actual_cost" field.
func (u *UsageLogUpsertOne) SetActualCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetActualCost(v)
})
}
// AddActualCost adds v to the "actual_cost" field.
func (u *UsageLogUpsertOne) AddActualCost(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddActualCost(v)
})
}
// UpdateActualCost sets the "actual_cost" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateActualCost() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateActualCost()
})
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (u *UsageLogUpsertOne) SetRateMultiplier(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetRateMultiplier(v)
})
}
// AddRateMultiplier adds v to the "rate_multiplier" field.
func (u *UsageLogUpsertOne) AddRateMultiplier(v float64) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddRateMultiplier(v)
})
}
// UpdateRateMultiplier sets the "rate_multiplier" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateRateMultiplier() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateRateMultiplier()
})
}
// SetBillingType sets the "billing_type" field.
func (u *UsageLogUpsertOne) SetBillingType(v int8) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetBillingType(v)
})
}
// AddBillingType adds v to the "billing_type" field.
func (u *UsageLogUpsertOne) AddBillingType(v int8) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddBillingType(v)
})
}
// UpdateBillingType sets the "billing_type" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateBillingType() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateBillingType()
})
}
// SetStream sets the "stream" field.
func (u *UsageLogUpsertOne) SetStream(v bool) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetStream(v)
})
}
// UpdateStream sets the "stream" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateStream() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateStream()
})
}
// SetDurationMs sets the "duration_ms" field.
func (u *UsageLogUpsertOne) SetDurationMs(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetDurationMs(v)
})
}
// AddDurationMs adds v to the "duration_ms" field.
func (u *UsageLogUpsertOne) AddDurationMs(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddDurationMs(v)
})
}
// UpdateDurationMs sets the "duration_ms" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateDurationMs() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateDurationMs()
})
}
// ClearDurationMs clears the value of the "duration_ms" field.
func (u *UsageLogUpsertOne) ClearDurationMs() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.ClearDurationMs()
})
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (u *UsageLogUpsertOne) SetFirstTokenMs(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.SetFirstTokenMs(v)
})
}
// AddFirstTokenMs adds v to the "first_token_ms" field.
func (u *UsageLogUpsertOne) AddFirstTokenMs(v int) *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.AddFirstTokenMs(v)
})
}
// UpdateFirstTokenMs sets the "first_token_ms" field to the value that was provided on create.
func (u *UsageLogUpsertOne) UpdateFirstTokenMs() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateFirstTokenMs()
})
}
// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (u *UsageLogUpsertOne) ClearFirstTokenMs() *UsageLogUpsertOne {
return u.Update(func(s *UsageLogUpsert) {
s.ClearFirstTokenMs()
})
}
// Exec executes the query.
func (u *UsageLogUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for UsageLogCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *UsageLogUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *UsageLogUpsertOne) ID(ctx context.Context) (id int64, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *UsageLogUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// UsageLogCreateBulk is the builder for creating many UsageLog entities in bulk.
type UsageLogCreateBulk struct {
config
err error
builders []*UsageLogCreate
conflict []sql.ConflictOption
}
// Save creates the UsageLog entities in the database.
func (_c *UsageLogCreateBulk) Save(ctx context.Context) ([]*UsageLog, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*UsageLog, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*UsageLogMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
var err error
nodes[i], specs[i] = builder.createSpec()
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
spec.OnConflict = _c.conflict
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
if specs[i].ID.Value != nil {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(id)
}
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *UsageLogCreateBulk) SaveX(ctx context.Context) []*UsageLog {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UsageLogCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UsageLogCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageLog.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageLogUpsert) {
// SetUserID(v+v).
// }).
// Exec(ctx)
func (_c *UsageLogCreateBulk) OnConflict(opts ...sql.ConflictOption) *UsageLogUpsertBulk {
_c.conflict = opts
return &UsageLogUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageLog.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *UsageLogCreateBulk) OnConflictColumns(columns ...string) *UsageLogUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &UsageLogUpsertBulk{
create: _c,
}
}
// UsageLogUpsertBulk is the builder for "upsert"-ing
// a bulk of UsageLog nodes.
type UsageLogUpsertBulk struct {
create *UsageLogCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.UsageLog.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *UsageLogUpsertBulk) UpdateNewValues() *UsageLogUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(usagelog.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageLog.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *UsageLogUpsertBulk) Ignore() *UsageLogUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *UsageLogUpsertBulk) DoNothing() *UsageLogUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the UsageLogCreateBulk.OnConflict
// documentation for more info.
func (u *UsageLogUpsertBulk) Update(set func(*UsageLogUpsert)) *UsageLogUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&UsageLogUpsert{UpdateSet: update})
}))
return u
}
// SetUserID sets the "user_id" field.
func (u *UsageLogUpsertBulk) SetUserID(v int64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateUserID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateUserID()
})
}
// SetAPIKeyID sets the "api_key_id" field.
func (u *UsageLogUpsertBulk) SetAPIKeyID(v int64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetAPIKeyID(v)
})
}
// UpdateAPIKeyID sets the "api_key_id" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateAPIKeyID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateAPIKeyID()
})
}
// SetAccountID sets the "account_id" field.
func (u *UsageLogUpsertBulk) SetAccountID(v int64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetAccountID(v)
})
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateAccountID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateAccountID()
})
}
// SetRequestID sets the "request_id" field.
func (u *UsageLogUpsertBulk) SetRequestID(v string) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetRequestID(v)
})
}
// UpdateRequestID sets the "request_id" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateRequestID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateRequestID()
})
}
// SetModel sets the "model" field.
func (u *UsageLogUpsertBulk) SetModel(v string) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetModel(v)
})
}
// UpdateModel sets the "model" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateModel() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateModel()
})
}
// SetGroupID sets the "group_id" field.
func (u *UsageLogUpsertBulk) SetGroupID(v int64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateGroupID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateGroupID()
})
}
// ClearGroupID clears the value of the "group_id" field.
func (u *UsageLogUpsertBulk) ClearGroupID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.ClearGroupID()
})
}
// SetSubscriptionID sets the "subscription_id" field.
func (u *UsageLogUpsertBulk) SetSubscriptionID(v int64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetSubscriptionID(v)
})
}
// UpdateSubscriptionID sets the "subscription_id" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateSubscriptionID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateSubscriptionID()
})
}
// ClearSubscriptionID clears the value of the "subscription_id" field.
func (u *UsageLogUpsertBulk) ClearSubscriptionID() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.ClearSubscriptionID()
})
}
// SetInputTokens sets the "input_tokens" field.
func (u *UsageLogUpsertBulk) SetInputTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetInputTokens(v)
})
}
// AddInputTokens adds v to the "input_tokens" field.
func (u *UsageLogUpsertBulk) AddInputTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddInputTokens(v)
})
}
// UpdateInputTokens sets the "input_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateInputTokens() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateInputTokens()
})
}
// SetOutputTokens sets the "output_tokens" field.
func (u *UsageLogUpsertBulk) SetOutputTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetOutputTokens(v)
})
}
// AddOutputTokens adds v to the "output_tokens" field.
func (u *UsageLogUpsertBulk) AddOutputTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddOutputTokens(v)
})
}
// UpdateOutputTokens sets the "output_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateOutputTokens() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateOutputTokens()
})
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (u *UsageLogUpsertBulk) SetCacheCreationTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreationTokens(v)
})
}
// AddCacheCreationTokens adds v to the "cache_creation_tokens" field.
func (u *UsageLogUpsertBulk) AddCacheCreationTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreationTokens(v)
})
}
// UpdateCacheCreationTokens sets the "cache_creation_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateCacheCreationTokens() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreationTokens()
})
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (u *UsageLogUpsertBulk) SetCacheReadTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheReadTokens(v)
})
}
// AddCacheReadTokens adds v to the "cache_read_tokens" field.
func (u *UsageLogUpsertBulk) AddCacheReadTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheReadTokens(v)
})
}
// UpdateCacheReadTokens sets the "cache_read_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateCacheReadTokens() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheReadTokens()
})
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (u *UsageLogUpsertBulk) SetCacheCreation5mTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreation5mTokens(v)
})
}
// AddCacheCreation5mTokens adds v to the "cache_creation_5m_tokens" field.
func (u *UsageLogUpsertBulk) AddCacheCreation5mTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreation5mTokens(v)
})
}
// UpdateCacheCreation5mTokens sets the "cache_creation_5m_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateCacheCreation5mTokens() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreation5mTokens()
})
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (u *UsageLogUpsertBulk) SetCacheCreation1hTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreation1hTokens(v)
})
}
// AddCacheCreation1hTokens adds v to the "cache_creation_1h_tokens" field.
func (u *UsageLogUpsertBulk) AddCacheCreation1hTokens(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreation1hTokens(v)
})
}
// UpdateCacheCreation1hTokens sets the "cache_creation_1h_tokens" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateCacheCreation1hTokens() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreation1hTokens()
})
}
// SetInputCost sets the "input_cost" field.
func (u *UsageLogUpsertBulk) SetInputCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetInputCost(v)
})
}
// AddInputCost adds v to the "input_cost" field.
func (u *UsageLogUpsertBulk) AddInputCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddInputCost(v)
})
}
// UpdateInputCost sets the "input_cost" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateInputCost() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateInputCost()
})
}
// SetOutputCost sets the "output_cost" field.
func (u *UsageLogUpsertBulk) SetOutputCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetOutputCost(v)
})
}
// AddOutputCost adds v to the "output_cost" field.
func (u *UsageLogUpsertBulk) AddOutputCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddOutputCost(v)
})
}
// UpdateOutputCost sets the "output_cost" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateOutputCost() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateOutputCost()
})
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (u *UsageLogUpsertBulk) SetCacheCreationCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheCreationCost(v)
})
}
// AddCacheCreationCost adds v to the "cache_creation_cost" field.
func (u *UsageLogUpsertBulk) AddCacheCreationCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheCreationCost(v)
})
}
// UpdateCacheCreationCost sets the "cache_creation_cost" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateCacheCreationCost() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheCreationCost()
})
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (u *UsageLogUpsertBulk) SetCacheReadCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetCacheReadCost(v)
})
}
// AddCacheReadCost adds v to the "cache_read_cost" field.
func (u *UsageLogUpsertBulk) AddCacheReadCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddCacheReadCost(v)
})
}
// UpdateCacheReadCost sets the "cache_read_cost" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateCacheReadCost() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateCacheReadCost()
})
}
// SetTotalCost sets the "total_cost" field.
func (u *UsageLogUpsertBulk) SetTotalCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetTotalCost(v)
})
}
// AddTotalCost adds v to the "total_cost" field.
func (u *UsageLogUpsertBulk) AddTotalCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddTotalCost(v)
})
}
// UpdateTotalCost sets the "total_cost" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateTotalCost() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateTotalCost()
})
}
// SetActualCost sets the "actual_cost" field.
func (u *UsageLogUpsertBulk) SetActualCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetActualCost(v)
})
}
// AddActualCost adds v to the "actual_cost" field.
func (u *UsageLogUpsertBulk) AddActualCost(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddActualCost(v)
})
}
// UpdateActualCost sets the "actual_cost" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateActualCost() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateActualCost()
})
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (u *UsageLogUpsertBulk) SetRateMultiplier(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetRateMultiplier(v)
})
}
// AddRateMultiplier adds v to the "rate_multiplier" field.
func (u *UsageLogUpsertBulk) AddRateMultiplier(v float64) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddRateMultiplier(v)
})
}
// UpdateRateMultiplier sets the "rate_multiplier" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateRateMultiplier() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateRateMultiplier()
})
}
// SetBillingType sets the "billing_type" field.
func (u *UsageLogUpsertBulk) SetBillingType(v int8) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetBillingType(v)
})
}
// AddBillingType adds v to the "billing_type" field.
func (u *UsageLogUpsertBulk) AddBillingType(v int8) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddBillingType(v)
})
}
// UpdateBillingType sets the "billing_type" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateBillingType() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateBillingType()
})
}
// SetStream sets the "stream" field.
func (u *UsageLogUpsertBulk) SetStream(v bool) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetStream(v)
})
}
// UpdateStream sets the "stream" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateStream() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateStream()
})
}
// SetDurationMs sets the "duration_ms" field.
func (u *UsageLogUpsertBulk) SetDurationMs(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetDurationMs(v)
})
}
// AddDurationMs adds v to the "duration_ms" field.
func (u *UsageLogUpsertBulk) AddDurationMs(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddDurationMs(v)
})
}
// UpdateDurationMs sets the "duration_ms" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateDurationMs() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateDurationMs()
})
}
// ClearDurationMs clears the value of the "duration_ms" field.
func (u *UsageLogUpsertBulk) ClearDurationMs() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.ClearDurationMs()
})
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (u *UsageLogUpsertBulk) SetFirstTokenMs(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.SetFirstTokenMs(v)
})
}
// AddFirstTokenMs adds v to the "first_token_ms" field.
func (u *UsageLogUpsertBulk) AddFirstTokenMs(v int) *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.AddFirstTokenMs(v)
})
}
// UpdateFirstTokenMs sets the "first_token_ms" field to the value that was provided on create.
func (u *UsageLogUpsertBulk) UpdateFirstTokenMs() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.UpdateFirstTokenMs()
})
}
// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (u *UsageLogUpsertBulk) ClearFirstTokenMs() *UsageLogUpsertBulk {
return u.Update(func(s *UsageLogUpsert) {
s.ClearFirstTokenMs()
})
}
// Exec executes the query.
func (u *UsageLogUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the UsageLogCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for UsageLogCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *UsageLogUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
)
// UsageLogDelete is the builder for deleting a UsageLog entity.
type UsageLogDelete struct {
config
hooks []Hook
mutation *UsageLogMutation
}
// Where appends a list predicates to the UsageLogDelete builder.
func (_d *UsageLogDelete) Where(ps ...predicate.UsageLog) *UsageLogDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *UsageLogDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *UsageLogDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *UsageLogDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(usagelog.Table, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// UsageLogDeleteOne is the builder for deleting a single UsageLog entity.
type UsageLogDeleteOne struct {
_d *UsageLogDelete
}
// Where appends a list predicates to the UsageLogDelete builder.
func (_d *UsageLogDeleteOne) Where(ps ...predicate.UsageLog) *UsageLogDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *UsageLogDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{usagelog.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *UsageLogDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"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/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
// UsageLogQuery is the builder for querying UsageLog entities.
type UsageLogQuery struct {
config
ctx *QueryContext
order []usagelog.OrderOption
inters []Interceptor
predicates []predicate.UsageLog
withUser *UserQuery
withAPIKey *ApiKeyQuery
withAccount *AccountQuery
withGroup *GroupQuery
withSubscription *UserSubscriptionQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the UsageLogQuery builder.
func (_q *UsageLogQuery) Where(ps ...predicate.UsageLog) *UsageLogQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *UsageLogQuery) Limit(limit int) *UsageLogQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *UsageLogQuery) Offset(offset int) *UsageLogQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *UsageLogQuery) Unique(unique bool) *UsageLogQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *UsageLogQuery) Order(o ...usagelog.OrderOption) *UsageLogQuery {
_q.order = append(_q.order, o...)
return _q
}
// QueryUser chains the current query on the "user" edge.
func (_q *UsageLogQuery) QueryUser() *UserQuery {
query := (&UserClient{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(usagelog.Table, usagelog.FieldID, selector),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, usagelog.UserTable, usagelog.UserColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryAPIKey chains the current query on the "api_key" edge.
func (_q *UsageLogQuery) QueryAPIKey() *ApiKeyQuery {
query := (&ApiKeyClient{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(usagelog.Table, usagelog.FieldID, selector),
sqlgraph.To(apikey.Table, apikey.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, usagelog.APIKeyTable, usagelog.APIKeyColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryAccount chains the current query on the "account" edge.
func (_q *UsageLogQuery) QueryAccount() *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(usagelog.Table, usagelog.FieldID, selector),
sqlgraph.To(account.Table, account.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, usagelog.AccountTable, usagelog.AccountColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryGroup chains the current query on the "group" edge.
func (_q *UsageLogQuery) QueryGroup() *GroupQuery {
query := (&GroupClient{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(usagelog.Table, usagelog.FieldID, selector),
sqlgraph.To(group.Table, group.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, usagelog.GroupTable, usagelog.GroupColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QuerySubscription chains the current query on the "subscription" edge.
func (_q *UsageLogQuery) QuerySubscription() *UserSubscriptionQuery {
query := (&UserSubscriptionClient{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(usagelog.Table, usagelog.FieldID, selector),
sqlgraph.To(usersubscription.Table, usersubscription.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, usagelog.SubscriptionTable, usagelog.SubscriptionColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first UsageLog entity from the query.
// Returns a *NotFoundError when no UsageLog was found.
func (_q *UsageLogQuery) First(ctx context.Context) (*UsageLog, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{usagelog.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *UsageLogQuery) FirstX(ctx context.Context) *UsageLog {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first UsageLog ID from the query.
// Returns a *NotFoundError when no UsageLog ID was found.
func (_q *UsageLogQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{usagelog.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *UsageLogQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single UsageLog entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one UsageLog entity is found.
// Returns a *NotFoundError when no UsageLog entities are found.
func (_q *UsageLogQuery) Only(ctx context.Context) (*UsageLog, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{usagelog.Label}
default:
return nil, &NotSingularError{usagelog.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *UsageLogQuery) OnlyX(ctx context.Context) *UsageLog {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only UsageLog ID in the query.
// Returns a *NotSingularError when more than one UsageLog ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *UsageLogQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{usagelog.Label}
default:
err = &NotSingularError{usagelog.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *UsageLogQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of UsageLogs.
func (_q *UsageLogQuery) All(ctx context.Context) ([]*UsageLog, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*UsageLog, *UsageLogQuery]()
return withInterceptors[[]*UsageLog](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *UsageLogQuery) AllX(ctx context.Context) []*UsageLog {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of UsageLog IDs.
func (_q *UsageLogQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(usagelog.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *UsageLogQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *UsageLogQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*UsageLogQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *UsageLogQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *UsageLogQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *UsageLogQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the UsageLogQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *UsageLogQuery) Clone() *UsageLogQuery {
if _q == nil {
return nil
}
return &UsageLogQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]usagelog.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.UsageLog{}, _q.predicates...),
withUser: _q.withUser.Clone(),
withAPIKey: _q.withAPIKey.Clone(),
withAccount: _q.withAccount.Clone(),
withGroup: _q.withGroup.Clone(),
withSubscription: _q.withSubscription.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// WithUser tells the query-builder to eager-load the nodes that are connected to
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UsageLogQuery) WithUser(opts ...func(*UserQuery)) *UsageLogQuery {
query := (&UserClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withUser = query
return _q
}
// WithAPIKey tells the query-builder to eager-load the nodes that are connected to
// the "api_key" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UsageLogQuery) WithAPIKey(opts ...func(*ApiKeyQuery)) *UsageLogQuery {
query := (&ApiKeyClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withAPIKey = query
return _q
}
// WithAccount tells the query-builder to eager-load the nodes that are connected to
// the "account" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UsageLogQuery) WithAccount(opts ...func(*AccountQuery)) *UsageLogQuery {
query := (&AccountClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withAccount = query
return _q
}
// WithGroup tells the query-builder to eager-load the nodes that are connected to
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UsageLogQuery) WithGroup(opts ...func(*GroupQuery)) *UsageLogQuery {
query := (&GroupClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withGroup = query
return _q
}
// WithSubscription tells the query-builder to eager-load the nodes that are connected to
// the "subscription" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UsageLogQuery) WithSubscription(opts ...func(*UserSubscriptionQuery)) *UsageLogQuery {
query := (&UserSubscriptionClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withSubscription = 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.
//
// Example:
//
// var v []struct {
// UserID int64 `json:"user_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.UsageLog.Query().
// GroupBy(usagelog.FieldUserID).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *UsageLogQuery) GroupBy(field string, fields ...string) *UsageLogGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &UsageLogGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = usagelog.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// UserID int64 `json:"user_id,omitempty"`
// }
//
// client.UsageLog.Query().
// Select(usagelog.FieldUserID).
// Scan(ctx, &v)
func (_q *UsageLogQuery) Select(fields ...string) *UsageLogSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &UsageLogSelect{UsageLogQuery: _q}
sbuild.label = usagelog.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a UsageLogSelect configured with the given aggregations.
func (_q *UsageLogQuery) Aggregate(fns ...AggregateFunc) *UsageLogSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *UsageLogQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !usagelog.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *UsageLogQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*UsageLog, error) {
var (
nodes = []*UsageLog{}
_spec = _q.querySpec()
loadedTypes = [5]bool{
_q.withUser != nil,
_q.withAPIKey != nil,
_q.withAccount != nil,
_q.withGroup != nil,
_q.withSubscription != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*UsageLog).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &UsageLog{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := _q.withUser; query != nil {
if err := _q.loadUser(ctx, query, nodes, nil,
func(n *UsageLog, e *User) { n.Edges.User = e }); err != nil {
return nil, err
}
}
if query := _q.withAPIKey; query != nil {
if err := _q.loadAPIKey(ctx, query, nodes, nil,
func(n *UsageLog, e *ApiKey) { n.Edges.APIKey = e }); err != nil {
return nil, err
}
}
if query := _q.withAccount; query != nil {
if err := _q.loadAccount(ctx, query, nodes, nil,
func(n *UsageLog, e *Account) { n.Edges.Account = e }); err != nil {
return nil, err
}
}
if query := _q.withGroup; query != nil {
if err := _q.loadGroup(ctx, query, nodes, nil,
func(n *UsageLog, e *Group) { n.Edges.Group = e }); err != nil {
return nil, err
}
}
if query := _q.withSubscription; query != nil {
if err := _q.loadSubscription(ctx, query, nodes, nil,
func(n *UsageLog, e *UserSubscription) { n.Edges.Subscription = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *UsageLogQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*UsageLog, init func(*UsageLog), assign func(*UsageLog, *User)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*UsageLog)
for i := range nodes {
fk := nodes[i].UserID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(user.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *UsageLogQuery) loadAPIKey(ctx context.Context, query *ApiKeyQuery, nodes []*UsageLog, init func(*UsageLog), assign func(*UsageLog, *ApiKey)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*UsageLog)
for i := range nodes {
fk := nodes[i].APIKeyID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(apikey.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "api_key_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *UsageLogQuery) loadAccount(ctx context.Context, query *AccountQuery, nodes []*UsageLog, init func(*UsageLog), assign func(*UsageLog, *Account)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*UsageLog)
for i := range nodes {
fk := nodes[i].AccountID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(account.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "account_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *UsageLogQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*UsageLog, init func(*UsageLog), assign func(*UsageLog, *Group)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*UsageLog)
for i := range nodes {
if nodes[i].GroupID == nil {
continue
}
fk := *nodes[i].GroupID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *UsageLogQuery) loadSubscription(ctx context.Context, query *UserSubscriptionQuery, nodes []*UsageLog, init func(*UsageLog), assign func(*UsageLog, *UserSubscription)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*UsageLog)
for i := range nodes {
if nodes[i].SubscriptionID == nil {
continue
}
fk := *nodes[i].SubscriptionID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(usersubscription.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "subscription_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *UsageLogQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *UsageLogQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(usagelog.Table, usagelog.Columns, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, usagelog.FieldID)
for i := range fields {
if fields[i] != usagelog.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
if _q.withUser != nil {
_spec.Node.AddColumnOnce(usagelog.FieldUserID)
}
if _q.withAPIKey != nil {
_spec.Node.AddColumnOnce(usagelog.FieldAPIKeyID)
}
if _q.withAccount != nil {
_spec.Node.AddColumnOnce(usagelog.FieldAccountID)
}
if _q.withGroup != nil {
_spec.Node.AddColumnOnce(usagelog.FieldGroupID)
}
if _q.withSubscription != nil {
_spec.Node.AddColumnOnce(usagelog.FieldSubscriptionID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *UsageLogQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(usagelog.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = usagelog.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// UsageLogGroupBy is the group-by builder for UsageLog entities.
type UsageLogGroupBy struct {
selector
build *UsageLogQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *UsageLogGroupBy) Aggregate(fns ...AggregateFunc) *UsageLogGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *UsageLogGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*UsageLogQuery, *UsageLogGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *UsageLogGroupBy) sqlScan(ctx context.Context, root *UsageLogQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// UsageLogSelect is the builder for selecting fields of UsageLog entities.
type UsageLogSelect struct {
*UsageLogQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *UsageLogSelect) Aggregate(fns ...AggregateFunc) *UsageLogSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *UsageLogSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*UsageLogQuery, *UsageLogSelect](ctx, _s.UsageLogQuery, _s, _s.inters, v)
}
func (_s *UsageLogSelect) sqlScan(ctx context.Context, root *UsageLogQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"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/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
// UsageLogUpdate is the builder for updating UsageLog entities.
type UsageLogUpdate struct {
config
hooks []Hook
mutation *UsageLogMutation
}
// Where appends a list predicates to the UsageLogUpdate builder.
func (_u *UsageLogUpdate) Where(ps ...predicate.UsageLog) *UsageLogUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUserID sets the "user_id" field.
func (_u *UsageLogUpdate) SetUserID(v int64) *UsageLogUpdate {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableUserID(v *int64) *UsageLogUpdate {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// SetAPIKeyID sets the "api_key_id" field.
func (_u *UsageLogUpdate) SetAPIKeyID(v int64) *UsageLogUpdate {
_u.mutation.SetAPIKeyID(v)
return _u
}
// SetNillableAPIKeyID sets the "api_key_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableAPIKeyID(v *int64) *UsageLogUpdate {
if v != nil {
_u.SetAPIKeyID(*v)
}
return _u
}
// SetAccountID sets the "account_id" field.
func (_u *UsageLogUpdate) SetAccountID(v int64) *UsageLogUpdate {
_u.mutation.SetAccountID(v)
return _u
}
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableAccountID(v *int64) *UsageLogUpdate {
if v != nil {
_u.SetAccountID(*v)
}
return _u
}
// SetRequestID sets the "request_id" field.
func (_u *UsageLogUpdate) SetRequestID(v string) *UsageLogUpdate {
_u.mutation.SetRequestID(v)
return _u
}
// SetNillableRequestID sets the "request_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableRequestID(v *string) *UsageLogUpdate {
if v != nil {
_u.SetRequestID(*v)
}
return _u
}
// SetModel sets the "model" field.
func (_u *UsageLogUpdate) SetModel(v string) *UsageLogUpdate {
_u.mutation.SetModel(v)
return _u
}
// SetNillableModel sets the "model" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableModel(v *string) *UsageLogUpdate {
if v != nil {
_u.SetModel(*v)
}
return _u
}
// SetGroupID sets the "group_id" field.
func (_u *UsageLogUpdate) SetGroupID(v int64) *UsageLogUpdate {
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableGroupID(v *int64) *UsageLogUpdate {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// ClearGroupID clears the value of the "group_id" field.
func (_u *UsageLogUpdate) ClearGroupID() *UsageLogUpdate {
_u.mutation.ClearGroupID()
return _u
}
// SetSubscriptionID sets the "subscription_id" field.
func (_u *UsageLogUpdate) SetSubscriptionID(v int64) *UsageLogUpdate {
_u.mutation.SetSubscriptionID(v)
return _u
}
// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableSubscriptionID(v *int64) *UsageLogUpdate {
if v != nil {
_u.SetSubscriptionID(*v)
}
return _u
}
// ClearSubscriptionID clears the value of the "subscription_id" field.
func (_u *UsageLogUpdate) ClearSubscriptionID() *UsageLogUpdate {
_u.mutation.ClearSubscriptionID()
return _u
}
// SetInputTokens sets the "input_tokens" field.
func (_u *UsageLogUpdate) SetInputTokens(v int) *UsageLogUpdate {
_u.mutation.ResetInputTokens()
_u.mutation.SetInputTokens(v)
return _u
}
// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableInputTokens(v *int) *UsageLogUpdate {
if v != nil {
_u.SetInputTokens(*v)
}
return _u
}
// AddInputTokens adds value to the "input_tokens" field.
func (_u *UsageLogUpdate) AddInputTokens(v int) *UsageLogUpdate {
_u.mutation.AddInputTokens(v)
return _u
}
// SetOutputTokens sets the "output_tokens" field.
func (_u *UsageLogUpdate) SetOutputTokens(v int) *UsageLogUpdate {
_u.mutation.ResetOutputTokens()
_u.mutation.SetOutputTokens(v)
return _u
}
// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableOutputTokens(v *int) *UsageLogUpdate {
if v != nil {
_u.SetOutputTokens(*v)
}
return _u
}
// AddOutputTokens adds value to the "output_tokens" field.
func (_u *UsageLogUpdate) AddOutputTokens(v int) *UsageLogUpdate {
_u.mutation.AddOutputTokens(v)
return _u
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (_u *UsageLogUpdate) SetCacheCreationTokens(v int) *UsageLogUpdate {
_u.mutation.ResetCacheCreationTokens()
_u.mutation.SetCacheCreationTokens(v)
return _u
}
// SetNillableCacheCreationTokens sets the "cache_creation_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreationTokens(v *int) *UsageLogUpdate {
if v != nil {
_u.SetCacheCreationTokens(*v)
}
return _u
}
// AddCacheCreationTokens adds value to the "cache_creation_tokens" field.
func (_u *UsageLogUpdate) AddCacheCreationTokens(v int) *UsageLogUpdate {
_u.mutation.AddCacheCreationTokens(v)
return _u
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (_u *UsageLogUpdate) SetCacheReadTokens(v int) *UsageLogUpdate {
_u.mutation.ResetCacheReadTokens()
_u.mutation.SetCacheReadTokens(v)
return _u
}
// SetNillableCacheReadTokens sets the "cache_read_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheReadTokens(v *int) *UsageLogUpdate {
if v != nil {
_u.SetCacheReadTokens(*v)
}
return _u
}
// AddCacheReadTokens adds value to the "cache_read_tokens" field.
func (_u *UsageLogUpdate) AddCacheReadTokens(v int) *UsageLogUpdate {
_u.mutation.AddCacheReadTokens(v)
return _u
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdate) SetCacheCreation5mTokens(v int) *UsageLogUpdate {
_u.mutation.ResetCacheCreation5mTokens()
_u.mutation.SetCacheCreation5mTokens(v)
return _u
}
// SetNillableCacheCreation5mTokens sets the "cache_creation_5m_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreation5mTokens(v *int) *UsageLogUpdate {
if v != nil {
_u.SetCacheCreation5mTokens(*v)
}
return _u
}
// AddCacheCreation5mTokens adds value to the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdate) AddCacheCreation5mTokens(v int) *UsageLogUpdate {
_u.mutation.AddCacheCreation5mTokens(v)
return _u
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdate) SetCacheCreation1hTokens(v int) *UsageLogUpdate {
_u.mutation.ResetCacheCreation1hTokens()
_u.mutation.SetCacheCreation1hTokens(v)
return _u
}
// SetNillableCacheCreation1hTokens sets the "cache_creation_1h_tokens" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreation1hTokens(v *int) *UsageLogUpdate {
if v != nil {
_u.SetCacheCreation1hTokens(*v)
}
return _u
}
// AddCacheCreation1hTokens adds value to the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdate) AddCacheCreation1hTokens(v int) *UsageLogUpdate {
_u.mutation.AddCacheCreation1hTokens(v)
return _u
}
// SetInputCost sets the "input_cost" field.
func (_u *UsageLogUpdate) SetInputCost(v float64) *UsageLogUpdate {
_u.mutation.ResetInputCost()
_u.mutation.SetInputCost(v)
return _u
}
// SetNillableInputCost sets the "input_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableInputCost(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetInputCost(*v)
}
return _u
}
// AddInputCost adds value to the "input_cost" field.
func (_u *UsageLogUpdate) AddInputCost(v float64) *UsageLogUpdate {
_u.mutation.AddInputCost(v)
return _u
}
// SetOutputCost sets the "output_cost" field.
func (_u *UsageLogUpdate) SetOutputCost(v float64) *UsageLogUpdate {
_u.mutation.ResetOutputCost()
_u.mutation.SetOutputCost(v)
return _u
}
// SetNillableOutputCost sets the "output_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableOutputCost(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetOutputCost(*v)
}
return _u
}
// AddOutputCost adds value to the "output_cost" field.
func (_u *UsageLogUpdate) AddOutputCost(v float64) *UsageLogUpdate {
_u.mutation.AddOutputCost(v)
return _u
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (_u *UsageLogUpdate) SetCacheCreationCost(v float64) *UsageLogUpdate {
_u.mutation.ResetCacheCreationCost()
_u.mutation.SetCacheCreationCost(v)
return _u
}
// SetNillableCacheCreationCost sets the "cache_creation_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheCreationCost(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetCacheCreationCost(*v)
}
return _u
}
// AddCacheCreationCost adds value to the "cache_creation_cost" field.
func (_u *UsageLogUpdate) AddCacheCreationCost(v float64) *UsageLogUpdate {
_u.mutation.AddCacheCreationCost(v)
return _u
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (_u *UsageLogUpdate) SetCacheReadCost(v float64) *UsageLogUpdate {
_u.mutation.ResetCacheReadCost()
_u.mutation.SetCacheReadCost(v)
return _u
}
// SetNillableCacheReadCost sets the "cache_read_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableCacheReadCost(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetCacheReadCost(*v)
}
return _u
}
// AddCacheReadCost adds value to the "cache_read_cost" field.
func (_u *UsageLogUpdate) AddCacheReadCost(v float64) *UsageLogUpdate {
_u.mutation.AddCacheReadCost(v)
return _u
}
// SetTotalCost sets the "total_cost" field.
func (_u *UsageLogUpdate) SetTotalCost(v float64) *UsageLogUpdate {
_u.mutation.ResetTotalCost()
_u.mutation.SetTotalCost(v)
return _u
}
// SetNillableTotalCost sets the "total_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableTotalCost(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetTotalCost(*v)
}
return _u
}
// AddTotalCost adds value to the "total_cost" field.
func (_u *UsageLogUpdate) AddTotalCost(v float64) *UsageLogUpdate {
_u.mutation.AddTotalCost(v)
return _u
}
// SetActualCost sets the "actual_cost" field.
func (_u *UsageLogUpdate) SetActualCost(v float64) *UsageLogUpdate {
_u.mutation.ResetActualCost()
_u.mutation.SetActualCost(v)
return _u
}
// SetNillableActualCost sets the "actual_cost" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableActualCost(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetActualCost(*v)
}
return _u
}
// AddActualCost adds value to the "actual_cost" field.
func (_u *UsageLogUpdate) AddActualCost(v float64) *UsageLogUpdate {
_u.mutation.AddActualCost(v)
return _u
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *UsageLogUpdate) SetRateMultiplier(v float64) *UsageLogUpdate {
_u.mutation.ResetRateMultiplier()
_u.mutation.SetRateMultiplier(v)
return _u
}
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableRateMultiplier(v *float64) *UsageLogUpdate {
if v != nil {
_u.SetRateMultiplier(*v)
}
return _u
}
// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *UsageLogUpdate) AddRateMultiplier(v float64) *UsageLogUpdate {
_u.mutation.AddRateMultiplier(v)
return _u
}
// SetBillingType sets the "billing_type" field.
func (_u *UsageLogUpdate) SetBillingType(v int8) *UsageLogUpdate {
_u.mutation.ResetBillingType()
_u.mutation.SetBillingType(v)
return _u
}
// SetNillableBillingType sets the "billing_type" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableBillingType(v *int8) *UsageLogUpdate {
if v != nil {
_u.SetBillingType(*v)
}
return _u
}
// AddBillingType adds value to the "billing_type" field.
func (_u *UsageLogUpdate) AddBillingType(v int8) *UsageLogUpdate {
_u.mutation.AddBillingType(v)
return _u
}
// SetStream sets the "stream" field.
func (_u *UsageLogUpdate) SetStream(v bool) *UsageLogUpdate {
_u.mutation.SetStream(v)
return _u
}
// SetNillableStream sets the "stream" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableStream(v *bool) *UsageLogUpdate {
if v != nil {
_u.SetStream(*v)
}
return _u
}
// SetDurationMs sets the "duration_ms" field.
func (_u *UsageLogUpdate) SetDurationMs(v int) *UsageLogUpdate {
_u.mutation.ResetDurationMs()
_u.mutation.SetDurationMs(v)
return _u
}
// SetNillableDurationMs sets the "duration_ms" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableDurationMs(v *int) *UsageLogUpdate {
if v != nil {
_u.SetDurationMs(*v)
}
return _u
}
// AddDurationMs adds value to the "duration_ms" field.
func (_u *UsageLogUpdate) AddDurationMs(v int) *UsageLogUpdate {
_u.mutation.AddDurationMs(v)
return _u
}
// ClearDurationMs clears the value of the "duration_ms" field.
func (_u *UsageLogUpdate) ClearDurationMs() *UsageLogUpdate {
_u.mutation.ClearDurationMs()
return _u
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (_u *UsageLogUpdate) SetFirstTokenMs(v int) *UsageLogUpdate {
_u.mutation.ResetFirstTokenMs()
_u.mutation.SetFirstTokenMs(v)
return _u
}
// SetNillableFirstTokenMs sets the "first_token_ms" field if the given value is not nil.
func (_u *UsageLogUpdate) SetNillableFirstTokenMs(v *int) *UsageLogUpdate {
if v != nil {
_u.SetFirstTokenMs(*v)
}
return _u
}
// AddFirstTokenMs adds value to the "first_token_ms" field.
func (_u *UsageLogUpdate) AddFirstTokenMs(v int) *UsageLogUpdate {
_u.mutation.AddFirstTokenMs(v)
return _u
}
// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (_u *UsageLogUpdate) ClearFirstTokenMs() *UsageLogUpdate {
_u.mutation.ClearFirstTokenMs()
return _u
}
// SetUser sets the "user" edge to the User entity.
func (_u *UsageLogUpdate) SetUser(v *User) *UsageLogUpdate {
return _u.SetUserID(v.ID)
}
// SetAPIKey sets the "api_key" edge to the ApiKey entity.
func (_u *UsageLogUpdate) SetAPIKey(v *ApiKey) *UsageLogUpdate {
return _u.SetAPIKeyID(v.ID)
}
// SetAccount sets the "account" edge to the Account entity.
func (_u *UsageLogUpdate) SetAccount(v *Account) *UsageLogUpdate {
return _u.SetAccountID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_u *UsageLogUpdate) SetGroup(v *Group) *UsageLogUpdate {
return _u.SetGroupID(v.ID)
}
// SetSubscription sets the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdate) SetSubscription(v *UserSubscription) *UsageLogUpdate {
return _u.SetSubscriptionID(v.ID)
}
// Mutation returns the UsageLogMutation object of the builder.
func (_u *UsageLogUpdate) Mutation() *UsageLogMutation {
return _u.mutation
}
// ClearUser clears the "user" edge to the User entity.
func (_u *UsageLogUpdate) ClearUser() *UsageLogUpdate {
_u.mutation.ClearUser()
return _u
}
// ClearAPIKey clears the "api_key" edge to the ApiKey entity.
func (_u *UsageLogUpdate) ClearAPIKey() *UsageLogUpdate {
_u.mutation.ClearAPIKey()
return _u
}
// ClearAccount clears the "account" edge to the Account entity.
func (_u *UsageLogUpdate) ClearAccount() *UsageLogUpdate {
_u.mutation.ClearAccount()
return _u
}
// ClearGroup clears the "group" edge to the Group entity.
func (_u *UsageLogUpdate) ClearGroup() *UsageLogUpdate {
_u.mutation.ClearGroup()
return _u
}
// ClearSubscription clears the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdate) ClearSubscription() *UsageLogUpdate {
_u.mutation.ClearSubscription()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *UsageLogUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *UsageLogUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *UsageLogUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *UsageLogUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *UsageLogUpdate) check() error {
if v, ok := _u.mutation.RequestID(); ok {
if err := usagelog.RequestIDValidator(v); err != nil {
return &ValidationError{Name: "request_id", err: fmt.Errorf(`ent: validator failed for field "UsageLog.request_id": %w`, err)}
}
}
if v, ok := _u.mutation.Model(); ok {
if err := usagelog.ModelValidator(v); err != nil {
return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "UsageLog.model": %w`, err)}
}
}
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "UsageLog.user"`)
}
if _u.mutation.APIKeyCleared() && len(_u.mutation.APIKeyIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "UsageLog.api_key"`)
}
if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "UsageLog.account"`)
}
return nil
}
func (_u *UsageLogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(usagelog.Table, usagelog.Columns, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.RequestID(); ok {
_spec.SetField(usagelog.FieldRequestID, field.TypeString, value)
}
if value, ok := _u.mutation.Model(); ok {
_spec.SetField(usagelog.FieldModel, field.TypeString, value)
}
if value, ok := _u.mutation.InputTokens(); ok {
_spec.SetField(usagelog.FieldInputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedInputTokens(); ok {
_spec.AddField(usagelog.FieldInputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.OutputTokens(); ok {
_spec.SetField(usagelog.FieldOutputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedOutputTokens(); ok {
_spec.AddField(usagelog.FieldOutputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheCreationTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheCreationTokens(); ok {
_spec.AddField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheReadTokens(); ok {
_spec.SetField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheReadTokens(); ok {
_spec.AddField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheCreation5mTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheCreation5mTokens(); ok {
_spec.AddField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheCreation1hTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheCreation1hTokens(); ok {
_spec.AddField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.InputCost(); ok {
_spec.SetField(usagelog.FieldInputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedInputCost(); ok {
_spec.AddField(usagelog.FieldInputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.OutputCost(); ok {
_spec.SetField(usagelog.FieldOutputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedOutputCost(); ok {
_spec.AddField(usagelog.FieldOutputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.CacheCreationCost(); ok {
_spec.SetField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedCacheCreationCost(); ok {
_spec.AddField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.CacheReadCost(); ok {
_spec.SetField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedCacheReadCost(); ok {
_spec.AddField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.TotalCost(); ok {
_spec.SetField(usagelog.FieldTotalCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedTotalCost(); ok {
_spec.AddField(usagelog.FieldTotalCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.ActualCost(); ok {
_spec.SetField(usagelog.FieldActualCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedActualCost(); ok {
_spec.AddField(usagelog.FieldActualCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.RateMultiplier(); ok {
_spec.SetField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedRateMultiplier(); ok {
_spec.AddField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.BillingType(); ok {
_spec.SetField(usagelog.FieldBillingType, field.TypeInt8, value)
}
if value, ok := _u.mutation.AddedBillingType(); ok {
_spec.AddField(usagelog.FieldBillingType, field.TypeInt8, value)
}
if value, ok := _u.mutation.Stream(); ok {
_spec.SetField(usagelog.FieldStream, field.TypeBool, value)
}
if value, ok := _u.mutation.DurationMs(); ok {
_spec.SetField(usagelog.FieldDurationMs, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedDurationMs(); ok {
_spec.AddField(usagelog.FieldDurationMs, field.TypeInt, value)
}
if _u.mutation.DurationMsCleared() {
_spec.ClearField(usagelog.FieldDurationMs, field.TypeInt)
}
if value, ok := _u.mutation.FirstTokenMs(); ok {
_spec.SetField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedFirstTokenMs(); ok {
_spec.AddField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
}
if _u.mutation.FirstTokenMsCleared() {
_spec.ClearField(usagelog.FieldFirstTokenMs, field.TypeInt)
}
if _u.mutation.UserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.UserTable,
Columns: []string{usagelog.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.UserTable,
Columns: []string{usagelog.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.APIKeyCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.APIKeyTable,
Columns: []string{usagelog.APIKeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.APIKeyIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.APIKeyTable,
Columns: []string{usagelog.APIKeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(apikey.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.AccountCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.AccountTable,
Columns: []string{usagelog.AccountColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.AccountTable,
Columns: []string{usagelog.AccountColumn},
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 _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.GroupTable,
Columns: []string{usagelog.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.GroupTable,
Columns: []string{usagelog.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SubscriptionCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.SubscriptionTable,
Columns: []string{usagelog.SubscriptionColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SubscriptionIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.SubscriptionTable,
Columns: []string{usagelog.SubscriptionColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersubscription.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{usagelog.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// UsageLogUpdateOne is the builder for updating a single UsageLog entity.
type UsageLogUpdateOne struct {
config
fields []string
hooks []Hook
mutation *UsageLogMutation
}
// SetUserID sets the "user_id" field.
func (_u *UsageLogUpdateOne) SetUserID(v int64) *UsageLogUpdateOne {
_u.mutation.SetUserID(v)
return _u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableUserID(v *int64) *UsageLogUpdateOne {
if v != nil {
_u.SetUserID(*v)
}
return _u
}
// SetAPIKeyID sets the "api_key_id" field.
func (_u *UsageLogUpdateOne) SetAPIKeyID(v int64) *UsageLogUpdateOne {
_u.mutation.SetAPIKeyID(v)
return _u
}
// SetNillableAPIKeyID sets the "api_key_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableAPIKeyID(v *int64) *UsageLogUpdateOne {
if v != nil {
_u.SetAPIKeyID(*v)
}
return _u
}
// SetAccountID sets the "account_id" field.
func (_u *UsageLogUpdateOne) SetAccountID(v int64) *UsageLogUpdateOne {
_u.mutation.SetAccountID(v)
return _u
}
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableAccountID(v *int64) *UsageLogUpdateOne {
if v != nil {
_u.SetAccountID(*v)
}
return _u
}
// SetRequestID sets the "request_id" field.
func (_u *UsageLogUpdateOne) SetRequestID(v string) *UsageLogUpdateOne {
_u.mutation.SetRequestID(v)
return _u
}
// SetNillableRequestID sets the "request_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableRequestID(v *string) *UsageLogUpdateOne {
if v != nil {
_u.SetRequestID(*v)
}
return _u
}
// SetModel sets the "model" field.
func (_u *UsageLogUpdateOne) SetModel(v string) *UsageLogUpdateOne {
_u.mutation.SetModel(v)
return _u
}
// SetNillableModel sets the "model" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableModel(v *string) *UsageLogUpdateOne {
if v != nil {
_u.SetModel(*v)
}
return _u
}
// SetGroupID sets the "group_id" field.
func (_u *UsageLogUpdateOne) SetGroupID(v int64) *UsageLogUpdateOne {
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableGroupID(v *int64) *UsageLogUpdateOne {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// ClearGroupID clears the value of the "group_id" field.
func (_u *UsageLogUpdateOne) ClearGroupID() *UsageLogUpdateOne {
_u.mutation.ClearGroupID()
return _u
}
// SetSubscriptionID sets the "subscription_id" field.
func (_u *UsageLogUpdateOne) SetSubscriptionID(v int64) *UsageLogUpdateOne {
_u.mutation.SetSubscriptionID(v)
return _u
}
// SetNillableSubscriptionID sets the "subscription_id" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableSubscriptionID(v *int64) *UsageLogUpdateOne {
if v != nil {
_u.SetSubscriptionID(*v)
}
return _u
}
// ClearSubscriptionID clears the value of the "subscription_id" field.
func (_u *UsageLogUpdateOne) ClearSubscriptionID() *UsageLogUpdateOne {
_u.mutation.ClearSubscriptionID()
return _u
}
// SetInputTokens sets the "input_tokens" field.
func (_u *UsageLogUpdateOne) SetInputTokens(v int) *UsageLogUpdateOne {
_u.mutation.ResetInputTokens()
_u.mutation.SetInputTokens(v)
return _u
}
// SetNillableInputTokens sets the "input_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableInputTokens(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetInputTokens(*v)
}
return _u
}
// AddInputTokens adds value to the "input_tokens" field.
func (_u *UsageLogUpdateOne) AddInputTokens(v int) *UsageLogUpdateOne {
_u.mutation.AddInputTokens(v)
return _u
}
// SetOutputTokens sets the "output_tokens" field.
func (_u *UsageLogUpdateOne) SetOutputTokens(v int) *UsageLogUpdateOne {
_u.mutation.ResetOutputTokens()
_u.mutation.SetOutputTokens(v)
return _u
}
// SetNillableOutputTokens sets the "output_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableOutputTokens(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetOutputTokens(*v)
}
return _u
}
// AddOutputTokens adds value to the "output_tokens" field.
func (_u *UsageLogUpdateOne) AddOutputTokens(v int) *UsageLogUpdateOne {
_u.mutation.AddOutputTokens(v)
return _u
}
// SetCacheCreationTokens sets the "cache_creation_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheCreationTokens(v int) *UsageLogUpdateOne {
_u.mutation.ResetCacheCreationTokens()
_u.mutation.SetCacheCreationTokens(v)
return _u
}
// SetNillableCacheCreationTokens sets the "cache_creation_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreationTokens(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetCacheCreationTokens(*v)
}
return _u
}
// AddCacheCreationTokens adds value to the "cache_creation_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheCreationTokens(v int) *UsageLogUpdateOne {
_u.mutation.AddCacheCreationTokens(v)
return _u
}
// SetCacheReadTokens sets the "cache_read_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheReadTokens(v int) *UsageLogUpdateOne {
_u.mutation.ResetCacheReadTokens()
_u.mutation.SetCacheReadTokens(v)
return _u
}
// SetNillableCacheReadTokens sets the "cache_read_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheReadTokens(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetCacheReadTokens(*v)
}
return _u
}
// AddCacheReadTokens adds value to the "cache_read_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheReadTokens(v int) *UsageLogUpdateOne {
_u.mutation.AddCacheReadTokens(v)
return _u
}
// SetCacheCreation5mTokens sets the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheCreation5mTokens(v int) *UsageLogUpdateOne {
_u.mutation.ResetCacheCreation5mTokens()
_u.mutation.SetCacheCreation5mTokens(v)
return _u
}
// SetNillableCacheCreation5mTokens sets the "cache_creation_5m_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreation5mTokens(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetCacheCreation5mTokens(*v)
}
return _u
}
// AddCacheCreation5mTokens adds value to the "cache_creation_5m_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheCreation5mTokens(v int) *UsageLogUpdateOne {
_u.mutation.AddCacheCreation5mTokens(v)
return _u
}
// SetCacheCreation1hTokens sets the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdateOne) SetCacheCreation1hTokens(v int) *UsageLogUpdateOne {
_u.mutation.ResetCacheCreation1hTokens()
_u.mutation.SetCacheCreation1hTokens(v)
return _u
}
// SetNillableCacheCreation1hTokens sets the "cache_creation_1h_tokens" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreation1hTokens(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetCacheCreation1hTokens(*v)
}
return _u
}
// AddCacheCreation1hTokens adds value to the "cache_creation_1h_tokens" field.
func (_u *UsageLogUpdateOne) AddCacheCreation1hTokens(v int) *UsageLogUpdateOne {
_u.mutation.AddCacheCreation1hTokens(v)
return _u
}
// SetInputCost sets the "input_cost" field.
func (_u *UsageLogUpdateOne) SetInputCost(v float64) *UsageLogUpdateOne {
_u.mutation.ResetInputCost()
_u.mutation.SetInputCost(v)
return _u
}
// SetNillableInputCost sets the "input_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableInputCost(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetInputCost(*v)
}
return _u
}
// AddInputCost adds value to the "input_cost" field.
func (_u *UsageLogUpdateOne) AddInputCost(v float64) *UsageLogUpdateOne {
_u.mutation.AddInputCost(v)
return _u
}
// SetOutputCost sets the "output_cost" field.
func (_u *UsageLogUpdateOne) SetOutputCost(v float64) *UsageLogUpdateOne {
_u.mutation.ResetOutputCost()
_u.mutation.SetOutputCost(v)
return _u
}
// SetNillableOutputCost sets the "output_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableOutputCost(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetOutputCost(*v)
}
return _u
}
// AddOutputCost adds value to the "output_cost" field.
func (_u *UsageLogUpdateOne) AddOutputCost(v float64) *UsageLogUpdateOne {
_u.mutation.AddOutputCost(v)
return _u
}
// SetCacheCreationCost sets the "cache_creation_cost" field.
func (_u *UsageLogUpdateOne) SetCacheCreationCost(v float64) *UsageLogUpdateOne {
_u.mutation.ResetCacheCreationCost()
_u.mutation.SetCacheCreationCost(v)
return _u
}
// SetNillableCacheCreationCost sets the "cache_creation_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheCreationCost(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetCacheCreationCost(*v)
}
return _u
}
// AddCacheCreationCost adds value to the "cache_creation_cost" field.
func (_u *UsageLogUpdateOne) AddCacheCreationCost(v float64) *UsageLogUpdateOne {
_u.mutation.AddCacheCreationCost(v)
return _u
}
// SetCacheReadCost sets the "cache_read_cost" field.
func (_u *UsageLogUpdateOne) SetCacheReadCost(v float64) *UsageLogUpdateOne {
_u.mutation.ResetCacheReadCost()
_u.mutation.SetCacheReadCost(v)
return _u
}
// SetNillableCacheReadCost sets the "cache_read_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableCacheReadCost(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetCacheReadCost(*v)
}
return _u
}
// AddCacheReadCost adds value to the "cache_read_cost" field.
func (_u *UsageLogUpdateOne) AddCacheReadCost(v float64) *UsageLogUpdateOne {
_u.mutation.AddCacheReadCost(v)
return _u
}
// SetTotalCost sets the "total_cost" field.
func (_u *UsageLogUpdateOne) SetTotalCost(v float64) *UsageLogUpdateOne {
_u.mutation.ResetTotalCost()
_u.mutation.SetTotalCost(v)
return _u
}
// SetNillableTotalCost sets the "total_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableTotalCost(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetTotalCost(*v)
}
return _u
}
// AddTotalCost adds value to the "total_cost" field.
func (_u *UsageLogUpdateOne) AddTotalCost(v float64) *UsageLogUpdateOne {
_u.mutation.AddTotalCost(v)
return _u
}
// SetActualCost sets the "actual_cost" field.
func (_u *UsageLogUpdateOne) SetActualCost(v float64) *UsageLogUpdateOne {
_u.mutation.ResetActualCost()
_u.mutation.SetActualCost(v)
return _u
}
// SetNillableActualCost sets the "actual_cost" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableActualCost(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetActualCost(*v)
}
return _u
}
// AddActualCost adds value to the "actual_cost" field.
func (_u *UsageLogUpdateOne) AddActualCost(v float64) *UsageLogUpdateOne {
_u.mutation.AddActualCost(v)
return _u
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (_u *UsageLogUpdateOne) SetRateMultiplier(v float64) *UsageLogUpdateOne {
_u.mutation.ResetRateMultiplier()
_u.mutation.SetRateMultiplier(v)
return _u
}
// SetNillableRateMultiplier sets the "rate_multiplier" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableRateMultiplier(v *float64) *UsageLogUpdateOne {
if v != nil {
_u.SetRateMultiplier(*v)
}
return _u
}
// AddRateMultiplier adds value to the "rate_multiplier" field.
func (_u *UsageLogUpdateOne) AddRateMultiplier(v float64) *UsageLogUpdateOne {
_u.mutation.AddRateMultiplier(v)
return _u
}
// SetBillingType sets the "billing_type" field.
func (_u *UsageLogUpdateOne) SetBillingType(v int8) *UsageLogUpdateOne {
_u.mutation.ResetBillingType()
_u.mutation.SetBillingType(v)
return _u
}
// SetNillableBillingType sets the "billing_type" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableBillingType(v *int8) *UsageLogUpdateOne {
if v != nil {
_u.SetBillingType(*v)
}
return _u
}
// AddBillingType adds value to the "billing_type" field.
func (_u *UsageLogUpdateOne) AddBillingType(v int8) *UsageLogUpdateOne {
_u.mutation.AddBillingType(v)
return _u
}
// SetStream sets the "stream" field.
func (_u *UsageLogUpdateOne) SetStream(v bool) *UsageLogUpdateOne {
_u.mutation.SetStream(v)
return _u
}
// SetNillableStream sets the "stream" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableStream(v *bool) *UsageLogUpdateOne {
if v != nil {
_u.SetStream(*v)
}
return _u
}
// SetDurationMs sets the "duration_ms" field.
func (_u *UsageLogUpdateOne) SetDurationMs(v int) *UsageLogUpdateOne {
_u.mutation.ResetDurationMs()
_u.mutation.SetDurationMs(v)
return _u
}
// SetNillableDurationMs sets the "duration_ms" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableDurationMs(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetDurationMs(*v)
}
return _u
}
// AddDurationMs adds value to the "duration_ms" field.
func (_u *UsageLogUpdateOne) AddDurationMs(v int) *UsageLogUpdateOne {
_u.mutation.AddDurationMs(v)
return _u
}
// ClearDurationMs clears the value of the "duration_ms" field.
func (_u *UsageLogUpdateOne) ClearDurationMs() *UsageLogUpdateOne {
_u.mutation.ClearDurationMs()
return _u
}
// SetFirstTokenMs sets the "first_token_ms" field.
func (_u *UsageLogUpdateOne) SetFirstTokenMs(v int) *UsageLogUpdateOne {
_u.mutation.ResetFirstTokenMs()
_u.mutation.SetFirstTokenMs(v)
return _u
}
// SetNillableFirstTokenMs sets the "first_token_ms" field if the given value is not nil.
func (_u *UsageLogUpdateOne) SetNillableFirstTokenMs(v *int) *UsageLogUpdateOne {
if v != nil {
_u.SetFirstTokenMs(*v)
}
return _u
}
// AddFirstTokenMs adds value to the "first_token_ms" field.
func (_u *UsageLogUpdateOne) AddFirstTokenMs(v int) *UsageLogUpdateOne {
_u.mutation.AddFirstTokenMs(v)
return _u
}
// ClearFirstTokenMs clears the value of the "first_token_ms" field.
func (_u *UsageLogUpdateOne) ClearFirstTokenMs() *UsageLogUpdateOne {
_u.mutation.ClearFirstTokenMs()
return _u
}
// SetUser sets the "user" edge to the User entity.
func (_u *UsageLogUpdateOne) SetUser(v *User) *UsageLogUpdateOne {
return _u.SetUserID(v.ID)
}
// SetAPIKey sets the "api_key" edge to the ApiKey entity.
func (_u *UsageLogUpdateOne) SetAPIKey(v *ApiKey) *UsageLogUpdateOne {
return _u.SetAPIKeyID(v.ID)
}
// SetAccount sets the "account" edge to the Account entity.
func (_u *UsageLogUpdateOne) SetAccount(v *Account) *UsageLogUpdateOne {
return _u.SetAccountID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_u *UsageLogUpdateOne) SetGroup(v *Group) *UsageLogUpdateOne {
return _u.SetGroupID(v.ID)
}
// SetSubscription sets the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdateOne) SetSubscription(v *UserSubscription) *UsageLogUpdateOne {
return _u.SetSubscriptionID(v.ID)
}
// Mutation returns the UsageLogMutation object of the builder.
func (_u *UsageLogUpdateOne) Mutation() *UsageLogMutation {
return _u.mutation
}
// ClearUser clears the "user" edge to the User entity.
func (_u *UsageLogUpdateOne) ClearUser() *UsageLogUpdateOne {
_u.mutation.ClearUser()
return _u
}
// ClearAPIKey clears the "api_key" edge to the ApiKey entity.
func (_u *UsageLogUpdateOne) ClearAPIKey() *UsageLogUpdateOne {
_u.mutation.ClearAPIKey()
return _u
}
// ClearAccount clears the "account" edge to the Account entity.
func (_u *UsageLogUpdateOne) ClearAccount() *UsageLogUpdateOne {
_u.mutation.ClearAccount()
return _u
}
// ClearGroup clears the "group" edge to the Group entity.
func (_u *UsageLogUpdateOne) ClearGroup() *UsageLogUpdateOne {
_u.mutation.ClearGroup()
return _u
}
// ClearSubscription clears the "subscription" edge to the UserSubscription entity.
func (_u *UsageLogUpdateOne) ClearSubscription() *UsageLogUpdateOne {
_u.mutation.ClearSubscription()
return _u
}
// Where appends a list predicates to the UsageLogUpdate builder.
func (_u *UsageLogUpdateOne) Where(ps ...predicate.UsageLog) *UsageLogUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *UsageLogUpdateOne) Select(field string, fields ...string) *UsageLogUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated UsageLog entity.
func (_u *UsageLogUpdateOne) Save(ctx context.Context) (*UsageLog, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *UsageLogUpdateOne) SaveX(ctx context.Context) *UsageLog {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *UsageLogUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *UsageLogUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *UsageLogUpdateOne) check() error {
if v, ok := _u.mutation.RequestID(); ok {
if err := usagelog.RequestIDValidator(v); err != nil {
return &ValidationError{Name: "request_id", err: fmt.Errorf(`ent: validator failed for field "UsageLog.request_id": %w`, err)}
}
}
if v, ok := _u.mutation.Model(); ok {
if err := usagelog.ModelValidator(v); err != nil {
return &ValidationError{Name: "model", err: fmt.Errorf(`ent: validator failed for field "UsageLog.model": %w`, err)}
}
}
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "UsageLog.user"`)
}
if _u.mutation.APIKeyCleared() && len(_u.mutation.APIKeyIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "UsageLog.api_key"`)
}
if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "UsageLog.account"`)
}
return nil
}
func (_u *UsageLogUpdateOne) sqlSave(ctx context.Context) (_node *UsageLog, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(usagelog.Table, usagelog.Columns, sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageLog.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, usagelog.FieldID)
for _, f := range fields {
if !usagelog.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != usagelog.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.RequestID(); ok {
_spec.SetField(usagelog.FieldRequestID, field.TypeString, value)
}
if value, ok := _u.mutation.Model(); ok {
_spec.SetField(usagelog.FieldModel, field.TypeString, value)
}
if value, ok := _u.mutation.InputTokens(); ok {
_spec.SetField(usagelog.FieldInputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedInputTokens(); ok {
_spec.AddField(usagelog.FieldInputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.OutputTokens(); ok {
_spec.SetField(usagelog.FieldOutputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedOutputTokens(); ok {
_spec.AddField(usagelog.FieldOutputTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheCreationTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheCreationTokens(); ok {
_spec.AddField(usagelog.FieldCacheCreationTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheReadTokens(); ok {
_spec.SetField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheReadTokens(); ok {
_spec.AddField(usagelog.FieldCacheReadTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheCreation5mTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheCreation5mTokens(); ok {
_spec.AddField(usagelog.FieldCacheCreation5mTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.CacheCreation1hTokens(); ok {
_spec.SetField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCacheCreation1hTokens(); ok {
_spec.AddField(usagelog.FieldCacheCreation1hTokens, field.TypeInt, value)
}
if value, ok := _u.mutation.InputCost(); ok {
_spec.SetField(usagelog.FieldInputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedInputCost(); ok {
_spec.AddField(usagelog.FieldInputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.OutputCost(); ok {
_spec.SetField(usagelog.FieldOutputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedOutputCost(); ok {
_spec.AddField(usagelog.FieldOutputCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.CacheCreationCost(); ok {
_spec.SetField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedCacheCreationCost(); ok {
_spec.AddField(usagelog.FieldCacheCreationCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.CacheReadCost(); ok {
_spec.SetField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedCacheReadCost(); ok {
_spec.AddField(usagelog.FieldCacheReadCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.TotalCost(); ok {
_spec.SetField(usagelog.FieldTotalCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedTotalCost(); ok {
_spec.AddField(usagelog.FieldTotalCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.ActualCost(); ok {
_spec.SetField(usagelog.FieldActualCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedActualCost(); ok {
_spec.AddField(usagelog.FieldActualCost, field.TypeFloat64, value)
}
if value, ok := _u.mutation.RateMultiplier(); ok {
_spec.SetField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedRateMultiplier(); ok {
_spec.AddField(usagelog.FieldRateMultiplier, field.TypeFloat64, value)
}
if value, ok := _u.mutation.BillingType(); ok {
_spec.SetField(usagelog.FieldBillingType, field.TypeInt8, value)
}
if value, ok := _u.mutation.AddedBillingType(); ok {
_spec.AddField(usagelog.FieldBillingType, field.TypeInt8, value)
}
if value, ok := _u.mutation.Stream(); ok {
_spec.SetField(usagelog.FieldStream, field.TypeBool, value)
}
if value, ok := _u.mutation.DurationMs(); ok {
_spec.SetField(usagelog.FieldDurationMs, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedDurationMs(); ok {
_spec.AddField(usagelog.FieldDurationMs, field.TypeInt, value)
}
if _u.mutation.DurationMsCleared() {
_spec.ClearField(usagelog.FieldDurationMs, field.TypeInt)
}
if value, ok := _u.mutation.FirstTokenMs(); ok {
_spec.SetField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedFirstTokenMs(); ok {
_spec.AddField(usagelog.FieldFirstTokenMs, field.TypeInt, value)
}
if _u.mutation.FirstTokenMsCleared() {
_spec.ClearField(usagelog.FieldFirstTokenMs, field.TypeInt)
}
if _u.mutation.UserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.UserTable,
Columns: []string{usagelog.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.UserTable,
Columns: []string{usagelog.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.APIKeyCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.APIKeyTable,
Columns: []string{usagelog.APIKeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.APIKeyIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.APIKeyTable,
Columns: []string{usagelog.APIKeyColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(apikey.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.AccountCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.AccountTable,
Columns: []string{usagelog.AccountColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.AccountIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.AccountTable,
Columns: []string{usagelog.AccountColumn},
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 _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.GroupTable,
Columns: []string{usagelog.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.GroupTable,
Columns: []string{usagelog.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.SubscriptionCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.SubscriptionTable,
Columns: []string{usagelog.SubscriptionColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.SubscriptionIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usagelog.SubscriptionTable,
Columns: []string{usagelog.SubscriptionColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &UsageLog{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{usagelog.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
......@@ -59,11 +59,13 @@ type UserEdges struct {
AssignedSubscriptions []*UserSubscription `json:"assigned_subscriptions,omitempty"`
// AllowedGroups holds the value of the allowed_groups edge.
AllowedGroups []*Group `json:"allowed_groups,omitempty"`
// UsageLogs holds the value of the usage_logs edge.
UsageLogs []*UsageLog `json:"usage_logs,omitempty"`
// UserAllowedGroups holds the value of the user_allowed_groups edge.
UserAllowedGroups []*UserAllowedGroup `json:"user_allowed_groups,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [6]bool
loadedTypes [7]bool
}
// APIKeysOrErr returns the APIKeys value or an error if the edge
......@@ -111,10 +113,19 @@ func (e UserEdges) AllowedGroupsOrErr() ([]*Group, error) {
return nil, &NotLoadedError{edge: "allowed_groups"}
}
// UsageLogsOrErr returns the UsageLogs value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) UsageLogsOrErr() ([]*UsageLog, error) {
if e.loadedTypes[5] {
return e.UsageLogs, nil
}
return nil, &NotLoadedError{edge: "usage_logs"}
}
// UserAllowedGroupsOrErr returns the UserAllowedGroups value or an error if the edge
// was not loaded in eager-loading.
func (e UserEdges) UserAllowedGroupsOrErr() ([]*UserAllowedGroup, error) {
if e.loadedTypes[5] {
if e.loadedTypes[6] {
return e.UserAllowedGroups, nil
}
return nil, &NotLoadedError{edge: "user_allowed_groups"}
......@@ -265,6 +276,11 @@ func (_m *User) QueryAllowedGroups() *GroupQuery {
return NewUserClient(_m.config).QueryAllowedGroups(_m)
}
// QueryUsageLogs queries the "usage_logs" edge of the User entity.
func (_m *User) QueryUsageLogs() *UsageLogQuery {
return NewUserClient(_m.config).QueryUsageLogs(_m)
}
// QueryUserAllowedGroups queries the "user_allowed_groups" edge of the User entity.
func (_m *User) QueryUserAllowedGroups() *UserAllowedGroupQuery {
return NewUserClient(_m.config).QueryUserAllowedGroups(_m)
......
......@@ -49,6 +49,8 @@ const (
EdgeAssignedSubscriptions = "assigned_subscriptions"
// EdgeAllowedGroups holds the string denoting the allowed_groups edge name in mutations.
EdgeAllowedGroups = "allowed_groups"
// EdgeUsageLogs holds the string denoting the usage_logs edge name in mutations.
EdgeUsageLogs = "usage_logs"
// EdgeUserAllowedGroups holds the string denoting the user_allowed_groups edge name in mutations.
EdgeUserAllowedGroups = "user_allowed_groups"
// Table holds the table name of the user in the database.
......@@ -86,6 +88,13 @@ const (
// AllowedGroupsInverseTable is the table name for the Group entity.
// It exists in this package in order to avoid circular dependency with the "group" package.
AllowedGroupsInverseTable = "groups"
// 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 = "user_id"
// UserAllowedGroupsTable is the table that holds the user_allowed_groups relation/edge.
UserAllowedGroupsTable = "user_allowed_groups"
// UserAllowedGroupsInverseTable is the table name for the UserAllowedGroup entity.
......@@ -308,6 +317,20 @@ func ByAllowedGroups(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...)...)
}
}
// ByUserAllowedGroupsCount orders the results by user_allowed_groups count.
func ByUserAllowedGroupsCount(opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
......@@ -356,6 +379,13 @@ func newAllowedGroupsStep() *sqlgraph.Step {
sqlgraph.Edge(sqlgraph.M2M, false, AllowedGroupsTable, AllowedGroupsPrimaryKey...),
)
}
func newUsageLogsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UsageLogsInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, UsageLogsTable, UsageLogsColumn),
)
}
func newUserAllowedGroupsStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
......
......@@ -895,6 +895,29 @@ func HasAllowedGroupsWith(preds ...predicate.Group) predicate.User {
})
}
// HasUsageLogs applies the HasEdge predicate on the "usage_logs" edge.
func HasUsageLogs() predicate.User {
return predicate.User(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.User {
return predicate.User(func(s *sql.Selector) {
step := newUsageLogsStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasUserAllowedGroups applies the HasEdge predicate on the "user_allowed_groups" edge.
func HasUserAllowedGroups() predicate.User {
return predicate.User(func(s *sql.Selector) {
......
......@@ -14,6 +14,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"
)
......@@ -253,6 +254,21 @@ func (_c *UserCreate) AddAllowedGroups(v ...*Group) *UserCreate {
return _c.AddAllowedGroupIDs(ids...)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_c *UserCreate) AddUsageLogIDs(ids ...int64) *UserCreate {
_c.mutation.AddUsageLogIDs(ids...)
return _c
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_c *UserCreate) AddUsageLogs(v ...*UsageLog) *UserCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddUsageLogIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (_c *UserCreate) Mutation() *UserMutation {
return _c.mutation
......@@ -559,6 +575,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
edge.Target.Fields = specE.Fields
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.UsageLogsTable,
Columns: []string{user.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)
}
return _node, _spec
}
......
......@@ -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/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
......@@ -33,6 +34,7 @@ type UserQuery struct {
withSubscriptions *UserSubscriptionQuery
withAssignedSubscriptions *UserSubscriptionQuery
withAllowedGroups *GroupQuery
withUsageLogs *UsageLogQuery
withUserAllowedGroups *UserAllowedGroupQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
......@@ -180,6 +182,28 @@ func (_q *UserQuery) QueryAllowedGroups() *GroupQuery {
return query
}
// QueryUsageLogs chains the current query on the "usage_logs" edge.
func (_q *UserQuery) 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(user.Table, user.FieldID, selector),
sqlgraph.To(usagelog.Table, usagelog.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, user.UsageLogsTable, user.UsageLogsColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryUserAllowedGroups chains the current query on the "user_allowed_groups" edge.
func (_q *UserQuery) QueryUserAllowedGroups() *UserAllowedGroupQuery {
query := (&UserAllowedGroupClient{config: _q.config}).Query()
......@@ -399,6 +423,7 @@ func (_q *UserQuery) Clone() *UserQuery {
withSubscriptions: _q.withSubscriptions.Clone(),
withAssignedSubscriptions: _q.withAssignedSubscriptions.Clone(),
withAllowedGroups: _q.withAllowedGroups.Clone(),
withUsageLogs: _q.withUsageLogs.Clone(),
withUserAllowedGroups: _q.withUserAllowedGroups.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
......@@ -461,6 +486,17 @@ func (_q *UserQuery) WithAllowedGroups(opts ...func(*GroupQuery)) *UserQuery {
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 *UserQuery) WithUsageLogs(opts ...func(*UsageLogQuery)) *UserQuery {
query := (&UsageLogClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withUsageLogs = query
return _q
}
// WithUserAllowedGroups tells the query-builder to eager-load the nodes that are connected to
// the "user_allowed_groups" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *UserQuery) WithUserAllowedGroups(opts ...func(*UserAllowedGroupQuery)) *UserQuery {
......@@ -550,12 +586,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
var (
nodes = []*User{}
_spec = _q.querySpec()
loadedTypes = [6]bool{
loadedTypes = [7]bool{
_q.withAPIKeys != nil,
_q.withRedeemCodes != nil,
_q.withSubscriptions != nil,
_q.withAssignedSubscriptions != nil,
_q.withAllowedGroups != nil,
_q.withUsageLogs != nil,
_q.withUserAllowedGroups != nil,
}
)
......@@ -614,6 +651,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
return nil, err
}
}
if query := _q.withUsageLogs; query != nil {
if err := _q.loadUsageLogs(ctx, query, nodes,
func(n *User) { n.Edges.UsageLogs = []*UsageLog{} },
func(n *User, e *UsageLog) { n.Edges.UsageLogs = append(n.Edges.UsageLogs, e) }); err != nil {
return nil, err
}
}
if query := _q.withUserAllowedGroups; query != nil {
if err := _q.loadUserAllowedGroups(ctx, query, nodes,
func(n *User) { n.Edges.UserAllowedGroups = []*UserAllowedGroup{} },
......@@ -811,6 +855,36 @@ func (_q *UserQuery) loadAllowedGroups(ctx context.Context, query *GroupQuery, n
}
return nil
}
func (_q *UserQuery) loadUsageLogs(ctx context.Context, query *UsageLogQuery, nodes []*User, init func(*User), assign func(*User, *UsageLog)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*User)
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.FieldUserID)
}
query.Where(predicate.UsageLog(func(s *sql.Selector) {
s.Where(sql.InValues(s.C(user.UsageLogsColumn), fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
fk := n.UserID
node, ok := nodeids[fk]
if !ok {
return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID)
}
assign(node, n)
}
return nil
}
func (_q *UserQuery) loadUserAllowedGroups(ctx context.Context, query *UserAllowedGroupQuery, nodes []*User, init func(*User), assign func(*User, *UserAllowedGroup)) error {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int64]*User)
......
......@@ -15,6 +15,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"
)
......@@ -273,6 +274,21 @@ func (_u *UserUpdate) AddAllowedGroups(v ...*Group) *UserUpdate {
return _u.AddAllowedGroupIDs(ids...)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *UserUpdate) AddUsageLogIDs(ids ...int64) *UserUpdate {
_u.mutation.AddUsageLogIDs(ids...)
return _u
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *UserUpdate) AddUsageLogs(v ...*UsageLog) *UserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddUsageLogIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (_u *UserUpdate) Mutation() *UserMutation {
return _u.mutation
......@@ -383,6 +399,27 @@ func (_u *UserUpdate) RemoveAllowedGroups(v ...*Group) *UserUpdate {
return _u.RemoveAllowedGroupIDs(ids...)
}
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *UserUpdate) ClearUsageLogs() *UserUpdate {
_u.mutation.ClearUsageLogs()
return _u
}
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *UserUpdate) RemoveUsageLogIDs(ids ...int64) *UserUpdate {
_u.mutation.RemoveUsageLogIDs(ids...)
return _u
}
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *UserUpdate) RemoveUsageLogs(v ...*UsageLog) *UserUpdate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveUsageLogIDs(ids...)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
if err := _u.defaults(); err != nil {
......@@ -751,6 +788,51 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.UsageLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.UsageLogsTable,
Columns: []string{user.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: user.UsageLogsTable,
Columns: []string{user.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: user.UsageLogsTable,
Columns: []string{user.UsageLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{user.Label}
......@@ -1012,6 +1094,21 @@ func (_u *UserUpdateOne) AddAllowedGroups(v ...*Group) *UserUpdateOne {
return _u.AddAllowedGroupIDs(ids...)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_u *UserUpdateOne) AddUsageLogIDs(ids ...int64) *UserUpdateOne {
_u.mutation.AddUsageLogIDs(ids...)
return _u
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_u *UserUpdateOne) AddUsageLogs(v ...*UsageLog) *UserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.AddUsageLogIDs(ids...)
}
// Mutation returns the UserMutation object of the builder.
func (_u *UserUpdateOne) Mutation() *UserMutation {
return _u.mutation
......@@ -1122,6 +1219,27 @@ func (_u *UserUpdateOne) RemoveAllowedGroups(v ...*Group) *UserUpdateOne {
return _u.RemoveAllowedGroupIDs(ids...)
}
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
func (_u *UserUpdateOne) ClearUsageLogs() *UserUpdateOne {
_u.mutation.ClearUsageLogs()
return _u
}
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
func (_u *UserUpdateOne) RemoveUsageLogIDs(ids ...int64) *UserUpdateOne {
_u.mutation.RemoveUsageLogIDs(ids...)
return _u
}
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
func (_u *UserUpdateOne) RemoveUsageLogs(v ...*UsageLog) *UserUpdateOne {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _u.RemoveUsageLogIDs(ids...)
}
// Where appends a list predicates to the UserUpdate builder.
func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
_u.mutation.Where(ps...)
......@@ -1520,6 +1638,51 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
edge.Target.Fields = specE.Fields
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.UsageLogsCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: user.UsageLogsTable,
Columns: []string{user.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: user.UsageLogsTable,
Columns: []string{user.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: user.UsageLogsTable,
Columns: []string{user.UsageLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &User{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
......
......@@ -23,6 +23,8 @@ type UserSubscription struct {
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// UserID holds the value of the "user_id" field.
UserID int64 `json:"user_id,omitempty"`
// GroupID holds the value of the "group_id" field.
......@@ -65,9 +67,11 @@ type UserSubscriptionEdges struct {
Group *Group `json:"group,omitempty"`
// AssignedByUser holds the value of the assigned_by_user edge.
AssignedByUser *User `json:"assigned_by_user,omitempty"`
// UsageLogs holds the value of the usage_logs edge.
UsageLogs []*UsageLog `json:"usage_logs,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [3]bool
loadedTypes [4]bool
}
// UserOrErr returns the User value or an error if the edge
......@@ -103,6 +107,15 @@ func (e UserSubscriptionEdges) AssignedByUserOrErr() (*User, error) {
return nil, &NotLoadedError{edge: "assigned_by_user"}
}
// UsageLogsOrErr returns the UsageLogs value or an error if the edge
// was not loaded in eager-loading.
func (e UserSubscriptionEdges) UsageLogsOrErr() ([]*UsageLog, error) {
if e.loadedTypes[3] {
return e.UsageLogs, nil
}
return nil, &NotLoadedError{edge: "usage_logs"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*UserSubscription) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
......@@ -114,7 +127,7 @@ func (*UserSubscription) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullInt64)
case usersubscription.FieldStatus, usersubscription.FieldNotes:
values[i] = new(sql.NullString)
case usersubscription.FieldCreatedAt, usersubscription.FieldUpdatedAt, usersubscription.FieldStartsAt, usersubscription.FieldExpiresAt, usersubscription.FieldDailyWindowStart, usersubscription.FieldWeeklyWindowStart, usersubscription.FieldMonthlyWindowStart, usersubscription.FieldAssignedAt:
case usersubscription.FieldCreatedAt, usersubscription.FieldUpdatedAt, usersubscription.FieldDeletedAt, usersubscription.FieldStartsAt, usersubscription.FieldExpiresAt, usersubscription.FieldDailyWindowStart, usersubscription.FieldWeeklyWindowStart, usersubscription.FieldMonthlyWindowStart, usersubscription.FieldAssignedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
......@@ -149,6 +162,13 @@ func (_m *UserSubscription) assignValues(columns []string, values []any) error {
} else if value.Valid {
_m.UpdatedAt = value.Time
}
case usersubscription.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
_m.DeletedAt = new(time.Time)
*_m.DeletedAt = value.Time
}
case usersubscription.FieldUserID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field user_id", values[i])
......@@ -266,6 +286,11 @@ func (_m *UserSubscription) QueryAssignedByUser() *UserQuery {
return NewUserSubscriptionClient(_m.config).QueryAssignedByUser(_m)
}
// QueryUsageLogs queries the "usage_logs" edge of the UserSubscription entity.
func (_m *UserSubscription) QueryUsageLogs() *UsageLogQuery {
return NewUserSubscriptionClient(_m.config).QueryUsageLogs(_m)
}
// Update returns a builder for updating this UserSubscription.
// Note that you need to call UserSubscription.Unwrap() before calling this method if this UserSubscription
// was returned from a transaction, and the transaction was committed or rolled back.
......@@ -295,6 +320,11 @@ func (_m *UserSubscription) String() string {
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("user_id=")
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
builder.WriteString(", ")
......
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