Files
xinghuoapi/backend/ent/usersubscription_create.go
yangjianbo 5906f9ab98 fix(数据层): 修复数据完整性与仓储一致性问题
## 数据完整性修复 (fix-critical-data-integrity)
- 添加 error_translate.go 统一错误转换层
- 修复 nil 输入和 NotFound 错误处理
- 增强仓储层错误一致性

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

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

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

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 14:11:57 +08:00

1701 lines
56 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/group"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
// UserSubscriptionCreate is the builder for creating a UserSubscription entity.
type UserSubscriptionCreate struct {
config
mutation *UserSubscriptionMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *UserSubscriptionCreate) SetCreatedAt(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableCreatedAt(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *UserSubscriptionCreate) SetUpdatedAt(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableUpdatedAt(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetDeletedAt sets the "deleted_at" field.
func (_c *UserSubscriptionCreate) SetDeletedAt(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetDeletedAt(v)
return _c
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableDeletedAt(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetDeletedAt(*v)
}
return _c
}
// SetUserID sets the "user_id" field.
func (_c *UserSubscriptionCreate) SetUserID(v int64) *UserSubscriptionCreate {
_c.mutation.SetUserID(v)
return _c
}
// SetGroupID sets the "group_id" field.
func (_c *UserSubscriptionCreate) SetGroupID(v int64) *UserSubscriptionCreate {
_c.mutation.SetGroupID(v)
return _c
}
// SetStartsAt sets the "starts_at" field.
func (_c *UserSubscriptionCreate) SetStartsAt(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetStartsAt(v)
return _c
}
// SetExpiresAt sets the "expires_at" field.
func (_c *UserSubscriptionCreate) SetExpiresAt(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetExpiresAt(v)
return _c
}
// SetStatus sets the "status" field.
func (_c *UserSubscriptionCreate) SetStatus(v string) *UserSubscriptionCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableStatus(v *string) *UserSubscriptionCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (_c *UserSubscriptionCreate) SetDailyWindowStart(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetDailyWindowStart(v)
return _c
}
// SetNillableDailyWindowStart sets the "daily_window_start" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableDailyWindowStart(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetDailyWindowStart(*v)
}
return _c
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (_c *UserSubscriptionCreate) SetWeeklyWindowStart(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetWeeklyWindowStart(v)
return _c
}
// SetNillableWeeklyWindowStart sets the "weekly_window_start" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableWeeklyWindowStart(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetWeeklyWindowStart(*v)
}
return _c
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (_c *UserSubscriptionCreate) SetMonthlyWindowStart(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetMonthlyWindowStart(v)
return _c
}
// SetNillableMonthlyWindowStart sets the "monthly_window_start" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableMonthlyWindowStart(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetMonthlyWindowStart(*v)
}
return _c
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (_c *UserSubscriptionCreate) SetDailyUsageUsd(v float64) *UserSubscriptionCreate {
_c.mutation.SetDailyUsageUsd(v)
return _c
}
// SetNillableDailyUsageUsd sets the "daily_usage_usd" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableDailyUsageUsd(v *float64) *UserSubscriptionCreate {
if v != nil {
_c.SetDailyUsageUsd(*v)
}
return _c
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (_c *UserSubscriptionCreate) SetWeeklyUsageUsd(v float64) *UserSubscriptionCreate {
_c.mutation.SetWeeklyUsageUsd(v)
return _c
}
// SetNillableWeeklyUsageUsd sets the "weekly_usage_usd" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableWeeklyUsageUsd(v *float64) *UserSubscriptionCreate {
if v != nil {
_c.SetWeeklyUsageUsd(*v)
}
return _c
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (_c *UserSubscriptionCreate) SetMonthlyUsageUsd(v float64) *UserSubscriptionCreate {
_c.mutation.SetMonthlyUsageUsd(v)
return _c
}
// SetNillableMonthlyUsageUsd sets the "monthly_usage_usd" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableMonthlyUsageUsd(v *float64) *UserSubscriptionCreate {
if v != nil {
_c.SetMonthlyUsageUsd(*v)
}
return _c
}
// SetAssignedBy sets the "assigned_by" field.
func (_c *UserSubscriptionCreate) SetAssignedBy(v int64) *UserSubscriptionCreate {
_c.mutation.SetAssignedBy(v)
return _c
}
// SetNillableAssignedBy sets the "assigned_by" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableAssignedBy(v *int64) *UserSubscriptionCreate {
if v != nil {
_c.SetAssignedBy(*v)
}
return _c
}
// SetAssignedAt sets the "assigned_at" field.
func (_c *UserSubscriptionCreate) SetAssignedAt(v time.Time) *UserSubscriptionCreate {
_c.mutation.SetAssignedAt(v)
return _c
}
// SetNillableAssignedAt sets the "assigned_at" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableAssignedAt(v *time.Time) *UserSubscriptionCreate {
if v != nil {
_c.SetAssignedAt(*v)
}
return _c
}
// SetNotes sets the "notes" field.
func (_c *UserSubscriptionCreate) SetNotes(v string) *UserSubscriptionCreate {
_c.mutation.SetNotes(v)
return _c
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableNotes(v *string) *UserSubscriptionCreate {
if v != nil {
_c.SetNotes(*v)
}
return _c
}
// SetUser sets the "user" edge to the User entity.
func (_c *UserSubscriptionCreate) SetUser(v *User) *UserSubscriptionCreate {
return _c.SetUserID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_c *UserSubscriptionCreate) SetGroup(v *Group) *UserSubscriptionCreate {
return _c.SetGroupID(v.ID)
}
// SetAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID.
func (_c *UserSubscriptionCreate) SetAssignedByUserID(id int64) *UserSubscriptionCreate {
_c.mutation.SetAssignedByUserID(id)
return _c
}
// SetNillableAssignedByUserID sets the "assigned_by_user" edge to the User entity by ID if the given value is not nil.
func (_c *UserSubscriptionCreate) SetNillableAssignedByUserID(id *int64) *UserSubscriptionCreate {
if id != nil {
_c = _c.SetAssignedByUserID(*id)
}
return _c
}
// SetAssignedByUser sets the "assigned_by_user" edge to the User entity.
func (_c *UserSubscriptionCreate) SetAssignedByUser(v *User) *UserSubscriptionCreate {
return _c.SetAssignedByUserID(v.ID)
}
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
func (_c *UserSubscriptionCreate) AddUsageLogIDs(ids ...int64) *UserSubscriptionCreate {
_c.mutation.AddUsageLogIDs(ids...)
return _c
}
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
func (_c *UserSubscriptionCreate) AddUsageLogs(v ...*UsageLog) *UserSubscriptionCreate {
ids := make([]int64, len(v))
for i := range v {
ids[i] = v[i].ID
}
return _c.AddUsageLogIDs(ids...)
}
// Mutation returns the UserSubscriptionMutation object of the builder.
func (_c *UserSubscriptionCreate) Mutation() *UserSubscriptionMutation {
return _c.mutation
}
// Save creates the UserSubscription in the database.
func (_c *UserSubscriptionCreate) Save(ctx context.Context) (*UserSubscription, 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 *UserSubscriptionCreate) SaveX(ctx context.Context) *UserSubscription {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UserSubscriptionCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UserSubscriptionCreate) 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 *UserSubscriptionCreate) defaults() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
if usersubscription.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized usersubscription.DefaultCreatedAt (forgotten import ent/runtime?)")
}
v := usersubscription.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
if usersubscription.DefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized usersubscription.DefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := usersubscription.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := usersubscription.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.DailyUsageUsd(); !ok {
v := usersubscription.DefaultDailyUsageUsd
_c.mutation.SetDailyUsageUsd(v)
}
if _, ok := _c.mutation.WeeklyUsageUsd(); !ok {
v := usersubscription.DefaultWeeklyUsageUsd
_c.mutation.SetWeeklyUsageUsd(v)
}
if _, ok := _c.mutation.MonthlyUsageUsd(); !ok {
v := usersubscription.DefaultMonthlyUsageUsd
_c.mutation.SetMonthlyUsageUsd(v)
}
if _, ok := _c.mutation.AssignedAt(); !ok {
if usersubscription.DefaultAssignedAt == nil {
return fmt.Errorf("ent: uninitialized usersubscription.DefaultAssignedAt (forgotten import ent/runtime?)")
}
v := usersubscription.DefaultAssignedAt()
_c.mutation.SetAssignedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_c *UserSubscriptionCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "UserSubscription.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "UserSubscription.updated_at"`)}
}
if _, ok := _c.mutation.UserID(); !ok {
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "UserSubscription.user_id"`)}
}
if _, ok := _c.mutation.GroupID(); !ok {
return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "UserSubscription.group_id"`)}
}
if _, ok := _c.mutation.StartsAt(); !ok {
return &ValidationError{Name: "starts_at", err: errors.New(`ent: missing required field "UserSubscription.starts_at"`)}
}
if _, ok := _c.mutation.ExpiresAt(); !ok {
return &ValidationError{Name: "expires_at", err: errors.New(`ent: missing required field "UserSubscription.expires_at"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "UserSubscription.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := usersubscription.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "UserSubscription.status": %w`, err)}
}
}
if _, ok := _c.mutation.DailyUsageUsd(); !ok {
return &ValidationError{Name: "daily_usage_usd", err: errors.New(`ent: missing required field "UserSubscription.daily_usage_usd"`)}
}
if _, ok := _c.mutation.WeeklyUsageUsd(); !ok {
return &ValidationError{Name: "weekly_usage_usd", err: errors.New(`ent: missing required field "UserSubscription.weekly_usage_usd"`)}
}
if _, ok := _c.mutation.MonthlyUsageUsd(); !ok {
return &ValidationError{Name: "monthly_usage_usd", err: errors.New(`ent: missing required field "UserSubscription.monthly_usage_usd"`)}
}
if _, ok := _c.mutation.AssignedAt(); !ok {
return &ValidationError{Name: "assigned_at", err: errors.New(`ent: missing required field "UserSubscription.assigned_at"`)}
}
if len(_c.mutation.UserIDs()) == 0 {
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "UserSubscription.user"`)}
}
if len(_c.mutation.GroupIDs()) == 0 {
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "UserSubscription.group"`)}
}
return nil
}
func (_c *UserSubscriptionCreate) sqlSave(ctx context.Context) (*UserSubscription, 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 *UserSubscriptionCreate) createSpec() (*UserSubscription, *sqlgraph.CreateSpec) {
var (
_node = &UserSubscription{config: _c.config}
_spec = sqlgraph.NewCreateSpec(usersubscription.Table, sqlgraph.NewFieldSpec(usersubscription.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(usersubscription.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(usersubscription.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.DeletedAt(); ok {
_spec.SetField(usersubscription.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = &value
}
if value, ok := _c.mutation.StartsAt(); ok {
_spec.SetField(usersubscription.FieldStartsAt, field.TypeTime, value)
_node.StartsAt = value
}
if value, ok := _c.mutation.ExpiresAt(); ok {
_spec.SetField(usersubscription.FieldExpiresAt, field.TypeTime, value)
_node.ExpiresAt = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(usersubscription.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.DailyWindowStart(); ok {
_spec.SetField(usersubscription.FieldDailyWindowStart, field.TypeTime, value)
_node.DailyWindowStart = &value
}
if value, ok := _c.mutation.WeeklyWindowStart(); ok {
_spec.SetField(usersubscription.FieldWeeklyWindowStart, field.TypeTime, value)
_node.WeeklyWindowStart = &value
}
if value, ok := _c.mutation.MonthlyWindowStart(); ok {
_spec.SetField(usersubscription.FieldMonthlyWindowStart, field.TypeTime, value)
_node.MonthlyWindowStart = &value
}
if value, ok := _c.mutation.DailyUsageUsd(); ok {
_spec.SetField(usersubscription.FieldDailyUsageUsd, field.TypeFloat64, value)
_node.DailyUsageUsd = value
}
if value, ok := _c.mutation.WeeklyUsageUsd(); ok {
_spec.SetField(usersubscription.FieldWeeklyUsageUsd, field.TypeFloat64, value)
_node.WeeklyUsageUsd = value
}
if value, ok := _c.mutation.MonthlyUsageUsd(); ok {
_spec.SetField(usersubscription.FieldMonthlyUsageUsd, field.TypeFloat64, value)
_node.MonthlyUsageUsd = value
}
if value, ok := _c.mutation.AssignedAt(); ok {
_spec.SetField(usersubscription.FieldAssignedAt, field.TypeTime, value)
_node.AssignedAt = value
}
if value, ok := _c.mutation.Notes(); ok {
_spec.SetField(usersubscription.FieldNotes, field.TypeString, value)
_node.Notes = &value
}
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usersubscription.UserTable,
Columns: []string{usersubscription.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.UserID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usersubscription.GroupTable,
Columns: []string{usersubscription.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_node.GroupID = nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.AssignedByUserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: usersubscription.AssignedByUserTable,
Columns: []string{usersubscription.AssignedByUserColumn},
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.AssignedBy = &nodes[0]
_spec.Edges = append(_spec.Edges, edge)
}
if nodes := _c.mutation.UsageLogsIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.O2M,
Inverse: false,
Table: usersubscription.UsageLogsTable,
Columns: []string{usersubscription.UsageLogsColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(usagelog.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges = append(_spec.Edges, edge)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UserSubscription.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.UserSubscriptionUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *UserSubscriptionCreate) OnConflict(opts ...sql.ConflictOption) *UserSubscriptionUpsertOne {
_c.conflict = opts
return &UserSubscriptionUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UserSubscription.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *UserSubscriptionCreate) OnConflictColumns(columns ...string) *UserSubscriptionUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &UserSubscriptionUpsertOne{
create: _c,
}
}
type (
// UserSubscriptionUpsertOne is the builder for "upsert"-ing
// one UserSubscription node.
UserSubscriptionUpsertOne struct {
create *UserSubscriptionCreate
}
// UserSubscriptionUpsert is the "OnConflict" setter.
UserSubscriptionUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *UserSubscriptionUpsert) SetUpdatedAt(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateUpdatedAt() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldUpdatedAt)
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserSubscriptionUpsert) SetDeletedAt(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateDeletedAt() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserSubscriptionUpsert) ClearDeletedAt() *UserSubscriptionUpsert {
u.SetNull(usersubscription.FieldDeletedAt)
return u
}
// SetUserID sets the "user_id" field.
func (u *UserSubscriptionUpsert) SetUserID(v int64) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldUserID, v)
return u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateUserID() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldUserID)
return u
}
// SetGroupID sets the "group_id" field.
func (u *UserSubscriptionUpsert) SetGroupID(v int64) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldGroupID, v)
return u
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateGroupID() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldGroupID)
return u
}
// SetStartsAt sets the "starts_at" field.
func (u *UserSubscriptionUpsert) SetStartsAt(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldStartsAt, v)
return u
}
// UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateStartsAt() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldStartsAt)
return u
}
// SetExpiresAt sets the "expires_at" field.
func (u *UserSubscriptionUpsert) SetExpiresAt(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldExpiresAt, v)
return u
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateExpiresAt() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldExpiresAt)
return u
}
// SetStatus sets the "status" field.
func (u *UserSubscriptionUpsert) SetStatus(v string) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateStatus() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldStatus)
return u
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (u *UserSubscriptionUpsert) SetDailyWindowStart(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldDailyWindowStart, v)
return u
}
// UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateDailyWindowStart() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldDailyWindowStart)
return u
}
// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (u *UserSubscriptionUpsert) ClearDailyWindowStart() *UserSubscriptionUpsert {
u.SetNull(usersubscription.FieldDailyWindowStart)
return u
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (u *UserSubscriptionUpsert) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldWeeklyWindowStart, v)
return u
}
// UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateWeeklyWindowStart() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldWeeklyWindowStart)
return u
}
// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (u *UserSubscriptionUpsert) ClearWeeklyWindowStart() *UserSubscriptionUpsert {
u.SetNull(usersubscription.FieldWeeklyWindowStart)
return u
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (u *UserSubscriptionUpsert) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldMonthlyWindowStart, v)
return u
}
// UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateMonthlyWindowStart() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldMonthlyWindowStart)
return u
}
// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (u *UserSubscriptionUpsert) ClearMonthlyWindowStart() *UserSubscriptionUpsert {
u.SetNull(usersubscription.FieldMonthlyWindowStart)
return u
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (u *UserSubscriptionUpsert) SetDailyUsageUsd(v float64) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldDailyUsageUsd, v)
return u
}
// UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateDailyUsageUsd() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldDailyUsageUsd)
return u
}
// AddDailyUsageUsd adds v to the "daily_usage_usd" field.
func (u *UserSubscriptionUpsert) AddDailyUsageUsd(v float64) *UserSubscriptionUpsert {
u.Add(usersubscription.FieldDailyUsageUsd, v)
return u
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (u *UserSubscriptionUpsert) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldWeeklyUsageUsd, v)
return u
}
// UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateWeeklyUsageUsd() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldWeeklyUsageUsd)
return u
}
// AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
func (u *UserSubscriptionUpsert) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpsert {
u.Add(usersubscription.FieldWeeklyUsageUsd, v)
return u
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (u *UserSubscriptionUpsert) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldMonthlyUsageUsd, v)
return u
}
// UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateMonthlyUsageUsd() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldMonthlyUsageUsd)
return u
}
// AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
func (u *UserSubscriptionUpsert) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpsert {
u.Add(usersubscription.FieldMonthlyUsageUsd, v)
return u
}
// SetAssignedBy sets the "assigned_by" field.
func (u *UserSubscriptionUpsert) SetAssignedBy(v int64) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldAssignedBy, v)
return u
}
// UpdateAssignedBy sets the "assigned_by" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateAssignedBy() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldAssignedBy)
return u
}
// ClearAssignedBy clears the value of the "assigned_by" field.
func (u *UserSubscriptionUpsert) ClearAssignedBy() *UserSubscriptionUpsert {
u.SetNull(usersubscription.FieldAssignedBy)
return u
}
// SetAssignedAt sets the "assigned_at" field.
func (u *UserSubscriptionUpsert) SetAssignedAt(v time.Time) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldAssignedAt, v)
return u
}
// UpdateAssignedAt sets the "assigned_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateAssignedAt() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldAssignedAt)
return u
}
// SetNotes sets the "notes" field.
func (u *UserSubscriptionUpsert) SetNotes(v string) *UserSubscriptionUpsert {
u.Set(usersubscription.FieldNotes, v)
return u
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func (u *UserSubscriptionUpsert) UpdateNotes() *UserSubscriptionUpsert {
u.SetExcluded(usersubscription.FieldNotes)
return u
}
// ClearNotes clears the value of the "notes" field.
func (u *UserSubscriptionUpsert) ClearNotes() *UserSubscriptionUpsert {
u.SetNull(usersubscription.FieldNotes)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.UserSubscription.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *UserSubscriptionUpsertOne) UpdateNewValues() *UserSubscriptionUpsertOne {
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(usersubscription.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UserSubscription.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *UserSubscriptionUpsertOne) Ignore() *UserSubscriptionUpsertOne {
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 *UserSubscriptionUpsertOne) DoNothing() *UserSubscriptionUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the UserSubscriptionCreate.OnConflict
// documentation for more info.
func (u *UserSubscriptionUpsertOne) Update(set func(*UserSubscriptionUpsert)) *UserSubscriptionUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&UserSubscriptionUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *UserSubscriptionUpsertOne) SetUpdatedAt(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateUpdatedAt() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserSubscriptionUpsertOne) SetDeletedAt(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateDeletedAt() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserSubscriptionUpsertOne) ClearDeletedAt() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearDeletedAt()
})
}
// SetUserID sets the "user_id" field.
func (u *UserSubscriptionUpsertOne) SetUserID(v int64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateUserID() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateUserID()
})
}
// SetGroupID sets the "group_id" field.
func (u *UserSubscriptionUpsertOne) SetGroupID(v int64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateGroupID() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateGroupID()
})
}
// SetStartsAt sets the "starts_at" field.
func (u *UserSubscriptionUpsertOne) SetStartsAt(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetStartsAt(v)
})
}
// UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateStartsAt() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateStartsAt()
})
}
// SetExpiresAt sets the "expires_at" field.
func (u *UserSubscriptionUpsertOne) SetExpiresAt(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetExpiresAt(v)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateExpiresAt() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateExpiresAt()
})
}
// SetStatus sets the "status" field.
func (u *UserSubscriptionUpsertOne) SetStatus(v string) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateStatus() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateStatus()
})
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (u *UserSubscriptionUpsertOne) SetDailyWindowStart(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetDailyWindowStart(v)
})
}
// UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateDailyWindowStart() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateDailyWindowStart()
})
}
// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (u *UserSubscriptionUpsertOne) ClearDailyWindowStart() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearDailyWindowStart()
})
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (u *UserSubscriptionUpsertOne) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetWeeklyWindowStart(v)
})
}
// UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateWeeklyWindowStart() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateWeeklyWindowStart()
})
}
// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (u *UserSubscriptionUpsertOne) ClearWeeklyWindowStart() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearWeeklyWindowStart()
})
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (u *UserSubscriptionUpsertOne) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetMonthlyWindowStart(v)
})
}
// UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateMonthlyWindowStart() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateMonthlyWindowStart()
})
}
// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (u *UserSubscriptionUpsertOne) ClearMonthlyWindowStart() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearMonthlyWindowStart()
})
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (u *UserSubscriptionUpsertOne) SetDailyUsageUsd(v float64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetDailyUsageUsd(v)
})
}
// AddDailyUsageUsd adds v to the "daily_usage_usd" field.
func (u *UserSubscriptionUpsertOne) AddDailyUsageUsd(v float64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.AddDailyUsageUsd(v)
})
}
// UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateDailyUsageUsd() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateDailyUsageUsd()
})
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (u *UserSubscriptionUpsertOne) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetWeeklyUsageUsd(v)
})
}
// AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
func (u *UserSubscriptionUpsertOne) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.AddWeeklyUsageUsd(v)
})
}
// UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateWeeklyUsageUsd() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateWeeklyUsageUsd()
})
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (u *UserSubscriptionUpsertOne) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetMonthlyUsageUsd(v)
})
}
// AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
func (u *UserSubscriptionUpsertOne) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.AddMonthlyUsageUsd(v)
})
}
// UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateMonthlyUsageUsd() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateMonthlyUsageUsd()
})
}
// SetAssignedBy sets the "assigned_by" field.
func (u *UserSubscriptionUpsertOne) SetAssignedBy(v int64) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetAssignedBy(v)
})
}
// UpdateAssignedBy sets the "assigned_by" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateAssignedBy() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateAssignedBy()
})
}
// ClearAssignedBy clears the value of the "assigned_by" field.
func (u *UserSubscriptionUpsertOne) ClearAssignedBy() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearAssignedBy()
})
}
// SetAssignedAt sets the "assigned_at" field.
func (u *UserSubscriptionUpsertOne) SetAssignedAt(v time.Time) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetAssignedAt(v)
})
}
// UpdateAssignedAt sets the "assigned_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateAssignedAt() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateAssignedAt()
})
}
// SetNotes sets the "notes" field.
func (u *UserSubscriptionUpsertOne) SetNotes(v string) *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetNotes(v)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func (u *UserSubscriptionUpsertOne) UpdateNotes() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateNotes()
})
}
// ClearNotes clears the value of the "notes" field.
func (u *UserSubscriptionUpsertOne) ClearNotes() *UserSubscriptionUpsertOne {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearNotes()
})
}
// Exec executes the query.
func (u *UserSubscriptionUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for UserSubscriptionCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *UserSubscriptionUpsertOne) 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 *UserSubscriptionUpsertOne) 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 *UserSubscriptionUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// UserSubscriptionCreateBulk is the builder for creating many UserSubscription entities in bulk.
type UserSubscriptionCreateBulk struct {
config
err error
builders []*UserSubscriptionCreate
conflict []sql.ConflictOption
}
// Save creates the UserSubscription entities in the database.
func (_c *UserSubscriptionCreateBulk) Save(ctx context.Context) ([]*UserSubscription, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*UserSubscription, 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.(*UserSubscriptionMutation)
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 *UserSubscriptionCreateBulk) SaveX(ctx context.Context) []*UserSubscription {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *UserSubscriptionCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *UserSubscriptionCreateBulk) 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.UserSubscription.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.UserSubscriptionUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *UserSubscriptionCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserSubscriptionUpsertBulk {
_c.conflict = opts
return &UserSubscriptionUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UserSubscription.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *UserSubscriptionCreateBulk) OnConflictColumns(columns ...string) *UserSubscriptionUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &UserSubscriptionUpsertBulk{
create: _c,
}
}
// UserSubscriptionUpsertBulk is the builder for "upsert"-ing
// a bulk of UserSubscription nodes.
type UserSubscriptionUpsertBulk struct {
create *UserSubscriptionCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.UserSubscription.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *UserSubscriptionUpsertBulk) UpdateNewValues() *UserSubscriptionUpsertBulk {
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(usersubscription.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UserSubscription.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *UserSubscriptionUpsertBulk) Ignore() *UserSubscriptionUpsertBulk {
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 *UserSubscriptionUpsertBulk) DoNothing() *UserSubscriptionUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the UserSubscriptionCreateBulk.OnConflict
// documentation for more info.
func (u *UserSubscriptionUpsertBulk) Update(set func(*UserSubscriptionUpsert)) *UserSubscriptionUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&UserSubscriptionUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *UserSubscriptionUpsertBulk) SetUpdatedAt(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateUpdatedAt() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *UserSubscriptionUpsertBulk) SetDeletedAt(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateDeletedAt() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *UserSubscriptionUpsertBulk) ClearDeletedAt() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearDeletedAt()
})
}
// SetUserID sets the "user_id" field.
func (u *UserSubscriptionUpsertBulk) SetUserID(v int64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetUserID(v)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateUserID() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateUserID()
})
}
// SetGroupID sets the "group_id" field.
func (u *UserSubscriptionUpsertBulk) SetGroupID(v int64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateGroupID() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateGroupID()
})
}
// SetStartsAt sets the "starts_at" field.
func (u *UserSubscriptionUpsertBulk) SetStartsAt(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetStartsAt(v)
})
}
// UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateStartsAt() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateStartsAt()
})
}
// SetExpiresAt sets the "expires_at" field.
func (u *UserSubscriptionUpsertBulk) SetExpiresAt(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetExpiresAt(v)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateExpiresAt() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateExpiresAt()
})
}
// SetStatus sets the "status" field.
func (u *UserSubscriptionUpsertBulk) SetStatus(v string) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateStatus() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateStatus()
})
}
// SetDailyWindowStart sets the "daily_window_start" field.
func (u *UserSubscriptionUpsertBulk) SetDailyWindowStart(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetDailyWindowStart(v)
})
}
// UpdateDailyWindowStart sets the "daily_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateDailyWindowStart() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateDailyWindowStart()
})
}
// ClearDailyWindowStart clears the value of the "daily_window_start" field.
func (u *UserSubscriptionUpsertBulk) ClearDailyWindowStart() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearDailyWindowStart()
})
}
// SetWeeklyWindowStart sets the "weekly_window_start" field.
func (u *UserSubscriptionUpsertBulk) SetWeeklyWindowStart(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetWeeklyWindowStart(v)
})
}
// UpdateWeeklyWindowStart sets the "weekly_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateWeeklyWindowStart() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateWeeklyWindowStart()
})
}
// ClearWeeklyWindowStart clears the value of the "weekly_window_start" field.
func (u *UserSubscriptionUpsertBulk) ClearWeeklyWindowStart() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearWeeklyWindowStart()
})
}
// SetMonthlyWindowStart sets the "monthly_window_start" field.
func (u *UserSubscriptionUpsertBulk) SetMonthlyWindowStart(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetMonthlyWindowStart(v)
})
}
// UpdateMonthlyWindowStart sets the "monthly_window_start" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateMonthlyWindowStart() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateMonthlyWindowStart()
})
}
// ClearMonthlyWindowStart clears the value of the "monthly_window_start" field.
func (u *UserSubscriptionUpsertBulk) ClearMonthlyWindowStart() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearMonthlyWindowStart()
})
}
// SetDailyUsageUsd sets the "daily_usage_usd" field.
func (u *UserSubscriptionUpsertBulk) SetDailyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetDailyUsageUsd(v)
})
}
// AddDailyUsageUsd adds v to the "daily_usage_usd" field.
func (u *UserSubscriptionUpsertBulk) AddDailyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.AddDailyUsageUsd(v)
})
}
// UpdateDailyUsageUsd sets the "daily_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateDailyUsageUsd() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateDailyUsageUsd()
})
}
// SetWeeklyUsageUsd sets the "weekly_usage_usd" field.
func (u *UserSubscriptionUpsertBulk) SetWeeklyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetWeeklyUsageUsd(v)
})
}
// AddWeeklyUsageUsd adds v to the "weekly_usage_usd" field.
func (u *UserSubscriptionUpsertBulk) AddWeeklyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.AddWeeklyUsageUsd(v)
})
}
// UpdateWeeklyUsageUsd sets the "weekly_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateWeeklyUsageUsd() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateWeeklyUsageUsd()
})
}
// SetMonthlyUsageUsd sets the "monthly_usage_usd" field.
func (u *UserSubscriptionUpsertBulk) SetMonthlyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetMonthlyUsageUsd(v)
})
}
// AddMonthlyUsageUsd adds v to the "monthly_usage_usd" field.
func (u *UserSubscriptionUpsertBulk) AddMonthlyUsageUsd(v float64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.AddMonthlyUsageUsd(v)
})
}
// UpdateMonthlyUsageUsd sets the "monthly_usage_usd" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateMonthlyUsageUsd() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateMonthlyUsageUsd()
})
}
// SetAssignedBy sets the "assigned_by" field.
func (u *UserSubscriptionUpsertBulk) SetAssignedBy(v int64) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetAssignedBy(v)
})
}
// UpdateAssignedBy sets the "assigned_by" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateAssignedBy() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateAssignedBy()
})
}
// ClearAssignedBy clears the value of the "assigned_by" field.
func (u *UserSubscriptionUpsertBulk) ClearAssignedBy() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearAssignedBy()
})
}
// SetAssignedAt sets the "assigned_at" field.
func (u *UserSubscriptionUpsertBulk) SetAssignedAt(v time.Time) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetAssignedAt(v)
})
}
// UpdateAssignedAt sets the "assigned_at" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateAssignedAt() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateAssignedAt()
})
}
// SetNotes sets the "notes" field.
func (u *UserSubscriptionUpsertBulk) SetNotes(v string) *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.SetNotes(v)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func (u *UserSubscriptionUpsertBulk) UpdateNotes() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.UpdateNotes()
})
}
// ClearNotes clears the value of the "notes" field.
func (u *UserSubscriptionUpsertBulk) ClearNotes() *UserSubscriptionUpsertBulk {
return u.Update(func(s *UserSubscriptionUpsert) {
s.ClearNotes()
})
}
// Exec executes the query.
func (u *UserSubscriptionUpsertBulk) 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 UserSubscriptionCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for UserSubscriptionCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *UserSubscriptionUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}