Commit 3d617de5 authored by yangjianbo's avatar yangjianbo
Browse files

refactor(数据库): 迁移持久层到 Ent 并清理 GORM

将仓储层/基础设施改为 Ent + 原生 SQL 执行路径,并移除 AutoMigrate 与 GORM 依赖。
重构内容包括:
- 仓储层改用 Ent/SQL(含 usage_log/account 等复杂查询),统一错误映射
- 基础设施与 setup 初始化切换为 Ent + SQL migrations
- 集成测试与 fixtures 迁移到 Ent 事务模型
- 清理遗留 GORM 模型/依赖,补充迁移与文档说明
- 增加根目录 Makefile 便于前后端编译

测试:
- go test -tags unit ./...
- go test -tags integration ./...
parent fd51ff69
// Code generated by ent, DO NOT EDIT.
package hook
import (
"context"
"fmt"
"github.com/Wei-Shaw/sub2api/ent"
)
// The AccountFunc type is an adapter to allow the use of ordinary
// function as Account mutator.
type AccountFunc func(context.Context, *ent.AccountMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f AccountFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.AccountMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AccountMutation", m)
}
// The AccountGroupFunc type is an adapter to allow the use of ordinary
// function as AccountGroup mutator.
type AccountGroupFunc func(context.Context, *ent.AccountGroupMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f AccountGroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.AccountGroupMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AccountGroupMutation", m)
}
// The ApiKeyFunc type is an adapter to allow the use of ordinary
// function as ApiKey mutator.
type ApiKeyFunc func(context.Context, *ent.ApiKeyMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ApiKeyFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ApiKeyMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ApiKeyMutation", m)
}
// The GroupFunc type is an adapter to allow the use of ordinary
// function as Group mutator.
type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.GroupMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m)
}
// The ProxyFunc type is an adapter to allow the use of ordinary
// function as Proxy mutator.
type ProxyFunc func(context.Context, *ent.ProxyMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ProxyFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ProxyMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProxyMutation", m)
}
// The RedeemCodeFunc type is an adapter to allow the use of ordinary
// function as RedeemCode mutator.
type RedeemCodeFunc func(context.Context, *ent.RedeemCodeMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f RedeemCodeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.RedeemCodeMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.RedeemCodeMutation", m)
}
// The SettingFunc type is an adapter to allow the use of ordinary
// function as Setting mutator.
type SettingFunc func(context.Context, *ent.SettingMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f SettingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.SettingMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SettingMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UserMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
}
// The UserAllowedGroupFunc type is an adapter to allow the use of ordinary
// function as UserAllowedGroup mutator.
type UserAllowedGroupFunc func(context.Context, *ent.UserAllowedGroupMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UserAllowedGroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UserAllowedGroupMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserAllowedGroupMutation", m)
}
// The UserSubscriptionFunc type is an adapter to allow the use of ordinary
// function as UserSubscription mutator.
type UserSubscriptionFunc func(context.Context, *ent.UserSubscriptionMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UserSubscriptionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UserSubscriptionMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserSubscriptionMutation", m)
}
// Condition is a hook condition function.
type Condition func(context.Context, ent.Mutation) bool
// And groups conditions with the AND operator.
func And(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if !first(ctx, m) || !second(ctx, m) {
return false
}
for _, cond := range rest {
if !cond(ctx, m) {
return false
}
}
return true
}
}
// Or groups conditions with the OR operator.
func Or(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
if first(ctx, m) || second(ctx, m) {
return true
}
for _, cond := range rest {
if cond(ctx, m) {
return true
}
}
return false
}
}
// Not negates a given condition.
func Not(cond Condition) Condition {
return func(ctx context.Context, m ent.Mutation) bool {
return !cond(ctx, m)
}
}
// HasOp is a condition testing mutation operation.
func HasOp(op ent.Op) Condition {
return func(_ context.Context, m ent.Mutation) bool {
return m.Op().Is(op)
}
}
// HasAddedFields is a condition validating `.AddedField` on fields.
func HasAddedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.AddedField(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.AddedField(field); !exists {
return false
}
}
return true
}
}
// HasClearedFields is a condition validating `.FieldCleared` on fields.
func HasClearedFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if exists := m.FieldCleared(field); !exists {
return false
}
for _, field := range fields {
if exists := m.FieldCleared(field); !exists {
return false
}
}
return true
}
}
// HasFields is a condition validating `.Field` on fields.
func HasFields(field string, fields ...string) Condition {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.Field(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.Field(field); !exists {
return false
}
}
return true
}
}
// If executes the given hook under condition.
//
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
func If(hk ent.Hook, cond Condition) ent.Hook {
return func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if cond(ctx, m) {
return hk(next).Mutate(ctx, m)
}
return next.Mutate(ctx, m)
})
}
}
// On executes the given hook only for the given operation.
//
// hook.On(Log, ent.Delete|ent.Create)
func On(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, HasOp(op))
}
// Unless skips the given hook only for the given operation.
//
// hook.Unless(Log, ent.Update|ent.UpdateOne)
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, Not(HasOp(op)))
}
// FixedError is a hook returning a fixed error.
func FixedError(err error) ent.Hook {
return func(ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
return nil, err
})
}
}
// Reject returns a hook that rejects all operations that match op.
//
// func (T) Hooks() []ent.Hook {
// return []ent.Hook{
// Reject(ent.Delete|ent.Update),
// }
// }
func Reject(op ent.Op) ent.Hook {
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
return On(hk, op)
}
// Chain acts as a list of hooks and is effectively immutable.
// Once created, it will always hold the same set of hooks in the same order.
type Chain struct {
hooks []ent.Hook
}
// NewChain creates a new chain of hooks.
func NewChain(hooks ...ent.Hook) Chain {
return Chain{append([]ent.Hook(nil), hooks...)}
}
// Hook chains the list of hooks and returns the final hook.
func (c Chain) Hook() ent.Hook {
return func(mutator ent.Mutator) ent.Mutator {
for i := len(c.hooks) - 1; i >= 0; i-- {
mutator = c.hooks[i](mutator)
}
return mutator
}
}
// Append extends a chain, adding the specified hook
// as the last ones in the mutation flow.
func (c Chain) Append(hooks ...ent.Hook) Chain {
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
newHooks = append(newHooks, c.hooks...)
newHooks = append(newHooks, hooks...)
return Chain{newHooks}
}
// Extend extends a chain, adding the specified chain
// as the last ones in the mutation flow.
func (c Chain) Extend(chain Chain) Chain {
return c.Append(chain.hooks...)
}
// Code generated by ent, DO NOT EDIT.
package intercept
import (
"context"
"fmt"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
"github.com/Wei-Shaw/sub2api/ent/usersubscription"
)
// The Query interface represents an operation that queries a graph.
// By using this interface, users can write generic code that manipulates
// query builders of different types.
type Query interface {
// Type returns the string representation of the query type.
Type() string
// Limit the number of records to be returned by this query.
Limit(int)
// Offset to start from.
Offset(int)
// Unique configures the query builder to filter duplicate records.
Unique(bool)
// Order specifies how the records should be ordered.
Order(...func(*sql.Selector))
// WhereP appends storage-level predicates to the query builder. Using this method, users
// can use type-assertion to append predicates that do not depend on any generated package.
WhereP(...func(*sql.Selector))
}
// The Func type is an adapter that allows ordinary functions to be used as interceptors.
// Unlike traversal functions, interceptors are skipped during graph traversals. Note that the
// implementation of Func is different from the one defined in entgo.io/ent.InterceptFunc.
type Func func(context.Context, Query) error
// Intercept calls f(ctx, q) and then applied the next Querier.
func (f Func) Intercept(next ent.Querier) ent.Querier {
return ent.QuerierFunc(func(ctx context.Context, q ent.Query) (ent.Value, error) {
query, err := NewQuery(q)
if err != nil {
return nil, err
}
if err := f(ctx, query); err != nil {
return nil, err
}
return next.Query(ctx, q)
})
}
// The TraverseFunc type is an adapter to allow the use of ordinary function as Traverser.
// If f is a function with the appropriate signature, TraverseFunc(f) is a Traverser that calls f.
type TraverseFunc func(context.Context, Query) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseFunc) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
query, err := NewQuery(q)
if err != nil {
return err
}
return f(ctx, query)
}
// The AccountFunc type is an adapter to allow the use of ordinary function as a Querier.
type AccountFunc func(context.Context, *ent.AccountQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AccountFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AccountQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AccountQuery", q)
}
// The TraverseAccount type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAccount func(context.Context, *ent.AccountQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAccount) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAccount) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AccountQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AccountQuery", q)
}
// The AccountGroupFunc type is an adapter to allow the use of ordinary function as a Querier.
type AccountGroupFunc func(context.Context, *ent.AccountGroupQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f AccountGroupFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.AccountGroupQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.AccountGroupQuery", q)
}
// The TraverseAccountGroup type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAccountGroup func(context.Context, *ent.AccountGroupQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAccountGroup) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAccountGroup) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.AccountGroupQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.AccountGroupQuery", q)
}
// The ApiKeyFunc type is an adapter to allow the use of ordinary function as a Querier.
type ApiKeyFunc func(context.Context, *ent.ApiKeyQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f ApiKeyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.ApiKeyQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.ApiKeyQuery", q)
}
// The TraverseApiKey type is an adapter to allow the use of ordinary function as Traverser.
type TraverseApiKey func(context.Context, *ent.ApiKeyQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseApiKey) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseApiKey) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.ApiKeyQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.ApiKeyQuery", q)
}
// The GroupFunc type is an adapter to allow the use of ordinary function as a Querier.
type GroupFunc func(context.Context, *ent.GroupQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f GroupFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.GroupQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.GroupQuery", q)
}
// The TraverseGroup type is an adapter to allow the use of ordinary function as Traverser.
type TraverseGroup func(context.Context, *ent.GroupQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseGroup) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseGroup) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.GroupQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.GroupQuery", q)
}
// The ProxyFunc type is an adapter to allow the use of ordinary function as a Querier.
type ProxyFunc func(context.Context, *ent.ProxyQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f ProxyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.ProxyQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.ProxyQuery", q)
}
// The TraverseProxy type is an adapter to allow the use of ordinary function as Traverser.
type TraverseProxy func(context.Context, *ent.ProxyQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseProxy) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseProxy) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.ProxyQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.ProxyQuery", q)
}
// The RedeemCodeFunc type is an adapter to allow the use of ordinary function as a Querier.
type RedeemCodeFunc func(context.Context, *ent.RedeemCodeQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f RedeemCodeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.RedeemCodeQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.RedeemCodeQuery", q)
}
// The TraverseRedeemCode type is an adapter to allow the use of ordinary function as Traverser.
type TraverseRedeemCode func(context.Context, *ent.RedeemCodeQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseRedeemCode) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseRedeemCode) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.RedeemCodeQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.RedeemCodeQuery", q)
}
// The SettingFunc type is an adapter to allow the use of ordinary function as a Querier.
type SettingFunc func(context.Context, *ent.SettingQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SettingFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SettingQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q)
}
// The TraverseSetting type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSetting func(context.Context, *ent.SettingQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSetting) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSetting) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SettingQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q)
}
// The UserFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserFunc func(context.Context, *ent.UserQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserQuery", q)
}
// The TraverseUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUser func(context.Context, *ent.UserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUser) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUser) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserQuery", q)
}
// The UserAllowedGroupFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserAllowedGroupFunc func(context.Context, *ent.UserAllowedGroupQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserAllowedGroupFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserAllowedGroupQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserAllowedGroupQuery", q)
}
// The TraverseUserAllowedGroup type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserAllowedGroup func(context.Context, *ent.UserAllowedGroupQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserAllowedGroup) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserAllowedGroup) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserAllowedGroupQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserAllowedGroupQuery", q)
}
// The UserSubscriptionFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserSubscriptionFunc func(context.Context, *ent.UserSubscriptionQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f UserSubscriptionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.UserSubscriptionQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserSubscriptionQuery", q)
}
// The TraverseUserSubscription type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserSubscription func(context.Context, *ent.UserSubscriptionQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserSubscription) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserSubscription) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.UserSubscriptionQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.UserSubscriptionQuery", q)
}
// NewQuery returns the generic Query interface for the given typed query.
func NewQuery(q ent.Query) (Query, error) {
switch q := q.(type) {
case *ent.AccountQuery:
return &query[*ent.AccountQuery, predicate.Account, account.OrderOption]{typ: ent.TypeAccount, tq: q}, nil
case *ent.AccountGroupQuery:
return &query[*ent.AccountGroupQuery, predicate.AccountGroup, accountgroup.OrderOption]{typ: ent.TypeAccountGroup, tq: q}, nil
case *ent.ApiKeyQuery:
return &query[*ent.ApiKeyQuery, predicate.ApiKey, apikey.OrderOption]{typ: ent.TypeApiKey, tq: q}, nil
case *ent.GroupQuery:
return &query[*ent.GroupQuery, predicate.Group, group.OrderOption]{typ: ent.TypeGroup, tq: q}, nil
case *ent.ProxyQuery:
return &query[*ent.ProxyQuery, predicate.Proxy, proxy.OrderOption]{typ: ent.TypeProxy, tq: q}, nil
case *ent.RedeemCodeQuery:
return &query[*ent.RedeemCodeQuery, predicate.RedeemCode, redeemcode.OrderOption]{typ: ent.TypeRedeemCode, tq: q}, nil
case *ent.SettingQuery:
return &query[*ent.SettingQuery, predicate.Setting, setting.OrderOption]{typ: ent.TypeSetting, tq: q}, nil
case *ent.UserQuery:
return &query[*ent.UserQuery, predicate.User, user.OrderOption]{typ: ent.TypeUser, tq: q}, nil
case *ent.UserAllowedGroupQuery:
return &query[*ent.UserAllowedGroupQuery, predicate.UserAllowedGroup, userallowedgroup.OrderOption]{typ: ent.TypeUserAllowedGroup, tq: q}, nil
case *ent.UserSubscriptionQuery:
return &query[*ent.UserSubscriptionQuery, predicate.UserSubscription, usersubscription.OrderOption]{typ: ent.TypeUserSubscription, tq: q}, nil
default:
return nil, fmt.Errorf("unknown query type %T", q)
}
}
type query[T any, P ~func(*sql.Selector), R ~func(*sql.Selector)] struct {
typ string
tq interface {
Limit(int) T
Offset(int) T
Unique(bool) T
Order(...R) T
Where(...P) T
}
}
func (q query[T, P, R]) Type() string {
return q.typ
}
func (q query[T, P, R]) Limit(limit int) {
q.tq.Limit(limit)
}
func (q query[T, P, R]) Offset(offset int) {
q.tq.Offset(offset)
}
func (q query[T, P, R]) Unique(unique bool) {
q.tq.Unique(unique)
}
func (q query[T, P, R]) Order(orders ...func(*sql.Selector)) {
rs := make([]R, len(orders))
for i := range orders {
rs[i] = orders[i]
}
q.tq.Order(rs...)
}
func (q query[T, P, R]) WhereP(ps ...func(*sql.Selector)) {
p := make([]P, len(ps))
for i := range ps {
p[i] = ps[i]
}
q.tq.Where(p...)
}
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
var (
// WithGlobalUniqueID sets the universal ids options to the migration.
// If this option is enabled, ent migration will allocate a 1<<32 range
// for the ids of each entity (table).
// Note that this option cannot be applied on tables that already exist.
WithGlobalUniqueID = schema.WithGlobalUniqueID
// WithDropColumn sets the drop column option to the migration.
// If this option is enabled, ent migration will drop old columns
// that were used for both fields and edges. This defaults to false.
WithDropColumn = schema.WithDropColumn
// WithDropIndex sets the drop index option to the migration.
// If this option is enabled, ent migration will drop old indexes
// that were defined in the schema. This defaults to false.
// Note that unique constraints are defined using `UNIQUE INDEX`,
// and therefore, it's recommended to enable this option to get more
// flexibility in the schema changes.
WithDropIndex = schema.WithDropIndex
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
WithForeignKeys = schema.WithForeignKeys
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
return Create(ctx, s, Tables, opts...)
}
// Create creates all table resources using the given schema driver.
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, tables...)
}
// WriteTo writes the schema changes to w instead of running them against the database.
//
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
// log.Fatal(err)
// }
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
}
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// AccountsColumns holds the columns for the "accounts" table.
AccountsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "name", Type: field.TypeString, Size: 100},
{Name: "platform", Type: field.TypeString, Size: 50},
{Name: "type", Type: field.TypeString, Size: 20},
{Name: "credentials", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
{Name: "extra", Type: field.TypeJSON, SchemaType: map[string]string{"postgres": "jsonb"}},
{Name: "proxy_id", Type: field.TypeInt64, Nullable: true},
{Name: "concurrency", Type: field.TypeInt, Default: 3},
{Name: "priority", Type: field.TypeInt, Default: 50},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
{Name: "error_message", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
{Name: "last_used_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "schedulable", Type: field.TypeBool, Default: true},
{Name: "rate_limited_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "rate_limit_reset_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "overload_until", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "session_window_start", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "session_window_end", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "session_window_status", Type: field.TypeString, Nullable: true, Size: 20},
}
// AccountsTable holds the schema information for the "accounts" table.
AccountsTable = &schema.Table{
Name: "accounts",
Columns: AccountsColumns,
PrimaryKey: []*schema.Column{AccountsColumns[0]},
Indexes: []*schema.Index{
{
Name: "account_platform",
Unique: false,
Columns: []*schema.Column{AccountsColumns[5]},
},
{
Name: "account_type",
Unique: false,
Columns: []*schema.Column{AccountsColumns[6]},
},
{
Name: "account_status",
Unique: false,
Columns: []*schema.Column{AccountsColumns[12]},
},
{
Name: "account_proxy_id",
Unique: false,
Columns: []*schema.Column{AccountsColumns[9]},
},
{
Name: "account_priority",
Unique: false,
Columns: []*schema.Column{AccountsColumns[11]},
},
{
Name: "account_last_used_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[14]},
},
{
Name: "account_schedulable",
Unique: false,
Columns: []*schema.Column{AccountsColumns[15]},
},
{
Name: "account_rate_limited_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[16]},
},
{
Name: "account_rate_limit_reset_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[17]},
},
{
Name: "account_overload_until",
Unique: false,
Columns: []*schema.Column{AccountsColumns[18]},
},
{
Name: "account_deleted_at",
Unique: false,
Columns: []*schema.Column{AccountsColumns[3]},
},
},
}
// AccountGroupsColumns holds the columns for the "account_groups" table.
AccountGroupsColumns = []*schema.Column{
{Name: "priority", Type: field.TypeInt, Default: 50},
{Name: "created_at", Type: field.TypeTime},
{Name: "account_id", Type: field.TypeInt64},
{Name: "group_id", Type: field.TypeInt64},
}
// AccountGroupsTable holds the schema information for the "account_groups" table.
AccountGroupsTable = &schema.Table{
Name: "account_groups",
Columns: AccountGroupsColumns,
PrimaryKey: []*schema.Column{AccountGroupsColumns[2], AccountGroupsColumns[3]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "account_groups_accounts_account",
Columns: []*schema.Column{AccountGroupsColumns[2]},
RefColumns: []*schema.Column{AccountsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "account_groups_groups_group",
Columns: []*schema.Column{AccountGroupsColumns[3]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "accountgroup_group_id",
Unique: false,
Columns: []*schema.Column{AccountGroupsColumns[3]},
},
{
Name: "accountgroup_priority",
Unique: false,
Columns: []*schema.Column{AccountGroupsColumns[0]},
},
},
}
// APIKeysColumns holds the columns for the "api_keys" table.
APIKeysColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "key", Type: field.TypeString, Unique: true, Size: 128},
{Name: "name", Type: field.TypeString, Size: 100},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
{Name: "group_id", Type: field.TypeInt64, Nullable: true},
{Name: "user_id", Type: field.TypeInt64},
}
// APIKeysTable holds the schema information for the "api_keys" table.
APIKeysTable = &schema.Table{
Name: "api_keys",
Columns: APIKeysColumns,
PrimaryKey: []*schema.Column{APIKeysColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "api_keys_groups_api_keys",
Columns: []*schema.Column{APIKeysColumns[7]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull,
},
{
Symbol: "api_keys_users_api_keys",
Columns: []*schema.Column{APIKeysColumns[8]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "apikey_key",
Unique: true,
Columns: []*schema.Column{APIKeysColumns[4]},
},
{
Name: "apikey_user_id",
Unique: false,
Columns: []*schema.Column{APIKeysColumns[8]},
},
{
Name: "apikey_group_id",
Unique: false,
Columns: []*schema.Column{APIKeysColumns[7]},
},
{
Name: "apikey_status",
Unique: false,
Columns: []*schema.Column{APIKeysColumns[6]},
},
{
Name: "apikey_deleted_at",
Unique: false,
Columns: []*schema.Column{APIKeysColumns[3]},
},
},
}
// GroupsColumns holds the columns for the "groups" table.
GroupsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "name", Type: field.TypeString, Unique: true, Size: 100},
{Name: "description", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
{Name: "rate_multiplier", Type: field.TypeFloat64, Default: 1, SchemaType: map[string]string{"postgres": "decimal(10,4)"}},
{Name: "is_exclusive", Type: field.TypeBool, Default: false},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
{Name: "platform", Type: field.TypeString, Size: 50, Default: "anthropic"},
{Name: "subscription_type", Type: field.TypeString, Size: 20, Default: "standard"},
{Name: "daily_limit_usd", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "weekly_limit_usd", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "monthly_limit_usd", Type: field.TypeFloat64, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
}
// GroupsTable holds the schema information for the "groups" table.
GroupsTable = &schema.Table{
Name: "groups",
Columns: GroupsColumns,
PrimaryKey: []*schema.Column{GroupsColumns[0]},
Indexes: []*schema.Index{
{
Name: "group_name",
Unique: true,
Columns: []*schema.Column{GroupsColumns[4]},
},
{
Name: "group_status",
Unique: false,
Columns: []*schema.Column{GroupsColumns[8]},
},
{
Name: "group_platform",
Unique: false,
Columns: []*schema.Column{GroupsColumns[9]},
},
{
Name: "group_subscription_type",
Unique: false,
Columns: []*schema.Column{GroupsColumns[10]},
},
{
Name: "group_is_exclusive",
Unique: false,
Columns: []*schema.Column{GroupsColumns[7]},
},
{
Name: "group_deleted_at",
Unique: false,
Columns: []*schema.Column{GroupsColumns[3]},
},
},
}
// ProxiesColumns holds the columns for the "proxies" table.
ProxiesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "name", Type: field.TypeString, Size: 100},
{Name: "protocol", Type: field.TypeString, Size: 20},
{Name: "host", Type: field.TypeString, Size: 255},
{Name: "port", Type: field.TypeInt},
{Name: "username", Type: field.TypeString, Nullable: true, Size: 100},
{Name: "password", Type: field.TypeString, Nullable: true, Size: 100},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
}
// ProxiesTable holds the schema information for the "proxies" table.
ProxiesTable = &schema.Table{
Name: "proxies",
Columns: ProxiesColumns,
PrimaryKey: []*schema.Column{ProxiesColumns[0]},
Indexes: []*schema.Index{
{
Name: "proxy_status",
Unique: false,
Columns: []*schema.Column{ProxiesColumns[10]},
},
{
Name: "proxy_deleted_at",
Unique: false,
Columns: []*schema.Column{ProxiesColumns[3]},
},
},
}
// RedeemCodesColumns holds the columns for the "redeem_codes" table.
RedeemCodesColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "code", Type: field.TypeString, Unique: true, Size: 32},
{Name: "type", Type: field.TypeString, Size: 20, Default: "balance"},
{Name: "value", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "status", Type: field.TypeString, Size: 20, Default: "unused"},
{Name: "used_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "notes", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "validity_days", Type: field.TypeInt, Default: 30},
{Name: "group_id", Type: field.TypeInt64, Nullable: true},
{Name: "used_by", Type: field.TypeInt64, Nullable: true},
}
// RedeemCodesTable holds the schema information for the "redeem_codes" table.
RedeemCodesTable = &schema.Table{
Name: "redeem_codes",
Columns: RedeemCodesColumns,
PrimaryKey: []*schema.Column{RedeemCodesColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "redeem_codes_groups_redeem_codes",
Columns: []*schema.Column{RedeemCodesColumns[9]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.SetNull,
},
{
Symbol: "redeem_codes_users_redeem_codes",
Columns: []*schema.Column{RedeemCodesColumns[10]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.SetNull,
},
},
Indexes: []*schema.Index{
{
Name: "redeemcode_code",
Unique: true,
Columns: []*schema.Column{RedeemCodesColumns[1]},
},
{
Name: "redeemcode_status",
Unique: false,
Columns: []*schema.Column{RedeemCodesColumns[4]},
},
{
Name: "redeemcode_used_by",
Unique: false,
Columns: []*schema.Column{RedeemCodesColumns[10]},
},
{
Name: "redeemcode_group_id",
Unique: false,
Columns: []*schema.Column{RedeemCodesColumns[9]},
},
},
}
// SettingsColumns holds the columns for the "settings" table.
SettingsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "key", Type: field.TypeString, Unique: true, Size: 100},
{Name: "value", Type: field.TypeString, SchemaType: map[string]string{"postgres": "text"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
}
// SettingsTable holds the schema information for the "settings" table.
SettingsTable = &schema.Table{
Name: "settings",
Columns: SettingsColumns,
PrimaryKey: []*schema.Column{SettingsColumns[0]},
Indexes: []*schema.Index{
{
Name: "setting_key",
Unique: true,
Columns: []*schema.Column{SettingsColumns[1]},
},
},
}
// UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "deleted_at", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "email", Type: field.TypeString, Unique: true, Size: 255},
{Name: "password_hash", Type: field.TypeString, Size: 255},
{Name: "role", Type: field.TypeString, Size: 20, Default: "user"},
{Name: "balance", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,8)"}},
{Name: "concurrency", Type: field.TypeInt, Default: 5},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
{Name: "username", Type: field.TypeString, Size: 100, Default: ""},
{Name: "wechat", Type: field.TypeString, Size: 100, Default: ""},
{Name: "notes", Type: field.TypeString, Default: "", SchemaType: map[string]string{"postgres": "text"}},
}
// UsersTable holds the schema information for the "users" table.
UsersTable = &schema.Table{
Name: "users",
Columns: UsersColumns,
PrimaryKey: []*schema.Column{UsersColumns[0]},
Indexes: []*schema.Index{
{
Name: "user_email",
Unique: true,
Columns: []*schema.Column{UsersColumns[4]},
},
{
Name: "user_status",
Unique: false,
Columns: []*schema.Column{UsersColumns[9]},
},
{
Name: "user_deleted_at",
Unique: false,
Columns: []*schema.Column{UsersColumns[3]},
},
},
}
// UserAllowedGroupsColumns holds the columns for the "user_allowed_groups" table.
UserAllowedGroupsColumns = []*schema.Column{
{Name: "created_at", Type: field.TypeTime},
{Name: "user_id", Type: field.TypeInt64},
{Name: "group_id", Type: field.TypeInt64},
}
// UserAllowedGroupsTable holds the schema information for the "user_allowed_groups" table.
UserAllowedGroupsTable = &schema.Table{
Name: "user_allowed_groups",
Columns: UserAllowedGroupsColumns,
PrimaryKey: []*schema.Column{UserAllowedGroupsColumns[1], UserAllowedGroupsColumns[2]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "user_allowed_groups_users_user",
Columns: []*schema.Column{UserAllowedGroupsColumns[1]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "user_allowed_groups_groups_group",
Columns: []*schema.Column{UserAllowedGroupsColumns[2]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "userallowedgroup_group_id",
Unique: false,
Columns: []*schema.Column{UserAllowedGroupsColumns[2]},
},
},
}
// UserSubscriptionsColumns holds the columns for the "user_subscriptions" table.
UserSubscriptionsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "starts_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "expires_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "status", Type: field.TypeString, Size: 20, Default: "active"},
{Name: "daily_window_start", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "weekly_window_start", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "monthly_window_start", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "daily_usage_usd", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "weekly_usage_usd", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "monthly_usage_usd", Type: field.TypeFloat64, Default: 0, SchemaType: map[string]string{"postgres": "decimal(20,10)"}},
{Name: "assigned_at", Type: field.TypeTime, SchemaType: map[string]string{"postgres": "timestamptz"}},
{Name: "notes", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "text"}},
{Name: "group_id", Type: field.TypeInt64},
{Name: "user_id", Type: field.TypeInt64},
{Name: "assigned_by", Type: field.TypeInt64, Nullable: true},
}
// UserSubscriptionsTable holds the schema information for the "user_subscriptions" table.
UserSubscriptionsTable = &schema.Table{
Name: "user_subscriptions",
Columns: UserSubscriptionsColumns,
PrimaryKey: []*schema.Column{UserSubscriptionsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "user_subscriptions_groups_subscriptions",
Columns: []*schema.Column{UserSubscriptionsColumns[14]},
RefColumns: []*schema.Column{GroupsColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "user_subscriptions_users_subscriptions",
Columns: []*schema.Column{UserSubscriptionsColumns[15]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
{
Symbol: "user_subscriptions_users_assigned_subscriptions",
Columns: []*schema.Column{UserSubscriptionsColumns[16]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.SetNull,
},
},
Indexes: []*schema.Index{
{
Name: "usersubscription_user_id",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[15]},
},
{
Name: "usersubscription_group_id",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[14]},
},
{
Name: "usersubscription_status",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[5]},
},
{
Name: "usersubscription_expires_at",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[4]},
},
{
Name: "usersubscription_assigned_by",
Unique: false,
Columns: []*schema.Column{UserSubscriptionsColumns[16]},
},
{
Name: "usersubscription_user_id_group_id",
Unique: true,
Columns: []*schema.Column{UserSubscriptionsColumns[15], UserSubscriptionsColumns[14]},
},
},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
AccountsTable,
AccountGroupsTable,
APIKeysTable,
GroupsTable,
ProxiesTable,
RedeemCodesTable,
SettingsTable,
UsersTable,
UserAllowedGroupsTable,
UserSubscriptionsTable,
}
)
func init() {
AccountsTable.Annotation = &entsql.Annotation{
Table: "accounts",
}
AccountGroupsTable.ForeignKeys[0].RefTable = AccountsTable
AccountGroupsTable.ForeignKeys[1].RefTable = GroupsTable
AccountGroupsTable.Annotation = &entsql.Annotation{
Table: "account_groups",
}
APIKeysTable.ForeignKeys[0].RefTable = GroupsTable
APIKeysTable.ForeignKeys[1].RefTable = UsersTable
APIKeysTable.Annotation = &entsql.Annotation{
Table: "api_keys",
}
GroupsTable.Annotation = &entsql.Annotation{
Table: "groups",
}
ProxiesTable.Annotation = &entsql.Annotation{
Table: "proxies",
}
RedeemCodesTable.ForeignKeys[0].RefTable = GroupsTable
RedeemCodesTable.ForeignKeys[1].RefTable = UsersTable
RedeemCodesTable.Annotation = &entsql.Annotation{
Table: "redeem_codes",
}
SettingsTable.Annotation = &entsql.Annotation{
Table: "settings",
}
UsersTable.Annotation = &entsql.Annotation{
Table: "users",
}
UserAllowedGroupsTable.ForeignKeys[0].RefTable = UsersTable
UserAllowedGroupsTable.ForeignKeys[1].RefTable = GroupsTable
UserAllowedGroupsTable.Annotation = &entsql.Annotation{
Table: "user_allowed_groups",
}
UserSubscriptionsTable.ForeignKeys[0].RefTable = GroupsTable
UserSubscriptionsTable.ForeignKeys[1].RefTable = UsersTable
UserSubscriptionsTable.ForeignKeys[2].RefTable = UsersTable
UserSubscriptionsTable.Annotation = &entsql.Annotation{
Table: "user_subscriptions",
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
// Code generated by ent, DO NOT EDIT.
package predicate
import (
"entgo.io/ent/dialect/sql"
)
// Account is the predicate function for account builders.
type Account func(*sql.Selector)
// AccountGroup is the predicate function for accountgroup builders.
type AccountGroup func(*sql.Selector)
// ApiKey is the predicate function for apikey builders.
type ApiKey func(*sql.Selector)
// Group is the predicate function for group builders.
type Group func(*sql.Selector)
// Proxy is the predicate function for proxy builders.
type Proxy func(*sql.Selector)
// RedeemCode is the predicate function for redeemcode builders.
type RedeemCode func(*sql.Selector)
// Setting is the predicate function for setting builders.
type Setting func(*sql.Selector)
// User is the predicate function for user builders.
type User func(*sql.Selector)
// UserAllowedGroup is the predicate function for userallowedgroup builders.
type UserAllowedGroup func(*sql.Selector)
// UserSubscription is the predicate function for usersubscription builders.
type UserSubscription func(*sql.Selector)
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
// Proxy is the model entity for the Proxy schema.
type Proxy struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// DeletedAt holds the value of the "deleted_at" field.
DeletedAt *time.Time `json:"deleted_at,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Protocol holds the value of the "protocol" field.
Protocol string `json:"protocol,omitempty"`
// Host holds the value of the "host" field.
Host string `json:"host,omitempty"`
// Port holds the value of the "port" field.
Port int `json:"port,omitempty"`
// Username holds the value of the "username" field.
Username *string `json:"username,omitempty"`
// Password holds the value of the "password" field.
Password *string `json:"password,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Proxy) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case proxy.FieldID, proxy.FieldPort:
values[i] = new(sql.NullInt64)
case proxy.FieldName, proxy.FieldProtocol, proxy.FieldHost, proxy.FieldUsername, proxy.FieldPassword, proxy.FieldStatus:
values[i] = new(sql.NullString)
case proxy.FieldCreatedAt, proxy.FieldUpdatedAt, proxy.FieldDeletedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Proxy fields.
func (_m *Proxy) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case proxy.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case proxy.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case proxy.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
case proxy.FieldDeletedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
} else if value.Valid {
_m.DeletedAt = new(time.Time)
*_m.DeletedAt = value.Time
}
case proxy.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case proxy.FieldProtocol:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field protocol", values[i])
} else if value.Valid {
_m.Protocol = value.String
}
case proxy.FieldHost:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field host", values[i])
} else if value.Valid {
_m.Host = value.String
}
case proxy.FieldPort:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field port", values[i])
} else if value.Valid {
_m.Port = int(value.Int64)
}
case proxy.FieldUsername:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field username", values[i])
} else if value.Valid {
_m.Username = new(string)
*_m.Username = value.String
}
case proxy.FieldPassword:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field password", values[i])
} else if value.Valid {
_m.Password = new(string)
*_m.Password = value.String
}
case proxy.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = value.String
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Proxy.
// This includes values selected through modifiers, order, etc.
func (_m *Proxy) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this Proxy.
// Note that you need to call Proxy.Unwrap() before calling this method if this Proxy
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Proxy) Update() *ProxyUpdateOne {
return NewProxyClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Proxy entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *Proxy) Unwrap() *Proxy {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: Proxy is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Proxy) String() string {
var builder strings.Builder
builder.WriteString("Proxy(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.DeletedAt; v != nil {
builder.WriteString("deleted_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
builder.WriteString("protocol=")
builder.WriteString(_m.Protocol)
builder.WriteString(", ")
builder.WriteString("host=")
builder.WriteString(_m.Host)
builder.WriteString(", ")
builder.WriteString("port=")
builder.WriteString(fmt.Sprintf("%v", _m.Port))
builder.WriteString(", ")
if v := _m.Username; v != nil {
builder.WriteString("username=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.Password; v != nil {
builder.WriteString("password=")
builder.WriteString(*v)
}
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(_m.Status)
builder.WriteByte(')')
return builder.String()
}
// Proxies is a parsable slice of Proxy.
type Proxies []*Proxy
// Code generated by ent, DO NOT EDIT.
package proxy
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the proxy type in the database.
Label = "proxy"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
FieldDeletedAt = "deleted_at"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldProtocol holds the string denoting the protocol field in the database.
FieldProtocol = "protocol"
// FieldHost holds the string denoting the host field in the database.
FieldHost = "host"
// FieldPort holds the string denoting the port field in the database.
FieldPort = "port"
// FieldUsername holds the string denoting the username field in the database.
FieldUsername = "username"
// FieldPassword holds the string denoting the password field in the database.
FieldPassword = "password"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// Table holds the table name of the proxy in the database.
Table = "proxies"
)
// Columns holds all SQL columns for proxy fields.
var Columns = []string{
FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldDeletedAt,
FieldName,
FieldProtocol,
FieldHost,
FieldPort,
FieldUsername,
FieldPassword,
FieldStatus,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
// Note that the variables below are initialized by the runtime
// package on the initialization of the application. Therefore,
// it should be imported in the main as follows:
//
// import _ "github.com/Wei-Shaw/sub2api/ent/runtime"
var (
Hooks [1]ent.Hook
Interceptors [1]ent.Interceptor
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// NameValidator is a validator for the "name" field. It is called by the builders before save.
NameValidator func(string) error
// ProtocolValidator is a validator for the "protocol" field. It is called by the builders before save.
ProtocolValidator func(string) error
// HostValidator is a validator for the "host" field. It is called by the builders before save.
HostValidator func(string) error
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
UsernameValidator func(string) error
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
PasswordValidator func(string) error
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator func(string) error
)
// OrderOption defines the ordering options for the Proxy queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByDeletedAt orders the results by the deleted_at field.
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByProtocol orders the results by the protocol field.
func ByProtocol(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldProtocol, opts...).ToFunc()
}
// ByHost orders the results by the host field.
func ByHost(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldHost, opts...).ToFunc()
}
// ByPort orders the results by the port field.
func ByPort(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPort, opts...).ToFunc()
}
// ByUsername orders the results by the username field.
func ByUsername(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUsername, opts...).ToFunc()
}
// ByPassword orders the results by the password field.
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPassword, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// Code generated by ent, DO NOT EDIT.
package proxy
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldID, id))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldUpdatedAt, v))
}
// DeletedAt applies equality check predicate on the "deleted_at" field. It's identical to DeletedAtEQ.
func DeletedAt(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldDeletedAt, v))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldName, v))
}
// Protocol applies equality check predicate on the "protocol" field. It's identical to ProtocolEQ.
func Protocol(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldProtocol, v))
}
// Host applies equality check predicate on the "host" field. It's identical to HostEQ.
func Host(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldHost, v))
}
// Port applies equality check predicate on the "port" field. It's identical to PortEQ.
func Port(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldPort, v))
}
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
func Username(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldUsername, v))
}
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
func Password(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldPassword, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldStatus, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldUpdatedAt, v))
}
// DeletedAtEQ applies the EQ predicate on the "deleted_at" field.
func DeletedAtEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldDeletedAt, v))
}
// DeletedAtNEQ applies the NEQ predicate on the "deleted_at" field.
func DeletedAtNEQ(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldDeletedAt, v))
}
// DeletedAtIn applies the In predicate on the "deleted_at" field.
func DeletedAtIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldDeletedAt, vs...))
}
// DeletedAtNotIn applies the NotIn predicate on the "deleted_at" field.
func DeletedAtNotIn(vs ...time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldDeletedAt, vs...))
}
// DeletedAtGT applies the GT predicate on the "deleted_at" field.
func DeletedAtGT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldDeletedAt, v))
}
// DeletedAtGTE applies the GTE predicate on the "deleted_at" field.
func DeletedAtGTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldDeletedAt, v))
}
// DeletedAtLT applies the LT predicate on the "deleted_at" field.
func DeletedAtLT(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldDeletedAt, v))
}
// DeletedAtLTE applies the LTE predicate on the "deleted_at" field.
func DeletedAtLTE(v time.Time) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldDeletedAt, v))
}
// DeletedAtIsNil applies the IsNil predicate on the "deleted_at" field.
func DeletedAtIsNil() predicate.Proxy {
return predicate.Proxy(sql.FieldIsNull(FieldDeletedAt))
}
// DeletedAtNotNil applies the NotNil predicate on the "deleted_at" field.
func DeletedAtNotNil() predicate.Proxy {
return predicate.Proxy(sql.FieldNotNull(FieldDeletedAt))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldName, v))
}
// ProtocolEQ applies the EQ predicate on the "protocol" field.
func ProtocolEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldProtocol, v))
}
// ProtocolNEQ applies the NEQ predicate on the "protocol" field.
func ProtocolNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldProtocol, v))
}
// ProtocolIn applies the In predicate on the "protocol" field.
func ProtocolIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldProtocol, vs...))
}
// ProtocolNotIn applies the NotIn predicate on the "protocol" field.
func ProtocolNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldProtocol, vs...))
}
// ProtocolGT applies the GT predicate on the "protocol" field.
func ProtocolGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldProtocol, v))
}
// ProtocolGTE applies the GTE predicate on the "protocol" field.
func ProtocolGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldProtocol, v))
}
// ProtocolLT applies the LT predicate on the "protocol" field.
func ProtocolLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldProtocol, v))
}
// ProtocolLTE applies the LTE predicate on the "protocol" field.
func ProtocolLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldProtocol, v))
}
// ProtocolContains applies the Contains predicate on the "protocol" field.
func ProtocolContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldProtocol, v))
}
// ProtocolHasPrefix applies the HasPrefix predicate on the "protocol" field.
func ProtocolHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldProtocol, v))
}
// ProtocolHasSuffix applies the HasSuffix predicate on the "protocol" field.
func ProtocolHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldProtocol, v))
}
// ProtocolEqualFold applies the EqualFold predicate on the "protocol" field.
func ProtocolEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldProtocol, v))
}
// ProtocolContainsFold applies the ContainsFold predicate on the "protocol" field.
func ProtocolContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldProtocol, v))
}
// HostEQ applies the EQ predicate on the "host" field.
func HostEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldHost, v))
}
// HostNEQ applies the NEQ predicate on the "host" field.
func HostNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldHost, v))
}
// HostIn applies the In predicate on the "host" field.
func HostIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldHost, vs...))
}
// HostNotIn applies the NotIn predicate on the "host" field.
func HostNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldHost, vs...))
}
// HostGT applies the GT predicate on the "host" field.
func HostGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldHost, v))
}
// HostGTE applies the GTE predicate on the "host" field.
func HostGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldHost, v))
}
// HostLT applies the LT predicate on the "host" field.
func HostLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldHost, v))
}
// HostLTE applies the LTE predicate on the "host" field.
func HostLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldHost, v))
}
// HostContains applies the Contains predicate on the "host" field.
func HostContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldHost, v))
}
// HostHasPrefix applies the HasPrefix predicate on the "host" field.
func HostHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldHost, v))
}
// HostHasSuffix applies the HasSuffix predicate on the "host" field.
func HostHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldHost, v))
}
// HostEqualFold applies the EqualFold predicate on the "host" field.
func HostEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldHost, v))
}
// HostContainsFold applies the ContainsFold predicate on the "host" field.
func HostContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldHost, v))
}
// PortEQ applies the EQ predicate on the "port" field.
func PortEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldPort, v))
}
// PortNEQ applies the NEQ predicate on the "port" field.
func PortNEQ(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldPort, v))
}
// PortIn applies the In predicate on the "port" field.
func PortIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldPort, vs...))
}
// PortNotIn applies the NotIn predicate on the "port" field.
func PortNotIn(vs ...int) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldPort, vs...))
}
// PortGT applies the GT predicate on the "port" field.
func PortGT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldPort, v))
}
// PortGTE applies the GTE predicate on the "port" field.
func PortGTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldPort, v))
}
// PortLT applies the LT predicate on the "port" field.
func PortLT(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldPort, v))
}
// PortLTE applies the LTE predicate on the "port" field.
func PortLTE(v int) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldPort, v))
}
// UsernameEQ applies the EQ predicate on the "username" field.
func UsernameEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldUsername, v))
}
// UsernameNEQ applies the NEQ predicate on the "username" field.
func UsernameNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldUsername, v))
}
// UsernameIn applies the In predicate on the "username" field.
func UsernameIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldUsername, vs...))
}
// UsernameNotIn applies the NotIn predicate on the "username" field.
func UsernameNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldUsername, vs...))
}
// UsernameGT applies the GT predicate on the "username" field.
func UsernameGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldUsername, v))
}
// UsernameGTE applies the GTE predicate on the "username" field.
func UsernameGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldUsername, v))
}
// UsernameLT applies the LT predicate on the "username" field.
func UsernameLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldUsername, v))
}
// UsernameLTE applies the LTE predicate on the "username" field.
func UsernameLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldUsername, v))
}
// UsernameContains applies the Contains predicate on the "username" field.
func UsernameContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldUsername, v))
}
// UsernameHasPrefix applies the HasPrefix predicate on the "username" field.
func UsernameHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldUsername, v))
}
// UsernameHasSuffix applies the HasSuffix predicate on the "username" field.
func UsernameHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldUsername, v))
}
// UsernameIsNil applies the IsNil predicate on the "username" field.
func UsernameIsNil() predicate.Proxy {
return predicate.Proxy(sql.FieldIsNull(FieldUsername))
}
// UsernameNotNil applies the NotNil predicate on the "username" field.
func UsernameNotNil() predicate.Proxy {
return predicate.Proxy(sql.FieldNotNull(FieldUsername))
}
// UsernameEqualFold applies the EqualFold predicate on the "username" field.
func UsernameEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldUsername, v))
}
// UsernameContainsFold applies the ContainsFold predicate on the "username" field.
func UsernameContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldUsername, v))
}
// PasswordEQ applies the EQ predicate on the "password" field.
func PasswordEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldPassword, v))
}
// PasswordNEQ applies the NEQ predicate on the "password" field.
func PasswordNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldPassword, v))
}
// PasswordIn applies the In predicate on the "password" field.
func PasswordIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldPassword, vs...))
}
// PasswordNotIn applies the NotIn predicate on the "password" field.
func PasswordNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldPassword, vs...))
}
// PasswordGT applies the GT predicate on the "password" field.
func PasswordGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldPassword, v))
}
// PasswordGTE applies the GTE predicate on the "password" field.
func PasswordGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldPassword, v))
}
// PasswordLT applies the LT predicate on the "password" field.
func PasswordLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldPassword, v))
}
// PasswordLTE applies the LTE predicate on the "password" field.
func PasswordLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldPassword, v))
}
// PasswordContains applies the Contains predicate on the "password" field.
func PasswordContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldPassword, v))
}
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
func PasswordHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldPassword, v))
}
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
func PasswordHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldPassword, v))
}
// PasswordIsNil applies the IsNil predicate on the "password" field.
func PasswordIsNil() predicate.Proxy {
return predicate.Proxy(sql.FieldIsNull(FieldPassword))
}
// PasswordNotNil applies the NotNil predicate on the "password" field.
func PasswordNotNil() predicate.Proxy {
return predicate.Proxy(sql.FieldNotNull(FieldPassword))
}
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
func PasswordEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldPassword, v))
}
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
func PasswordContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldPassword, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.Proxy {
return predicate.Proxy(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.Proxy {
return predicate.Proxy(sql.FieldContainsFold(FieldStatus, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Proxy) predicate.Proxy {
return predicate.Proxy(sql.NotPredicates(p))
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
// ProxyCreate is the builder for creating a Proxy entity.
type ProxyCreate struct {
config
mutation *ProxyMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func (_c *ProxyCreate) SetCreatedAt(v time.Time) *ProxyCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableCreatedAt(v *time.Time) *ProxyCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *ProxyCreate) SetUpdatedAt(v time.Time) *ProxyCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableUpdatedAt(v *time.Time) *ProxyCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetDeletedAt sets the "deleted_at" field.
func (_c *ProxyCreate) SetDeletedAt(v time.Time) *ProxyCreate {
_c.mutation.SetDeletedAt(v)
return _c
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableDeletedAt(v *time.Time) *ProxyCreate {
if v != nil {
_c.SetDeletedAt(*v)
}
return _c
}
// SetName sets the "name" field.
func (_c *ProxyCreate) SetName(v string) *ProxyCreate {
_c.mutation.SetName(v)
return _c
}
// SetProtocol sets the "protocol" field.
func (_c *ProxyCreate) SetProtocol(v string) *ProxyCreate {
_c.mutation.SetProtocol(v)
return _c
}
// SetHost sets the "host" field.
func (_c *ProxyCreate) SetHost(v string) *ProxyCreate {
_c.mutation.SetHost(v)
return _c
}
// SetPort sets the "port" field.
func (_c *ProxyCreate) SetPort(v int) *ProxyCreate {
_c.mutation.SetPort(v)
return _c
}
// SetUsername sets the "username" field.
func (_c *ProxyCreate) SetUsername(v string) *ProxyCreate {
_c.mutation.SetUsername(v)
return _c
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableUsername(v *string) *ProxyCreate {
if v != nil {
_c.SetUsername(*v)
}
return _c
}
// SetPassword sets the "password" field.
func (_c *ProxyCreate) SetPassword(v string) *ProxyCreate {
_c.mutation.SetPassword(v)
return _c
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_c *ProxyCreate) SetNillablePassword(v *string) *ProxyCreate {
if v != nil {
_c.SetPassword(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *ProxyCreate) SetStatus(v string) *ProxyCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *ProxyCreate) SetNillableStatus(v *string) *ProxyCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// Mutation returns the ProxyMutation object of the builder.
func (_c *ProxyCreate) Mutation() *ProxyMutation {
return _c.mutation
}
// Save creates the Proxy in the database.
func (_c *ProxyCreate) Save(ctx context.Context) (*Proxy, 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 *ProxyCreate) SaveX(ctx context.Context) *Proxy {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ProxyCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ProxyCreate) 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 *ProxyCreate) defaults() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
if proxy.DefaultCreatedAt == nil {
return fmt.Errorf("ent: uninitialized proxy.DefaultCreatedAt (forgotten import ent/runtime?)")
}
v := proxy.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
if proxy.DefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized proxy.DefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := proxy.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := proxy.DefaultStatus
_c.mutation.SetStatus(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_c *ProxyCreate) check() error {
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Proxy.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Proxy.updated_at"`)}
}
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Proxy.name"`)}
}
if v, ok := _c.mutation.Name(); ok {
if err := proxy.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
}
}
if _, ok := _c.mutation.Protocol(); !ok {
return &ValidationError{Name: "protocol", err: errors.New(`ent: missing required field "Proxy.protocol"`)}
}
if v, ok := _c.mutation.Protocol(); ok {
if err := proxy.ProtocolValidator(v); err != nil {
return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
}
}
if _, ok := _c.mutation.Host(); !ok {
return &ValidationError{Name: "host", err: errors.New(`ent: missing required field "Proxy.host"`)}
}
if v, ok := _c.mutation.Host(); ok {
if err := proxy.HostValidator(v); err != nil {
return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
}
}
if _, ok := _c.mutation.Port(); !ok {
return &ValidationError{Name: "port", err: errors.New(`ent: missing required field "Proxy.port"`)}
}
if v, ok := _c.mutation.Username(); ok {
if err := proxy.UsernameValidator(v); err != nil {
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
}
}
if v, ok := _c.mutation.Password(); ok {
if err := proxy.PasswordValidator(v); err != nil {
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Proxy.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := proxy.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
}
}
return nil
}
func (_c *ProxyCreate) sqlSave(ctx context.Context) (*Proxy, 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 *ProxyCreate) createSpec() (*Proxy, *sqlgraph.CreateSpec) {
var (
_node = &Proxy{config: _c.config}
_spec = sqlgraph.NewCreateSpec(proxy.Table, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
if value, ok := _c.mutation.DeletedAt(); ok {
_spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
_node.DeletedAt = &value
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.Protocol(); ok {
_spec.SetField(proxy.FieldProtocol, field.TypeString, value)
_node.Protocol = value
}
if value, ok := _c.mutation.Host(); ok {
_spec.SetField(proxy.FieldHost, field.TypeString, value)
_node.Host = value
}
if value, ok := _c.mutation.Port(); ok {
_spec.SetField(proxy.FieldPort, field.TypeInt, value)
_node.Port = value
}
if value, ok := _c.mutation.Username(); ok {
_spec.SetField(proxy.FieldUsername, field.TypeString, value)
_node.Username = &value
}
if value, ok := _c.mutation.Password(); ok {
_spec.SetField(proxy.FieldPassword, field.TypeString, value)
_node.Password = &value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
_node.Status = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Proxy.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.ProxyUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *ProxyCreate) OnConflict(opts ...sql.ConflictOption) *ProxyUpsertOne {
_c.conflict = opts
return &ProxyUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Proxy.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *ProxyCreate) OnConflictColumns(columns ...string) *ProxyUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &ProxyUpsertOne{
create: _c,
}
}
type (
// ProxyUpsertOne is the builder for "upsert"-ing
// one Proxy node.
ProxyUpsertOne struct {
create *ProxyCreate
}
// ProxyUpsert is the "OnConflict" setter.
ProxyUpsert struct {
*sql.UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func (u *ProxyUpsert) SetUpdatedAt(v time.Time) *ProxyUpsert {
u.Set(proxy.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateUpdatedAt() *ProxyUpsert {
u.SetExcluded(proxy.FieldUpdatedAt)
return u
}
// SetDeletedAt sets the "deleted_at" field.
func (u *ProxyUpsert) SetDeletedAt(v time.Time) *ProxyUpsert {
u.Set(proxy.FieldDeletedAt, v)
return u
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateDeletedAt() *ProxyUpsert {
u.SetExcluded(proxy.FieldDeletedAt)
return u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *ProxyUpsert) ClearDeletedAt() *ProxyUpsert {
u.SetNull(proxy.FieldDeletedAt)
return u
}
// SetName sets the "name" field.
func (u *ProxyUpsert) SetName(v string) *ProxyUpsert {
u.Set(proxy.FieldName, v)
return u
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateName() *ProxyUpsert {
u.SetExcluded(proxy.FieldName)
return u
}
// SetProtocol sets the "protocol" field.
func (u *ProxyUpsert) SetProtocol(v string) *ProxyUpsert {
u.Set(proxy.FieldProtocol, v)
return u
}
// UpdateProtocol sets the "protocol" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateProtocol() *ProxyUpsert {
u.SetExcluded(proxy.FieldProtocol)
return u
}
// SetHost sets the "host" field.
func (u *ProxyUpsert) SetHost(v string) *ProxyUpsert {
u.Set(proxy.FieldHost, v)
return u
}
// UpdateHost sets the "host" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateHost() *ProxyUpsert {
u.SetExcluded(proxy.FieldHost)
return u
}
// SetPort sets the "port" field.
func (u *ProxyUpsert) SetPort(v int) *ProxyUpsert {
u.Set(proxy.FieldPort, v)
return u
}
// UpdatePort sets the "port" field to the value that was provided on create.
func (u *ProxyUpsert) UpdatePort() *ProxyUpsert {
u.SetExcluded(proxy.FieldPort)
return u
}
// AddPort adds v to the "port" field.
func (u *ProxyUpsert) AddPort(v int) *ProxyUpsert {
u.Add(proxy.FieldPort, v)
return u
}
// SetUsername sets the "username" field.
func (u *ProxyUpsert) SetUsername(v string) *ProxyUpsert {
u.Set(proxy.FieldUsername, v)
return u
}
// UpdateUsername sets the "username" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateUsername() *ProxyUpsert {
u.SetExcluded(proxy.FieldUsername)
return u
}
// ClearUsername clears the value of the "username" field.
func (u *ProxyUpsert) ClearUsername() *ProxyUpsert {
u.SetNull(proxy.FieldUsername)
return u
}
// SetPassword sets the "password" field.
func (u *ProxyUpsert) SetPassword(v string) *ProxyUpsert {
u.Set(proxy.FieldPassword, v)
return u
}
// UpdatePassword sets the "password" field to the value that was provided on create.
func (u *ProxyUpsert) UpdatePassword() *ProxyUpsert {
u.SetExcluded(proxy.FieldPassword)
return u
}
// ClearPassword clears the value of the "password" field.
func (u *ProxyUpsert) ClearPassword() *ProxyUpsert {
u.SetNull(proxy.FieldPassword)
return u
}
// SetStatus sets the "status" field.
func (u *ProxyUpsert) SetStatus(v string) *ProxyUpsert {
u.Set(proxy.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *ProxyUpsert) UpdateStatus() *ProxyUpsert {
u.SetExcluded(proxy.FieldStatus)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.Proxy.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *ProxyUpsertOne) UpdateNewValues() *ProxyUpsertOne {
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(proxy.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Proxy.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *ProxyUpsertOne) Ignore() *ProxyUpsertOne {
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 *ProxyUpsertOne) DoNothing() *ProxyUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the ProxyCreate.OnConflict
// documentation for more info.
func (u *ProxyUpsertOne) Update(set func(*ProxyUpsert)) *ProxyUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&ProxyUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *ProxyUpsertOne) SetUpdatedAt(v time.Time) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateUpdatedAt() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *ProxyUpsertOne) SetDeletedAt(v time.Time) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateDeletedAt() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *ProxyUpsertOne) ClearDeletedAt() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.ClearDeletedAt()
})
}
// SetName sets the "name" field.
func (u *ProxyUpsertOne) SetName(v string) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateName() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateName()
})
}
// SetProtocol sets the "protocol" field.
func (u *ProxyUpsertOne) SetProtocol(v string) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetProtocol(v)
})
}
// UpdateProtocol sets the "protocol" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateProtocol() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateProtocol()
})
}
// SetHost sets the "host" field.
func (u *ProxyUpsertOne) SetHost(v string) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetHost(v)
})
}
// UpdateHost sets the "host" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateHost() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateHost()
})
}
// SetPort sets the "port" field.
func (u *ProxyUpsertOne) SetPort(v int) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetPort(v)
})
}
// AddPort adds v to the "port" field.
func (u *ProxyUpsertOne) AddPort(v int) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.AddPort(v)
})
}
// UpdatePort sets the "port" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdatePort() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdatePort()
})
}
// SetUsername sets the "username" field.
func (u *ProxyUpsertOne) SetUsername(v string) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetUsername(v)
})
}
// UpdateUsername sets the "username" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateUsername() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateUsername()
})
}
// ClearUsername clears the value of the "username" field.
func (u *ProxyUpsertOne) ClearUsername() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.ClearUsername()
})
}
// SetPassword sets the "password" field.
func (u *ProxyUpsertOne) SetPassword(v string) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetPassword(v)
})
}
// UpdatePassword sets the "password" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdatePassword() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdatePassword()
})
}
// ClearPassword clears the value of the "password" field.
func (u *ProxyUpsertOne) ClearPassword() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.ClearPassword()
})
}
// SetStatus sets the "status" field.
func (u *ProxyUpsertOne) SetStatus(v string) *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *ProxyUpsertOne) UpdateStatus() *ProxyUpsertOne {
return u.Update(func(s *ProxyUpsert) {
s.UpdateStatus()
})
}
// Exec executes the query.
func (u *ProxyUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for ProxyCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *ProxyUpsertOne) 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 *ProxyUpsertOne) 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 *ProxyUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// ProxyCreateBulk is the builder for creating many Proxy entities in bulk.
type ProxyCreateBulk struct {
config
err error
builders []*ProxyCreate
conflict []sql.ConflictOption
}
// Save creates the Proxy entities in the database.
func (_c *ProxyCreateBulk) Save(ctx context.Context) ([]*Proxy, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Proxy, 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.(*ProxyMutation)
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 *ProxyCreateBulk) SaveX(ctx context.Context) []*Proxy {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ProxyCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ProxyCreateBulk) 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.Proxy.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.ProxyUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func (_c *ProxyCreateBulk) OnConflict(opts ...sql.ConflictOption) *ProxyUpsertBulk {
_c.conflict = opts
return &ProxyUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Proxy.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *ProxyCreateBulk) OnConflictColumns(columns ...string) *ProxyUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &ProxyUpsertBulk{
create: _c,
}
}
// ProxyUpsertBulk is the builder for "upsert"-ing
// a bulk of Proxy nodes.
type ProxyUpsertBulk struct {
create *ProxyCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Proxy.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *ProxyUpsertBulk) UpdateNewValues() *ProxyUpsertBulk {
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(proxy.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Proxy.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *ProxyUpsertBulk) Ignore() *ProxyUpsertBulk {
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 *ProxyUpsertBulk) DoNothing() *ProxyUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the ProxyCreateBulk.OnConflict
// documentation for more info.
func (u *ProxyUpsertBulk) Update(set func(*ProxyUpsert)) *ProxyUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&ProxyUpsert{UpdateSet: update})
}))
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *ProxyUpsertBulk) SetUpdatedAt(v time.Time) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateUpdatedAt() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateUpdatedAt()
})
}
// SetDeletedAt sets the "deleted_at" field.
func (u *ProxyUpsertBulk) SetDeletedAt(v time.Time) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetDeletedAt(v)
})
}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateDeletedAt() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateDeletedAt()
})
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *ProxyUpsertBulk) ClearDeletedAt() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.ClearDeletedAt()
})
}
// SetName sets the "name" field.
func (u *ProxyUpsertBulk) SetName(v string) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetName(v)
})
}
// UpdateName sets the "name" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateName() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateName()
})
}
// SetProtocol sets the "protocol" field.
func (u *ProxyUpsertBulk) SetProtocol(v string) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetProtocol(v)
})
}
// UpdateProtocol sets the "protocol" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateProtocol() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateProtocol()
})
}
// SetHost sets the "host" field.
func (u *ProxyUpsertBulk) SetHost(v string) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetHost(v)
})
}
// UpdateHost sets the "host" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateHost() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateHost()
})
}
// SetPort sets the "port" field.
func (u *ProxyUpsertBulk) SetPort(v int) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetPort(v)
})
}
// AddPort adds v to the "port" field.
func (u *ProxyUpsertBulk) AddPort(v int) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.AddPort(v)
})
}
// UpdatePort sets the "port" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdatePort() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdatePort()
})
}
// SetUsername sets the "username" field.
func (u *ProxyUpsertBulk) SetUsername(v string) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetUsername(v)
})
}
// UpdateUsername sets the "username" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateUsername() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateUsername()
})
}
// ClearUsername clears the value of the "username" field.
func (u *ProxyUpsertBulk) ClearUsername() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.ClearUsername()
})
}
// SetPassword sets the "password" field.
func (u *ProxyUpsertBulk) SetPassword(v string) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetPassword(v)
})
}
// UpdatePassword sets the "password" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdatePassword() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdatePassword()
})
}
// ClearPassword clears the value of the "password" field.
func (u *ProxyUpsertBulk) ClearPassword() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.ClearPassword()
})
}
// SetStatus sets the "status" field.
func (u *ProxyUpsertBulk) SetStatus(v string) *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *ProxyUpsertBulk) UpdateStatus() *ProxyUpsertBulk {
return u.Update(func(s *ProxyUpsert) {
s.UpdateStatus()
})
}
// Exec executes the query.
func (u *ProxyUpsertBulk) 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 ProxyCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for ProxyCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *ProxyUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
// ProxyDelete is the builder for deleting a Proxy entity.
type ProxyDelete struct {
config
hooks []Hook
mutation *ProxyMutation
}
// Where appends a list predicates to the ProxyDelete builder.
func (_d *ProxyDelete) Where(ps ...predicate.Proxy) *ProxyDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ProxyDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ProxyDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ProxyDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(proxy.Table, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// ProxyDeleteOne is the builder for deleting a single Proxy entity.
type ProxyDeleteOne struct {
_d *ProxyDelete
}
// Where appends a list predicates to the ProxyDelete builder.
func (_d *ProxyDeleteOne) Where(ps ...predicate.Proxy) *ProxyDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ProxyDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{proxy.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ProxyDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
// ProxyQuery is the builder for querying Proxy entities.
type ProxyQuery struct {
config
ctx *QueryContext
order []proxy.OrderOption
inters []Interceptor
predicates []predicate.Proxy
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ProxyQuery builder.
func (_q *ProxyQuery) Where(ps ...predicate.Proxy) *ProxyQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ProxyQuery) Limit(limit int) *ProxyQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ProxyQuery) Offset(offset int) *ProxyQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *ProxyQuery) Unique(unique bool) *ProxyQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ProxyQuery) Order(o ...proxy.OrderOption) *ProxyQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first Proxy entity from the query.
// Returns a *NotFoundError when no Proxy was found.
func (_q *ProxyQuery) First(ctx context.Context) (*Proxy, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{proxy.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ProxyQuery) FirstX(ctx context.Context) *Proxy {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Proxy ID from the query.
// Returns a *NotFoundError when no Proxy ID was found.
func (_q *ProxyQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{proxy.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ProxyQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Proxy entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Proxy entity is found.
// Returns a *NotFoundError when no Proxy entities are found.
func (_q *ProxyQuery) Only(ctx context.Context) (*Proxy, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{proxy.Label}
default:
return nil, &NotSingularError{proxy.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ProxyQuery) OnlyX(ctx context.Context) *Proxy {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Proxy ID in the query.
// Returns a *NotSingularError when more than one Proxy ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ProxyQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{proxy.Label}
default:
err = &NotSingularError{proxy.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ProxyQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of Proxies.
func (_q *ProxyQuery) All(ctx context.Context) ([]*Proxy, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Proxy, *ProxyQuery]()
return withInterceptors[[]*Proxy](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ProxyQuery) AllX(ctx context.Context) []*Proxy {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Proxy IDs.
func (_q *ProxyQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(proxy.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ProxyQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *ProxyQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*ProxyQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ProxyQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *ProxyQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *ProxyQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ProxyQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *ProxyQuery) Clone() *ProxyQuery {
if _q == nil {
return nil
}
return &ProxyQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]proxy.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.Proxy{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Proxy.Query().
// GroupBy(proxy.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *ProxyQuery) GroupBy(field string, fields ...string) *ProxyGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ProxyGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = proxy.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// }
//
// client.Proxy.Query().
// Select(proxy.FieldCreatedAt).
// Scan(ctx, &v)
func (_q *ProxyQuery) Select(fields ...string) *ProxySelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ProxySelect{ProxyQuery: _q}
sbuild.label = proxy.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ProxySelect configured with the given aggregations.
func (_q *ProxyQuery) Aggregate(fns ...AggregateFunc) *ProxySelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ProxyQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !proxy.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *ProxyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Proxy, error) {
var (
nodes = []*Proxy{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Proxy).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Proxy{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *ProxyQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *ProxyQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
for i := range fields {
if fields[i] != proxy.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *ProxyQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(proxy.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = proxy.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ProxyGroupBy is the group-by builder for Proxy entities.
type ProxyGroupBy struct {
selector
build *ProxyQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ProxyGroupBy) Aggregate(fns ...AggregateFunc) *ProxyGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ProxyGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ProxyQuery, *ProxyGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ProxyGroupBy) sqlScan(ctx context.Context, root *ProxyQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ProxySelect is the builder for selecting fields of Proxy entities.
type ProxySelect struct {
*ProxyQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ProxySelect) Aggregate(fns ...AggregateFunc) *ProxySelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ProxySelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ProxyQuery, *ProxySelect](ctx, _s.ProxyQuery, _s, _s.inters, v)
}
func (_s *ProxySelect) sqlScan(ctx context.Context, root *ProxyQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/proxy"
)
// ProxyUpdate is the builder for updating Proxy entities.
type ProxyUpdate struct {
config
hooks []Hook
mutation *ProxyMutation
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdate) Where(ps ...predicate.Proxy) *ProxyUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProxyUpdate) SetUpdatedAt(v time.Time) *ProxyUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *ProxyUpdate) SetDeletedAt(v time.Time) *ProxyUpdate {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableDeletedAt(v *time.Time) *ProxyUpdate {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *ProxyUpdate) ClearDeletedAt() *ProxyUpdate {
_u.mutation.ClearDeletedAt()
return _u
}
// SetName sets the "name" field.
func (_u *ProxyUpdate) SetName(v string) *ProxyUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableName(v *string) *ProxyUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProtocol sets the "protocol" field.
func (_u *ProxyUpdate) SetProtocol(v string) *ProxyUpdate {
_u.mutation.SetProtocol(v)
return _u
}
// SetNillableProtocol sets the "protocol" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableProtocol(v *string) *ProxyUpdate {
if v != nil {
_u.SetProtocol(*v)
}
return _u
}
// SetHost sets the "host" field.
func (_u *ProxyUpdate) SetHost(v string) *ProxyUpdate {
_u.mutation.SetHost(v)
return _u
}
// SetNillableHost sets the "host" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableHost(v *string) *ProxyUpdate {
if v != nil {
_u.SetHost(*v)
}
return _u
}
// SetPort sets the "port" field.
func (_u *ProxyUpdate) SetPort(v int) *ProxyUpdate {
_u.mutation.ResetPort()
_u.mutation.SetPort(v)
return _u
}
// SetNillablePort sets the "port" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillablePort(v *int) *ProxyUpdate {
if v != nil {
_u.SetPort(*v)
}
return _u
}
// AddPort adds value to the "port" field.
func (_u *ProxyUpdate) AddPort(v int) *ProxyUpdate {
_u.mutation.AddPort(v)
return _u
}
// SetUsername sets the "username" field.
func (_u *ProxyUpdate) SetUsername(v string) *ProxyUpdate {
_u.mutation.SetUsername(v)
return _u
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableUsername(v *string) *ProxyUpdate {
if v != nil {
_u.SetUsername(*v)
}
return _u
}
// ClearUsername clears the value of the "username" field.
func (_u *ProxyUpdate) ClearUsername() *ProxyUpdate {
_u.mutation.ClearUsername()
return _u
}
// SetPassword sets the "password" field.
func (_u *ProxyUpdate) SetPassword(v string) *ProxyUpdate {
_u.mutation.SetPassword(v)
return _u
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillablePassword(v *string) *ProxyUpdate {
if v != nil {
_u.SetPassword(*v)
}
return _u
}
// ClearPassword clears the value of the "password" field.
func (_u *ProxyUpdate) ClearPassword() *ProxyUpdate {
_u.mutation.ClearPassword()
return _u
}
// SetStatus sets the "status" field.
func (_u *ProxyUpdate) SetStatus(v string) *ProxyUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableStatus(v *string) *ProxyUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdate) Mutation() *ProxyMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ProxyUpdate) Save(ctx context.Context) (int, error) {
if err := _u.defaults(); err != nil {
return 0, err
}
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProxyUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ProxyUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProxyUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ProxyUpdate) defaults() error {
if _, ok := _u.mutation.UpdatedAt(); !ok {
if proxy.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized proxy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := proxy.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_u *ProxyUpdate) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := proxy.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
}
}
if v, ok := _u.mutation.Protocol(); ok {
if err := proxy.ProtocolValidator(v); err != nil {
return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
}
}
if v, ok := _u.mutation.Host(); ok {
if err := proxy.HostValidator(v); err != nil {
return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
}
}
if v, ok := _u.mutation.Username(); ok {
if err := proxy.UsernameValidator(v); err != nil {
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
}
}
if v, ok := _u.mutation.Password(); ok {
if err := proxy.PasswordValidator(v); err != nil {
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := proxy.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
}
}
return nil
}
func (_u *ProxyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.DeletedAt(); ok {
_spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(proxy.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Protocol(); ok {
_spec.SetField(proxy.FieldProtocol, field.TypeString, value)
}
if value, ok := _u.mutation.Host(); ok {
_spec.SetField(proxy.FieldHost, field.TypeString, value)
}
if value, ok := _u.mutation.Port(); ok {
_spec.SetField(proxy.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPort(); ok {
_spec.AddField(proxy.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.Username(); ok {
_spec.SetField(proxy.FieldUsername, field.TypeString, value)
}
if _u.mutation.UsernameCleared() {
_spec.ClearField(proxy.FieldUsername, field.TypeString)
}
if value, ok := _u.mutation.Password(); ok {
_spec.SetField(proxy.FieldPassword, field.TypeString, value)
}
if _u.mutation.PasswordCleared() {
_spec.ClearField(proxy.FieldPassword, field.TypeString)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{proxy.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ProxyUpdateOne is the builder for updating a single Proxy entity.
type ProxyUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ProxyMutation
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProxyUpdateOne) SetUpdatedAt(v time.Time) *ProxyUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetDeletedAt sets the "deleted_at" field.
func (_u *ProxyUpdateOne) SetDeletedAt(v time.Time) *ProxyUpdateOne {
_u.mutation.SetDeletedAt(v)
return _u
}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableDeletedAt(v *time.Time) *ProxyUpdateOne {
if v != nil {
_u.SetDeletedAt(*v)
}
return _u
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (_u *ProxyUpdateOne) ClearDeletedAt() *ProxyUpdateOne {
_u.mutation.ClearDeletedAt()
return _u
}
// SetName sets the "name" field.
func (_u *ProxyUpdateOne) SetName(v string) *ProxyUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableName(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProtocol sets the "protocol" field.
func (_u *ProxyUpdateOne) SetProtocol(v string) *ProxyUpdateOne {
_u.mutation.SetProtocol(v)
return _u
}
// SetNillableProtocol sets the "protocol" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableProtocol(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetProtocol(*v)
}
return _u
}
// SetHost sets the "host" field.
func (_u *ProxyUpdateOne) SetHost(v string) *ProxyUpdateOne {
_u.mutation.SetHost(v)
return _u
}
// SetNillableHost sets the "host" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableHost(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetHost(*v)
}
return _u
}
// SetPort sets the "port" field.
func (_u *ProxyUpdateOne) SetPort(v int) *ProxyUpdateOne {
_u.mutation.ResetPort()
_u.mutation.SetPort(v)
return _u
}
// SetNillablePort sets the "port" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillablePort(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetPort(*v)
}
return _u
}
// AddPort adds value to the "port" field.
func (_u *ProxyUpdateOne) AddPort(v int) *ProxyUpdateOne {
_u.mutation.AddPort(v)
return _u
}
// SetUsername sets the "username" field.
func (_u *ProxyUpdateOne) SetUsername(v string) *ProxyUpdateOne {
_u.mutation.SetUsername(v)
return _u
}
// SetNillableUsername sets the "username" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableUsername(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetUsername(*v)
}
return _u
}
// ClearUsername clears the value of the "username" field.
func (_u *ProxyUpdateOne) ClearUsername() *ProxyUpdateOne {
_u.mutation.ClearUsername()
return _u
}
// SetPassword sets the "password" field.
func (_u *ProxyUpdateOne) SetPassword(v string) *ProxyUpdateOne {
_u.mutation.SetPassword(v)
return _u
}
// SetNillablePassword sets the "password" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillablePassword(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetPassword(*v)
}
return _u
}
// ClearPassword clears the value of the "password" field.
func (_u *ProxyUpdateOne) ClearPassword() *ProxyUpdateOne {
_u.mutation.ClearPassword()
return _u
}
// SetStatus sets the "status" field.
func (_u *ProxyUpdateOne) SetStatus(v string) *ProxyUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableStatus(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdateOne) Mutation() *ProxyMutation {
return _u.mutation
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdateOne) Where(ps ...predicate.Proxy) *ProxyUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ProxyUpdateOne) Select(field string, fields ...string) *ProxyUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Proxy entity.
func (_u *ProxyUpdateOne) Save(ctx context.Context) (*Proxy, error) {
if err := _u.defaults(); err != nil {
return nil, err
}
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProxyUpdateOne) SaveX(ctx context.Context) *Proxy {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ProxyUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProxyUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ProxyUpdateOne) defaults() error {
if _, ok := _u.mutation.UpdatedAt(); !ok {
if proxy.UpdateDefaultUpdatedAt == nil {
return fmt.Errorf("ent: uninitialized proxy.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
}
v := proxy.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
return nil
}
// check runs all checks and user-defined validators on the builder.
func (_u *ProxyUpdateOne) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := proxy.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Proxy.name": %w`, err)}
}
}
if v, ok := _u.mutation.Protocol(); ok {
if err := proxy.ProtocolValidator(v); err != nil {
return &ValidationError{Name: "protocol", err: fmt.Errorf(`ent: validator failed for field "Proxy.protocol": %w`, err)}
}
}
if v, ok := _u.mutation.Host(); ok {
if err := proxy.HostValidator(v); err != nil {
return &ValidationError{Name: "host", err: fmt.Errorf(`ent: validator failed for field "Proxy.host": %w`, err)}
}
}
if v, ok := _u.mutation.Username(); ok {
if err := proxy.UsernameValidator(v); err != nil {
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "Proxy.username": %w`, err)}
}
}
if v, ok := _u.mutation.Password(); ok {
if err := proxy.PasswordValidator(v); err != nil {
return &ValidationError{Name: "password", err: fmt.Errorf(`ent: validator failed for field "Proxy.password": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := proxy.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Proxy.status": %w`, err)}
}
}
return nil
}
func (_u *ProxyUpdateOne) sqlSave(ctx context.Context) (_node *Proxy, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Proxy.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
for _, f := range fields {
if !proxy.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != proxy.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.DeletedAt(); ok {
_spec.SetField(proxy.FieldDeletedAt, field.TypeTime, value)
}
if _u.mutation.DeletedAtCleared() {
_spec.ClearField(proxy.FieldDeletedAt, field.TypeTime)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Protocol(); ok {
_spec.SetField(proxy.FieldProtocol, field.TypeString, value)
}
if value, ok := _u.mutation.Host(); ok {
_spec.SetField(proxy.FieldHost, field.TypeString, value)
}
if value, ok := _u.mutation.Port(); ok {
_spec.SetField(proxy.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPort(); ok {
_spec.AddField(proxy.FieldPort, field.TypeInt, value)
}
if value, ok := _u.mutation.Username(); ok {
_spec.SetField(proxy.FieldUsername, field.TypeString, value)
}
if _u.mutation.UsernameCleared() {
_spec.ClearField(proxy.FieldUsername, field.TypeString)
}
if value, ok := _u.mutation.Password(); ok {
_spec.SetField(proxy.FieldPassword, field.TypeString, value)
}
if _u.mutation.PasswordCleared() {
_spec.ClearField(proxy.FieldPassword, field.TypeString)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
_node = &Proxy{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{proxy.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// RedeemCode is the model entity for the RedeemCode schema.
type RedeemCode struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// Code holds the value of the "code" field.
Code string `json:"code,omitempty"`
// Type holds the value of the "type" field.
Type string `json:"type,omitempty"`
// Value holds the value of the "value" field.
Value float64 `json:"value,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// UsedBy holds the value of the "used_by" field.
UsedBy *int64 `json:"used_by,omitempty"`
// UsedAt holds the value of the "used_at" field.
UsedAt *time.Time `json:"used_at,omitempty"`
// Notes holds the value of the "notes" field.
Notes *string `json:"notes,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// GroupID holds the value of the "group_id" field.
GroupID *int64 `json:"group_id,omitempty"`
// ValidityDays holds the value of the "validity_days" field.
ValidityDays int `json:"validity_days,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the RedeemCodeQuery when eager-loading is set.
Edges RedeemCodeEdges `json:"edges"`
selectValues sql.SelectValues
}
// RedeemCodeEdges holds the relations/edges for other nodes in the graph.
type RedeemCodeEdges struct {
// User holds the value of the user edge.
User *User `json:"user,omitempty"`
// Group holds the value of the group edge.
Group *Group `json:"group,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
}
// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RedeemCodeEdges) UserOrErr() (*User, error) {
if e.User != nil {
return e.User, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: user.Label}
}
return nil, &NotLoadedError{edge: "user"}
}
// GroupOrErr returns the Group value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RedeemCodeEdges) GroupOrErr() (*Group, error) {
if e.Group != nil {
return e.Group, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: group.Label}
}
return nil, &NotLoadedError{edge: "group"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*RedeemCode) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case redeemcode.FieldValue:
values[i] = new(sql.NullFloat64)
case redeemcode.FieldID, redeemcode.FieldUsedBy, redeemcode.FieldGroupID, redeemcode.FieldValidityDays:
values[i] = new(sql.NullInt64)
case redeemcode.FieldCode, redeemcode.FieldType, redeemcode.FieldStatus, redeemcode.FieldNotes:
values[i] = new(sql.NullString)
case redeemcode.FieldUsedAt, redeemcode.FieldCreatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the RedeemCode fields.
func (_m *RedeemCode) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case redeemcode.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case redeemcode.FieldCode:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field code", values[i])
} else if value.Valid {
_m.Code = value.String
}
case redeemcode.FieldType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field type", values[i])
} else if value.Valid {
_m.Type = value.String
}
case redeemcode.FieldValue:
if value, ok := values[i].(*sql.NullFloat64); !ok {
return fmt.Errorf("unexpected type %T for field value", values[i])
} else if value.Valid {
_m.Value = value.Float64
}
case redeemcode.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = value.String
}
case redeemcode.FieldUsedBy:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field used_by", values[i])
} else if value.Valid {
_m.UsedBy = new(int64)
*_m.UsedBy = value.Int64
}
case redeemcode.FieldUsedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field used_at", values[i])
} else if value.Valid {
_m.UsedAt = new(time.Time)
*_m.UsedAt = value.Time
}
case redeemcode.FieldNotes:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field notes", values[i])
} else if value.Valid {
_m.Notes = new(string)
*_m.Notes = value.String
}
case redeemcode.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case redeemcode.FieldGroupID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field group_id", values[i])
} else if value.Valid {
_m.GroupID = new(int64)
*_m.GroupID = value.Int64
}
case redeemcode.FieldValidityDays:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field validity_days", values[i])
} else if value.Valid {
_m.ValidityDays = int(value.Int64)
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// GetValue returns the ent.Value that was dynamically selected and assigned to the RedeemCode.
// This includes values selected through modifiers, order, etc.
func (_m *RedeemCode) GetValue(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// QueryUser queries the "user" edge of the RedeemCode entity.
func (_m *RedeemCode) QueryUser() *UserQuery {
return NewRedeemCodeClient(_m.config).QueryUser(_m)
}
// QueryGroup queries the "group" edge of the RedeemCode entity.
func (_m *RedeemCode) QueryGroup() *GroupQuery {
return NewRedeemCodeClient(_m.config).QueryGroup(_m)
}
// Update returns a builder for updating this RedeemCode.
// Note that you need to call RedeemCode.Unwrap() before calling this method if this RedeemCode
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *RedeemCode) Update() *RedeemCodeUpdateOne {
return NewRedeemCodeClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the RedeemCode entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *RedeemCode) Unwrap() *RedeemCode {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("ent: RedeemCode is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *RedeemCode) String() string {
var builder strings.Builder
builder.WriteString("RedeemCode(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("code=")
builder.WriteString(_m.Code)
builder.WriteString(", ")
builder.WriteString("type=")
builder.WriteString(_m.Type)
builder.WriteString(", ")
builder.WriteString("value=")
builder.WriteString(fmt.Sprintf("%v", _m.Value))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(_m.Status)
builder.WriteString(", ")
if v := _m.UsedBy; v != nil {
builder.WriteString("used_by=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := _m.UsedAt; v != nil {
builder.WriteString("used_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
if v := _m.Notes; v != nil {
builder.WriteString("notes=")
builder.WriteString(*v)
}
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.GroupID; v != nil {
builder.WriteString("group_id=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
builder.WriteString("validity_days=")
builder.WriteString(fmt.Sprintf("%v", _m.ValidityDays))
builder.WriteByte(')')
return builder.String()
}
// RedeemCodes is a parsable slice of RedeemCode.
type RedeemCodes []*RedeemCode
// Code generated by ent, DO NOT EDIT.
package redeemcode
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the redeemcode type in the database.
Label = "redeem_code"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCode holds the string denoting the code field in the database.
FieldCode = "code"
// FieldType holds the string denoting the type field in the database.
FieldType = "type"
// FieldValue holds the string denoting the value field in the database.
FieldValue = "value"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldUsedBy holds the string denoting the used_by field in the database.
FieldUsedBy = "used_by"
// FieldUsedAt holds the string denoting the used_at field in the database.
FieldUsedAt = "used_at"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes = "notes"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldGroupID holds the string denoting the group_id field in the database.
FieldGroupID = "group_id"
// FieldValidityDays holds the string denoting the validity_days field in the database.
FieldValidityDays = "validity_days"
// EdgeUser holds the string denoting the user edge name in mutations.
EdgeUser = "user"
// EdgeGroup holds the string denoting the group edge name in mutations.
EdgeGroup = "group"
// Table holds the table name of the redeemcode in the database.
Table = "redeem_codes"
// UserTable is the table that holds the user relation/edge.
UserTable = "redeem_codes"
// UserInverseTable is the table name for the User entity.
// It exists in this package in order to avoid circular dependency with the "user" package.
UserInverseTable = "users"
// UserColumn is the table column denoting the user relation/edge.
UserColumn = "used_by"
// GroupTable is the table that holds the group relation/edge.
GroupTable = "redeem_codes"
// GroupInverseTable is the table name for the Group entity.
// It exists in this package in order to avoid circular dependency with the "group" package.
GroupInverseTable = "groups"
// GroupColumn is the table column denoting the group relation/edge.
GroupColumn = "group_id"
)
// Columns holds all SQL columns for redeemcode fields.
var Columns = []string{
FieldID,
FieldCode,
FieldType,
FieldValue,
FieldStatus,
FieldUsedBy,
FieldUsedAt,
FieldNotes,
FieldCreatedAt,
FieldGroupID,
FieldValidityDays,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// CodeValidator is a validator for the "code" field. It is called by the builders before save.
CodeValidator func(string) error
// DefaultType holds the default value on creation for the "type" field.
DefaultType string
// TypeValidator is a validator for the "type" field. It is called by the builders before save.
TypeValidator func(string) error
// DefaultValue holds the default value on creation for the "value" field.
DefaultValue float64
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator func(string) error
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultValidityDays holds the default value on creation for the "validity_days" field.
DefaultValidityDays int
)
// OrderOption defines the ordering options for the RedeemCode queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByCode orders the results by the code field.
func ByCode(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCode, opts...).ToFunc()
}
// ByType orders the results by the type field.
func ByType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldType, opts...).ToFunc()
}
// ByValue orders the results by the value field.
func ByValue(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldValue, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByUsedBy orders the results by the used_by field.
func ByUsedBy(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUsedBy, opts...).ToFunc()
}
// ByUsedAt orders the results by the used_at field.
func ByUsedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUsedAt, opts...).ToFunc()
}
// ByNotes orders the results by the notes field.
func ByNotes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNotes, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByGroupID orders the results by the group_id field.
func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldGroupID, opts...).ToFunc()
}
// ByValidityDays orders the results by the validity_days field.
func ByValidityDays(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldValidityDays, opts...).ToFunc()
}
// ByUserField orders the results by user field.
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
}
}
// ByGroupField orders the results by group field.
func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
}
}
func newUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UserInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
}
func newGroupStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(GroupInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
)
}
// Code generated by ent, DO NOT EDIT.
package redeemcode
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldID, id))
}
// Code applies equality check predicate on the "code" field. It's identical to CodeEQ.
func Code(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldCode, v))
}
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
func Type(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldType, v))
}
// Value applies equality check predicate on the "value" field. It's identical to ValueEQ.
func Value(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldValue, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldStatus, v))
}
// UsedBy applies equality check predicate on the "used_by" field. It's identical to UsedByEQ.
func UsedBy(v int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldUsedBy, v))
}
// UsedAt applies equality check predicate on the "used_at" field. It's identical to UsedAtEQ.
func UsedAt(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldUsedAt, v))
}
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
func Notes(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldNotes, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldCreatedAt, v))
}
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
func GroupID(v int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldGroupID, v))
}
// ValidityDays applies equality check predicate on the "validity_days" field. It's identical to ValidityDaysEQ.
func ValidityDays(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldValidityDays, v))
}
// CodeEQ applies the EQ predicate on the "code" field.
func CodeEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldCode, v))
}
// CodeNEQ applies the NEQ predicate on the "code" field.
func CodeNEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldCode, v))
}
// CodeIn applies the In predicate on the "code" field.
func CodeIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldCode, vs...))
}
// CodeNotIn applies the NotIn predicate on the "code" field.
func CodeNotIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldCode, vs...))
}
// CodeGT applies the GT predicate on the "code" field.
func CodeGT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldCode, v))
}
// CodeGTE applies the GTE predicate on the "code" field.
func CodeGTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldCode, v))
}
// CodeLT applies the LT predicate on the "code" field.
func CodeLT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldCode, v))
}
// CodeLTE applies the LTE predicate on the "code" field.
func CodeLTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldCode, v))
}
// CodeContains applies the Contains predicate on the "code" field.
func CodeContains(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContains(FieldCode, v))
}
// CodeHasPrefix applies the HasPrefix predicate on the "code" field.
func CodeHasPrefix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasPrefix(FieldCode, v))
}
// CodeHasSuffix applies the HasSuffix predicate on the "code" field.
func CodeHasSuffix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasSuffix(FieldCode, v))
}
// CodeEqualFold applies the EqualFold predicate on the "code" field.
func CodeEqualFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEqualFold(FieldCode, v))
}
// CodeContainsFold applies the ContainsFold predicate on the "code" field.
func CodeContainsFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContainsFold(FieldCode, v))
}
// TypeEQ applies the EQ predicate on the "type" field.
func TypeEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldType, v))
}
// TypeNEQ applies the NEQ predicate on the "type" field.
func TypeNEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldType, v))
}
// TypeIn applies the In predicate on the "type" field.
func TypeIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldType, vs...))
}
// TypeNotIn applies the NotIn predicate on the "type" field.
func TypeNotIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldType, vs...))
}
// TypeGT applies the GT predicate on the "type" field.
func TypeGT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldType, v))
}
// TypeGTE applies the GTE predicate on the "type" field.
func TypeGTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldType, v))
}
// TypeLT applies the LT predicate on the "type" field.
func TypeLT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldType, v))
}
// TypeLTE applies the LTE predicate on the "type" field.
func TypeLTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldType, v))
}
// TypeContains applies the Contains predicate on the "type" field.
func TypeContains(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContains(FieldType, v))
}
// TypeHasPrefix applies the HasPrefix predicate on the "type" field.
func TypeHasPrefix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasPrefix(FieldType, v))
}
// TypeHasSuffix applies the HasSuffix predicate on the "type" field.
func TypeHasSuffix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasSuffix(FieldType, v))
}
// TypeEqualFold applies the EqualFold predicate on the "type" field.
func TypeEqualFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEqualFold(FieldType, v))
}
// TypeContainsFold applies the ContainsFold predicate on the "type" field.
func TypeContainsFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContainsFold(FieldType, v))
}
// ValueEQ applies the EQ predicate on the "value" field.
func ValueEQ(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldValue, v))
}
// ValueNEQ applies the NEQ predicate on the "value" field.
func ValueNEQ(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldValue, v))
}
// ValueIn applies the In predicate on the "value" field.
func ValueIn(vs ...float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldValue, vs...))
}
// ValueNotIn applies the NotIn predicate on the "value" field.
func ValueNotIn(vs ...float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldValue, vs...))
}
// ValueGT applies the GT predicate on the "value" field.
func ValueGT(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldValue, v))
}
// ValueGTE applies the GTE predicate on the "value" field.
func ValueGTE(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldValue, v))
}
// ValueLT applies the LT predicate on the "value" field.
func ValueLT(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldValue, v))
}
// ValueLTE applies the LTE predicate on the "value" field.
func ValueLTE(v float64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldValue, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContainsFold(FieldStatus, v))
}
// UsedByEQ applies the EQ predicate on the "used_by" field.
func UsedByEQ(v int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldUsedBy, v))
}
// UsedByNEQ applies the NEQ predicate on the "used_by" field.
func UsedByNEQ(v int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldUsedBy, v))
}
// UsedByIn applies the In predicate on the "used_by" field.
func UsedByIn(vs ...int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldUsedBy, vs...))
}
// UsedByNotIn applies the NotIn predicate on the "used_by" field.
func UsedByNotIn(vs ...int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldUsedBy, vs...))
}
// UsedByIsNil applies the IsNil predicate on the "used_by" field.
func UsedByIsNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIsNull(FieldUsedBy))
}
// UsedByNotNil applies the NotNil predicate on the "used_by" field.
func UsedByNotNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotNull(FieldUsedBy))
}
// UsedAtEQ applies the EQ predicate on the "used_at" field.
func UsedAtEQ(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldUsedAt, v))
}
// UsedAtNEQ applies the NEQ predicate on the "used_at" field.
func UsedAtNEQ(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldUsedAt, v))
}
// UsedAtIn applies the In predicate on the "used_at" field.
func UsedAtIn(vs ...time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldUsedAt, vs...))
}
// UsedAtNotIn applies the NotIn predicate on the "used_at" field.
func UsedAtNotIn(vs ...time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldUsedAt, vs...))
}
// UsedAtGT applies the GT predicate on the "used_at" field.
func UsedAtGT(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldUsedAt, v))
}
// UsedAtGTE applies the GTE predicate on the "used_at" field.
func UsedAtGTE(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldUsedAt, v))
}
// UsedAtLT applies the LT predicate on the "used_at" field.
func UsedAtLT(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldUsedAt, v))
}
// UsedAtLTE applies the LTE predicate on the "used_at" field.
func UsedAtLTE(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldUsedAt, v))
}
// UsedAtIsNil applies the IsNil predicate on the "used_at" field.
func UsedAtIsNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIsNull(FieldUsedAt))
}
// UsedAtNotNil applies the NotNil predicate on the "used_at" field.
func UsedAtNotNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotNull(FieldUsedAt))
}
// NotesEQ applies the EQ predicate on the "notes" field.
func NotesEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldNotes, v))
}
// NotesNEQ applies the NEQ predicate on the "notes" field.
func NotesNEQ(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldNotes, v))
}
// NotesIn applies the In predicate on the "notes" field.
func NotesIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldNotes, vs...))
}
// NotesNotIn applies the NotIn predicate on the "notes" field.
func NotesNotIn(vs ...string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldNotes, vs...))
}
// NotesGT applies the GT predicate on the "notes" field.
func NotesGT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldNotes, v))
}
// NotesGTE applies the GTE predicate on the "notes" field.
func NotesGTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldNotes, v))
}
// NotesLT applies the LT predicate on the "notes" field.
func NotesLT(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldNotes, v))
}
// NotesLTE applies the LTE predicate on the "notes" field.
func NotesLTE(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldNotes, v))
}
// NotesContains applies the Contains predicate on the "notes" field.
func NotesContains(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContains(FieldNotes, v))
}
// NotesHasPrefix applies the HasPrefix predicate on the "notes" field.
func NotesHasPrefix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasPrefix(FieldNotes, v))
}
// NotesHasSuffix applies the HasSuffix predicate on the "notes" field.
func NotesHasSuffix(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldHasSuffix(FieldNotes, v))
}
// NotesIsNil applies the IsNil predicate on the "notes" field.
func NotesIsNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIsNull(FieldNotes))
}
// NotesNotNil applies the NotNil predicate on the "notes" field.
func NotesNotNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotNull(FieldNotes))
}
// NotesEqualFold applies the EqualFold predicate on the "notes" field.
func NotesEqualFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEqualFold(FieldNotes, v))
}
// NotesContainsFold applies the ContainsFold predicate on the "notes" field.
func NotesContainsFold(v string) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldContainsFold(FieldNotes, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldCreatedAt, v))
}
// GroupIDEQ applies the EQ predicate on the "group_id" field.
func GroupIDEQ(v int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldGroupID, v))
}
// GroupIDNEQ applies the NEQ predicate on the "group_id" field.
func GroupIDNEQ(v int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldGroupID, v))
}
// GroupIDIn applies the In predicate on the "group_id" field.
func GroupIDIn(vs ...int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldGroupID, vs...))
}
// GroupIDNotIn applies the NotIn predicate on the "group_id" field.
func GroupIDNotIn(vs ...int64) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldGroupID, vs...))
}
// GroupIDIsNil applies the IsNil predicate on the "group_id" field.
func GroupIDIsNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIsNull(FieldGroupID))
}
// GroupIDNotNil applies the NotNil predicate on the "group_id" field.
func GroupIDNotNil() predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotNull(FieldGroupID))
}
// ValidityDaysEQ applies the EQ predicate on the "validity_days" field.
func ValidityDaysEQ(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldEQ(FieldValidityDays, v))
}
// ValidityDaysNEQ applies the NEQ predicate on the "validity_days" field.
func ValidityDaysNEQ(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNEQ(FieldValidityDays, v))
}
// ValidityDaysIn applies the In predicate on the "validity_days" field.
func ValidityDaysIn(vs ...int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldIn(FieldValidityDays, vs...))
}
// ValidityDaysNotIn applies the NotIn predicate on the "validity_days" field.
func ValidityDaysNotIn(vs ...int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldNotIn(FieldValidityDays, vs...))
}
// ValidityDaysGT applies the GT predicate on the "validity_days" field.
func ValidityDaysGT(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGT(FieldValidityDays, v))
}
// ValidityDaysGTE applies the GTE predicate on the "validity_days" field.
func ValidityDaysGTE(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldGTE(FieldValidityDays, v))
}
// ValidityDaysLT applies the LT predicate on the "validity_days" field.
func ValidityDaysLT(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLT(FieldValidityDays, v))
}
// ValidityDaysLTE applies the LTE predicate on the "validity_days" field.
func ValidityDaysLTE(v int) predicate.RedeemCode {
return predicate.RedeemCode(sql.FieldLTE(FieldValidityDays, v))
}
// HasUser applies the HasEdge predicate on the "user" edge.
func HasUser() predicate.RedeemCode {
return predicate.RedeemCode(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
func HasUserWith(preds ...predicate.User) predicate.RedeemCode {
return predicate.RedeemCode(func(s *sql.Selector) {
step := newUserStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// HasGroup applies the HasEdge predicate on the "group" edge.
func HasGroup() predicate.RedeemCode {
return predicate.RedeemCode(func(s *sql.Selector) {
step := sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
)
sqlgraph.HasNeighbors(s, step)
})
}
// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates).
func HasGroupWith(preds ...predicate.Group) predicate.RedeemCode {
return predicate.RedeemCode(func(s *sql.Selector) {
step := newGroupStep()
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
})
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.RedeemCode) predicate.RedeemCode {
return predicate.RedeemCode(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.RedeemCode) predicate.RedeemCode {
return predicate.RedeemCode(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.RedeemCode) predicate.RedeemCode {
return predicate.RedeemCode(sql.NotPredicates(p))
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// RedeemCodeCreate is the builder for creating a RedeemCode entity.
type RedeemCodeCreate struct {
config
mutation *RedeemCodeMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetCode sets the "code" field.
func (_c *RedeemCodeCreate) SetCode(v string) *RedeemCodeCreate {
_c.mutation.SetCode(v)
return _c
}
// SetType sets the "type" field.
func (_c *RedeemCodeCreate) SetType(v string) *RedeemCodeCreate {
_c.mutation.SetType(v)
return _c
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableType(v *string) *RedeemCodeCreate {
if v != nil {
_c.SetType(*v)
}
return _c
}
// SetValue sets the "value" field.
func (_c *RedeemCodeCreate) SetValue(v float64) *RedeemCodeCreate {
_c.mutation.SetValue(v)
return _c
}
// SetNillableValue sets the "value" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableValue(v *float64) *RedeemCodeCreate {
if v != nil {
_c.SetValue(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *RedeemCodeCreate) SetStatus(v string) *RedeemCodeCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableStatus(v *string) *RedeemCodeCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetUsedBy sets the "used_by" field.
func (_c *RedeemCodeCreate) SetUsedBy(v int64) *RedeemCodeCreate {
_c.mutation.SetUsedBy(v)
return _c
}
// SetNillableUsedBy sets the "used_by" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableUsedBy(v *int64) *RedeemCodeCreate {
if v != nil {
_c.SetUsedBy(*v)
}
return _c
}
// SetUsedAt sets the "used_at" field.
func (_c *RedeemCodeCreate) SetUsedAt(v time.Time) *RedeemCodeCreate {
_c.mutation.SetUsedAt(v)
return _c
}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableUsedAt(v *time.Time) *RedeemCodeCreate {
if v != nil {
_c.SetUsedAt(*v)
}
return _c
}
// SetNotes sets the "notes" field.
func (_c *RedeemCodeCreate) SetNotes(v string) *RedeemCodeCreate {
_c.mutation.SetNotes(v)
return _c
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableNotes(v *string) *RedeemCodeCreate {
if v != nil {
_c.SetNotes(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *RedeemCodeCreate) SetCreatedAt(v time.Time) *RedeemCodeCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableCreatedAt(v *time.Time) *RedeemCodeCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetGroupID sets the "group_id" field.
func (_c *RedeemCodeCreate) SetGroupID(v int64) *RedeemCodeCreate {
_c.mutation.SetGroupID(v)
return _c
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableGroupID(v *int64) *RedeemCodeCreate {
if v != nil {
_c.SetGroupID(*v)
}
return _c
}
// SetValidityDays sets the "validity_days" field.
func (_c *RedeemCodeCreate) SetValidityDays(v int) *RedeemCodeCreate {
_c.mutation.SetValidityDays(v)
return _c
}
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableValidityDays(v *int) *RedeemCodeCreate {
if v != nil {
_c.SetValidityDays(*v)
}
return _c
}
// SetUserID sets the "user" edge to the User entity by ID.
func (_c *RedeemCodeCreate) SetUserID(id int64) *RedeemCodeCreate {
_c.mutation.SetUserID(id)
return _c
}
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (_c *RedeemCodeCreate) SetNillableUserID(id *int64) *RedeemCodeCreate {
if id != nil {
_c = _c.SetUserID(*id)
}
return _c
}
// SetUser sets the "user" edge to the User entity.
func (_c *RedeemCodeCreate) SetUser(v *User) *RedeemCodeCreate {
return _c.SetUserID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_c *RedeemCodeCreate) SetGroup(v *Group) *RedeemCodeCreate {
return _c.SetGroupID(v.ID)
}
// Mutation returns the RedeemCodeMutation object of the builder.
func (_c *RedeemCodeCreate) Mutation() *RedeemCodeMutation {
return _c.mutation
}
// Save creates the RedeemCode in the database.
func (_c *RedeemCodeCreate) Save(ctx context.Context) (*RedeemCode, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *RedeemCodeCreate) SaveX(ctx context.Context) *RedeemCode {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *RedeemCodeCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *RedeemCodeCreate) 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 *RedeemCodeCreate) defaults() {
if _, ok := _c.mutation.GetType(); !ok {
v := redeemcode.DefaultType
_c.mutation.SetType(v)
}
if _, ok := _c.mutation.Value(); !ok {
v := redeemcode.DefaultValue
_c.mutation.SetValue(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := redeemcode.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := redeemcode.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.ValidityDays(); !ok {
v := redeemcode.DefaultValidityDays
_c.mutation.SetValidityDays(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *RedeemCodeCreate) check() error {
if _, ok := _c.mutation.Code(); !ok {
return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "RedeemCode.code"`)}
}
if v, ok := _c.mutation.Code(); ok {
if err := redeemcode.CodeValidator(v); err != nil {
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.code": %w`, err)}
}
}
if _, ok := _c.mutation.GetType(); !ok {
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "RedeemCode.type"`)}
}
if v, ok := _c.mutation.GetType(); ok {
if err := redeemcode.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.type": %w`, err)}
}
}
if _, ok := _c.mutation.Value(); !ok {
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "RedeemCode.value"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "RedeemCode.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := redeemcode.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.status": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RedeemCode.created_at"`)}
}
if _, ok := _c.mutation.ValidityDays(); !ok {
return &ValidationError{Name: "validity_days", err: errors.New(`ent: missing required field "RedeemCode.validity_days"`)}
}
return nil
}
func (_c *RedeemCodeCreate) sqlSave(ctx context.Context) (*RedeemCode, 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 *RedeemCodeCreate) createSpec() (*RedeemCode, *sqlgraph.CreateSpec) {
var (
_node = &RedeemCode{config: _c.config}
_spec = sqlgraph.NewCreateSpec(redeemcode.Table, sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.Code(); ok {
_spec.SetField(redeemcode.FieldCode, field.TypeString, value)
_node.Code = value
}
if value, ok := _c.mutation.GetType(); ok {
_spec.SetField(redeemcode.FieldType, field.TypeString, value)
_node.Type = value
}
if value, ok := _c.mutation.Value(); ok {
_spec.SetField(redeemcode.FieldValue, field.TypeFloat64, value)
_node.Value = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(redeemcode.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.UsedAt(); ok {
_spec.SetField(redeemcode.FieldUsedAt, field.TypeTime, value)
_node.UsedAt = &value
}
if value, ok := _c.mutation.Notes(); ok {
_spec.SetField(redeemcode.FieldNotes, field.TypeString, value)
_node.Notes = &value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(redeemcode.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.ValidityDays(); ok {
_spec.SetField(redeemcode.FieldValidityDays, field.TypeInt, value)
_node.ValidityDays = value
}
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.UserTable,
Columns: []string{redeemcode.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.UsedBy = &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: redeemcode.GroupTable,
Columns: []string{redeemcode.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)
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.RedeemCode.Create().
// SetCode(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.RedeemCodeUpsert) {
// SetCode(v+v).
// }).
// Exec(ctx)
func (_c *RedeemCodeCreate) OnConflict(opts ...sql.ConflictOption) *RedeemCodeUpsertOne {
_c.conflict = opts
return &RedeemCodeUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.RedeemCode.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *RedeemCodeCreate) OnConflictColumns(columns ...string) *RedeemCodeUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &RedeemCodeUpsertOne{
create: _c,
}
}
type (
// RedeemCodeUpsertOne is the builder for "upsert"-ing
// one RedeemCode node.
RedeemCodeUpsertOne struct {
create *RedeemCodeCreate
}
// RedeemCodeUpsert is the "OnConflict" setter.
RedeemCodeUpsert struct {
*sql.UpdateSet
}
)
// SetCode sets the "code" field.
func (u *RedeemCodeUpsert) SetCode(v string) *RedeemCodeUpsert {
u.Set(redeemcode.FieldCode, v)
return u
}
// UpdateCode sets the "code" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateCode() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldCode)
return u
}
// SetType sets the "type" field.
func (u *RedeemCodeUpsert) SetType(v string) *RedeemCodeUpsert {
u.Set(redeemcode.FieldType, v)
return u
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateType() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldType)
return u
}
// SetValue sets the "value" field.
func (u *RedeemCodeUpsert) SetValue(v float64) *RedeemCodeUpsert {
u.Set(redeemcode.FieldValue, v)
return u
}
// UpdateValue sets the "value" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateValue() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldValue)
return u
}
// AddValue adds v to the "value" field.
func (u *RedeemCodeUpsert) AddValue(v float64) *RedeemCodeUpsert {
u.Add(redeemcode.FieldValue, v)
return u
}
// SetStatus sets the "status" field.
func (u *RedeemCodeUpsert) SetStatus(v string) *RedeemCodeUpsert {
u.Set(redeemcode.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateStatus() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldStatus)
return u
}
// SetUsedBy sets the "used_by" field.
func (u *RedeemCodeUpsert) SetUsedBy(v int64) *RedeemCodeUpsert {
u.Set(redeemcode.FieldUsedBy, v)
return u
}
// UpdateUsedBy sets the "used_by" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateUsedBy() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldUsedBy)
return u
}
// ClearUsedBy clears the value of the "used_by" field.
func (u *RedeemCodeUpsert) ClearUsedBy() *RedeemCodeUpsert {
u.SetNull(redeemcode.FieldUsedBy)
return u
}
// SetUsedAt sets the "used_at" field.
func (u *RedeemCodeUpsert) SetUsedAt(v time.Time) *RedeemCodeUpsert {
u.Set(redeemcode.FieldUsedAt, v)
return u
}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateUsedAt() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldUsedAt)
return u
}
// ClearUsedAt clears the value of the "used_at" field.
func (u *RedeemCodeUpsert) ClearUsedAt() *RedeemCodeUpsert {
u.SetNull(redeemcode.FieldUsedAt)
return u
}
// SetNotes sets the "notes" field.
func (u *RedeemCodeUpsert) SetNotes(v string) *RedeemCodeUpsert {
u.Set(redeemcode.FieldNotes, v)
return u
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateNotes() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldNotes)
return u
}
// ClearNotes clears the value of the "notes" field.
func (u *RedeemCodeUpsert) ClearNotes() *RedeemCodeUpsert {
u.SetNull(redeemcode.FieldNotes)
return u
}
// SetGroupID sets the "group_id" field.
func (u *RedeemCodeUpsert) SetGroupID(v int64) *RedeemCodeUpsert {
u.Set(redeemcode.FieldGroupID, v)
return u
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateGroupID() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldGroupID)
return u
}
// ClearGroupID clears the value of the "group_id" field.
func (u *RedeemCodeUpsert) ClearGroupID() *RedeemCodeUpsert {
u.SetNull(redeemcode.FieldGroupID)
return u
}
// SetValidityDays sets the "validity_days" field.
func (u *RedeemCodeUpsert) SetValidityDays(v int) *RedeemCodeUpsert {
u.Set(redeemcode.FieldValidityDays, v)
return u
}
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
func (u *RedeemCodeUpsert) UpdateValidityDays() *RedeemCodeUpsert {
u.SetExcluded(redeemcode.FieldValidityDays)
return u
}
// AddValidityDays adds v to the "validity_days" field.
func (u *RedeemCodeUpsert) AddValidityDays(v int) *RedeemCodeUpsert {
u.Add(redeemcode.FieldValidityDays, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.RedeemCode.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *RedeemCodeUpsertOne) UpdateNewValues() *RedeemCodeUpsertOne {
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(redeemcode.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.RedeemCode.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *RedeemCodeUpsertOne) Ignore() *RedeemCodeUpsertOne {
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 *RedeemCodeUpsertOne) DoNothing() *RedeemCodeUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the RedeemCodeCreate.OnConflict
// documentation for more info.
func (u *RedeemCodeUpsertOne) Update(set func(*RedeemCodeUpsert)) *RedeemCodeUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&RedeemCodeUpsert{UpdateSet: update})
}))
return u
}
// SetCode sets the "code" field.
func (u *RedeemCodeUpsertOne) SetCode(v string) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetCode(v)
})
}
// UpdateCode sets the "code" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateCode() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateCode()
})
}
// SetType sets the "type" field.
func (u *RedeemCodeUpsertOne) SetType(v string) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateType() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateType()
})
}
// SetValue sets the "value" field.
func (u *RedeemCodeUpsertOne) SetValue(v float64) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetValue(v)
})
}
// AddValue adds v to the "value" field.
func (u *RedeemCodeUpsertOne) AddValue(v float64) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.AddValue(v)
})
}
// UpdateValue sets the "value" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateValue() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateValue()
})
}
// SetStatus sets the "status" field.
func (u *RedeemCodeUpsertOne) SetStatus(v string) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateStatus() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateStatus()
})
}
// SetUsedBy sets the "used_by" field.
func (u *RedeemCodeUpsertOne) SetUsedBy(v int64) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetUsedBy(v)
})
}
// UpdateUsedBy sets the "used_by" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateUsedBy() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateUsedBy()
})
}
// ClearUsedBy clears the value of the "used_by" field.
func (u *RedeemCodeUpsertOne) ClearUsedBy() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearUsedBy()
})
}
// SetUsedAt sets the "used_at" field.
func (u *RedeemCodeUpsertOne) SetUsedAt(v time.Time) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetUsedAt(v)
})
}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateUsedAt() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateUsedAt()
})
}
// ClearUsedAt clears the value of the "used_at" field.
func (u *RedeemCodeUpsertOne) ClearUsedAt() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearUsedAt()
})
}
// SetNotes sets the "notes" field.
func (u *RedeemCodeUpsertOne) SetNotes(v string) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetNotes(v)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateNotes() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateNotes()
})
}
// ClearNotes clears the value of the "notes" field.
func (u *RedeemCodeUpsertOne) ClearNotes() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearNotes()
})
}
// SetGroupID sets the "group_id" field.
func (u *RedeemCodeUpsertOne) SetGroupID(v int64) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateGroupID() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateGroupID()
})
}
// ClearGroupID clears the value of the "group_id" field.
func (u *RedeemCodeUpsertOne) ClearGroupID() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearGroupID()
})
}
// SetValidityDays sets the "validity_days" field.
func (u *RedeemCodeUpsertOne) SetValidityDays(v int) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetValidityDays(v)
})
}
// AddValidityDays adds v to the "validity_days" field.
func (u *RedeemCodeUpsertOne) AddValidityDays(v int) *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.AddValidityDays(v)
})
}
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
func (u *RedeemCodeUpsertOne) UpdateValidityDays() *RedeemCodeUpsertOne {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateValidityDays()
})
}
// Exec executes the query.
func (u *RedeemCodeUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for RedeemCodeCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *RedeemCodeUpsertOne) 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 *RedeemCodeUpsertOne) 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 *RedeemCodeUpsertOne) IDX(ctx context.Context) int64 {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// RedeemCodeCreateBulk is the builder for creating many RedeemCode entities in bulk.
type RedeemCodeCreateBulk struct {
config
err error
builders []*RedeemCodeCreate
conflict []sql.ConflictOption
}
// Save creates the RedeemCode entities in the database.
func (_c *RedeemCodeCreateBulk) Save(ctx context.Context) ([]*RedeemCode, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*RedeemCode, 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.(*RedeemCodeMutation)
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 *RedeemCodeCreateBulk) SaveX(ctx context.Context) []*RedeemCode {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *RedeemCodeCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *RedeemCodeCreateBulk) 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.RedeemCode.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.RedeemCodeUpsert) {
// SetCode(v+v).
// }).
// Exec(ctx)
func (_c *RedeemCodeCreateBulk) OnConflict(opts ...sql.ConflictOption) *RedeemCodeUpsertBulk {
_c.conflict = opts
return &RedeemCodeUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.RedeemCode.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *RedeemCodeCreateBulk) OnConflictColumns(columns ...string) *RedeemCodeUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &RedeemCodeUpsertBulk{
create: _c,
}
}
// RedeemCodeUpsertBulk is the builder for "upsert"-ing
// a bulk of RedeemCode nodes.
type RedeemCodeUpsertBulk struct {
create *RedeemCodeCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.RedeemCode.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *RedeemCodeUpsertBulk) UpdateNewValues() *RedeemCodeUpsertBulk {
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(redeemcode.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.RedeemCode.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *RedeemCodeUpsertBulk) Ignore() *RedeemCodeUpsertBulk {
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 *RedeemCodeUpsertBulk) DoNothing() *RedeemCodeUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the RedeemCodeCreateBulk.OnConflict
// documentation for more info.
func (u *RedeemCodeUpsertBulk) Update(set func(*RedeemCodeUpsert)) *RedeemCodeUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&RedeemCodeUpsert{UpdateSet: update})
}))
return u
}
// SetCode sets the "code" field.
func (u *RedeemCodeUpsertBulk) SetCode(v string) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetCode(v)
})
}
// UpdateCode sets the "code" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateCode() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateCode()
})
}
// SetType sets the "type" field.
func (u *RedeemCodeUpsertBulk) SetType(v string) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetType(v)
})
}
// UpdateType sets the "type" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateType() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateType()
})
}
// SetValue sets the "value" field.
func (u *RedeemCodeUpsertBulk) SetValue(v float64) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetValue(v)
})
}
// AddValue adds v to the "value" field.
func (u *RedeemCodeUpsertBulk) AddValue(v float64) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.AddValue(v)
})
}
// UpdateValue sets the "value" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateValue() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateValue()
})
}
// SetStatus sets the "status" field.
func (u *RedeemCodeUpsertBulk) SetStatus(v string) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateStatus() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateStatus()
})
}
// SetUsedBy sets the "used_by" field.
func (u *RedeemCodeUpsertBulk) SetUsedBy(v int64) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetUsedBy(v)
})
}
// UpdateUsedBy sets the "used_by" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateUsedBy() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateUsedBy()
})
}
// ClearUsedBy clears the value of the "used_by" field.
func (u *RedeemCodeUpsertBulk) ClearUsedBy() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearUsedBy()
})
}
// SetUsedAt sets the "used_at" field.
func (u *RedeemCodeUpsertBulk) SetUsedAt(v time.Time) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetUsedAt(v)
})
}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateUsedAt() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateUsedAt()
})
}
// ClearUsedAt clears the value of the "used_at" field.
func (u *RedeemCodeUpsertBulk) ClearUsedAt() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearUsedAt()
})
}
// SetNotes sets the "notes" field.
func (u *RedeemCodeUpsertBulk) SetNotes(v string) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetNotes(v)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateNotes() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateNotes()
})
}
// ClearNotes clears the value of the "notes" field.
func (u *RedeemCodeUpsertBulk) ClearNotes() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearNotes()
})
}
// SetGroupID sets the "group_id" field.
func (u *RedeemCodeUpsertBulk) SetGroupID(v int64) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetGroupID(v)
})
}
// UpdateGroupID sets the "group_id" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateGroupID() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateGroupID()
})
}
// ClearGroupID clears the value of the "group_id" field.
func (u *RedeemCodeUpsertBulk) ClearGroupID() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.ClearGroupID()
})
}
// SetValidityDays sets the "validity_days" field.
func (u *RedeemCodeUpsertBulk) SetValidityDays(v int) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.SetValidityDays(v)
})
}
// AddValidityDays adds v to the "validity_days" field.
func (u *RedeemCodeUpsertBulk) AddValidityDays(v int) *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.AddValidityDays(v)
})
}
// UpdateValidityDays sets the "validity_days" field to the value that was provided on create.
func (u *RedeemCodeUpsertBulk) UpdateValidityDays() *RedeemCodeUpsertBulk {
return u.Update(func(s *RedeemCodeUpsert) {
s.UpdateValidityDays()
})
}
// Exec executes the query.
func (u *RedeemCodeUpsertBulk) 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 RedeemCodeCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for RedeemCodeCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *RedeemCodeUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
)
// RedeemCodeDelete is the builder for deleting a RedeemCode entity.
type RedeemCodeDelete struct {
config
hooks []Hook
mutation *RedeemCodeMutation
}
// Where appends a list predicates to the RedeemCodeDelete builder.
func (_d *RedeemCodeDelete) Where(ps ...predicate.RedeemCode) *RedeemCodeDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *RedeemCodeDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *RedeemCodeDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *RedeemCodeDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(redeemcode.Table, sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// RedeemCodeDeleteOne is the builder for deleting a single RedeemCode entity.
type RedeemCodeDeleteOne struct {
_d *RedeemCodeDelete
}
// Where appends a list predicates to the RedeemCodeDelete builder.
func (_d *RedeemCodeDeleteOne) Where(ps ...predicate.RedeemCode) *RedeemCodeDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *RedeemCodeDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{redeemcode.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *RedeemCodeDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// RedeemCodeQuery is the builder for querying RedeemCode entities.
type RedeemCodeQuery struct {
config
ctx *QueryContext
order []redeemcode.OrderOption
inters []Interceptor
predicates []predicate.RedeemCode
withUser *UserQuery
withGroup *GroupQuery
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the RedeemCodeQuery builder.
func (_q *RedeemCodeQuery) Where(ps ...predicate.RedeemCode) *RedeemCodeQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *RedeemCodeQuery) Limit(limit int) *RedeemCodeQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *RedeemCodeQuery) Offset(offset int) *RedeemCodeQuery {
_q.ctx.Offset = &offset
return _q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (_q *RedeemCodeQuery) Unique(unique bool) *RedeemCodeQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *RedeemCodeQuery) Order(o ...redeemcode.OrderOption) *RedeemCodeQuery {
_q.order = append(_q.order, o...)
return _q
}
// QueryUser chains the current query on the "user" edge.
func (_q *RedeemCodeQuery) QueryUser() *UserQuery {
query := (&UserClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(redeemcode.Table, redeemcode.FieldID, selector),
sqlgraph.To(user.Table, user.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, redeemcode.UserTable, redeemcode.UserColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryGroup chains the current query on the "group" edge.
func (_q *RedeemCodeQuery) QueryGroup() *GroupQuery {
query := (&GroupClient{config: _q.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
selector := _q.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(redeemcode.Table, redeemcode.FieldID, selector),
sqlgraph.To(group.Table, group.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, redeemcode.GroupTable, redeemcode.GroupColumn),
)
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first RedeemCode entity from the query.
// Returns a *NotFoundError when no RedeemCode was found.
func (_q *RedeemCodeQuery) First(ctx context.Context) (*RedeemCode, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{redeemcode.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *RedeemCodeQuery) FirstX(ctx context.Context) *RedeemCode {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first RedeemCode ID from the query.
// Returns a *NotFoundError when no RedeemCode ID was found.
func (_q *RedeemCodeQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{redeemcode.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *RedeemCodeQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single RedeemCode entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one RedeemCode entity is found.
// Returns a *NotFoundError when no RedeemCode entities are found.
func (_q *RedeemCodeQuery) Only(ctx context.Context) (*RedeemCode, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{redeemcode.Label}
default:
return nil, &NotSingularError{redeemcode.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *RedeemCodeQuery) OnlyX(ctx context.Context) *RedeemCode {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only RedeemCode ID in the query.
// Returns a *NotSingularError when more than one RedeemCode ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *RedeemCodeQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{redeemcode.Label}
default:
err = &NotSingularError{redeemcode.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *RedeemCodeQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of RedeemCodes.
func (_q *RedeemCodeQuery) All(ctx context.Context) ([]*RedeemCode, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*RedeemCode, *RedeemCodeQuery]()
return withInterceptors[[]*RedeemCode](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *RedeemCodeQuery) AllX(ctx context.Context) []*RedeemCode {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of RedeemCode IDs.
func (_q *RedeemCodeQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(redeemcode.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *RedeemCodeQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *RedeemCodeQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*RedeemCodeQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *RedeemCodeQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *RedeemCodeQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *RedeemCodeQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the RedeemCodeQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *RedeemCodeQuery) Clone() *RedeemCodeQuery {
if _q == nil {
return nil
}
return &RedeemCodeQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]redeemcode.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.RedeemCode{}, _q.predicates...),
withUser: _q.withUser.Clone(),
withGroup: _q.withGroup.Clone(),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// WithUser tells the query-builder to eager-load the nodes that are connected to
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *RedeemCodeQuery) WithUser(opts ...func(*UserQuery)) *RedeemCodeQuery {
query := (&UserClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withUser = query
return _q
}
// WithGroup tells the query-builder to eager-load the nodes that are connected to
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
func (_q *RedeemCodeQuery) WithGroup(opts ...func(*GroupQuery)) *RedeemCodeQuery {
query := (&GroupClient{config: _q.config}).Query()
for _, opt := range opts {
opt(query)
}
_q.withGroup = query
return _q
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Code string `json:"code,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.RedeemCode.Query().
// GroupBy(redeemcode.FieldCode).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (_q *RedeemCodeQuery) GroupBy(field string, fields ...string) *RedeemCodeGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &RedeemCodeGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = redeemcode.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Code string `json:"code,omitempty"`
// }
//
// client.RedeemCode.Query().
// Select(redeemcode.FieldCode).
// Scan(ctx, &v)
func (_q *RedeemCodeQuery) Select(fields ...string) *RedeemCodeSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &RedeemCodeSelect{RedeemCodeQuery: _q}
sbuild.label = redeemcode.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a RedeemCodeSelect configured with the given aggregations.
func (_q *RedeemCodeQuery) Aggregate(fns ...AggregateFunc) *RedeemCodeSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *RedeemCodeQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !redeemcode.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *RedeemCodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*RedeemCode, error) {
var (
nodes = []*RedeemCode{}
_spec = _q.querySpec()
loadedTypes = [2]bool{
_q.withUser != nil,
_q.withGroup != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*RedeemCode).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &RedeemCode{config: _q.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := _q.withUser; query != nil {
if err := _q.loadUser(ctx, query, nodes, nil,
func(n *RedeemCode, e *User) { n.Edges.User = e }); err != nil {
return nil, err
}
}
if query := _q.withGroup; query != nil {
if err := _q.loadGroup(ctx, query, nodes, nil,
func(n *RedeemCode, e *Group) { n.Edges.Group = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (_q *RedeemCodeQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*RedeemCode, init func(*RedeemCode), assign func(*RedeemCode, *User)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*RedeemCode)
for i := range nodes {
if nodes[i].UsedBy == nil {
continue
}
fk := *nodes[i].UsedBy
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(user.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "used_by" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *RedeemCodeQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*RedeemCode, init func(*RedeemCode), assign func(*RedeemCode, *Group)) error {
ids := make([]int64, 0, len(nodes))
nodeids := make(map[int64][]*RedeemCode)
for i := range nodes {
if nodes[i].GroupID == nil {
continue
}
fk := *nodes[i].GroupID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(group.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "group_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (_q *RedeemCodeQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *RedeemCodeQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(redeemcode.Table, redeemcode.Columns, sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, redeemcode.FieldID)
for i := range fields {
if fields[i] != redeemcode.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
if _q.withUser != nil {
_spec.Node.AddColumnOnce(redeemcode.FieldUsedBy)
}
if _q.withGroup != nil {
_spec.Node.AddColumnOnce(redeemcode.FieldGroupID)
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *RedeemCodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(redeemcode.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = redeemcode.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// RedeemCodeGroupBy is the group-by builder for RedeemCode entities.
type RedeemCodeGroupBy struct {
selector
build *RedeemCodeQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *RedeemCodeGroupBy) Aggregate(fns ...AggregateFunc) *RedeemCodeGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *RedeemCodeGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*RedeemCodeQuery, *RedeemCodeGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *RedeemCodeGroupBy) sqlScan(ctx context.Context, root *RedeemCodeQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// RedeemCodeSelect is the builder for selecting fields of RedeemCode entities.
type RedeemCodeSelect struct {
*RedeemCodeQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *RedeemCodeSelect) Aggregate(fns ...AggregateFunc) *RedeemCodeSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *RedeemCodeSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*RedeemCodeQuery, *RedeemCodeSelect](ctx, _s.RedeemCodeQuery, _s, _s.inters, v)
}
func (_s *RedeemCodeSelect) sqlScan(ctx context.Context, root *RedeemCodeQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"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/predicate"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// RedeemCodeUpdate is the builder for updating RedeemCode entities.
type RedeemCodeUpdate struct {
config
hooks []Hook
mutation *RedeemCodeMutation
}
// Where appends a list predicates to the RedeemCodeUpdate builder.
func (_u *RedeemCodeUpdate) Where(ps ...predicate.RedeemCode) *RedeemCodeUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetCode sets the "code" field.
func (_u *RedeemCodeUpdate) SetCode(v string) *RedeemCodeUpdate {
_u.mutation.SetCode(v)
return _u
}
// SetNillableCode sets the "code" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableCode(v *string) *RedeemCodeUpdate {
if v != nil {
_u.SetCode(*v)
}
return _u
}
// SetType sets the "type" field.
func (_u *RedeemCodeUpdate) SetType(v string) *RedeemCodeUpdate {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableType(v *string) *RedeemCodeUpdate {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetValue sets the "value" field.
func (_u *RedeemCodeUpdate) SetValue(v float64) *RedeemCodeUpdate {
_u.mutation.ResetValue()
_u.mutation.SetValue(v)
return _u
}
// SetNillableValue sets the "value" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableValue(v *float64) *RedeemCodeUpdate {
if v != nil {
_u.SetValue(*v)
}
return _u
}
// AddValue adds value to the "value" field.
func (_u *RedeemCodeUpdate) AddValue(v float64) *RedeemCodeUpdate {
_u.mutation.AddValue(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *RedeemCodeUpdate) SetStatus(v string) *RedeemCodeUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableStatus(v *string) *RedeemCodeUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetUsedBy sets the "used_by" field.
func (_u *RedeemCodeUpdate) SetUsedBy(v int64) *RedeemCodeUpdate {
_u.mutation.SetUsedBy(v)
return _u
}
// SetNillableUsedBy sets the "used_by" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableUsedBy(v *int64) *RedeemCodeUpdate {
if v != nil {
_u.SetUsedBy(*v)
}
return _u
}
// ClearUsedBy clears the value of the "used_by" field.
func (_u *RedeemCodeUpdate) ClearUsedBy() *RedeemCodeUpdate {
_u.mutation.ClearUsedBy()
return _u
}
// SetUsedAt sets the "used_at" field.
func (_u *RedeemCodeUpdate) SetUsedAt(v time.Time) *RedeemCodeUpdate {
_u.mutation.SetUsedAt(v)
return _u
}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableUsedAt(v *time.Time) *RedeemCodeUpdate {
if v != nil {
_u.SetUsedAt(*v)
}
return _u
}
// ClearUsedAt clears the value of the "used_at" field.
func (_u *RedeemCodeUpdate) ClearUsedAt() *RedeemCodeUpdate {
_u.mutation.ClearUsedAt()
return _u
}
// SetNotes sets the "notes" field.
func (_u *RedeemCodeUpdate) SetNotes(v string) *RedeemCodeUpdate {
_u.mutation.SetNotes(v)
return _u
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableNotes(v *string) *RedeemCodeUpdate {
if v != nil {
_u.SetNotes(*v)
}
return _u
}
// ClearNotes clears the value of the "notes" field.
func (_u *RedeemCodeUpdate) ClearNotes() *RedeemCodeUpdate {
_u.mutation.ClearNotes()
return _u
}
// SetGroupID sets the "group_id" field.
func (_u *RedeemCodeUpdate) SetGroupID(v int64) *RedeemCodeUpdate {
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableGroupID(v *int64) *RedeemCodeUpdate {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// ClearGroupID clears the value of the "group_id" field.
func (_u *RedeemCodeUpdate) ClearGroupID() *RedeemCodeUpdate {
_u.mutation.ClearGroupID()
return _u
}
// SetValidityDays sets the "validity_days" field.
func (_u *RedeemCodeUpdate) SetValidityDays(v int) *RedeemCodeUpdate {
_u.mutation.ResetValidityDays()
_u.mutation.SetValidityDays(v)
return _u
}
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableValidityDays(v *int) *RedeemCodeUpdate {
if v != nil {
_u.SetValidityDays(*v)
}
return _u
}
// AddValidityDays adds value to the "validity_days" field.
func (_u *RedeemCodeUpdate) AddValidityDays(v int) *RedeemCodeUpdate {
_u.mutation.AddValidityDays(v)
return _u
}
// SetUserID sets the "user" edge to the User entity by ID.
func (_u *RedeemCodeUpdate) SetUserID(id int64) *RedeemCodeUpdate {
_u.mutation.SetUserID(id)
return _u
}
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (_u *RedeemCodeUpdate) SetNillableUserID(id *int64) *RedeemCodeUpdate {
if id != nil {
_u = _u.SetUserID(*id)
}
return _u
}
// SetUser sets the "user" edge to the User entity.
func (_u *RedeemCodeUpdate) SetUser(v *User) *RedeemCodeUpdate {
return _u.SetUserID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_u *RedeemCodeUpdate) SetGroup(v *Group) *RedeemCodeUpdate {
return _u.SetGroupID(v.ID)
}
// Mutation returns the RedeemCodeMutation object of the builder.
func (_u *RedeemCodeUpdate) Mutation() *RedeemCodeMutation {
return _u.mutation
}
// ClearUser clears the "user" edge to the User entity.
func (_u *RedeemCodeUpdate) ClearUser() *RedeemCodeUpdate {
_u.mutation.ClearUser()
return _u
}
// ClearGroup clears the "group" edge to the Group entity.
func (_u *RedeemCodeUpdate) ClearGroup() *RedeemCodeUpdate {
_u.mutation.ClearGroup()
return _u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *RedeemCodeUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *RedeemCodeUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *RedeemCodeUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *RedeemCodeUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *RedeemCodeUpdate) check() error {
if v, ok := _u.mutation.Code(); ok {
if err := redeemcode.CodeValidator(v); err != nil {
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.code": %w`, err)}
}
}
if v, ok := _u.mutation.GetType(); ok {
if err := redeemcode.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.type": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := redeemcode.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.status": %w`, err)}
}
}
return nil
}
func (_u *RedeemCodeUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(redeemcode.Table, redeemcode.Columns, sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Code(); ok {
_spec.SetField(redeemcode.FieldCode, field.TypeString, value)
}
if value, ok := _u.mutation.GetType(); ok {
_spec.SetField(redeemcode.FieldType, field.TypeString, value)
}
if value, ok := _u.mutation.Value(); ok {
_spec.SetField(redeemcode.FieldValue, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedValue(); ok {
_spec.AddField(redeemcode.FieldValue, field.TypeFloat64, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(redeemcode.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.UsedAt(); ok {
_spec.SetField(redeemcode.FieldUsedAt, field.TypeTime, value)
}
if _u.mutation.UsedAtCleared() {
_spec.ClearField(redeemcode.FieldUsedAt, field.TypeTime)
}
if value, ok := _u.mutation.Notes(); ok {
_spec.SetField(redeemcode.FieldNotes, field.TypeString, value)
}
if _u.mutation.NotesCleared() {
_spec.ClearField(redeemcode.FieldNotes, field.TypeString)
}
if value, ok := _u.mutation.ValidityDays(); ok {
_spec.SetField(redeemcode.FieldValidityDays, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedValidityDays(); ok {
_spec.AddField(redeemcode.FieldValidityDays, field.TypeInt, value)
}
if _u.mutation.UserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.UserTable,
Columns: []string{redeemcode.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.UserTable,
Columns: []string{redeemcode.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.GroupTable,
Columns: []string{redeemcode.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.GroupTable,
Columns: []string{redeemcode.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{redeemcode.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// RedeemCodeUpdateOne is the builder for updating a single RedeemCode entity.
type RedeemCodeUpdateOne struct {
config
fields []string
hooks []Hook
mutation *RedeemCodeMutation
}
// SetCode sets the "code" field.
func (_u *RedeemCodeUpdateOne) SetCode(v string) *RedeemCodeUpdateOne {
_u.mutation.SetCode(v)
return _u
}
// SetNillableCode sets the "code" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableCode(v *string) *RedeemCodeUpdateOne {
if v != nil {
_u.SetCode(*v)
}
return _u
}
// SetType sets the "type" field.
func (_u *RedeemCodeUpdateOne) SetType(v string) *RedeemCodeUpdateOne {
_u.mutation.SetType(v)
return _u
}
// SetNillableType sets the "type" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableType(v *string) *RedeemCodeUpdateOne {
if v != nil {
_u.SetType(*v)
}
return _u
}
// SetValue sets the "value" field.
func (_u *RedeemCodeUpdateOne) SetValue(v float64) *RedeemCodeUpdateOne {
_u.mutation.ResetValue()
_u.mutation.SetValue(v)
return _u
}
// SetNillableValue sets the "value" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableValue(v *float64) *RedeemCodeUpdateOne {
if v != nil {
_u.SetValue(*v)
}
return _u
}
// AddValue adds value to the "value" field.
func (_u *RedeemCodeUpdateOne) AddValue(v float64) *RedeemCodeUpdateOne {
_u.mutation.AddValue(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *RedeemCodeUpdateOne) SetStatus(v string) *RedeemCodeUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableStatus(v *string) *RedeemCodeUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetUsedBy sets the "used_by" field.
func (_u *RedeemCodeUpdateOne) SetUsedBy(v int64) *RedeemCodeUpdateOne {
_u.mutation.SetUsedBy(v)
return _u
}
// SetNillableUsedBy sets the "used_by" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableUsedBy(v *int64) *RedeemCodeUpdateOne {
if v != nil {
_u.SetUsedBy(*v)
}
return _u
}
// ClearUsedBy clears the value of the "used_by" field.
func (_u *RedeemCodeUpdateOne) ClearUsedBy() *RedeemCodeUpdateOne {
_u.mutation.ClearUsedBy()
return _u
}
// SetUsedAt sets the "used_at" field.
func (_u *RedeemCodeUpdateOne) SetUsedAt(v time.Time) *RedeemCodeUpdateOne {
_u.mutation.SetUsedAt(v)
return _u
}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableUsedAt(v *time.Time) *RedeemCodeUpdateOne {
if v != nil {
_u.SetUsedAt(*v)
}
return _u
}
// ClearUsedAt clears the value of the "used_at" field.
func (_u *RedeemCodeUpdateOne) ClearUsedAt() *RedeemCodeUpdateOne {
_u.mutation.ClearUsedAt()
return _u
}
// SetNotes sets the "notes" field.
func (_u *RedeemCodeUpdateOne) SetNotes(v string) *RedeemCodeUpdateOne {
_u.mutation.SetNotes(v)
return _u
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableNotes(v *string) *RedeemCodeUpdateOne {
if v != nil {
_u.SetNotes(*v)
}
return _u
}
// ClearNotes clears the value of the "notes" field.
func (_u *RedeemCodeUpdateOne) ClearNotes() *RedeemCodeUpdateOne {
_u.mutation.ClearNotes()
return _u
}
// SetGroupID sets the "group_id" field.
func (_u *RedeemCodeUpdateOne) SetGroupID(v int64) *RedeemCodeUpdateOne {
_u.mutation.SetGroupID(v)
return _u
}
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableGroupID(v *int64) *RedeemCodeUpdateOne {
if v != nil {
_u.SetGroupID(*v)
}
return _u
}
// ClearGroupID clears the value of the "group_id" field.
func (_u *RedeemCodeUpdateOne) ClearGroupID() *RedeemCodeUpdateOne {
_u.mutation.ClearGroupID()
return _u
}
// SetValidityDays sets the "validity_days" field.
func (_u *RedeemCodeUpdateOne) SetValidityDays(v int) *RedeemCodeUpdateOne {
_u.mutation.ResetValidityDays()
_u.mutation.SetValidityDays(v)
return _u
}
// SetNillableValidityDays sets the "validity_days" field if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableValidityDays(v *int) *RedeemCodeUpdateOne {
if v != nil {
_u.SetValidityDays(*v)
}
return _u
}
// AddValidityDays adds value to the "validity_days" field.
func (_u *RedeemCodeUpdateOne) AddValidityDays(v int) *RedeemCodeUpdateOne {
_u.mutation.AddValidityDays(v)
return _u
}
// SetUserID sets the "user" edge to the User entity by ID.
func (_u *RedeemCodeUpdateOne) SetUserID(id int64) *RedeemCodeUpdateOne {
_u.mutation.SetUserID(id)
return _u
}
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (_u *RedeemCodeUpdateOne) SetNillableUserID(id *int64) *RedeemCodeUpdateOne {
if id != nil {
_u = _u.SetUserID(*id)
}
return _u
}
// SetUser sets the "user" edge to the User entity.
func (_u *RedeemCodeUpdateOne) SetUser(v *User) *RedeemCodeUpdateOne {
return _u.SetUserID(v.ID)
}
// SetGroup sets the "group" edge to the Group entity.
func (_u *RedeemCodeUpdateOne) SetGroup(v *Group) *RedeemCodeUpdateOne {
return _u.SetGroupID(v.ID)
}
// Mutation returns the RedeemCodeMutation object of the builder.
func (_u *RedeemCodeUpdateOne) Mutation() *RedeemCodeMutation {
return _u.mutation
}
// ClearUser clears the "user" edge to the User entity.
func (_u *RedeemCodeUpdateOne) ClearUser() *RedeemCodeUpdateOne {
_u.mutation.ClearUser()
return _u
}
// ClearGroup clears the "group" edge to the Group entity.
func (_u *RedeemCodeUpdateOne) ClearGroup() *RedeemCodeUpdateOne {
_u.mutation.ClearGroup()
return _u
}
// Where appends a list predicates to the RedeemCodeUpdate builder.
func (_u *RedeemCodeUpdateOne) Where(ps ...predicate.RedeemCode) *RedeemCodeUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *RedeemCodeUpdateOne) Select(field string, fields ...string) *RedeemCodeUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated RedeemCode entity.
func (_u *RedeemCodeUpdateOne) Save(ctx context.Context) (*RedeemCode, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *RedeemCodeUpdateOne) SaveX(ctx context.Context) *RedeemCode {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *RedeemCodeUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *RedeemCodeUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *RedeemCodeUpdateOne) check() error {
if v, ok := _u.mutation.Code(); ok {
if err := redeemcode.CodeValidator(v); err != nil {
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.code": %w`, err)}
}
}
if v, ok := _u.mutation.GetType(); ok {
if err := redeemcode.TypeValidator(v); err != nil {
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.type": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := redeemcode.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RedeemCode.status": %w`, err)}
}
}
return nil
}
func (_u *RedeemCodeUpdateOne) sqlSave(ctx context.Context) (_node *RedeemCode, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(redeemcode.Table, redeemcode.Columns, sqlgraph.NewFieldSpec(redeemcode.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "RedeemCode.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, redeemcode.FieldID)
for _, f := range fields {
if !redeemcode.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != redeemcode.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Code(); ok {
_spec.SetField(redeemcode.FieldCode, field.TypeString, value)
}
if value, ok := _u.mutation.GetType(); ok {
_spec.SetField(redeemcode.FieldType, field.TypeString, value)
}
if value, ok := _u.mutation.Value(); ok {
_spec.SetField(redeemcode.FieldValue, field.TypeFloat64, value)
}
if value, ok := _u.mutation.AddedValue(); ok {
_spec.AddField(redeemcode.FieldValue, field.TypeFloat64, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(redeemcode.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.UsedAt(); ok {
_spec.SetField(redeemcode.FieldUsedAt, field.TypeTime, value)
}
if _u.mutation.UsedAtCleared() {
_spec.ClearField(redeemcode.FieldUsedAt, field.TypeTime)
}
if value, ok := _u.mutation.Notes(); ok {
_spec.SetField(redeemcode.FieldNotes, field.TypeString, value)
}
if _u.mutation.NotesCleared() {
_spec.ClearField(redeemcode.FieldNotes, field.TypeString)
}
if value, ok := _u.mutation.ValidityDays(); ok {
_spec.SetField(redeemcode.FieldValidityDays, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedValidityDays(); ok {
_spec.AddField(redeemcode.FieldValidityDays, field.TypeInt, value)
}
if _u.mutation.UserCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.UserTable,
Columns: []string{redeemcode.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.UserTable,
Columns: []string{redeemcode.UserColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
if _u.mutation.GroupCleared() {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.GroupTable,
Columns: []string{redeemcode.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
}
if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{
Rel: sqlgraph.M2O,
Inverse: true,
Table: redeemcode.GroupTable,
Columns: []string{redeemcode.GroupColumn},
Bidi: false,
Target: &sqlgraph.EdgeTarget{
IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt64),
},
}
for _, k := range nodes {
edge.Target.Nodes = append(edge.Target.Nodes, k)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
_node = &RedeemCode{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{redeemcode.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment