* fix(ops): 修复运维监控系统的关键安全和稳定性问题
## 修复内容
### P0 严重问题
1. **DNS Rebinding防护** (ops_alert_service.go)
- 实现IP钉住机制防止验证后的DNS rebinding攻击
- 自定义Transport.DialContext强制只允许拨号到验证过的公网IP
- 扩展IP黑名单,包括云metadata地址(169.254.169.254)
- 添加完整的单元测试覆盖
2. **OpsAlertService生命周期管理** (wire.go)
- 在ProvideOpsMetricsCollector中添加opsAlertService.Start()调用
- 确保stopCtx正确初始化,避免nil指针问题
- 实现防御式启动,保证服务启动顺序
3. **数据库查询排序** (ops_repo.go)
- 在ListRecentSystemMetrics中添加显式ORDER BY updated_at DESC, id DESC
- 在GetLatestSystemMetric中添加排序保证
- 避免数据库返回顺序不确定导致告警误判
### P1 重要问题
4. **并发安全** (ops_metrics_collector.go)
- 为lastGCPauseTotal字段添加sync.Mutex保护
- 防止数据竞争
5. **Goroutine泄漏** (ops_error_logger.go)
- 实现worker pool模式限制并发goroutine数量
- 使用256容量缓冲队列和10个固定worker
- 非阻塞投递,队列满时丢弃任务
6. **生命周期控制** (ops_alert_service.go)
- 添加Start/Stop方法实现优雅关闭
- 使用context控制goroutine生命周期
- 实现WaitGroup等待后台任务完成
7. **Webhook URL验证** (ops_alert_service.go)
- 防止SSRF攻击:验证scheme、禁止内网IP
- DNS解析验证,拒绝解析到私有IP的域名
- 添加8个单元测试覆盖各种攻击场景
8. **资源泄漏** (ops_repo.go)
- 修复多处defer rows.Close()问题
- 简化冗余的defer func()包装
9. **HTTP超时控制** (ops_alert_service.go)
- 创建带10秒超时的http.Client
- 添加buildWebhookHTTPClient辅助函数
- 防止HTTP请求无限期挂起
10. **数据库查询优化** (ops_repo.go)
- 将GetWindowStats的4次独立查询合并为1次CTE查询
- 减少网络往返和表扫描次数
- 显著提升性能
11. **重试机制** (ops_alert_service.go)
- 实现邮件发送重试:最多3次,指数退避(1s/2s/4s)
- 添加webhook备用通道
- 实现完整的错误处理和日志记录
12. **魔法数字** (ops_repo.go, ops_metrics_collector.go)
- 提取硬编码数字为有意义的常量
- 提高代码可读性和可维护性
## 测试验证
- ✅ go test ./internal/service -tags opsalert_unit 通过
- ✅ 所有webhook验证测试通过
- ✅ 重试机制测试通过
## 影响范围
- 运维监控系统安全性显著提升
- 系统稳定性和性能优化
- 无破坏性变更,向后兼容
* feat(ops): 运维监控系统V2 - 完整实现
## 核心功能
- 运维监控仪表盘V2(实时监控、历史趋势、告警管理)
- WebSocket实时QPS/TPS监控(30s心跳,自动重连)
- 系统指标采集(CPU、内存、延迟、错误率等)
- 多维度统计分析(按provider、model、user等维度)
- 告警规则管理(阈值配置、通知渠道)
- 错误日志追踪(详细错误信息、堆栈跟踪)
## 数据库Schema (Migration 025)
### 扩展现有表
- ops_system_metrics: 新增RED指标、错误分类、延迟指标、资源指标、业务指标
- ops_alert_rules: 新增JSONB字段(dimension_filters, notify_channels, notify_config)
### 新增表
- ops_dimension_stats: 多维度统计数据
- ops_data_retention_config: 数据保留策略配置
### 新增视图和函数
- ops_latest_metrics: 最新1分钟窗口指标(已修复字段名和window过滤)
- ops_active_alerts: 当前活跃告警(已修复字段名和状态值)
- calculate_health_score: 健康分数计算函数
## 一致性修复(98/100分)
### P0级别(阻塞Migration)
- ✅ 修复ops_latest_metrics视图字段名(latency_p99→p99_latency_ms, cpu_usage→cpu_usage_percent)
- ✅ 修复ops_active_alerts视图字段名(metric→metric_type, triggered_at→fired_at, trigger_value→metric_value, threshold→threshold_value)
- ✅ 统一告警历史表名(删除ops_alert_history,使用ops_alert_events)
- ✅ 统一API参数限制(ListMetricsHistory和ListErrorLogs的limit改为5000)
### P1级别(功能完整性)
- ✅ 修复ops_latest_metrics视图未过滤window_minutes(添加WHERE m.window_minutes = 1)
- ✅ 修复数据回填UPDATE逻辑(QPS计算改为request_count/(window_minutes*60.0))
- ✅ 添加ops_alert_rules JSONB字段后端支持(Go结构体+序列化)
### P2级别(优化)
- ✅ 前端WebSocket自动重连(指数退避1s→2s→4s→8s→16s,最大5次)
- ✅ 后端WebSocket心跳检测(30s ping,60s pong超时)
## 技术实现
### 后端 (Go)
- Handler层: ops_handler.go(REST API), ops_ws_handler.go(WebSocket)
- Service层: ops_service.go(核心逻辑), ops_cache.go(缓存), ops_alerts.go(告警)
- Repository层: ops_repo.go(数据访问), ops.go(模型定义)
- 路由: admin.go(新增ops相关路由)
- 依赖注入: wire_gen.go(自动生成)
### 前端 (Vue3 + TypeScript)
- 组件: OpsDashboardV2.vue(仪表盘主组件)
- API: ops.ts(REST API + WebSocket封装)
- 路由: index.ts(新增/admin/ops路由)
- 国际化: en.ts, zh.ts(中英文支持)
## 测试验证
- ✅ 所有Go测试通过
- ✅ Migration可正常执行
- ✅ WebSocket连接稳定
- ✅ 前后端数据结构对齐
* refactor: 代码清理和测试优化
## 测试文件优化
- 简化integration test fixtures和断言
- 优化test helper函数
- 统一测试数据格式
## 代码清理
- 移除未使用的代码和注释
- 简化concurrency_cache实现
- 优化middleware错误处理
## 小修复
- 修复gateway_handler和openai_gateway_handler的小问题
- 统一代码风格和格式
变更统计: 27个文件,292行新增,322行删除(净减少30行)
* fix(ops): 运维监控系统安全加固和功能优化
## 安全增强
- feat(security): WebSocket日志脱敏机制,防止token/api_key泄露
- feat(security): X-Forwarded-Host白名单验证,防止CSRF绕过
- feat(security): Origin策略配置化,支持strict/permissive模式
- feat(auth): WebSocket认证支持query参数传递token
## 配置优化
- feat(config): 支持环境变量配置代理信任和Origin策略
- OPS_WS_TRUST_PROXY
- OPS_WS_TRUSTED_PROXIES
- OPS_WS_ORIGIN_POLICY
- fix(ops): 错误日志查询限流从5000降至500,优化内存使用
## 架构改进
- refactor(ops): 告警服务解耦,独立运行评估定时器
- refactor(ops): OpsDashboard统一版本,移除V2分离
## 测试和文档
- test(ops): 添加WebSocket安全验证单元测试(8个测试用例)
- test(ops): 添加告警服务集成测试
- docs(api): 更新API文档,标注限流变更
- docs: 添加CHANGELOG记录breaking changes
## 修复文件
Backend:
- backend/internal/server/middleware/logger.go
- backend/internal/handler/admin/ops_handler.go
- backend/internal/handler/admin/ops_ws_handler.go
- backend/internal/server/middleware/admin_auth.go
- backend/internal/service/ops_alert_service.go
- backend/internal/service/ops_metrics_collector.go
- backend/internal/service/wire.go
Frontend:
- frontend/src/views/admin/ops/OpsDashboard.vue
- frontend/src/router/index.ts
- frontend/src/api/admin/ops.ts
Tests:
- backend/internal/handler/admin/ops_ws_handler_test.go (新增)
- backend/internal/service/ops_alert_service_integration_test.go (新增)
Docs:
- CHANGELOG.md (新增)
- docs/API-运维监控中心2.0.md (更新)
* fix(migrations): 修复calculate_health_score函数类型匹配问题
在ops_latest_metrics视图中添加显式类型转换,确保参数类型与函数签名匹配
* fix(lint): 修复golangci-lint检查发现的所有问题
- 将Redis依赖从service层移到repository层
- 添加错误检查(WebSocket连接和读取超时)
- 运行gofmt格式化代码
- 添加nil指针检查
- 删除未使用的alertService字段
修复问题:
- depguard: 3个(service层不应直接import redis)
- errcheck: 3个(未检查错误返回值)
- gofmt: 2个(代码格式问题)
- staticcheck: 4个(nil指针解引用)
- unused: 1个(未使用字段)
代码统计:
- 修改文件:11个
- 删除代码:490行
- 新增代码:105行
- 净减少:385行
2432 lines
74 KiB
Go
2432 lines
74 KiB
Go
// 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)
|
|
}
|
|
}
|