Files
sub2api/backend/ent/sorausagestat_create.go
yangjianbo 13262a5698 feat(sora): 新增 Sora 平台支持并修复高危安全和性能问题
新增功能:
- 新增 Sora 账号管理和 OAuth 认证
- 新增 Sora 视频/图片生成 API 网关
- 新增 Sora 任务调度和缓存机制
- 新增 Sora 使用统计和计费支持
- 前端增加 Sora 平台配置界面

安全修复(代码审核):
- [SEC-001] 限制媒体下载响应体大小(图片 20MB、视频 200MB),防止 DoS 攻击
- [SEC-002] 限制 SDK API 响应大小(1MB),防止内存耗尽
- [SEC-003] 修复 SSRF 风险,添加 URL 验证并强制使用代理配置

BUG 修复(代码审核):
- [BUG-001] 修复 for 循环内 defer 累积导致的资源泄漏
- [BUG-002] 修复图片并发槽位获取失败时已持有锁未释放的永久泄漏

性能优化(代码审核):
- [PERF-001] 添加 Sentinel Token 缓存(3 分钟有效期),减少 PoW 计算开销

技术细节:
- 使用 io.LimitReader 限制所有外部输入的大小
- 添加 urlvalidator 验证防止 SSRF 攻击
- 使用 sync.Map 实现线程安全的包级缓存
- 优化并发槽位管理,添加 releaseAll 模式防止泄漏

影响范围:
- 后端:新增 Sora 相关数据模型、服务、网关和管理接口
- 前端:新增 Sora 平台配置、账号管理和监控界面
- 配置:新增 Sora 相关配置项和环境变量

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-29 16:18:38 +08:00

1335 lines
42 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/sorausagestat"
)
// SoraUsageStatCreate is the builder for creating a SoraUsageStat entity.
type SoraUsageStatCreate struct {
config
mutation *SoraUsageStatMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *SoraUsageStatCreate) SetCreatedAt(v time.Time) *SoraUsageStatCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableCreatedAt(v *time.Time) *SoraUsageStatCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *SoraUsageStatCreate) SetUpdatedAt(v time.Time) *SoraUsageStatCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableUpdatedAt(v *time.Time) *SoraUsageStatCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetAccountID sets the "account_id" field.
func (_c *SoraUsageStatCreate) SetAccountID(v int64) *SoraUsageStatCreate {
_c.mutation.SetAccountID(v)
return _c
}
// SetImageCount sets the "image_count" field.
func (_c *SoraUsageStatCreate) SetImageCount(v int) *SoraUsageStatCreate {
_c.mutation.SetImageCount(v)
return _c
}
// SetNillableImageCount sets the "image_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableImageCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetImageCount(*v)
}
return _c
}
// SetVideoCount sets the "video_count" field.
func (_c *SoraUsageStatCreate) SetVideoCount(v int) *SoraUsageStatCreate {
_c.mutation.SetVideoCount(v)
return _c
}
// SetNillableVideoCount sets the "video_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableVideoCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetVideoCount(*v)
}
return _c
}
// SetErrorCount sets the "error_count" field.
func (_c *SoraUsageStatCreate) SetErrorCount(v int) *SoraUsageStatCreate {
_c.mutation.SetErrorCount(v)
return _c
}
// SetNillableErrorCount sets the "error_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableErrorCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetErrorCount(*v)
}
return _c
}
// SetLastErrorAt sets the "last_error_at" field.
func (_c *SoraUsageStatCreate) SetLastErrorAt(v time.Time) *SoraUsageStatCreate {
_c.mutation.SetLastErrorAt(v)
return _c
}
// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableLastErrorAt(v *time.Time) *SoraUsageStatCreate {
if v != nil {
_c.SetLastErrorAt(*v)
}
return _c
}
// SetTodayImageCount sets the "today_image_count" field.
func (_c *SoraUsageStatCreate) SetTodayImageCount(v int) *SoraUsageStatCreate {
_c.mutation.SetTodayImageCount(v)
return _c
}
// SetNillableTodayImageCount sets the "today_image_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableTodayImageCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetTodayImageCount(*v)
}
return _c
}
// SetTodayVideoCount sets the "today_video_count" field.
func (_c *SoraUsageStatCreate) SetTodayVideoCount(v int) *SoraUsageStatCreate {
_c.mutation.SetTodayVideoCount(v)
return _c
}
// SetNillableTodayVideoCount sets the "today_video_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableTodayVideoCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetTodayVideoCount(*v)
}
return _c
}
// SetTodayErrorCount sets the "today_error_count" field.
func (_c *SoraUsageStatCreate) SetTodayErrorCount(v int) *SoraUsageStatCreate {
_c.mutation.SetTodayErrorCount(v)
return _c
}
// SetNillableTodayErrorCount sets the "today_error_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableTodayErrorCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetTodayErrorCount(*v)
}
return _c
}
// SetTodayDate sets the "today_date" field.
func (_c *SoraUsageStatCreate) SetTodayDate(v time.Time) *SoraUsageStatCreate {
_c.mutation.SetTodayDate(v)
return _c
}
// SetNillableTodayDate sets the "today_date" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableTodayDate(v *time.Time) *SoraUsageStatCreate {
if v != nil {
_c.SetTodayDate(*v)
}
return _c
}
// SetConsecutiveErrorCount sets the "consecutive_error_count" field.
func (_c *SoraUsageStatCreate) SetConsecutiveErrorCount(v int) *SoraUsageStatCreate {
_c.mutation.SetConsecutiveErrorCount(v)
return _c
}
// SetNillableConsecutiveErrorCount sets the "consecutive_error_count" field if the given value is not nil.
func (_c *SoraUsageStatCreate) SetNillableConsecutiveErrorCount(v *int) *SoraUsageStatCreate {
if v != nil {
_c.SetConsecutiveErrorCount(*v)
}
return _c
}
// Mutation returns the SoraUsageStatMutation object of the builder.
func (_c *SoraUsageStatCreate) Mutation() *SoraUsageStatMutation {
return _c.mutation
}
// Save creates the SoraUsageStat in the database.
func (_c *SoraUsageStatCreate) Save(ctx context.Context) (*SoraUsageStat, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *SoraUsageStatCreate) SaveX(ctx context.Context) *SoraUsageStat {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SoraUsageStatCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SoraUsageStatCreate) 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 *SoraUsageStatCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := sorausagestat.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := sorausagestat.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.ImageCount(); !ok {
v := sorausagestat.DefaultImageCount
_c.mutation.SetImageCount(v)
}
if _, ok := _c.mutation.VideoCount(); !ok {
v := sorausagestat.DefaultVideoCount
_c.mutation.SetVideoCount(v)
}
if _, ok := _c.mutation.ErrorCount(); !ok {
v := sorausagestat.DefaultErrorCount
_c.mutation.SetErrorCount(v)
}
if _, ok := _c.mutation.TodayImageCount(); !ok {
v := sorausagestat.DefaultTodayImageCount
_c.mutation.SetTodayImageCount(v)
}
if _, ok := _c.mutation.TodayVideoCount(); !ok {
v := sorausagestat.DefaultTodayVideoCount
_c.mutation.SetTodayVideoCount(v)
}
if _, ok := _c.mutation.TodayErrorCount(); !ok {
v := sorausagestat.DefaultTodayErrorCount
_c.mutation.SetTodayErrorCount(v)
}
if _, ok := _c.mutation.ConsecutiveErrorCount(); !ok {
v := sorausagestat.DefaultConsecutiveErrorCount
_c.mutation.SetConsecutiveErrorCount(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *SoraUsageStatCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SoraUsageStat.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SoraUsageStat.updated_at"`)}
}
if _, ok := _c.mutation.AccountID(); !ok {
return &ValidationError{Name: "account_id", err: errors.New(`ent: missing required field "SoraUsageStat.account_id"`)}
}
if _, ok := _c.mutation.ImageCount(); !ok {
return &ValidationError{Name: "image_count", err: errors.New(`ent: missing required field "SoraUsageStat.image_count"`)}
}
if _, ok := _c.mutation.VideoCount(); !ok {
return &ValidationError{Name: "video_count", err: errors.New(`ent: missing required field "SoraUsageStat.video_count"`)}
}
if _, ok := _c.mutation.ErrorCount(); !ok {
return &ValidationError{Name: "error_count", err: errors.New(`ent: missing required field "SoraUsageStat.error_count"`)}
}
if _, ok := _c.mutation.TodayImageCount(); !ok {
return &ValidationError{Name: "today_image_count", err: errors.New(`ent: missing required field "SoraUsageStat.today_image_count"`)}
}
if _, ok := _c.mutation.TodayVideoCount(); !ok {
return &ValidationError{Name: "today_video_count", err: errors.New(`ent: missing required field "SoraUsageStat.today_video_count"`)}
}
if _, ok := _c.mutation.TodayErrorCount(); !ok {
return &ValidationError{Name: "today_error_count", err: errors.New(`ent: missing required field "SoraUsageStat.today_error_count"`)}
}
if _, ok := _c.mutation.ConsecutiveErrorCount(); !ok {
return &ValidationError{Name: "consecutive_error_count", err: errors.New(`ent: missing required field "SoraUsageStat.consecutive_error_count"`)}
}
return nil
}
func (_c *SoraUsageStatCreate) sqlSave(ctx context.Context) (*SoraUsageStat, 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 *SoraUsageStatCreate) createSpec() (*SoraUsageStat, *sqlgraph.CreateSpec) {
var (
_node = &SoraUsageStat{config: _c.config}
_spec = sqlgraph.NewCreateSpec(sorausagestat.Table, sqlgraph.NewFieldSpec(sorausagestat.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(sorausagestat.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(sorausagestat.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.AccountID(); ok {
_spec.SetField(sorausagestat.FieldAccountID, field.TypeInt64, value)
_node.AccountID = value
}
if value, ok := _c.mutation.ImageCount(); ok {
_spec.SetField(sorausagestat.FieldImageCount, field.TypeInt, value)
_node.ImageCount = value
}
if value, ok := _c.mutation.VideoCount(); ok {
_spec.SetField(sorausagestat.FieldVideoCount, field.TypeInt, value)
_node.VideoCount = value
}
if value, ok := _c.mutation.ErrorCount(); ok {
_spec.SetField(sorausagestat.FieldErrorCount, field.TypeInt, value)
_node.ErrorCount = value
}
if value, ok := _c.mutation.LastErrorAt(); ok {
_spec.SetField(sorausagestat.FieldLastErrorAt, field.TypeTime, value)
_node.LastErrorAt = &value
}
if value, ok := _c.mutation.TodayImageCount(); ok {
_spec.SetField(sorausagestat.FieldTodayImageCount, field.TypeInt, value)
_node.TodayImageCount = value
}
if value, ok := _c.mutation.TodayVideoCount(); ok {
_spec.SetField(sorausagestat.FieldTodayVideoCount, field.TypeInt, value)
_node.TodayVideoCount = value
}
if value, ok := _c.mutation.TodayErrorCount(); ok {
_spec.SetField(sorausagestat.FieldTodayErrorCount, field.TypeInt, value)
_node.TodayErrorCount = value
}
if value, ok := _c.mutation.TodayDate(); ok {
_spec.SetField(sorausagestat.FieldTodayDate, field.TypeTime, value)
_node.TodayDate = &value
}
if value, ok := _c.mutation.ConsecutiveErrorCount(); ok {
_spec.SetField(sorausagestat.FieldConsecutiveErrorCount, field.TypeInt, value)
_node.ConsecutiveErrorCount = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.SoraUsageStat.Create().
// SetCreatedAt(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.SoraUsageStatUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *SoraUsageStatCreate) OnConflict(opts ...sql.ConflictOption) *SoraUsageStatUpsertOne {
_c.conflict = opts
return &SoraUsageStatUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.SoraUsageStat.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *SoraUsageStatCreate) OnConflictColumns(columns ...string) *SoraUsageStatUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &SoraUsageStatUpsertOne{
create: _c,
}
}
type (
// SoraUsageStatUpsertOne is the builder for "upsert"-ing
// one SoraUsageStat node.
SoraUsageStatUpsertOne struct {
create *SoraUsageStatCreate
}
// SoraUsageStatUpsert is the "OnConflict" setter.
SoraUsageStatUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *SoraUsageStatUpsert) SetUpdatedAt(v time.Time) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateUpdatedAt() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldUpdatedAt)
return u
}
// SetAccountID sets the "account_id" field.
func (u *SoraUsageStatUpsert) SetAccountID(v int64) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldAccountID, v)
return u
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateAccountID() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldAccountID)
return u
}
// AddAccountID adds v to the "account_id" field.
func (u *SoraUsageStatUpsert) AddAccountID(v int64) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldAccountID, v)
return u
}
// SetImageCount sets the "image_count" field.
func (u *SoraUsageStatUpsert) SetImageCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldImageCount, v)
return u
}
// UpdateImageCount sets the "image_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateImageCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldImageCount)
return u
}
// AddImageCount adds v to the "image_count" field.
func (u *SoraUsageStatUpsert) AddImageCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldImageCount, v)
return u
}
// SetVideoCount sets the "video_count" field.
func (u *SoraUsageStatUpsert) SetVideoCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldVideoCount, v)
return u
}
// UpdateVideoCount sets the "video_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateVideoCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldVideoCount)
return u
}
// AddVideoCount adds v to the "video_count" field.
func (u *SoraUsageStatUpsert) AddVideoCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldVideoCount, v)
return u
}
// SetErrorCount sets the "error_count" field.
func (u *SoraUsageStatUpsert) SetErrorCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldErrorCount, v)
return u
}
// UpdateErrorCount sets the "error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateErrorCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldErrorCount)
return u
}
// AddErrorCount adds v to the "error_count" field.
func (u *SoraUsageStatUpsert) AddErrorCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldErrorCount, v)
return u
}
// SetLastErrorAt sets the "last_error_at" field.
func (u *SoraUsageStatUpsert) SetLastErrorAt(v time.Time) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldLastErrorAt, v)
return u
}
// UpdateLastErrorAt sets the "last_error_at" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateLastErrorAt() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldLastErrorAt)
return u
}
// ClearLastErrorAt clears the value of the "last_error_at" field.
func (u *SoraUsageStatUpsert) ClearLastErrorAt() *SoraUsageStatUpsert {
u.SetNull(sorausagestat.FieldLastErrorAt)
return u
}
// SetTodayImageCount sets the "today_image_count" field.
func (u *SoraUsageStatUpsert) SetTodayImageCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldTodayImageCount, v)
return u
}
// UpdateTodayImageCount sets the "today_image_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateTodayImageCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldTodayImageCount)
return u
}
// AddTodayImageCount adds v to the "today_image_count" field.
func (u *SoraUsageStatUpsert) AddTodayImageCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldTodayImageCount, v)
return u
}
// SetTodayVideoCount sets the "today_video_count" field.
func (u *SoraUsageStatUpsert) SetTodayVideoCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldTodayVideoCount, v)
return u
}
// UpdateTodayVideoCount sets the "today_video_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateTodayVideoCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldTodayVideoCount)
return u
}
// AddTodayVideoCount adds v to the "today_video_count" field.
func (u *SoraUsageStatUpsert) AddTodayVideoCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldTodayVideoCount, v)
return u
}
// SetTodayErrorCount sets the "today_error_count" field.
func (u *SoraUsageStatUpsert) SetTodayErrorCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldTodayErrorCount, v)
return u
}
// UpdateTodayErrorCount sets the "today_error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateTodayErrorCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldTodayErrorCount)
return u
}
// AddTodayErrorCount adds v to the "today_error_count" field.
func (u *SoraUsageStatUpsert) AddTodayErrorCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldTodayErrorCount, v)
return u
}
// SetTodayDate sets the "today_date" field.
func (u *SoraUsageStatUpsert) SetTodayDate(v time.Time) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldTodayDate, v)
return u
}
// UpdateTodayDate sets the "today_date" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateTodayDate() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldTodayDate)
return u
}
// ClearTodayDate clears the value of the "today_date" field.
func (u *SoraUsageStatUpsert) ClearTodayDate() *SoraUsageStatUpsert {
u.SetNull(sorausagestat.FieldTodayDate)
return u
}
// SetConsecutiveErrorCount sets the "consecutive_error_count" field.
func (u *SoraUsageStatUpsert) SetConsecutiveErrorCount(v int) *SoraUsageStatUpsert {
u.Set(sorausagestat.FieldConsecutiveErrorCount, v)
return u
}
// UpdateConsecutiveErrorCount sets the "consecutive_error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsert) UpdateConsecutiveErrorCount() *SoraUsageStatUpsert {
u.SetExcluded(sorausagestat.FieldConsecutiveErrorCount)
return u
}
// AddConsecutiveErrorCount adds v to the "consecutive_error_count" field.
func (u *SoraUsageStatUpsert) AddConsecutiveErrorCount(v int) *SoraUsageStatUpsert {
u.Add(sorausagestat.FieldConsecutiveErrorCount, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.SoraUsageStat.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *SoraUsageStatUpsertOne) UpdateNewValues() *SoraUsageStatUpsertOne {
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(sorausagestat.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.SoraUsageStat.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *SoraUsageStatUpsertOne) Ignore() *SoraUsageStatUpsertOne {
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 *SoraUsageStatUpsertOne) DoNothing() *SoraUsageStatUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the SoraUsageStatCreate.OnConflict
// documentation for more info.
func (u *SoraUsageStatUpsertOne) Update(set func(*SoraUsageStatUpsert)) *SoraUsageStatUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&SoraUsageStatUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *SoraUsageStatUpsertOne) SetUpdatedAt(v time.Time) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateUpdatedAt() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateUpdatedAt()
})
}
// SetAccountID sets the "account_id" field.
func (u *SoraUsageStatUpsertOne) SetAccountID(v int64) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetAccountID(v)
})
}
// AddAccountID adds v to the "account_id" field.
func (u *SoraUsageStatUpsertOne) AddAccountID(v int64) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddAccountID(v)
})
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateAccountID() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateAccountID()
})
}
// SetImageCount sets the "image_count" field.
func (u *SoraUsageStatUpsertOne) SetImageCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetImageCount(v)
})
}
// AddImageCount adds v to the "image_count" field.
func (u *SoraUsageStatUpsertOne) AddImageCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddImageCount(v)
})
}
// UpdateImageCount sets the "image_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateImageCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateImageCount()
})
}
// SetVideoCount sets the "video_count" field.
func (u *SoraUsageStatUpsertOne) SetVideoCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetVideoCount(v)
})
}
// AddVideoCount adds v to the "video_count" field.
func (u *SoraUsageStatUpsertOne) AddVideoCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddVideoCount(v)
})
}
// UpdateVideoCount sets the "video_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateVideoCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateVideoCount()
})
}
// SetErrorCount sets the "error_count" field.
func (u *SoraUsageStatUpsertOne) SetErrorCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetErrorCount(v)
})
}
// AddErrorCount adds v to the "error_count" field.
func (u *SoraUsageStatUpsertOne) AddErrorCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddErrorCount(v)
})
}
// UpdateErrorCount sets the "error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateErrorCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateErrorCount()
})
}
// SetLastErrorAt sets the "last_error_at" field.
func (u *SoraUsageStatUpsertOne) SetLastErrorAt(v time.Time) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetLastErrorAt(v)
})
}
// UpdateLastErrorAt sets the "last_error_at" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateLastErrorAt() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateLastErrorAt()
})
}
// ClearLastErrorAt clears the value of the "last_error_at" field.
func (u *SoraUsageStatUpsertOne) ClearLastErrorAt() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.ClearLastErrorAt()
})
}
// SetTodayImageCount sets the "today_image_count" field.
func (u *SoraUsageStatUpsertOne) SetTodayImageCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayImageCount(v)
})
}
// AddTodayImageCount adds v to the "today_image_count" field.
func (u *SoraUsageStatUpsertOne) AddTodayImageCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddTodayImageCount(v)
})
}
// UpdateTodayImageCount sets the "today_image_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateTodayImageCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayImageCount()
})
}
// SetTodayVideoCount sets the "today_video_count" field.
func (u *SoraUsageStatUpsertOne) SetTodayVideoCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayVideoCount(v)
})
}
// AddTodayVideoCount adds v to the "today_video_count" field.
func (u *SoraUsageStatUpsertOne) AddTodayVideoCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddTodayVideoCount(v)
})
}
// UpdateTodayVideoCount sets the "today_video_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateTodayVideoCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayVideoCount()
})
}
// SetTodayErrorCount sets the "today_error_count" field.
func (u *SoraUsageStatUpsertOne) SetTodayErrorCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayErrorCount(v)
})
}
// AddTodayErrorCount adds v to the "today_error_count" field.
func (u *SoraUsageStatUpsertOne) AddTodayErrorCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddTodayErrorCount(v)
})
}
// UpdateTodayErrorCount sets the "today_error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateTodayErrorCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayErrorCount()
})
}
// SetTodayDate sets the "today_date" field.
func (u *SoraUsageStatUpsertOne) SetTodayDate(v time.Time) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayDate(v)
})
}
// UpdateTodayDate sets the "today_date" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateTodayDate() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayDate()
})
}
// ClearTodayDate clears the value of the "today_date" field.
func (u *SoraUsageStatUpsertOne) ClearTodayDate() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.ClearTodayDate()
})
}
// SetConsecutiveErrorCount sets the "consecutive_error_count" field.
func (u *SoraUsageStatUpsertOne) SetConsecutiveErrorCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetConsecutiveErrorCount(v)
})
}
// AddConsecutiveErrorCount adds v to the "consecutive_error_count" field.
func (u *SoraUsageStatUpsertOne) AddConsecutiveErrorCount(v int) *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddConsecutiveErrorCount(v)
})
}
// UpdateConsecutiveErrorCount sets the "consecutive_error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertOne) UpdateConsecutiveErrorCount() *SoraUsageStatUpsertOne {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateConsecutiveErrorCount()
})
}
// Exec executes the query.
func (u *SoraUsageStatUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for SoraUsageStatCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *SoraUsageStatUpsertOne) 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 *SoraUsageStatUpsertOne) 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 *SoraUsageStatUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// SoraUsageStatCreateBulk is the builder for creating many SoraUsageStat entities in bulk.
type SoraUsageStatCreateBulk struct {
config
err error
builders []*SoraUsageStatCreate
conflict []sql.ConflictOption
}
// Save creates the SoraUsageStat entities in the database.
func (_c *SoraUsageStatCreateBulk) Save(ctx context.Context) ([]*SoraUsageStat, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*SoraUsageStat, 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.(*SoraUsageStatMutation)
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 *SoraUsageStatCreateBulk) SaveX(ctx context.Context) []*SoraUsageStat {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SoraUsageStatCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SoraUsageStatCreateBulk) 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.SoraUsageStat.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.SoraUsageStatUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *SoraUsageStatCreateBulk) OnConflict(opts ...sql.ConflictOption) *SoraUsageStatUpsertBulk {
_c.conflict = opts
return &SoraUsageStatUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.SoraUsageStat.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *SoraUsageStatCreateBulk) OnConflictColumns(columns ...string) *SoraUsageStatUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &SoraUsageStatUpsertBulk{
create: _c,
}
}
// SoraUsageStatUpsertBulk is the builder for "upsert"-ing
// a bulk of SoraUsageStat nodes.
type SoraUsageStatUpsertBulk struct {
create *SoraUsageStatCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.SoraUsageStat.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *SoraUsageStatUpsertBulk) UpdateNewValues() *SoraUsageStatUpsertBulk {
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(sorausagestat.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.SoraUsageStat.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *SoraUsageStatUpsertBulk) Ignore() *SoraUsageStatUpsertBulk {
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 *SoraUsageStatUpsertBulk) DoNothing() *SoraUsageStatUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the SoraUsageStatCreateBulk.OnConflict
// documentation for more info.
func (u *SoraUsageStatUpsertBulk) Update(set func(*SoraUsageStatUpsert)) *SoraUsageStatUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&SoraUsageStatUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *SoraUsageStatUpsertBulk) SetUpdatedAt(v time.Time) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateUpdatedAt() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateUpdatedAt()
})
}
// SetAccountID sets the "account_id" field.
func (u *SoraUsageStatUpsertBulk) SetAccountID(v int64) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetAccountID(v)
})
}
// AddAccountID adds v to the "account_id" field.
func (u *SoraUsageStatUpsertBulk) AddAccountID(v int64) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddAccountID(v)
})
}
// UpdateAccountID sets the "account_id" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateAccountID() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateAccountID()
})
}
// SetImageCount sets the "image_count" field.
func (u *SoraUsageStatUpsertBulk) SetImageCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetImageCount(v)
})
}
// AddImageCount adds v to the "image_count" field.
func (u *SoraUsageStatUpsertBulk) AddImageCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddImageCount(v)
})
}
// UpdateImageCount sets the "image_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateImageCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateImageCount()
})
}
// SetVideoCount sets the "video_count" field.
func (u *SoraUsageStatUpsertBulk) SetVideoCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetVideoCount(v)
})
}
// AddVideoCount adds v to the "video_count" field.
func (u *SoraUsageStatUpsertBulk) AddVideoCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddVideoCount(v)
})
}
// UpdateVideoCount sets the "video_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateVideoCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateVideoCount()
})
}
// SetErrorCount sets the "error_count" field.
func (u *SoraUsageStatUpsertBulk) SetErrorCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetErrorCount(v)
})
}
// AddErrorCount adds v to the "error_count" field.
func (u *SoraUsageStatUpsertBulk) AddErrorCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddErrorCount(v)
})
}
// UpdateErrorCount sets the "error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateErrorCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateErrorCount()
})
}
// SetLastErrorAt sets the "last_error_at" field.
func (u *SoraUsageStatUpsertBulk) SetLastErrorAt(v time.Time) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetLastErrorAt(v)
})
}
// UpdateLastErrorAt sets the "last_error_at" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateLastErrorAt() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateLastErrorAt()
})
}
// ClearLastErrorAt clears the value of the "last_error_at" field.
func (u *SoraUsageStatUpsertBulk) ClearLastErrorAt() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.ClearLastErrorAt()
})
}
// SetTodayImageCount sets the "today_image_count" field.
func (u *SoraUsageStatUpsertBulk) SetTodayImageCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayImageCount(v)
})
}
// AddTodayImageCount adds v to the "today_image_count" field.
func (u *SoraUsageStatUpsertBulk) AddTodayImageCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddTodayImageCount(v)
})
}
// UpdateTodayImageCount sets the "today_image_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateTodayImageCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayImageCount()
})
}
// SetTodayVideoCount sets the "today_video_count" field.
func (u *SoraUsageStatUpsertBulk) SetTodayVideoCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayVideoCount(v)
})
}
// AddTodayVideoCount adds v to the "today_video_count" field.
func (u *SoraUsageStatUpsertBulk) AddTodayVideoCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddTodayVideoCount(v)
})
}
// UpdateTodayVideoCount sets the "today_video_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateTodayVideoCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayVideoCount()
})
}
// SetTodayErrorCount sets the "today_error_count" field.
func (u *SoraUsageStatUpsertBulk) SetTodayErrorCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayErrorCount(v)
})
}
// AddTodayErrorCount adds v to the "today_error_count" field.
func (u *SoraUsageStatUpsertBulk) AddTodayErrorCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddTodayErrorCount(v)
})
}
// UpdateTodayErrorCount sets the "today_error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateTodayErrorCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayErrorCount()
})
}
// SetTodayDate sets the "today_date" field.
func (u *SoraUsageStatUpsertBulk) SetTodayDate(v time.Time) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetTodayDate(v)
})
}
// UpdateTodayDate sets the "today_date" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateTodayDate() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateTodayDate()
})
}
// ClearTodayDate clears the value of the "today_date" field.
func (u *SoraUsageStatUpsertBulk) ClearTodayDate() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.ClearTodayDate()
})
}
// SetConsecutiveErrorCount sets the "consecutive_error_count" field.
func (u *SoraUsageStatUpsertBulk) SetConsecutiveErrorCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.SetConsecutiveErrorCount(v)
})
}
// AddConsecutiveErrorCount adds v to the "consecutive_error_count" field.
func (u *SoraUsageStatUpsertBulk) AddConsecutiveErrorCount(v int) *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.AddConsecutiveErrorCount(v)
})
}
// UpdateConsecutiveErrorCount sets the "consecutive_error_count" field to the value that was provided on create.
func (u *SoraUsageStatUpsertBulk) UpdateConsecutiveErrorCount() *SoraUsageStatUpsertBulk {
return u.Update(func(s *SoraUsageStatUpsert) {
s.UpdateConsecutiveErrorCount()
})
}
// Exec executes the query.
func (u *SoraUsageStatUpsertBulk) 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 SoraUsageStatCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for SoraUsageStatCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *SoraUsageStatUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}