sub2api/backend/ent/userplatformquota_create.go
DaydreamCoding 6b39b344d8 feat(quota): 用户 × 平台 USD 配额
为用户在 anthropic/openai/gemini/antigravity 四个平台上提供日/周/月
三个窗口的 USD 配额管控。配额语义:未设置=不限制,0=禁用,>0=美元上限。

两层模型:
- 配置层:系统默认配额,以及 email/linuxdo/oidc/wechat/github/google/
  dingtalk 七个鉴权来源的默认配额,存于 settings,以嵌套 JSON 整体读写
  (系统 1 个 key + 每个来源 1 个 key),整体替换语义。
- 运行时层:user_platform_quota 表按用户记录实际配额,与配置层解耦。

后端:新增 ent schema 与 140_user_platform_quotas.sql 迁移、repository
与 service 端口、计费链路集成、管理端与用户端读写接口。
前端:管理端设置页配额编辑、用户配额管理 Modal、用户 Dashboard 展示、
中英文案。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 10:49:20 +08:00

1514 lines
51 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/user"
"github.com/Wei-Shaw/sub2api/ent/userplatformquota"
)
// UserPlatformQuotaCreate is the builder for creating a UserPlatformQuota entity.
type UserPlatformQuotaCreate struct {
config
mutation *UserPlatformQuotaMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *UserPlatformQuotaCreate) SetCreatedAt(v time.Time) *UserPlatformQuotaCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableCreatedAt(v *time.Time) *UserPlatformQuotaCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *UserPlatformQuotaCreate) SetUpdatedAt(v time.Time) *UserPlatformQuotaCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableUpdatedAt(v *time.Time) *UserPlatformQuotaCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetDeletedAt sets the "deleted_at" field.
func (_c *UserPlatformQuotaCreate) SetDeletedAt(v time.Time) *UserPlatformQuotaCreate {
_c.mutation.SetDeletedAt(v)
return _c
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableDeletedAt(v *time.Time) *UserPlatformQuotaCreate {
if v != nil {
_c.SetDeletedAt(*v)
}
return _c
}
// SetUserID sets the "user_id" field.
func (_c *UserPlatformQuotaCreate) SetUserID(v int64) *UserPlatformQuotaCreate {
_c.mutation.SetUserID(v)
return _c
}
// SetPlatform sets the "platform" field.
func (_c *UserPlatformQuotaCreate) SetPlatform(v string) *UserPlatformQuotaCreate {
_c.mutation.SetPlatform(v)
return _c
}
// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (_c *UserPlatformQuotaCreate) SetDailyLimitUsd(v float64) *UserPlatformQuotaCreate {
_c.mutation.SetDailyLimitUsd(v)
return _c
}
// SetNillableDailyLimitUsd sets the "daily_limit_usd" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableDailyLimitUsd(v *float64) *UserPlatformQuotaCreate {
if v != nil {
_c.SetDailyLimitUsd(*v)
}
return _c
}
// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (_c *UserPlatformQuotaCreate) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaCreate {
_c.mutation.SetWeeklyLimitUsd(v)
return _c
}
// SetNillableWeeklyLimitUsd sets the "weekly_limit_usd" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableWeeklyLimitUsd(v *float64) *UserPlatformQuotaCreate {
if v != nil {
_c.SetWeeklyLimitUsd(*v)
}
return _c
}
// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (_c *UserPlatformQuotaCreate) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaCreate {
_c.mutation.SetMonthlyLimitUsd(v)
return _c
}
// SetNillableMonthlyLimitUsd sets the "monthly_limit_usd" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableMonthlyLimitUsd(v *float64) *UserPlatformQuotaCreate {
if v != nil {
_c.SetMonthlyLimitUsd(*v)
}
return _c
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (_c *UserPlatformQuotaCreate) SetDailyUsageUsd(v float64) *UserPlatformQuotaCreate {
_c.mutation.SetDailyUsageUsd(v)
return _c
}
// SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableDailyUsageUsd(v *float64) *UserPlatformQuotaCreate {
if v != nil {
_c.SetDailyUsageUsd(*v)
}
return _c
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (_c *UserPlatformQuotaCreate) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaCreate {
_c.mutation.SetWeeklyUsageUsd(v)
return _c
}
// SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableWeeklyUsageUsd(v *float64) *UserPlatformQuotaCreate {
if v != nil {
_c.SetWeeklyUsageUsd(*v)
}
return _c
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (_c *UserPlatformQuotaCreate) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaCreate {
_c.mutation.SetMonthlyUsageUsd(v)
return _c
}
// SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableMonthlyUsageUsd(v *float64) *UserPlatformQuotaCreate {
if v != nil {
_c.SetMonthlyUsageUsd(*v)
}
return _c
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (_c *UserPlatformQuotaCreate) SetDailyWindowStart(v time.Time) *UserPlatformQuotaCreate {
_c.mutation.SetDailyWindowStart(v)
return _c
}
// SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableDailyWindowStart(v *time.Time) *UserPlatformQuotaCreate {
if v != nil {
_c.SetDailyWindowStart(*v)
}
return _c
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (_c *UserPlatformQuotaCreate) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaCreate {
_c.mutation.SetWeeklyWindowStart(v)
return _c
}
// SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableWeeklyWindowStart(v *time.Time) *UserPlatformQuotaCreate {
if v != nil {
_c.SetWeeklyWindowStart(*v)
}
return _c
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (_c *UserPlatformQuotaCreate) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaCreate {
_c.mutation.SetMonthlyWindowStart(v)
return _c
}
// SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
func (_c *UserPlatformQuotaCreate) SetNillableMonthlyWindowStart(v *time.Time) *UserPlatformQuotaCreate {
if v != nil {
_c.SetMonthlyWindowStart(*v)
}
return _c
}
// SetUser sets the "user" edge to the User entity.
func (_c *UserPlatformQuotaCreate) SetUser(v *User) *UserPlatformQuotaCreate {
return _c.SetUserID(v.ID)
}
// Mutation returns the UserPlatformQuotaMutation object of the builder.
func (_c *UserPlatformQuotaCreate) Mutation() *UserPlatformQuotaMutation {
return _c.mutation
}
// Save creates the UserPlatformQuota in the database.
func (_c *UserPlatformQuotaCreate) Save(ctx context.Context) (*UserPlatformQuota, error) {
if err := _c.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *UserPlatformQuotaCreate) SaveX(ctx context.Context) *UserPlatformQuota {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UserPlatformQuotaCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UserPlatformQuotaCreate) 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 *UserPlatformQuotaCreate) defaults() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
if userplatformquota.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized userplatformquota.DefaultCreatedAt (forgotten import ent/runtime?)")
}
v := userplatformquota.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
if userplatformquota.DefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized userplatformquota.DefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := userplatformquota.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.DailyUsageUsd(); !ok {
v := userplatformquota.DefaultDailyUsageUsd
_c.mutation.SetDailyUsageUsd(v)
}
if _, ok := _c.mutation.WeeklyUsageUsd(); !ok {
v := userplatformquota.DefaultWeeklyUsageUsd
_c.mutation.SetWeeklyUsageUsd(v)
}
if _, ok := _c.mutation.MonthlyUsageUsd(); !ok {
v := userplatformquota.DefaultMonthlyUsageUsd
_c.mutation.SetMonthlyUsageUsd(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_c *UserPlatformQuotaCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UserPlatformQuota.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UserPlatformQuota.updated_at"`)}
}
if _, ok := _c.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserPlatformQuota.user_id"`)}
}
if _, ok := _c.mutation.Platform(); !ok {
return &ValidationError{Name: "platform", err: errors.New(`ent: missing required field "UserPlatformQuota.platform"`)}
}
if v, ok := _c.mutation.Platform(); ok {
if err := userplatformquota.PlatformValidator(v); err != nil {
return &ValidationError{Name: "platform", err: fmt.Errorf(`ent: validator failed for field "UserPlatformQuota.platform": %w`, err)}
}
}
if _, ok := _c.mutation.DailyUsageUsd(); !ok {
return &ValidationError{Name: "daily_usage_usd", err: errors.New(`ent: missing required field "UserPlatformQuota.daily_usage_usd"`)}
}
if _, ok := _c.mutation.WeeklyUsageUsd(); !ok {
return &ValidationError{Name: "weekly_usage_usd", err: errors.New(`ent: missing required field "UserPlatformQuota.weekly_usage_usd"`)}
}
if _, ok := _c.mutation.MonthlyUsageUsd(); !ok {
return &ValidationError{Name: "monthly_usage_usd", err: errors.New(`ent: missing required field "UserPlatformQuota.monthly_usage_usd"`)}
}
if len(_c.mutation.UserIDs()) == 0 {
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UserPlatformQuota.user"`)}
}
return nil
}
func (_c *UserPlatformQuotaCreate) sqlSave(ctx context.Context) (*UserPlatformQuota, 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 *UserPlatformQuotaCreate) createSpec() (*UserPlatformQuota, *sqlgraph.CreateSpec) {
var (
_node = &UserPlatformQuota{config: _c.config}
_spec = sqlgraph.NewCreateSpec(userplatformquota.Table, sqlgraph.NewFieldSpec(userplatformquota.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(userplatformquota.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(userplatformquota.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.DeletedAt(); ok {
_spec.SetField(userplatformquota.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = &value
}
if value, ok := _c.mutation.Platform(); ok {
_spec.SetField(userplatformquota.FieldPlatform, field.TypeString, value)
_node.Platform = value
}
if value, ok := _c.mutation.DailyLimitUsd(); ok {
_spec.SetField(userplatformquota.FieldDailyLimitUsd, field.TypeFloat64, value)
_node.DailyLimitUsd = &value
}
if value, ok := _c.mutation.WeeklyLimitUsd(); ok {
_spec.SetField(userplatformquota.FieldWeeklyLimitUsd, field.TypeFloat64, value)
_node.WeeklyLimitUsd = &value
}
if value, ok := _c.mutation.MonthlyLimitUsd(); ok {
_spec.SetField(userplatformquota.FieldMonthlyLimitUsd, field.TypeFloat64, value)
_node.MonthlyLimitUsd = &value
}
if value, ok := _c.mutation.DailyUsageUsd(); ok {
_spec.SetField(userplatformquota.FieldDailyUsageUsd, field.TypeFloat64, value)
_node.DailyUsageUsd = value
}
if value, ok := _c.mutation.WeeklyUsageUsd(); ok {
_spec.SetField(userplatformquota.FieldWeeklyUsageUsd, field.TypeFloat64, value)
_node.WeeklyUsageUsd = value
}
if value, ok := _c.mutation.MonthlyUsageUsd(); ok {
_spec.SetField(userplatformquota.FieldMonthlyUsageUsd, field.TypeFloat64, value)
_node.MonthlyUsageUsd = value
}
if value, ok := _c.mutation.DailyWindowStart(); ok {
_spec.SetField(userplatformquota.FieldDailyWindowStart, field.TypeTime, value)
_node.DailyWindowStart = &value
}
if value, ok := _c.mutation.WeeklyWindowStart(); ok {
_spec.SetField(userplatformquota.FieldWeeklyWindowStart, field.TypeTime, value)
_node.WeeklyWindowStart = &value
}
if value, ok := _c.mutation.MonthlyWindowStart(); ok {
_spec.SetField(userplatformquota.FieldMonthlyWindowStart, field.TypeTime, value)
_node.MonthlyWindowStart = &value
}
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: userplatformquota.UserTable,
Columns: []string{userplatformquota.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)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UserPlatformQuota.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.UserPlatformQuotaUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *UserPlatformQuotaCreate) OnConflict(opts ...sql.ConflictOption) *UserPlatformQuotaUpsertOne {
_c.conflict = opts
return &UserPlatformQuotaUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UserPlatformQuota.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *UserPlatformQuotaCreate) OnConflictColumns(columns ...string) *UserPlatformQuotaUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &UserPlatformQuotaUpsertOne{
create: _c,
}
}
type (
// UserPlatformQuotaUpsertOne is the builder for "upsert"-ing
// one UserPlatformQuota node.
UserPlatformQuotaUpsertOne struct {
create *UserPlatformQuotaCreate
}
// UserPlatformQuotaUpsert is the "OnConflict" setter.
UserPlatformQuotaUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *UserPlatformQuotaUpsert) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateUpdatedAt() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldUpdatedAt)
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserPlatformQuotaUpsert) SetDeletedAt(v time.Time) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateDeletedAt() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserPlatformQuotaUpsert) ClearDeletedAt() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldDeletedAt)
return u
}
// SetUserID sets the "user_id" field.
func (u *UserPlatformQuotaUpsert) SetUserID(v int64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldUserID, v)
return u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateUserID() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldUserID)
return u
}
// SetPlatform sets the "platform" field.
func (u *UserPlatformQuotaUpsert) SetPlatform(v string) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldPlatform, v)
return u
}
// UpdatePlatform sets the "platform" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdatePlatform() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldPlatform)
return u
}
// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsert) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldDailyLimitUsd, v)
return u
}
// UpdateDailyLimitUsd sets the "daily_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateDailyLimitUsd() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldDailyLimitUsd)
return u
}
// AddDailyLimitUsd adds v to the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsert) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpsert {
u.Add(userplatformquota.FieldDailyLimitUsd, v)
return u
}
// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsert) ClearDailyLimitUsd() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldDailyLimitUsd)
return u
}
// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsert) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldWeeklyLimitUsd, v)
return u
}
// UpdateWeeklyLimitUsd sets the "weekly_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateWeeklyLimitUsd() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldWeeklyLimitUsd)
return u
}
// AddWeeklyLimitUsd adds v to the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsert) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpsert {
u.Add(userplatformquota.FieldWeeklyLimitUsd, v)
return u
}
// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsert) ClearWeeklyLimitUsd() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldWeeklyLimitUsd)
return u
}
// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsert) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldMonthlyLimitUsd, v)
return u
}
// UpdateMonthlyLimitUsd sets the "monthly_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateMonthlyLimitUsd() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldMonthlyLimitUsd)
return u
}
// AddMonthlyLimitUsd adds v to the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsert) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpsert {
u.Add(userplatformquota.FieldMonthlyLimitUsd, v)
return u
}
// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsert) ClearMonthlyLimitUsd() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldMonthlyLimitUsd)
return u
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (u *UserPlatformQuotaUpsert) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldDailyUsageUsd, v)
return u
}
// UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateDailyUsageUsd() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldDailyUsageUsd)
return u
}
// AddDailyUsageUsd adds v to the "daily_usage_usd" field.
func (u *UserPlatformQuotaUpsert) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpsert {
u.Add(userplatformquota.FieldDailyUsageUsd, v)
return u
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (u *UserPlatformQuotaUpsert) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldWeeklyUsageUsd, v)
return u
}
// UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateWeeklyUsageUsd() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldWeeklyUsageUsd)
return u
}
// AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
func (u *UserPlatformQuotaUpsert) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpsert {
u.Add(userplatformquota.FieldWeeklyUsageUsd, v)
return u
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (u *UserPlatformQuotaUpsert) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldMonthlyUsageUsd, v)
return u
}
// UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateMonthlyUsageUsd() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldMonthlyUsageUsd)
return u
}
// AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
func (u *UserPlatformQuotaUpsert) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpsert {
u.Add(userplatformquota.FieldMonthlyUsageUsd, v)
return u
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (u *UserPlatformQuotaUpsert) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldDailyWindowStart, v)
return u
}
// UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateDailyWindowStart() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldDailyWindowStart)
return u
}
// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (u *UserPlatformQuotaUpsert) ClearDailyWindowStart() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldDailyWindowStart)
return u
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (u *UserPlatformQuotaUpsert) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldWeeklyWindowStart, v)
return u
}
// UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateWeeklyWindowStart() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldWeeklyWindowStart)
return u
}
// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (u *UserPlatformQuotaUpsert) ClearWeeklyWindowStart() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldWeeklyWindowStart)
return u
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (u *UserPlatformQuotaUpsert) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpsert {
u.Set(userplatformquota.FieldMonthlyWindowStart, v)
return u
}
// UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsert) UpdateMonthlyWindowStart() *UserPlatformQuotaUpsert {
u.SetExcluded(userplatformquota.FieldMonthlyWindowStart)
return u
}
// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (u *UserPlatformQuotaUpsert) ClearMonthlyWindowStart() *UserPlatformQuotaUpsert {
u.SetNull(userplatformquota.FieldMonthlyWindowStart)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.UserPlatformQuota.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *UserPlatformQuotaUpsertOne) UpdateNewValues() *UserPlatformQuotaUpsertOne {
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(userplatformquota.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UserPlatformQuota.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *UserPlatformQuotaUpsertOne) Ignore() *UserPlatformQuotaUpsertOne {
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 *UserPlatformQuotaUpsertOne) DoNothing() *UserPlatformQuotaUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the UserPlatformQuotaCreate.OnConflict
// documentation for more info.
func (u *UserPlatformQuotaUpsertOne) Update(set func(*UserPlatformQuotaUpsert)) *UserPlatformQuotaUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&UserPlatformQuotaUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *UserPlatformQuotaUpsertOne) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateUpdatedAt() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserPlatformQuotaUpsertOne) SetDeletedAt(v time.Time) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateDeletedAt() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserPlatformQuotaUpsertOne) ClearDeletedAt() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearDeletedAt()
})
}
// SetUserID sets the "user_id" field.
func (u *UserPlatformQuotaUpsertOne) SetUserID(v int64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateUserID() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateUserID()
})
}
// SetPlatform sets the "platform" field.
func (u *UserPlatformQuotaUpsertOne) SetPlatform(v string) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetPlatform(v)
})
}
// UpdatePlatform sets the "platform" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdatePlatform() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdatePlatform()
})
}
// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDailyLimitUsd(v)
})
}
// AddDailyLimitUsd adds v to the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddDailyLimitUsd(v)
})
}
// UpdateDailyLimitUsd sets the "daily_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateDailyLimitUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDailyLimitUsd()
})
}
// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) ClearDailyLimitUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearDailyLimitUsd()
})
}
// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetWeeklyLimitUsd(v)
})
}
// AddWeeklyLimitUsd adds v to the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddWeeklyLimitUsd(v)
})
}
// UpdateWeeklyLimitUsd sets the "weekly_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateWeeklyLimitUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateWeeklyLimitUsd()
})
}
// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) ClearWeeklyLimitUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearWeeklyLimitUsd()
})
}
// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetMonthlyLimitUsd(v)
})
}
// AddMonthlyLimitUsd adds v to the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddMonthlyLimitUsd(v)
})
}
// UpdateMonthlyLimitUsd sets the "monthly_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateMonthlyLimitUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateMonthlyLimitUsd()
})
}
// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsertOne) ClearMonthlyLimitUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearMonthlyLimitUsd()
})
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (u *UserPlatformQuotaUpsertOne) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDailyUsageUsd(v)
})
}
// AddDailyUsageUsd adds v to the "daily_usage_usd" field.
func (u *UserPlatformQuotaUpsertOne) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddDailyUsageUsd(v)
})
}
// UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateDailyUsageUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDailyUsageUsd()
})
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (u *UserPlatformQuotaUpsertOne) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetWeeklyUsageUsd(v)
})
}
// AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
func (u *UserPlatformQuotaUpsertOne) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddWeeklyUsageUsd(v)
})
}
// UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateWeeklyUsageUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateWeeklyUsageUsd()
})
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (u *UserPlatformQuotaUpsertOne) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetMonthlyUsageUsd(v)
})
}
// AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
func (u *UserPlatformQuotaUpsertOne) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddMonthlyUsageUsd(v)
})
}
// UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateMonthlyUsageUsd() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateMonthlyUsageUsd()
})
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (u *UserPlatformQuotaUpsertOne) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDailyWindowStart(v)
})
}
// UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateDailyWindowStart() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDailyWindowStart()
})
}
// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (u *UserPlatformQuotaUpsertOne) ClearDailyWindowStart() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearDailyWindowStart()
})
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (u *UserPlatformQuotaUpsertOne) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetWeeklyWindowStart(v)
})
}
// UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateWeeklyWindowStart() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateWeeklyWindowStart()
})
}
// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (u *UserPlatformQuotaUpsertOne) ClearWeeklyWindowStart() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearWeeklyWindowStart()
})
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (u *UserPlatformQuotaUpsertOne) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetMonthlyWindowStart(v)
})
}
// UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertOne) UpdateMonthlyWindowStart() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateMonthlyWindowStart()
})
}
// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (u *UserPlatformQuotaUpsertOne) ClearMonthlyWindowStart() *UserPlatformQuotaUpsertOne {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearMonthlyWindowStart()
})
}
// Exec executes the query.
func (u *UserPlatformQuotaUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for UserPlatformQuotaCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *UserPlatformQuotaUpsertOne) 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 *UserPlatformQuotaUpsertOne) 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 *UserPlatformQuotaUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// UserPlatformQuotaCreateBulk is the builder for creating many UserPlatformQuota entities in bulk.
type UserPlatformQuotaCreateBulk struct {
config
err error
builders []*UserPlatformQuotaCreate
conflict []sql.ConflictOption
}
// Save creates the UserPlatformQuota entities in the database.
func (_c *UserPlatformQuotaCreateBulk) Save(ctx context.Context) ([]*UserPlatformQuota, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*UserPlatformQuota, 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.(*UserPlatformQuotaMutation)
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 *UserPlatformQuotaCreateBulk) SaveX(ctx context.Context) []*UserPlatformQuota {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UserPlatformQuotaCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UserPlatformQuotaCreateBulk) 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.UserPlatformQuota.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.UserPlatformQuotaUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *UserPlatformQuotaCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserPlatformQuotaUpsertBulk {
_c.conflict = opts
return &UserPlatformQuotaUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UserPlatformQuota.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *UserPlatformQuotaCreateBulk) OnConflictColumns(columns ...string) *UserPlatformQuotaUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &UserPlatformQuotaUpsertBulk{
create: _c,
}
}
// UserPlatformQuotaUpsertBulk is the builder for "upsert"-ing
// a bulk of UserPlatformQuota nodes.
type UserPlatformQuotaUpsertBulk struct {
create *UserPlatformQuotaCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.UserPlatformQuota.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *UserPlatformQuotaUpsertBulk) UpdateNewValues() *UserPlatformQuotaUpsertBulk {
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(userplatformquota.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UserPlatformQuota.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *UserPlatformQuotaUpsertBulk) Ignore() *UserPlatformQuotaUpsertBulk {
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 *UserPlatformQuotaUpsertBulk) DoNothing() *UserPlatformQuotaUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the UserPlatformQuotaCreateBulk.OnConflict
// documentation for more info.
func (u *UserPlatformQuotaUpsertBulk) Update(set func(*UserPlatformQuotaUpsert)) *UserPlatformQuotaUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&UserPlatformQuotaUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *UserPlatformQuotaUpsertBulk) SetUpdatedAt(v time.Time) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateUpdatedAt() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserPlatformQuotaUpsertBulk) SetDeletedAt(v time.Time) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateDeletedAt() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserPlatformQuotaUpsertBulk) ClearDeletedAt() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearDeletedAt()
})
}
// SetUserID sets the "user_id" field.
func (u *UserPlatformQuotaUpsertBulk) SetUserID(v int64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateUserID() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateUserID()
})
}
// SetPlatform sets the "platform" field.
func (u *UserPlatformQuotaUpsertBulk) SetPlatform(v string) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetPlatform(v)
})
}
// UpdatePlatform sets the "platform" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdatePlatform() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdatePlatform()
})
}
// SetDailyLimitUsd sets the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) SetDailyLimitUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDailyLimitUsd(v)
})
}
// AddDailyLimitUsd adds v to the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) AddDailyLimitUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddDailyLimitUsd(v)
})
}
// UpdateDailyLimitUsd sets the "daily_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateDailyLimitUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDailyLimitUsd()
})
}
// ClearDailyLimitUsd clears the value of the "daily_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) ClearDailyLimitUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearDailyLimitUsd()
})
}
// SetWeeklyLimitUsd sets the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) SetWeeklyLimitUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetWeeklyLimitUsd(v)
})
}
// AddWeeklyLimitUsd adds v to the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) AddWeeklyLimitUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddWeeklyLimitUsd(v)
})
}
// UpdateWeeklyLimitUsd sets the "weekly_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateWeeklyLimitUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateWeeklyLimitUsd()
})
}
// ClearWeeklyLimitUsd clears the value of the "weekly_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) ClearWeeklyLimitUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearWeeklyLimitUsd()
})
}
// SetMonthlyLimitUsd sets the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) SetMonthlyLimitUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetMonthlyLimitUsd(v)
})
}
// AddMonthlyLimitUsd adds v to the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) AddMonthlyLimitUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddMonthlyLimitUsd(v)
})
}
// UpdateMonthlyLimitUsd sets the "monthly_limit_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateMonthlyLimitUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateMonthlyLimitUsd()
})
}
// ClearMonthlyLimitUsd clears the value of the "monthly_limit_usd" field.
func (u *UserPlatformQuotaUpsertBulk) ClearMonthlyLimitUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearMonthlyLimitUsd()
})
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (u *UserPlatformQuotaUpsertBulk) SetDailyUsageUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDailyUsageUsd(v)
})
}
// AddDailyUsageUsd adds v to the "daily_usage_usd" field.
func (u *UserPlatformQuotaUpsertBulk) AddDailyUsageUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddDailyUsageUsd(v)
})
}
// UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateDailyUsageUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDailyUsageUsd()
})
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (u *UserPlatformQuotaUpsertBulk) SetWeeklyUsageUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetWeeklyUsageUsd(v)
})
}
// AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
func (u *UserPlatformQuotaUpsertBulk) AddWeeklyUsageUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddWeeklyUsageUsd(v)
})
}
// UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateWeeklyUsageUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateWeeklyUsageUsd()
})
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (u *UserPlatformQuotaUpsertBulk) SetMonthlyUsageUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetMonthlyUsageUsd(v)
})
}
// AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
func (u *UserPlatformQuotaUpsertBulk) AddMonthlyUsageUsd(v float64) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.AddMonthlyUsageUsd(v)
})
}
// UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateMonthlyUsageUsd() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateMonthlyUsageUsd()
})
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (u *UserPlatformQuotaUpsertBulk) SetDailyWindowStart(v time.Time) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetDailyWindowStart(v)
})
}
// UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateDailyWindowStart() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateDailyWindowStart()
})
}
// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (u *UserPlatformQuotaUpsertBulk) ClearDailyWindowStart() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearDailyWindowStart()
})
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (u *UserPlatformQuotaUpsertBulk) SetWeeklyWindowStart(v time.Time) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetWeeklyWindowStart(v)
})
}
// UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateWeeklyWindowStart() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateWeeklyWindowStart()
})
}
// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (u *UserPlatformQuotaUpsertBulk) ClearWeeklyWindowStart() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearWeeklyWindowStart()
})
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (u *UserPlatformQuotaUpsertBulk) SetMonthlyWindowStart(v time.Time) *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.SetMonthlyWindowStart(v)
})
}
// UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
func (u *UserPlatformQuotaUpsertBulk) UpdateMonthlyWindowStart() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.UpdateMonthlyWindowStart()
})
}
// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (u *UserPlatformQuotaUpsertBulk) ClearMonthlyWindowStart() *UserPlatformQuotaUpsertBulk {
return u.Update(func(s *UserPlatformQuotaUpsert) {
s.ClearMonthlyWindowStart()
})
}
// Exec executes the query.
func (u *UserPlatformQuotaUpsertBulk) 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 UserPlatformQuotaCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for UserPlatformQuotaCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *UserPlatformQuotaUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}