Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
1a641392
Commit
1a641392
authored
Jan 10, 2026
by
cyhhao
Browse files
Merge up/main
parents
36b817d0
24d19a5f
Changes
174
Show whitespace changes
Inline
Side-by-side
backend/ent/mutation.go
View file @
1a641392
...
...
@@ -16,6 +16,8 @@ import (
"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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
...
@@ -40,6 +42,8 @@ const (
TypeAccount = "Account"
TypeAccountGroup = "AccountGroup"
TypeGroup = "Group"
TypePromoCode = "PromoCode"
TypePromoCodeUsage = "PromoCodeUsage"
TypeProxy = "Proxy"
TypeRedeemCode = "RedeemCode"
TypeSetting = "Setting"
...
...
@@ -63,6 +67,10 @@ type APIKeyMutation struct {
key *string
name *string
status *string
ip_whitelist *[]string
appendip_whitelist []string
ip_blacklist *[]string
appendip_blacklist []string
clearedFields map[string]struct{}
user *int64
cleareduser bool
...
...
@@ -488,6 +496,136 @@ func (m *APIKeyMutation) ResetStatus() {
m.status = nil
}
// SetIPWhitelist sets the "ip_whitelist" field.
func (m *APIKeyMutation) SetIPWhitelist(s []string) {
m.ip_whitelist = &s
m.appendip_whitelist = nil
}
// IPWhitelist returns the value of the "ip_whitelist" field in the mutation.
func (m *APIKeyMutation) IPWhitelist() (r []string, exists bool) {
v := m.ip_whitelist
if v == nil {
return
}
return *v, true
}
// OldIPWhitelist returns the old "ip_whitelist" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldIPWhitelist(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIPWhitelist is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIPWhitelist requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIPWhitelist: %w", err)
}
return oldValue.IPWhitelist, nil
}
// AppendIPWhitelist adds s to the "ip_whitelist" field.
func (m *APIKeyMutation) AppendIPWhitelist(s []string) {
m.appendip_whitelist = append(m.appendip_whitelist, s...)
}
// AppendedIPWhitelist returns the list of values that were appended to the "ip_whitelist" field in this mutation.
func (m *APIKeyMutation) AppendedIPWhitelist() ([]string, bool) {
if len(m.appendip_whitelist) == 0 {
return nil, false
}
return m.appendip_whitelist, true
}
// ClearIPWhitelist clears the value of the "ip_whitelist" field.
func (m *APIKeyMutation) ClearIPWhitelist() {
m.ip_whitelist = nil
m.appendip_whitelist = nil
m.clearedFields[apikey.FieldIPWhitelist] = struct{}{}
}
// IPWhitelistCleared returns if the "ip_whitelist" field was cleared in this mutation.
func (m *APIKeyMutation) IPWhitelistCleared() bool {
_, ok := m.clearedFields[apikey.FieldIPWhitelist]
return ok
}
// ResetIPWhitelist resets all changes to the "ip_whitelist" field.
func (m *APIKeyMutation) ResetIPWhitelist() {
m.ip_whitelist = nil
m.appendip_whitelist = nil
delete(m.clearedFields, apikey.FieldIPWhitelist)
}
// SetIPBlacklist sets the "ip_blacklist" field.
func (m *APIKeyMutation) SetIPBlacklist(s []string) {
m.ip_blacklist = &s
m.appendip_blacklist = nil
}
// IPBlacklist returns the value of the "ip_blacklist" field in the mutation.
func (m *APIKeyMutation) IPBlacklist() (r []string, exists bool) {
v := m.ip_blacklist
if v == nil {
return
}
return *v, true
}
// OldIPBlacklist returns the old "ip_blacklist" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldIPBlacklist(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIPBlacklist is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIPBlacklist requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIPBlacklist: %w", err)
}
return oldValue.IPBlacklist, nil
}
// AppendIPBlacklist adds s to the "ip_blacklist" field.
func (m *APIKeyMutation) AppendIPBlacklist(s []string) {
m.appendip_blacklist = append(m.appendip_blacklist, s...)
}
// AppendedIPBlacklist returns the list of values that were appended to the "ip_blacklist" field in this mutation.
func (m *APIKeyMutation) AppendedIPBlacklist() ([]string, bool) {
if len(m.appendip_blacklist) == 0 {
return nil, false
}
return m.appendip_blacklist, true
}
// ClearIPBlacklist clears the value of the "ip_blacklist" field.
func (m *APIKeyMutation) ClearIPBlacklist() {
m.ip_blacklist = nil
m.appendip_blacklist = nil
m.clearedFields[apikey.FieldIPBlacklist] = struct{}{}
}
// IPBlacklistCleared returns if the "ip_blacklist" field was cleared in this mutation.
func (m *APIKeyMutation) IPBlacklistCleared() bool {
_, ok := m.clearedFields[apikey.FieldIPBlacklist]
return ok
}
// ResetIPBlacklist resets all changes to the "ip_blacklist" field.
func (m *APIKeyMutation) ResetIPBlacklist() {
m.ip_blacklist = nil
m.appendip_blacklist = nil
delete(m.clearedFields, apikey.FieldIPBlacklist)
}
// ClearUser clears the "user" edge to the User entity.
func (m *APIKeyMutation) ClearUser() {
m.cleareduser = true
...
...
@@ -630,7 +768,7 @@ func (m *APIKeyMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *APIKeyMutation) Fields() []string {
fields := make([]string, 0,
8
)
fields := make([]string, 0,
10
)
if m.created_at != nil {
fields = append(fields, apikey.FieldCreatedAt)
}
...
...
@@ -655,6 +793,12 @@ func (m *APIKeyMutation) Fields() []string {
if m.status != nil {
fields = append(fields, apikey.FieldStatus)
}
if m.ip_whitelist != nil {
fields = append(fields, apikey.FieldIPWhitelist)
}
if m.ip_blacklist != nil {
fields = append(fields, apikey.FieldIPBlacklist)
}
return fields
}
...
...
@@ -679,6 +823,10 @@ func (m *APIKeyMutation) Field(name string) (ent.Value, bool) {
return m.GroupID()
case apikey.FieldStatus:
return m.Status()
case apikey.FieldIPWhitelist:
return m.IPWhitelist()
case apikey.FieldIPBlacklist:
return m.IPBlacklist()
}
return nil, false
}
...
...
@@ -704,6 +852,10 @@ func (m *APIKeyMutation) OldField(ctx context.Context, name string) (ent.Value,
return m.OldGroupID(ctx)
case apikey.FieldStatus:
return m.OldStatus(ctx)
case apikey.FieldIPWhitelist:
return m.OldIPWhitelist(ctx)
case apikey.FieldIPBlacklist:
return m.OldIPBlacklist(ctx)
}
return nil, fmt.Errorf("unknown APIKey field %s", name)
}
...
...
@@ -769,6 +921,20 @@ func (m *APIKeyMutation) SetField(name string, value ent.Value) error {
}
m.SetStatus(v)
return nil
case apikey.FieldIPWhitelist:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIPWhitelist(v)
return nil
case apikey.FieldIPBlacklist:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIPBlacklist(v)
return nil
}
return fmt.Errorf("unknown APIKey field %s", name)
}
...
...
@@ -808,6 +974,12 @@ func (m *APIKeyMutation) ClearedFields() []string {
if m.FieldCleared(apikey.FieldGroupID) {
fields = append(fields, apikey.FieldGroupID)
}
if m.FieldCleared(apikey.FieldIPWhitelist) {
fields = append(fields, apikey.FieldIPWhitelist)
}
if m.FieldCleared(apikey.FieldIPBlacklist) {
fields = append(fields, apikey.FieldIPBlacklist)
}
return fields
}
...
...
@@ -828,6 +1000,12 @@ func (m *APIKeyMutation) ClearField(name string) error {
case apikey.FieldGroupID:
m.ClearGroupID()
return nil
case apikey.FieldIPWhitelist:
m.ClearIPWhitelist()
return nil
case apikey.FieldIPBlacklist:
m.ClearIPBlacklist()
return nil
}
return fmt.Errorf("unknown APIKey nullable field %s", name)
}
...
...
@@ -860,6 +1038,12 @@ func (m *APIKeyMutation) ResetField(name string) error {
case apikey.FieldStatus:
m.ResetStatus()
return nil
case apikey.FieldIPWhitelist:
m.ResetIPWhitelist()
return nil
case apikey.FieldIPBlacklist:
m.ResetIPBlacklist()
return nil
}
return fmt.Errorf("unknown APIKey field %s", name)
}
...
...
@@ -5619,231 +5803,1849 @@ func (m *GroupMutation) ResetField(name string) error {
case group.FieldImagePrice2k:
m.ResetImagePrice2k()
return nil
case group.FieldImagePrice4k:
m.ResetImagePrice4k()
case group.FieldImagePrice4k:
m.ResetImagePrice4k()
return nil
case group.FieldClaudeCodeOnly:
m.ResetClaudeCodeOnly()
return nil
case group.FieldFallbackGroupID:
m.ResetFallbackGroupID()
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GroupMutation) AddedEdges() []string {
edges := make([]string, 0, 6)
if m.api_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
if m.redeem_codes != nil {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.subscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.usage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.accounts != nil {
edges = append(edges, group.EdgeAccounts)
}
if m.allowed_users != nil {
edges = append(edges, group.EdgeAllowedUsers)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *GroupMutation) AddedIDs(name string) []ent.Value {
switch name {
case group.EdgeAPIKeys:
ids := make([]ent.Value, 0, len(m.api_keys))
for id := range m.api_keys {
ids = append(ids, id)
}
return ids
case group.EdgeRedeemCodes:
ids := make([]ent.Value, 0, len(m.redeem_codes))
for id := range m.redeem_codes {
ids = append(ids, id)
}
return ids
case group.EdgeSubscriptions:
ids := make([]ent.Value, 0, len(m.subscriptions))
for id := range m.subscriptions {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.accounts))
for id := range m.accounts {
ids = append(ids, id)
}
return ids
case group.EdgeAllowedUsers:
ids := make([]ent.Value, 0, len(m.allowed_users))
for id := range m.allowed_users {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GroupMutation) RemovedEdges() []string {
edges := make([]string, 0, 6)
if m.removedapi_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
if m.removedredeem_codes != nil {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.removedsubscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.removedusage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.removedaccounts != nil {
edges = append(edges, group.EdgeAccounts)
}
if m.removedallowed_users != nil {
edges = append(edges, group.EdgeAllowedUsers)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
switch name {
case group.EdgeAPIKeys:
ids := make([]ent.Value, 0, len(m.removedapi_keys))
for id := range m.removedapi_keys {
ids = append(ids, id)
}
return ids
case group.EdgeRedeemCodes:
ids := make([]ent.Value, 0, len(m.removedredeem_codes))
for id := range m.removedredeem_codes {
ids = append(ids, id)
}
return ids
case group.EdgeSubscriptions:
ids := make([]ent.Value, 0, len(m.removedsubscriptions))
for id := range m.removedsubscriptions {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
ids = append(ids, id)
}
return ids
case group.EdgeAllowedUsers:
ids := make([]ent.Value, 0, len(m.removedallowed_users))
for id := range m.removedallowed_users {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
edges := make([]string, 0, 6)
if m.clearedapi_keys {
edges = append(edges, group.EdgeAPIKeys)
}
if m.clearedredeem_codes {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.clearedsubscriptions {
edges = append(edges, group.EdgeSubscriptions)
}
if m.clearedusage_logs {
edges = append(edges, group.EdgeUsageLogs)
}
if m.clearedaccounts {
edges = append(edges, group.EdgeAccounts)
}
if m.clearedallowed_users {
edges = append(edges, group.EdgeAllowedUsers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GroupMutation) EdgeCleared(name string) bool {
switch name {
case group.EdgeAPIKeys:
return m.clearedapi_keys
case group.EdgeRedeemCodes:
return m.clearedredeem_codes
case group.EdgeSubscriptions:
return m.clearedsubscriptions
case group.EdgeUsageLogs:
return m.clearedusage_logs
case group.EdgeAccounts:
return m.clearedaccounts
case group.EdgeAllowedUsers:
return m.clearedallowed_users
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *GroupMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown Group unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *GroupMutation) ResetEdge(name string) error {
switch name {
case group.EdgeAPIKeys:
m.ResetAPIKeys()
return nil
case group.EdgeRedeemCodes:
m.ResetRedeemCodes()
return nil
case group.EdgeSubscriptions:
m.ResetSubscriptions()
return nil
case group.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
case group.EdgeAccounts:
m.ResetAccounts()
return nil
case group.EdgeAllowedUsers:
m.ResetAllowedUsers()
return nil
}
return fmt.Errorf("unknown Group edge %s", name)
}
// PromoCodeMutation represents an operation that mutates the PromoCode nodes in the graph.
type PromoCodeMutation struct {
config
op Op
typ string
id *int64
code *string
bonus_amount *float64
addbonus_amount *float64
max_uses *int
addmax_uses *int
used_count *int
addused_count *int
status *string
expires_at *time.Time
notes *string
created_at *time.Time
updated_at *time.Time
clearedFields map[string]struct{}
usage_records map[int64]struct{}
removedusage_records map[int64]struct{}
clearedusage_records bool
done bool
oldValue func(context.Context) (*PromoCode, error)
predicates []predicate.PromoCode
}
var _ ent.Mutation = (*PromoCodeMutation)(nil)
// promocodeOption allows management of the mutation configuration using functional options.
type promocodeOption func(*PromoCodeMutation)
// newPromoCodeMutation creates new mutation for the PromoCode entity.
func newPromoCodeMutation(c config, op Op, opts ...promocodeOption) *PromoCodeMutation {
m := &PromoCodeMutation{
config: c,
op: op,
typ: TypePromoCode,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withPromoCodeID sets the ID field of the mutation.
func withPromoCodeID(id int64) promocodeOption {
return func(m *PromoCodeMutation) {
var (
err error
once sync.Once
value *PromoCode
)
m.oldValue = func(ctx context.Context) (*PromoCode, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().PromoCode.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withPromoCode sets the old PromoCode of the mutation.
func withPromoCode(node *PromoCode) promocodeOption {
return func(m *PromoCodeMutation) {
m.oldValue = func(context.Context) (*PromoCode, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PromoCodeMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PromoCodeMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PromoCodeMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PromoCodeMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().PromoCode.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCode sets the "code" field.
func (m *PromoCodeMutation) SetCode(s string) {
m.code = &s
}
// Code returns the value of the "code" field in the mutation.
func (m *PromoCodeMutation) Code() (r string, exists bool) {
v := m.code
if v == nil {
return
}
return *v, true
}
// OldCode returns the old "code" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldCode(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCode is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCode requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCode: %w", err)
}
return oldValue.Code, nil
}
// ResetCode resets all changes to the "code" field.
func (m *PromoCodeMutation) ResetCode() {
m.code = nil
}
// SetBonusAmount sets the "bonus_amount" field.
func (m *PromoCodeMutation) SetBonusAmount(f float64) {
m.bonus_amount = &f
m.addbonus_amount = nil
}
// BonusAmount returns the value of the "bonus_amount" field in the mutation.
func (m *PromoCodeMutation) BonusAmount() (r float64, exists bool) {
v := m.bonus_amount
if v == nil {
return
}
return *v, true
}
// OldBonusAmount returns the old "bonus_amount" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldBonusAmount(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBonusAmount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBonusAmount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBonusAmount: %w", err)
}
return oldValue.BonusAmount, nil
}
// AddBonusAmount adds f to the "bonus_amount" field.
func (m *PromoCodeMutation) AddBonusAmount(f float64) {
if m.addbonus_amount != nil {
*m.addbonus_amount += f
} else {
m.addbonus_amount = &f
}
}
// AddedBonusAmount returns the value that was added to the "bonus_amount" field in this mutation.
func (m *PromoCodeMutation) AddedBonusAmount() (r float64, exists bool) {
v := m.addbonus_amount
if v == nil {
return
}
return *v, true
}
// ResetBonusAmount resets all changes to the "bonus_amount" field.
func (m *PromoCodeMutation) ResetBonusAmount() {
m.bonus_amount = nil
m.addbonus_amount = nil
}
// SetMaxUses sets the "max_uses" field.
func (m *PromoCodeMutation) SetMaxUses(i int) {
m.max_uses = &i
m.addmax_uses = nil
}
// MaxUses returns the value of the "max_uses" field in the mutation.
func (m *PromoCodeMutation) MaxUses() (r int, exists bool) {
v := m.max_uses
if v == nil {
return
}
return *v, true
}
// OldMaxUses returns the old "max_uses" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldMaxUses(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMaxUses is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMaxUses requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMaxUses: %w", err)
}
return oldValue.MaxUses, nil
}
// AddMaxUses adds i to the "max_uses" field.
func (m *PromoCodeMutation) AddMaxUses(i int) {
if m.addmax_uses != nil {
*m.addmax_uses += i
} else {
m.addmax_uses = &i
}
}
// AddedMaxUses returns the value that was added to the "max_uses" field in this mutation.
func (m *PromoCodeMutation) AddedMaxUses() (r int, exists bool) {
v := m.addmax_uses
if v == nil {
return
}
return *v, true
}
// ResetMaxUses resets all changes to the "max_uses" field.
func (m *PromoCodeMutation) ResetMaxUses() {
m.max_uses = nil
m.addmax_uses = nil
}
// SetUsedCount sets the "used_count" field.
func (m *PromoCodeMutation) SetUsedCount(i int) {
m.used_count = &i
m.addused_count = nil
}
// UsedCount returns the value of the "used_count" field in the mutation.
func (m *PromoCodeMutation) UsedCount() (r int, exists bool) {
v := m.used_count
if v == nil {
return
}
return *v, true
}
// OldUsedCount returns the old "used_count" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldUsedCount(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsedCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsedCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsedCount: %w", err)
}
return oldValue.UsedCount, nil
}
// AddUsedCount adds i to the "used_count" field.
func (m *PromoCodeMutation) AddUsedCount(i int) {
if m.addused_count != nil {
*m.addused_count += i
} else {
m.addused_count = &i
}
}
// AddedUsedCount returns the value that was added to the "used_count" field in this mutation.
func (m *PromoCodeMutation) AddedUsedCount() (r int, exists bool) {
v := m.addused_count
if v == nil {
return
}
return *v, true
}
// ResetUsedCount resets all changes to the "used_count" field.
func (m *PromoCodeMutation) ResetUsedCount() {
m.used_count = nil
m.addused_count = nil
}
// SetStatus sets the "status" field.
func (m *PromoCodeMutation) SetStatus(s string) {
m.status = &s
}
// Status returns the value of the "status" field in the mutation.
func (m *PromoCodeMutation) Status() (r string, exists bool) {
v := m.status
if v == nil {
return
}
return *v, true
}
// OldStatus returns the old "status" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldStatus(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
}
return oldValue.Status, nil
}
// ResetStatus resets all changes to the "status" field.
func (m *PromoCodeMutation) ResetStatus() {
m.status = nil
}
// SetExpiresAt sets the "expires_at" field.
func (m *PromoCodeMutation) SetExpiresAt(t time.Time) {
m.expires_at = &t
}
// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *PromoCodeMutation) ExpiresAt() (r time.Time, exists bool) {
v := m.expires_at
if v == nil {
return
}
return *v, true
}
// OldExpiresAt returns the old "expires_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldExpiresAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldExpiresAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
}
return oldValue.ExpiresAt, nil
}
// ClearExpiresAt clears the value of the "expires_at" field.
func (m *PromoCodeMutation) ClearExpiresAt() {
m.expires_at = nil
m.clearedFields[promocode.FieldExpiresAt] = struct{}{}
}
// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
func (m *PromoCodeMutation) ExpiresAtCleared() bool {
_, ok := m.clearedFields[promocode.FieldExpiresAt]
return ok
}
// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *PromoCodeMutation) ResetExpiresAt() {
m.expires_at = nil
delete(m.clearedFields, promocode.FieldExpiresAt)
}
// SetNotes sets the "notes" field.
func (m *PromoCodeMutation) SetNotes(s string) {
m.notes = &s
}
// Notes returns the value of the "notes" field in the mutation.
func (m *PromoCodeMutation) Notes() (r string, exists bool) {
v := m.notes
if v == nil {
return
}
return *v, true
}
// OldNotes returns the old "notes" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldNotes(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotes is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotes requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotes: %w", err)
}
return oldValue.Notes, nil
}
// ClearNotes clears the value of the "notes" field.
func (m *PromoCodeMutation) ClearNotes() {
m.notes = nil
m.clearedFields[promocode.FieldNotes] = struct{}{}
}
// NotesCleared returns if the "notes" field was cleared in this mutation.
func (m *PromoCodeMutation) NotesCleared() bool {
_, ok := m.clearedFields[promocode.FieldNotes]
return ok
}
// ResetNotes resets all changes to the "notes" field.
func (m *PromoCodeMutation) ResetNotes() {
m.notes = nil
delete(m.clearedFields, promocode.FieldNotes)
}
// SetCreatedAt sets the "created_at" field.
func (m *PromoCodeMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PromoCodeMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *PromoCodeMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *PromoCodeMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PromoCodeMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *PromoCodeMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by ids.
func (m *PromoCodeMutation) AddUsageRecordIDs(ids ...int64) {
if m.usage_records == nil {
m.usage_records = make(map[int64]struct{})
}
for i := range ids {
m.usage_records[ids[i]] = struct{}{}
}
}
// ClearUsageRecords clears the "usage_records" edge to the PromoCodeUsage entity.
func (m *PromoCodeMutation) ClearUsageRecords() {
m.clearedusage_records = true
}
// UsageRecordsCleared reports if the "usage_records" edge to the PromoCodeUsage entity was cleared.
func (m *PromoCodeMutation) UsageRecordsCleared() bool {
return m.clearedusage_records
}
// RemoveUsageRecordIDs removes the "usage_records" edge to the PromoCodeUsage entity by IDs.
func (m *PromoCodeMutation) RemoveUsageRecordIDs(ids ...int64) {
if m.removedusage_records == nil {
m.removedusage_records = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_records, ids[i])
m.removedusage_records[ids[i]] = struct{}{}
}
}
// RemovedUsageRecords returns the removed IDs of the "usage_records" edge to the PromoCodeUsage entity.
func (m *PromoCodeMutation) RemovedUsageRecordsIDs() (ids []int64) {
for id := range m.removedusage_records {
ids = append(ids, id)
}
return
}
// UsageRecordsIDs returns the "usage_records" edge IDs in the mutation.
func (m *PromoCodeMutation) UsageRecordsIDs() (ids []int64) {
for id := range m.usage_records {
ids = append(ids, id)
}
return
}
// ResetUsageRecords resets all changes to the "usage_records" edge.
func (m *PromoCodeMutation) ResetUsageRecords() {
m.usage_records = nil
m.clearedusage_records = false
m.removedusage_records = nil
}
// Where appends a list predicates to the PromoCodeMutation builder.
func (m *PromoCodeMutation) Where(ps ...predicate.PromoCode) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the PromoCodeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PromoCodeMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.PromoCode, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *PromoCodeMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *PromoCodeMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (PromoCode).
func (m *PromoCodeMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PromoCodeMutation) Fields() []string {
fields := make([]string, 0, 9)
if m.code != nil {
fields = append(fields, promocode.FieldCode)
}
if m.bonus_amount != nil {
fields = append(fields, promocode.FieldBonusAmount)
}
if m.max_uses != nil {
fields = append(fields, promocode.FieldMaxUses)
}
if m.used_count != nil {
fields = append(fields, promocode.FieldUsedCount)
}
if m.status != nil {
fields = append(fields, promocode.FieldStatus)
}
if m.expires_at != nil {
fields = append(fields, promocode.FieldExpiresAt)
}
if m.notes != nil {
fields = append(fields, promocode.FieldNotes)
}
if m.created_at != nil {
fields = append(fields, promocode.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, promocode.FieldUpdatedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PromoCodeMutation) Field(name string) (ent.Value, bool) {
switch name {
case promocode.FieldCode:
return m.Code()
case promocode.FieldBonusAmount:
return m.BonusAmount()
case promocode.FieldMaxUses:
return m.MaxUses()
case promocode.FieldUsedCount:
return m.UsedCount()
case promocode.FieldStatus:
return m.Status()
case promocode.FieldExpiresAt:
return m.ExpiresAt()
case promocode.FieldNotes:
return m.Notes()
case promocode.FieldCreatedAt:
return m.CreatedAt()
case promocode.FieldUpdatedAt:
return m.UpdatedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PromoCodeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case promocode.FieldCode:
return m.OldCode(ctx)
case promocode.FieldBonusAmount:
return m.OldBonusAmount(ctx)
case promocode.FieldMaxUses:
return m.OldMaxUses(ctx)
case promocode.FieldUsedCount:
return m.OldUsedCount(ctx)
case promocode.FieldStatus:
return m.OldStatus(ctx)
case promocode.FieldExpiresAt:
return m.OldExpiresAt(ctx)
case promocode.FieldNotes:
return m.OldNotes(ctx)
case promocode.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case promocode.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
}
return nil, fmt.Errorf("unknown PromoCode field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeMutation) SetField(name string, value ent.Value) error {
switch name {
case promocode.FieldCode:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCode(v)
return nil
case promocode.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBonusAmount(v)
return nil
case promocode.FieldMaxUses:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMaxUses(v)
return nil
case promocode.FieldUsedCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsedCount(v)
return nil
case promocode.FieldStatus:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStatus(v)
return nil
case promocode.FieldExpiresAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetExpiresAt(v)
return nil
case promocode.FieldNotes:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNotes(v)
return nil
case promocode.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case promocode.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
}
return fmt.Errorf("unknown PromoCode field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PromoCodeMutation) AddedFields() []string {
var fields []string
if m.addbonus_amount != nil {
fields = append(fields, promocode.FieldBonusAmount)
}
if m.addmax_uses != nil {
fields = append(fields, promocode.FieldMaxUses)
}
if m.addused_count != nil {
fields = append(fields, promocode.FieldUsedCount)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PromoCodeMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case promocode.FieldBonusAmount:
return m.AddedBonusAmount()
case promocode.FieldMaxUses:
return m.AddedMaxUses()
case promocode.FieldUsedCount:
return m.AddedUsedCount()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeMutation) AddField(name string, value ent.Value) error {
switch name {
case promocode.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddBonusAmount(v)
return nil
case promocode.FieldMaxUses:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMaxUses(v)
return nil
case promocode.FieldUsedCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUsedCount(v)
return nil
}
return fmt.Errorf("unknown PromoCode numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PromoCodeMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(promocode.FieldExpiresAt) {
fields = append(fields, promocode.FieldExpiresAt)
}
if m.FieldCleared(promocode.FieldNotes) {
fields = append(fields, promocode.FieldNotes)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PromoCodeMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PromoCodeMutation) ClearField(name string) error {
switch name {
case promocode.FieldExpiresAt:
m.ClearExpiresAt()
return nil
case promocode.FieldNotes:
m.ClearNotes()
return nil
}
return fmt.Errorf("unknown PromoCode nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PromoCodeMutation) ResetField(name string) error {
switch name {
case promocode.FieldCode:
m.ResetCode()
return nil
case promocode.FieldBonusAmount:
m.ResetBonusAmount()
return nil
case promocode.FieldMaxUses:
m.ResetMaxUses()
return nil
case promocode.FieldUsedCount:
m.ResetUsedCount()
return nil
case promocode.FieldStatus:
m.ResetStatus()
return nil
case promocode.FieldExpiresAt:
m.ResetExpiresAt()
return nil
case promocode.FieldNotes:
m.ResetNotes()
return nil
case promocode.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case promocode.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
}
return fmt.Errorf("unknown PromoCode field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PromoCodeMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.usage_records != nil {
edges = append(edges, promocode.EdgeUsageRecords)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PromoCodeMutation) AddedIDs(name string) []ent.Value {
switch name {
case promocode.EdgeUsageRecords:
ids := make([]ent.Value, 0, len(m.usage_records))
for id := range m.usage_records {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PromoCodeMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
if m.removedusage_records != nil {
edges = append(edges, promocode.EdgeUsageRecords)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PromoCodeMutation) RemovedIDs(name string) []ent.Value {
switch name {
case promocode.EdgeUsageRecords:
ids := make([]ent.Value, 0, len(m.removedusage_records))
for id := range m.removedusage_records {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PromoCodeMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.clearedusage_records {
edges = append(edges, promocode.EdgeUsageRecords)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PromoCodeMutation) EdgeCleared(name string) bool {
switch name {
case promocode.EdgeUsageRecords:
return m.clearedusage_records
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *PromoCodeMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown PromoCode unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *PromoCodeMutation) ResetEdge(name string) error {
switch name {
case promocode.EdgeUsageRecords:
m.ResetUsageRecords()
return nil
}
return fmt.Errorf("unknown PromoCode edge %s", name)
}
// PromoCodeUsageMutation represents an operation that mutates the PromoCodeUsage nodes in the graph.
type PromoCodeUsageMutation struct {
config
op Op
typ string
id *int64
bonus_amount *float64
addbonus_amount *float64
used_at *time.Time
clearedFields map[string]struct{}
promo_code *int64
clearedpromo_code bool
user *int64
cleareduser bool
done bool
oldValue func(context.Context) (*PromoCodeUsage, error)
predicates []predicate.PromoCodeUsage
}
var _ ent.Mutation = (*PromoCodeUsageMutation)(nil)
// promocodeusageOption allows management of the mutation configuration using functional options.
type promocodeusageOption func(*PromoCodeUsageMutation)
// newPromoCodeUsageMutation creates new mutation for the PromoCodeUsage entity.
func newPromoCodeUsageMutation(c config, op Op, opts ...promocodeusageOption) *PromoCodeUsageMutation {
m := &PromoCodeUsageMutation{
config: c,
op: op,
typ: TypePromoCodeUsage,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withPromoCodeUsageID sets the ID field of the mutation.
func withPromoCodeUsageID(id int64) promocodeusageOption {
return func(m *PromoCodeUsageMutation) {
var (
err error
once sync.Once
value *PromoCodeUsage
)
m.oldValue = func(ctx context.Context) (*PromoCodeUsage, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().PromoCodeUsage.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withPromoCodeUsage sets the old PromoCodeUsage of the mutation.
func withPromoCodeUsage(node *PromoCodeUsage) promocodeusageOption {
return func(m *PromoCodeUsageMutation) {
m.oldValue = func(context.Context) (*PromoCodeUsage, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PromoCodeUsageMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PromoCodeUsageMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PromoCodeUsageMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PromoCodeUsageMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().PromoCodeUsage.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetPromoCodeID sets the "promo_code_id" field.
func (m *PromoCodeUsageMutation) SetPromoCodeID(i int64) {
m.promo_code = &i
}
// PromoCodeID returns the value of the "promo_code_id" field in the mutation.
func (m *PromoCodeUsageMutation) PromoCodeID() (r int64, exists bool) {
v := m.promo_code
if v == nil {
return
}
return *v, true
}
// OldPromoCodeID returns the old "promo_code_id" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldPromoCodeID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPromoCodeID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPromoCodeID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPromoCodeID: %w", err)
}
return oldValue.PromoCodeID, nil
}
// ResetPromoCodeID resets all changes to the "promo_code_id" field.
func (m *PromoCodeUsageMutation) ResetPromoCodeID() {
m.promo_code = nil
}
// SetUserID sets the "user_id" field.
func (m *PromoCodeUsageMutation) SetUserID(i int64) {
m.user = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *PromoCodeUsageMutation) UserID() (r int64, exists bool) {
v := m.user
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// ResetUserID resets all changes to the "user_id" field.
func (m *PromoCodeUsageMutation) ResetUserID() {
m.user = nil
}
// SetBonusAmount sets the "bonus_amount" field.
func (m *PromoCodeUsageMutation) SetBonusAmount(f float64) {
m.bonus_amount = &f
m.addbonus_amount = nil
}
// BonusAmount returns the value of the "bonus_amount" field in the mutation.
func (m *PromoCodeUsageMutation) BonusAmount() (r float64, exists bool) {
v := m.bonus_amount
if v == nil {
return
}
return *v, true
}
// OldBonusAmount returns the old "bonus_amount" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldBonusAmount(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBonusAmount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBonusAmount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBonusAmount: %w", err)
}
return oldValue.BonusAmount, nil
}
// AddBonusAmount adds f to the "bonus_amount" field.
func (m *PromoCodeUsageMutation) AddBonusAmount(f float64) {
if m.addbonus_amount != nil {
*m.addbonus_amount += f
} else {
m.addbonus_amount = &f
}
}
// AddedBonusAmount returns the value that was added to the "bonus_amount" field in this mutation.
func (m *PromoCodeUsageMutation) AddedBonusAmount() (r float64, exists bool) {
v := m.addbonus_amount
if v == nil {
return
}
return *v, true
}
// ResetBonusAmount resets all changes to the "bonus_amount" field.
func (m *PromoCodeUsageMutation) ResetBonusAmount() {
m.bonus_amount = nil
m.addbonus_amount = nil
}
// SetUsedAt sets the "used_at" field.
func (m *PromoCodeUsageMutation) SetUsedAt(t time.Time) {
m.used_at = &t
}
// UsedAt returns the value of the "used_at" field in the mutation.
func (m *PromoCodeUsageMutation) UsedAt() (r time.Time, exists bool) {
v := m.used_at
if v == nil {
return
}
return *v, true
}
// OldUsedAt returns the old "used_at" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldUsedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsedAt: %w", err)
}
return oldValue.UsedAt, nil
}
// ResetUsedAt resets all changes to the "used_at" field.
func (m *PromoCodeUsageMutation) ResetUsedAt() {
m.used_at = nil
}
// ClearPromoCode clears the "promo_code" edge to the PromoCode entity.
func (m *PromoCodeUsageMutation) ClearPromoCode() {
m.clearedpromo_code = true
m.clearedFields[promocodeusage.FieldPromoCodeID] = struct{}{}
}
// PromoCodeCleared reports if the "promo_code" edge to the PromoCode entity was cleared.
func (m *PromoCodeUsageMutation) PromoCodeCleared() bool {
return m.clearedpromo_code
}
// PromoCodeIDs returns the "promo_code" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// PromoCodeID instead. It exists only for internal usage by the builders.
func (m *PromoCodeUsageMutation) PromoCodeIDs() (ids []int64) {
if id := m.promo_code; id != nil {
ids = append(ids, *id)
}
return
}
// ResetPromoCode resets all changes to the "promo_code" edge.
func (m *PromoCodeUsageMutation) ResetPromoCode() {
m.promo_code = nil
m.clearedpromo_code = false
}
// ClearUser clears the "user" edge to the User entity.
func (m *PromoCodeUsageMutation) ClearUser() {
m.cleareduser = true
m.clearedFields[promocodeusage.FieldUserID] = struct{}{}
}
// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *PromoCodeUsageMutation) UserCleared() bool {
return m.cleareduser
}
// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *PromoCodeUsageMutation) UserIDs() (ids []int64) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *PromoCodeUsageMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// Where appends a list predicates to the PromoCodeUsageMutation builder.
func (m *PromoCodeUsageMutation) Where(ps ...predicate.PromoCodeUsage) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the PromoCodeUsageMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PromoCodeUsageMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.PromoCodeUsage, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *PromoCodeUsageMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *PromoCodeUsageMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (PromoCodeUsage).
func (m *PromoCodeUsageMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PromoCodeUsageMutation) Fields() []string {
fields := make([]string, 0, 4)
if m.promo_code != nil {
fields = append(fields, promocodeusage.FieldPromoCodeID)
}
if m.user != nil {
fields = append(fields, promocodeusage.FieldUserID)
}
if m.bonus_amount != nil {
fields = append(fields, promocodeusage.FieldBonusAmount)
}
if m.used_at != nil {
fields = append(fields, promocodeusage.FieldUsedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PromoCodeUsageMutation) Field(name string) (ent.Value, bool) {
switch name {
case promocodeusage.FieldPromoCodeID:
return m.PromoCodeID()
case promocodeusage.FieldUserID:
return m.UserID()
case promocodeusage.FieldBonusAmount:
return m.BonusAmount()
case promocodeusage.FieldUsedAt:
return m.UsedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PromoCodeUsageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case promocodeusage.FieldPromoCodeID:
return m.OldPromoCodeID(ctx)
case promocodeusage.FieldUserID:
return m.OldUserID(ctx)
case promocodeusage.FieldBonusAmount:
return m.OldBonusAmount(ctx)
case promocodeusage.FieldUsedAt:
return m.OldUsedAt(ctx)
}
return nil, fmt.Errorf("unknown PromoCodeUsage field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeUsageMutation) SetField(name string, value ent.Value) error {
switch name {
case promocodeusage.FieldPromoCodeID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPromoCodeID(v)
return nil
case promocodeusage.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case promocodeusage.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBonusAmount(v)
return nil
case promocodeusage.FieldUsedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsedAt(v)
return nil
}
return fmt.Errorf("unknown PromoCodeUsage field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PromoCodeUsageMutation) AddedFields() []string {
var fields []string
if m.addbonus_amount != nil {
fields = append(fields, promocodeusage.FieldBonusAmount)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PromoCodeUsageMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case promocodeusage.FieldBonusAmount:
return m.AddedBonusAmount()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeUsageMutation) AddField(name string, value ent.Value) error {
switch name {
case promocodeusage.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddBonusAmount(v)
return nil
}
return fmt.Errorf("unknown PromoCodeUsage numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PromoCodeUsageMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PromoCodeUsageMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PromoCodeUsageMutation) ClearField(name string) error {
return fmt.Errorf("unknown PromoCodeUsage nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PromoCodeUsageMutation) ResetField(name string) error {
switch name {
case promocodeusage.FieldPromoCodeID:
m.ResetPromoCodeID()
return nil
case promocodeusage.FieldUserID:
m.ResetUserID()
return nil
case
g
ro
up.FieldClaudeCodeOnly
:
m.Reset
ClaudeCodeOnly
()
case
p
ro
mocodeusage.FieldBonusAmount
:
m.Reset
BonusAmount
()
return nil
case
g
ro
up.FieldFallbackGroupID
:
m.Reset
FallbackGroupID
()
case
p
ro
mocodeusage.FieldUsedAt
:
m.Reset
UsedAt
()
return nil
}
return fmt.Errorf("unknown
G
ro
up
field %s", name)
return fmt.Errorf("unknown
P
ro
moCodeUsage
field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GroupMutation) AddedEdges() []string {
edges := make([]string, 0, 6)
if m.api_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
if m.redeem_codes != nil {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.subscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.usage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.accounts != nil {
edges = append(edges, group.EdgeAccounts)
func (m *PromoCodeUsageMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.promo_code != nil {
edges = append(edges, promocodeusage.EdgePromoCode)
}
if m.
allowed_
user
s
!= nil {
edges = append(edges,
g
ro
up.EdgeAllowed
User
s
)
if m.user != nil {
edges = append(edges,
p
ro
mocodeusage.Edge
User)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *
G
ro
up
Mutation) AddedIDs(name string) []ent.Value {
func (m *
P
ro
moCodeUsage
Mutation) AddedIDs(name string) []ent.Value {
switch name {
case group.EdgeAPIKeys:
ids := make([]ent.Value, 0, len(m.api_keys))
for id := range m.api_keys {
ids = append(ids, id)
}
return ids
case group.EdgeRedeemCodes:
ids := make([]ent.Value, 0, len(m.redeem_codes))
for id := range m.redeem_codes {
ids = append(ids, id)
}
return ids
case group.EdgeSubscriptions:
ids := make([]ent.Value, 0, len(m.subscriptions))
for id := range m.subscriptions {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.usage_logs))
for id := range m.usage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.accounts))
for id := range m.accounts {
ids = append(ids, id)
case promocodeusage.EdgePromoCode:
if id := m.promo_code; id != nil {
return []ent.Value{*id}
}
return ids
case group.EdgeAllowedUsers:
ids := make([]ent.Value, 0, len(m.allowed_users))
for id := range m.allowed_users {
ids = append(ids, id)
case promocodeusage.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GroupMutation) RemovedEdges() []string {
edges := make([]string, 0, 6)
if m.removedapi_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
if m.removedredeem_codes != nil {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.removedsubscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.removedusage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.removedaccounts != nil {
edges = append(edges, group.EdgeAccounts)
}
if m.removedallowed_users != nil {
edges = append(edges, group.EdgeAllowedUsers)
}
func (m *PromoCodeUsageMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
switch name {
case group.EdgeAPIKeys:
ids := make([]ent.Value, 0, len(m.removedapi_keys))
for id := range m.removedapi_keys {
ids = append(ids, id)
}
return ids
case group.EdgeRedeemCodes:
ids := make([]ent.Value, 0, len(m.removedredeem_codes))
for id := range m.removedredeem_codes {
ids = append(ids, id)
}
return ids
case group.EdgeSubscriptions:
ids := make([]ent.Value, 0, len(m.removedsubscriptions))
for id := range m.removedsubscriptions {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
ids = append(ids, id)
}
return ids
case group.EdgeAllowedUsers:
ids := make([]ent.Value, 0, len(m.removedallowed_users))
for id := range m.removedallowed_users {
ids = append(ids, id)
}
return ids
}
func (m *PromoCodeUsageMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
edges := make([]string, 0, 6)
if m.clearedapi_keys {
edges = append(edges, group.EdgeAPIKeys)
}
if m.clearedredeem_codes {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.clearedsubscriptions {
edges = append(edges, group.EdgeSubscriptions)
}
if m.clearedusage_logs {
edges = append(edges, group.EdgeUsageLogs)
}
if m.clearedaccounts {
edges = append(edges, group.EdgeAccounts)
func (m *PromoCodeUsageMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.clearedpromo_code {
edges = append(edges, promocodeusage.EdgePromoCode)
}
if m.cleared
allowed_
user
s
{
edges = append(edges,
g
ro
up.EdgeAllowed
User
s
)
if m.cleareduser {
edges = append(edges,
p
ro
mocodeusage.Edge
User)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *
G
ro
up
Mutation) EdgeCleared(name string) bool {
func (m *
P
ro
moCodeUsage
Mutation) EdgeCleared(name string) bool {
switch name {
case group.EdgeAPIKeys:
return m.clearedapi_keys
case group.EdgeRedeemCodes:
return m.clearedredeem_codes
case group.EdgeSubscriptions:
return m.clearedsubscriptions
case group.EdgeUsageLogs:
return m.clearedusage_logs
case group.EdgeAccounts:
return m.clearedaccounts
case group.EdgeAllowedUsers:
return m.clearedallowed_users
case promocodeusage.EdgePromoCode:
return m.clearedpromo_code
case promocodeusage.EdgeUser:
return m.cleareduser
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *
G
ro
up
Mutation) ClearEdge(name string) error {
func (m *
P
ro
moCodeUsage
Mutation) ClearEdge(name string) error {
switch name {
case promocodeusage.EdgePromoCode:
m.ClearPromoCode()
return nil
case promocodeusage.EdgeUser:
m.ClearUser()
return nil
}
return fmt.Errorf("unknown
G
ro
up
unique edge %s", name)
return fmt.Errorf("unknown
P
ro
moCodeUsage
unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *
G
ro
up
Mutation) ResetEdge(name string) error {
func (m *
P
ro
moCodeUsage
Mutation) ResetEdge(name string) error {
switch name {
case group.EdgeAPIKeys:
m.ResetAPIKeys()
return nil
case group.EdgeRedeemCodes:
m.ResetRedeemCodes()
return nil
case group.EdgeSubscriptions:
m.ResetSubscriptions()
return nil
case group.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
case group.EdgeAccounts:
m.ResetAccounts()
case promocodeusage.EdgePromoCode:
m.ResetPromoCode()
return nil
case
g
ro
up.EdgeAllowed
User
s
:
m.Reset
Allowed
User
s
()
case
p
ro
mocodeusage.Edge
User:
m.ResetUser()
return nil
}
return fmt.Errorf("unknown
G
ro
up
edge %s", name)
return fmt.Errorf("unknown
P
ro
moCodeUsage
edge %s", name)
}
// ProxyMutation represents an operation that mutates the Proxy nodes in the graph.
...
...
@@ -8396,6 +10198,7 @@ type UsageLogMutation struct {
first_token_ms *int
addfirst_token_ms *int
user_agent *string
ip_address *string
image_count *int
addimage_count *int
image_size *string
...
...
@@ -9801,6 +11604,55 @@ func (m *UsageLogMutation) ResetUserAgent() {
delete(m.clearedFields, usagelog.FieldUserAgent)
}
// SetIPAddress sets the "ip_address" field.
func (m *UsageLogMutation) SetIPAddress(s string) {
m.ip_address = &s
}
// IPAddress returns the value of the "ip_address" field in the mutation.
func (m *UsageLogMutation) IPAddress() (r string, exists bool) {
v := m.ip_address
if v == nil {
return
}
return *v, true
}
// OldIPAddress returns the old "ip_address" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldIPAddress(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIPAddress is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIPAddress requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIPAddress: %w", err)
}
return oldValue.IPAddress, nil
}
// ClearIPAddress clears the value of the "ip_address" field.
func (m *UsageLogMutation) ClearIPAddress() {
m.ip_address = nil
m.clearedFields[usagelog.FieldIPAddress] = struct{}{}
}
// IPAddressCleared returns if the "ip_address" field was cleared in this mutation.
func (m *UsageLogMutation) IPAddressCleared() bool {
_, ok := m.clearedFields[usagelog.FieldIPAddress]
return ok
}
// ResetIPAddress resets all changes to the "ip_address" field.
func (m *UsageLogMutation) ResetIPAddress() {
m.ip_address = nil
delete(m.clearedFields, usagelog.FieldIPAddress)
}
// SetImageCount sets the "image_count" field.
func (m *UsageLogMutation) SetImageCount(i int) {
m.image_count = &i
...
...
@@ -10111,7 +11963,7 @@ func (m *UsageLogMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UsageLogMutation) Fields() []string {
fields := make([]string, 0, 2
8
)
fields := make([]string, 0, 2
9
)
if m.user != nil {
fields = append(fields, usagelog.FieldUserID)
}
...
...
@@ -10187,6 +12039,9 @@ func (m *UsageLogMutation) Fields() []string {
if m.user_agent != nil {
fields = append(fields, usagelog.FieldUserAgent)
}
if m.ip_address != nil {
fields = append(fields, usagelog.FieldIPAddress)
}
if m.image_count != nil {
fields = append(fields, usagelog.FieldImageCount)
}
...
...
@@ -10254,6 +12109,8 @@ func (m *UsageLogMutation) Field(name string) (ent.Value, bool) {
return m.FirstTokenMs()
case usagelog.FieldUserAgent:
return m.UserAgent()
case usagelog.FieldIPAddress:
return m.IPAddress()
case usagelog.FieldImageCount:
return m.ImageCount()
case usagelog.FieldImageSize:
...
...
@@ -10319,6 +12176,8 @@ func (m *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value
return m.OldFirstTokenMs(ctx)
case usagelog.FieldUserAgent:
return m.OldUserAgent(ctx)
case usagelog.FieldIPAddress:
return m.OldIPAddress(ctx)
case usagelog.FieldImageCount:
return m.OldImageCount(ctx)
case usagelog.FieldImageSize:
...
...
@@ -10509,6 +12368,13 @@ func (m *UsageLogMutation) SetField(name string, value ent.Value) error {
}
m.SetUserAgent(v)
return nil
case usagelog.FieldIPAddress:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIPAddress(v)
return nil
case usagelog.FieldImageCount:
v, ok := value.(int)
if !ok {
...
...
@@ -10782,6 +12648,9 @@ func (m *UsageLogMutation) ClearedFields() []string {
if m.FieldCleared(usagelog.FieldUserAgent) {
fields = append(fields, usagelog.FieldUserAgent)
}
if m.FieldCleared(usagelog.FieldIPAddress) {
fields = append(fields, usagelog.FieldIPAddress)
}
if m.FieldCleared(usagelog.FieldImageSize) {
fields = append(fields, usagelog.FieldImageSize)
}
...
...
@@ -10814,6 +12683,9 @@ func (m *UsageLogMutation) ClearField(name string) error {
case usagelog.FieldUserAgent:
m.ClearUserAgent()
return nil
case usagelog.FieldIPAddress:
m.ClearIPAddress()
return nil
case usagelog.FieldImageSize:
m.ClearImageSize()
return nil
...
...
@@ -10900,6 +12772,9 @@ func (m *UsageLogMutation) ResetField(name string) error {
case usagelog.FieldUserAgent:
m.ResetUserAgent()
return nil
case usagelog.FieldIPAddress:
m.ResetIPAddress()
return nil
case usagelog.FieldImageCount:
m.ResetImageCount()
return nil
...
...
@@ -11100,6 +12975,9 @@ type UserMutation struct {
attribute_values map[int64]struct{}
removedattribute_values map[int64]struct{}
clearedattribute_values bool
promo_code_usages map[int64]struct{}
removedpromo_code_usages map[int64]struct{}
clearedpromo_code_usages bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
...
...
@@ -12030,6 +13908,60 @@ func (m *UserMutation) ResetAttributeValues() {
m.removedattribute_values = nil
}
// AddPromoCodeUsageIDs adds the "promo_code_usages" edge to the PromoCodeUsage entity by ids.
func (m *UserMutation) AddPromoCodeUsageIDs(ids ...int64) {
if m.promo_code_usages == nil {
m.promo_code_usages = make(map[int64]struct{})
}
for i := range ids {
m.promo_code_usages[ids[i]] = struct{}{}
}
}
// ClearPromoCodeUsages clears the "promo_code_usages" edge to the PromoCodeUsage entity.
func (m *UserMutation) ClearPromoCodeUsages() {
m.clearedpromo_code_usages = true
}
// PromoCodeUsagesCleared reports if the "promo_code_usages" edge to the PromoCodeUsage entity was cleared.
func (m *UserMutation) PromoCodeUsagesCleared() bool {
return m.clearedpromo_code_usages
}
// RemovePromoCodeUsageIDs removes the "promo_code_usages" edge to the PromoCodeUsage entity by IDs.
func (m *UserMutation) RemovePromoCodeUsageIDs(ids ...int64) {
if m.removedpromo_code_usages == nil {
m.removedpromo_code_usages = make(map[int64]struct{})
}
for i := range ids {
delete(m.promo_code_usages, ids[i])
m.removedpromo_code_usages[ids[i]] = struct{}{}
}
}
// RemovedPromoCodeUsages returns the removed IDs of the "promo_code_usages" edge to the PromoCodeUsage entity.
func (m *UserMutation) RemovedPromoCodeUsagesIDs() (ids []int64) {
for id := range m.removedpromo_code_usages {
ids = append(ids, id)
}
return
}
// PromoCodeUsagesIDs returns the "promo_code_usages" edge IDs in the mutation.
func (m *UserMutation) PromoCodeUsagesIDs() (ids []int64) {
for id := range m.promo_code_usages {
ids = append(ids, id)
}
return
}
// ResetPromoCodeUsages resets all changes to the "promo_code_usages" edge.
func (m *UserMutation) ResetPromoCodeUsages() {
m.promo_code_usages = nil
m.clearedpromo_code_usages = false
m.removedpromo_code_usages = nil
}
// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
m.predicates = append(m.predicates, ps...)
...
...
@@ -12369,7 +14301,7 @@ func (m *UserMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.api_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
}
...
...
@@ -12391,6 +14323,9 @@ func (m *UserMutation) AddedEdges() []string {
if m.attribute_values != nil {
edges = append(edges, user.EdgeAttributeValues)
}
if m.promo_code_usages != nil {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
}
...
...
@@ -12440,13 +14375,19 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case user.EdgePromoCodeUsages:
ids := make([]ent.Value, 0, len(m.promo_code_usages))
for id := range m.promo_code_usages {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.removedapi_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
}
...
...
@@ -12468,6 +14409,9 @@ func (m *UserMutation) RemovedEdges() []string {
if m.removedattribute_values != nil {
edges = append(edges, user.EdgeAttributeValues)
}
if m.removedpromo_code_usages != nil {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
}
...
...
@@ -12517,13 +14461,19 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case user.EdgePromoCodeUsages:
ids := make([]ent.Value, 0, len(m.removedpromo_code_usages))
for id := range m.removedpromo_code_usages {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.clearedapi_keys {
edges = append(edges, user.EdgeAPIKeys)
}
...
...
@@ -12545,6 +14495,9 @@ func (m *UserMutation) ClearedEdges() []string {
if m.clearedattribute_values {
edges = append(edges, user.EdgeAttributeValues)
}
if m.clearedpromo_code_usages {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
}
...
...
@@ -12566,6 +14519,8 @@ func (m *UserMutation) EdgeCleared(name string) bool {
return m.clearedusage_logs
case user.EdgeAttributeValues:
return m.clearedattribute_values
case user.EdgePromoCodeUsages:
return m.clearedpromo_code_usages
}
return false
}
...
...
@@ -12603,6 +14558,9 @@ func (m *UserMutation) ResetEdge(name string) error {
case user.EdgeAttributeValues:
m.ResetAttributeValues()
return nil
case user.EdgePromoCodeUsages:
m.ResetPromoCodeUsages()
return nil
}
return fmt.Errorf("unknown User edge %s", name)
}
...
...
backend/ent/predicate/predicate.go
View file @
1a641392
...
...
@@ -18,6 +18,12 @@ type AccountGroup func(*sql.Selector)
// Group is the predicate function for group builders.
type
Group
func
(
*
sql
.
Selector
)
// PromoCode is the predicate function for promocode builders.
type
PromoCode
func
(
*
sql
.
Selector
)
// PromoCodeUsage is the predicate function for promocodeusage builders.
type
PromoCodeUsage
func
(
*
sql
.
Selector
)
// Proxy is the predicate function for proxy builders.
type
Proxy
func
(
*
sql
.
Selector
)
...
...
backend/ent/promocode.go
0 → 100644
View file @
1a641392
// 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/promocode"
)
// PromoCode is the model entity for the PromoCode schema.
type
PromoCode
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// 优惠码
Code
string
`json:"code,omitempty"`
// 赠送余额金额
BonusAmount
float64
`json:"bonus_amount,omitempty"`
// 最大使用次数,0表示无限制
MaxUses
int
`json:"max_uses,omitempty"`
// 已使用次数
UsedCount
int
`json:"used_count,omitempty"`
// 状态: active, disabled
Status
string
`json:"status,omitempty"`
// 过期时间,null表示永不过期
ExpiresAt
*
time
.
Time
`json:"expires_at,omitempty"`
// 备注
Notes
*
string
`json:"notes,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"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PromoCodeQuery when eager-loading is set.
Edges
PromoCodeEdges
`json:"edges"`
selectValues
sql
.
SelectValues
}
// PromoCodeEdges holds the relations/edges for other nodes in the graph.
type
PromoCodeEdges
struct
{
// UsageRecords holds the value of the usage_records edge.
UsageRecords
[]
*
PromoCodeUsage
`json:"usage_records,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes
[
1
]
bool
}
// UsageRecordsOrErr returns the UsageRecords value or an error if the edge
// was not loaded in eager-loading.
func
(
e
PromoCodeEdges
)
UsageRecordsOrErr
()
([]
*
PromoCodeUsage
,
error
)
{
if
e
.
loadedTypes
[
0
]
{
return
e
.
UsageRecords
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"usage_records"
}
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
PromoCode
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
promocode
.
FieldBonusAmount
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
promocode
.
FieldID
,
promocode
.
FieldMaxUses
,
promocode
.
FieldUsedCount
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
promocode
.
FieldCode
,
promocode
.
FieldStatus
,
promocode
.
FieldNotes
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
promocode
.
FieldExpiresAt
,
promocode
.
FieldCreatedAt
,
promocode
.
FieldUpdatedAt
:
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 PromoCode fields.
func
(
_m
*
PromoCode
)
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
promocode
.
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
promocode
.
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
promocode
.
FieldBonusAmount
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullFloat64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field bonus_amount"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
BonusAmount
=
value
.
Float64
}
case
promocode
.
FieldMaxUses
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field max_uses"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
MaxUses
=
int
(
value
.
Int64
)
}
case
promocode
.
FieldUsedCount
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field used_count"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UsedCount
=
int
(
value
.
Int64
)
}
case
promocode
.
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
promocode
.
FieldExpiresAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field expires_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ExpiresAt
=
new
(
time
.
Time
)
*
_m
.
ExpiresAt
=
value
.
Time
}
case
promocode
.
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
promocode
.
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
promocode
.
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
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
}
return
nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the PromoCode.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
PromoCode
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// QueryUsageRecords queries the "usage_records" edge of the PromoCode entity.
func
(
_m
*
PromoCode
)
QueryUsageRecords
()
*
PromoCodeUsageQuery
{
return
NewPromoCodeClient
(
_m
.
config
)
.
QueryUsageRecords
(
_m
)
}
// Update returns a builder for updating this PromoCode.
// Note that you need to call PromoCode.Unwrap() before calling this method if this PromoCode
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
PromoCode
)
Update
()
*
PromoCodeUpdateOne
{
return
NewPromoCodeClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the PromoCode 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
*
PromoCode
)
Unwrap
()
*
PromoCode
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: PromoCode is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
PromoCode
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"PromoCode("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"code="
)
builder
.
WriteString
(
_m
.
Code
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"bonus_amount="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
BonusAmount
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"max_uses="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
MaxUses
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"used_count="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
UsedCount
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"status="
)
builder
.
WriteString
(
_m
.
Status
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ExpiresAt
;
v
!=
nil
{
builder
.
WriteString
(
"expires_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
(
", "
)
builder
.
WriteString
(
"updated_at="
)
builder
.
WriteString
(
_m
.
UpdatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// PromoCodes is a parsable slice of PromoCode.
type
PromoCodes
[]
*
PromoCode
backend/ent/promocode/promocode.go
0 → 100644
View file @
1a641392
// Code generated by ent, DO NOT EDIT.
package
promocode
import
(
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const
(
// Label holds the string label denoting the promocode type in the database.
Label
=
"promo_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"
// FieldBonusAmount holds the string denoting the bonus_amount field in the database.
FieldBonusAmount
=
"bonus_amount"
// FieldMaxUses holds the string denoting the max_uses field in the database.
FieldMaxUses
=
"max_uses"
// FieldUsedCount holds the string denoting the used_count field in the database.
FieldUsedCount
=
"used_count"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus
=
"status"
// FieldExpiresAt holds the string denoting the expires_at field in the database.
FieldExpiresAt
=
"expires_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"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt
=
"updated_at"
// EdgeUsageRecords holds the string denoting the usage_records edge name in mutations.
EdgeUsageRecords
=
"usage_records"
// Table holds the table name of the promocode in the database.
Table
=
"promo_codes"
// UsageRecordsTable is the table that holds the usage_records relation/edge.
UsageRecordsTable
=
"promo_code_usages"
// UsageRecordsInverseTable is the table name for the PromoCodeUsage entity.
// It exists in this package in order to avoid circular dependency with the "promocodeusage" package.
UsageRecordsInverseTable
=
"promo_code_usages"
// UsageRecordsColumn is the table column denoting the usage_records relation/edge.
UsageRecordsColumn
=
"promo_code_id"
)
// Columns holds all SQL columns for promocode fields.
var
Columns
=
[]
string
{
FieldID
,
FieldCode
,
FieldBonusAmount
,
FieldMaxUses
,
FieldUsedCount
,
FieldStatus
,
FieldExpiresAt
,
FieldNotes
,
FieldCreatedAt
,
FieldUpdatedAt
,
}
// 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
// DefaultBonusAmount holds the default value on creation for the "bonus_amount" field.
DefaultBonusAmount
float64
// DefaultMaxUses holds the default value on creation for the "max_uses" field.
DefaultMaxUses
int
// DefaultUsedCount holds the default value on creation for the "used_count" field.
DefaultUsedCount
int
// 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
// 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
)
// OrderOption defines the ordering options for the PromoCode 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
()
}
// ByBonusAmount orders the results by the bonus_amount field.
func
ByBonusAmount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldBonusAmount
,
opts
...
)
.
ToFunc
()
}
// ByMaxUses orders the results by the max_uses field.
func
ByMaxUses
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldMaxUses
,
opts
...
)
.
ToFunc
()
}
// ByUsedCount orders the results by the used_count field.
func
ByUsedCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUsedCount
,
opts
...
)
.
ToFunc
()
}
// ByStatus orders the results by the status field.
func
ByStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStatus
,
opts
...
)
.
ToFunc
()
}
// ByExpiresAt orders the results by the expires_at field.
func
ByExpiresAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldExpiresAt
,
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
()
}
// ByUpdatedAt orders the results by the updated_at field.
func
ByUpdatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpdatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUsageRecordsCount orders the results by usage_records count.
func
ByUsageRecordsCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborsCount
(
s
,
newUsageRecordsStep
(),
opts
...
)
}
}
// ByUsageRecords orders the results by usage_records terms.
func
ByUsageRecords
(
term
sql
.
OrderTerm
,
terms
...
sql
.
OrderTerm
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborTerms
(
s
,
newUsageRecordsStep
(),
append
([]
sql
.
OrderTerm
{
term
},
terms
...
)
...
)
}
}
func
newUsageRecordsStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
UsageRecordsInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
UsageRecordsTable
,
UsageRecordsColumn
),
)
}
backend/ent/promocode/where.go
0 → 100644
View file @
1a641392
// Code generated by ent, DO NOT EDIT.
package
promocode
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
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// Code applies equality check predicate on the "code" field. It's identical to CodeEQ.
func
Code
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCode
,
v
))
}
// BonusAmount applies equality check predicate on the "bonus_amount" field. It's identical to BonusAmountEQ.
func
BonusAmount
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldBonusAmount
,
v
))
}
// MaxUses applies equality check predicate on the "max_uses" field. It's identical to MaxUsesEQ.
func
MaxUses
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldMaxUses
,
v
))
}
// UsedCount applies equality check predicate on the "used_count" field. It's identical to UsedCountEQ.
func
UsedCount
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUsedCount
,
v
))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func
Status
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
func
ExpiresAt
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldExpiresAt
,
v
))
}
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
func
Notes
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
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
.
PromoCode
{
return
predicate
.
PromoCode
(
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
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// CodeEQ applies the EQ predicate on the "code" field.
func
CodeEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCode
,
v
))
}
// CodeNEQ applies the NEQ predicate on the "code" field.
func
CodeNEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldCode
,
v
))
}
// CodeIn applies the In predicate on the "code" field.
func
CodeIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldCode
,
vs
...
))
}
// CodeNotIn applies the NotIn predicate on the "code" field.
func
CodeNotIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldCode
,
vs
...
))
}
// CodeGT applies the GT predicate on the "code" field.
func
CodeGT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldCode
,
v
))
}
// CodeGTE applies the GTE predicate on the "code" field.
func
CodeGTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldCode
,
v
))
}
// CodeLT applies the LT predicate on the "code" field.
func
CodeLT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldCode
,
v
))
}
// CodeLTE applies the LTE predicate on the "code" field.
func
CodeLTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldCode
,
v
))
}
// CodeContains applies the Contains predicate on the "code" field.
func
CodeContains
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContains
(
FieldCode
,
v
))
}
// CodeHasPrefix applies the HasPrefix predicate on the "code" field.
func
CodeHasPrefix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasPrefix
(
FieldCode
,
v
))
}
// CodeHasSuffix applies the HasSuffix predicate on the "code" field.
func
CodeHasSuffix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasSuffix
(
FieldCode
,
v
))
}
// CodeEqualFold applies the EqualFold predicate on the "code" field.
func
CodeEqualFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEqualFold
(
FieldCode
,
v
))
}
// CodeContainsFold applies the ContainsFold predicate on the "code" field.
func
CodeContainsFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContainsFold
(
FieldCode
,
v
))
}
// BonusAmountEQ applies the EQ predicate on the "bonus_amount" field.
func
BonusAmountEQ
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldBonusAmount
,
v
))
}
// BonusAmountNEQ applies the NEQ predicate on the "bonus_amount" field.
func
BonusAmountNEQ
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldBonusAmount
,
v
))
}
// BonusAmountIn applies the In predicate on the "bonus_amount" field.
func
BonusAmountIn
(
vs
...
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldBonusAmount
,
vs
...
))
}
// BonusAmountNotIn applies the NotIn predicate on the "bonus_amount" field.
func
BonusAmountNotIn
(
vs
...
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldBonusAmount
,
vs
...
))
}
// BonusAmountGT applies the GT predicate on the "bonus_amount" field.
func
BonusAmountGT
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldBonusAmount
,
v
))
}
// BonusAmountGTE applies the GTE predicate on the "bonus_amount" field.
func
BonusAmountGTE
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldBonusAmount
,
v
))
}
// BonusAmountLT applies the LT predicate on the "bonus_amount" field.
func
BonusAmountLT
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldBonusAmount
,
v
))
}
// BonusAmountLTE applies the LTE predicate on the "bonus_amount" field.
func
BonusAmountLTE
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldBonusAmount
,
v
))
}
// MaxUsesEQ applies the EQ predicate on the "max_uses" field.
func
MaxUsesEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldMaxUses
,
v
))
}
// MaxUsesNEQ applies the NEQ predicate on the "max_uses" field.
func
MaxUsesNEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldMaxUses
,
v
))
}
// MaxUsesIn applies the In predicate on the "max_uses" field.
func
MaxUsesIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldMaxUses
,
vs
...
))
}
// MaxUsesNotIn applies the NotIn predicate on the "max_uses" field.
func
MaxUsesNotIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldMaxUses
,
vs
...
))
}
// MaxUsesGT applies the GT predicate on the "max_uses" field.
func
MaxUsesGT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldMaxUses
,
v
))
}
// MaxUsesGTE applies the GTE predicate on the "max_uses" field.
func
MaxUsesGTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldMaxUses
,
v
))
}
// MaxUsesLT applies the LT predicate on the "max_uses" field.
func
MaxUsesLT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldMaxUses
,
v
))
}
// MaxUsesLTE applies the LTE predicate on the "max_uses" field.
func
MaxUsesLTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldMaxUses
,
v
))
}
// UsedCountEQ applies the EQ predicate on the "used_count" field.
func
UsedCountEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUsedCount
,
v
))
}
// UsedCountNEQ applies the NEQ predicate on the "used_count" field.
func
UsedCountNEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldUsedCount
,
v
))
}
// UsedCountIn applies the In predicate on the "used_count" field.
func
UsedCountIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldUsedCount
,
vs
...
))
}
// UsedCountNotIn applies the NotIn predicate on the "used_count" field.
func
UsedCountNotIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldUsedCount
,
vs
...
))
}
// UsedCountGT applies the GT predicate on the "used_count" field.
func
UsedCountGT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldUsedCount
,
v
))
}
// UsedCountGTE applies the GTE predicate on the "used_count" field.
func
UsedCountGTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldUsedCount
,
v
))
}
// UsedCountLT applies the LT predicate on the "used_count" field.
func
UsedCountLT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldUsedCount
,
v
))
}
// UsedCountLTE applies the LTE predicate on the "used_count" field.
func
UsedCountLTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldUsedCount
,
v
))
}
// StatusEQ applies the EQ predicate on the "status" field.
func
StatusEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func
StatusNEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldStatus
,
v
))
}
// StatusIn applies the In predicate on the "status" field.
func
StatusIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldStatus
,
vs
...
))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func
StatusNotIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldStatus
,
vs
...
))
}
// StatusGT applies the GT predicate on the "status" field.
func
StatusGT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldStatus
,
v
))
}
// StatusGTE applies the GTE predicate on the "status" field.
func
StatusGTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldStatus
,
v
))
}
// StatusLT applies the LT predicate on the "status" field.
func
StatusLT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldStatus
,
v
))
}
// StatusLTE applies the LTE predicate on the "status" field.
func
StatusLTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldStatus
,
v
))
}
// StatusContains applies the Contains predicate on the "status" field.
func
StatusContains
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContains
(
FieldStatus
,
v
))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func
StatusHasPrefix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasPrefix
(
FieldStatus
,
v
))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func
StatusHasSuffix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasSuffix
(
FieldStatus
,
v
))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func
StatusEqualFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEqualFold
(
FieldStatus
,
v
))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func
StatusContainsFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContainsFold
(
FieldStatus
,
v
))
}
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
func
ExpiresAtEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldExpiresAt
,
v
))
}
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
func
ExpiresAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldExpiresAt
,
v
))
}
// ExpiresAtIn applies the In predicate on the "expires_at" field.
func
ExpiresAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldExpiresAt
,
vs
...
))
}
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
func
ExpiresAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldExpiresAt
,
vs
...
))
}
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
func
ExpiresAtGT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldExpiresAt
,
v
))
}
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
func
ExpiresAtGTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldExpiresAt
,
v
))
}
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
func
ExpiresAtLT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldExpiresAt
,
v
))
}
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
func
ExpiresAtLTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldExpiresAt
,
v
))
}
// ExpiresAtIsNil applies the IsNil predicate on the "expires_at" field.
func
ExpiresAtIsNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIsNull
(
FieldExpiresAt
))
}
// ExpiresAtNotNil applies the NotNil predicate on the "expires_at" field.
func
ExpiresAtNotNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotNull
(
FieldExpiresAt
))
}
// NotesEQ applies the EQ predicate on the "notes" field.
func
NotesEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
}
// NotesNEQ applies the NEQ predicate on the "notes" field.
func
NotesNEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldNotes
,
v
))
}
// NotesIn applies the In predicate on the "notes" field.
func
NotesIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldNotes
,
vs
...
))
}
// NotesNotIn applies the NotIn predicate on the "notes" field.
func
NotesNotIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldNotes
,
vs
...
))
}
// NotesGT applies the GT predicate on the "notes" field.
func
NotesGT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldNotes
,
v
))
}
// NotesGTE applies the GTE predicate on the "notes" field.
func
NotesGTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldNotes
,
v
))
}
// NotesLT applies the LT predicate on the "notes" field.
func
NotesLT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldNotes
,
v
))
}
// NotesLTE applies the LTE predicate on the "notes" field.
func
NotesLTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldNotes
,
v
))
}
// NotesContains applies the Contains predicate on the "notes" field.
func
NotesContains
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContains
(
FieldNotes
,
v
))
}
// NotesHasPrefix applies the HasPrefix predicate on the "notes" field.
func
NotesHasPrefix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasPrefix
(
FieldNotes
,
v
))
}
// NotesHasSuffix applies the HasSuffix predicate on the "notes" field.
func
NotesHasSuffix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasSuffix
(
FieldNotes
,
v
))
}
// NotesIsNil applies the IsNil predicate on the "notes" field.
func
NotesIsNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIsNull
(
FieldNotes
))
}
// NotesNotNil applies the NotNil predicate on the "notes" field.
func
NotesNotNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotNull
(
FieldNotes
))
}
// NotesEqualFold applies the EqualFold predicate on the "notes" field.
func
NotesEqualFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEqualFold
(
FieldNotes
,
v
))
}
// NotesContainsFold applies the ContainsFold predicate on the "notes" field.
func
NotesContainsFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContainsFold
(
FieldNotes
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func
CreatedAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func
CreatedAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func
CreatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func
CreatedAtGT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldCreatedAt
,
v
))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func
CreatedAtGTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldCreatedAt
,
v
))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func
CreatedAtLT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldCreatedAt
,
v
))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func
CreatedAtLTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldCreatedAt
,
v
))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func
UpdatedAtEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func
UpdatedAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func
UpdatedAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func
UpdatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func
UpdatedAtGT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func
UpdatedAtGTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func
UpdatedAtLT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func
UpdatedAtLTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldUpdatedAt
,
v
))
}
// HasUsageRecords applies the HasEdge predicate on the "usage_records" edge.
func
HasUsageRecords
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
func
(
s
*
sql
.
Selector
)
{
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
UsageRecordsTable
,
UsageRecordsColumn
),
)
sqlgraph
.
HasNeighbors
(
s
,
step
)
})
}
// HasUsageRecordsWith applies the HasEdge predicate on the "usage_records" edge with a given conditions (other predicates).
func
HasUsageRecordsWith
(
preds
...
predicate
.
PromoCodeUsage
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newUsageRecordsStep
()
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
.
PromoCode
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
PromoCode
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
PromoCode
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
NotPredicates
(
p
))
}
backend/ent/promocode_create.go
0 → 100644
View file @
1a641392
// 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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
)
// PromoCodeCreate is the builder for creating a PromoCode entity.
type
PromoCodeCreate
struct
{
config
mutation
*
PromoCodeMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetCode sets the "code" field.
func
(
_c
*
PromoCodeCreate
)
SetCode
(
v
string
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetCode
(
v
)
return
_c
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_c
*
PromoCodeCreate
)
SetBonusAmount
(
v
float64
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetBonusAmount
(
v
)
return
_c
}
// SetNillableBonusAmount sets the "bonus_amount" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableBonusAmount
(
v
*
float64
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetBonusAmount
(
*
v
)
}
return
_c
}
// SetMaxUses sets the "max_uses" field.
func
(
_c
*
PromoCodeCreate
)
SetMaxUses
(
v
int
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetMaxUses
(
v
)
return
_c
}
// SetNillableMaxUses sets the "max_uses" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableMaxUses
(
v
*
int
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetMaxUses
(
*
v
)
}
return
_c
}
// SetUsedCount sets the "used_count" field.
func
(
_c
*
PromoCodeCreate
)
SetUsedCount
(
v
int
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetUsedCount
(
v
)
return
_c
}
// SetNillableUsedCount sets the "used_count" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableUsedCount
(
v
*
int
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetUsedCount
(
*
v
)
}
return
_c
}
// SetStatus sets the "status" field.
func
(
_c
*
PromoCodeCreate
)
SetStatus
(
v
string
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetStatus
(
v
)
return
_c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableStatus
(
v
*
string
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetStatus
(
*
v
)
}
return
_c
}
// SetExpiresAt sets the "expires_at" field.
func
(
_c
*
PromoCodeCreate
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetExpiresAt
(
v
)
return
_c
}
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableExpiresAt
(
v
*
time
.
Time
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetExpiresAt
(
*
v
)
}
return
_c
}
// SetNotes sets the "notes" field.
func
(
_c
*
PromoCodeCreate
)
SetNotes
(
v
string
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetNotes
(
v
)
return
_c
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableNotes
(
v
*
string
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetNotes
(
*
v
)
}
return
_c
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
PromoCodeCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_c
*
PromoCodeCreate
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetUpdatedAt
(
v
)
return
_c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableUpdatedAt
(
v
*
time
.
Time
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetUpdatedAt
(
*
v
)
}
return
_c
}
// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by IDs.
func
(
_c
*
PromoCodeCreate
)
AddUsageRecordIDs
(
ids
...
int64
)
*
PromoCodeCreate
{
_c
.
mutation
.
AddUsageRecordIDs
(
ids
...
)
return
_c
}
// AddUsageRecords adds the "usage_records" edges to the PromoCodeUsage entity.
func
(
_c
*
PromoCodeCreate
)
AddUsageRecords
(
v
...*
PromoCodeUsage
)
*
PromoCodeCreate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_c
.
AddUsageRecordIDs
(
ids
...
)
}
// Mutation returns the PromoCodeMutation object of the builder.
func
(
_c
*
PromoCodeCreate
)
Mutation
()
*
PromoCodeMutation
{
return
_c
.
mutation
}
// Save creates the PromoCode in the database.
func
(
_c
*
PromoCodeCreate
)
Save
(
ctx
context
.
Context
)
(
*
PromoCode
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
PromoCodeCreate
)
SaveX
(
ctx
context
.
Context
)
*
PromoCode
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
PromoCodeCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
PromoCodeCreate
)
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
*
PromoCodeCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
BonusAmount
();
!
ok
{
v
:=
promocode
.
DefaultBonusAmount
_c
.
mutation
.
SetBonusAmount
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
MaxUses
();
!
ok
{
v
:=
promocode
.
DefaultMaxUses
_c
.
mutation
.
SetMaxUses
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UsedCount
();
!
ok
{
v
:=
promocode
.
DefaultUsedCount
_c
.
mutation
.
SetUsedCount
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
v
:=
promocode
.
DefaultStatus
_c
.
mutation
.
SetStatus
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
promocode
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
promocode
.
DefaultUpdatedAt
()
_c
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
PromoCodeCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
Code
();
!
ok
{
return
&
ValidationError
{
Name
:
"code"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.code"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Code
();
ok
{
if
err
:=
promocode
.
CodeValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"code"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.code": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
BonusAmount
();
!
ok
{
return
&
ValidationError
{
Name
:
"bonus_amount"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.bonus_amount"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
MaxUses
();
!
ok
{
return
&
ValidationError
{
Name
:
"max_uses"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.max_uses"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UsedCount
();
!
ok
{
return
&
ValidationError
{
Name
:
"used_count"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.used_count"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.status"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
if
err
:=
promocode
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.status": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.created_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"updated_at"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.updated_at"`
)}
}
return
nil
}
func
(
_c
*
PromoCodeCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
PromoCode
,
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
*
PromoCodeCreate
)
createSpec
()
(
*
PromoCode
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
PromoCode
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
promocode
.
Table
,
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
Code
();
ok
{
_spec
.
SetField
(
promocode
.
FieldCode
,
field
.
TypeString
,
value
)
_node
.
Code
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
_node
.
BonusAmount
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
MaxUses
();
ok
{
_spec
.
SetField
(
promocode
.
FieldMaxUses
,
field
.
TypeInt
,
value
)
_node
.
MaxUses
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UsedCount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUsedCount
,
field
.
TypeInt
,
value
)
_node
.
UsedCount
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
promocode
.
FieldStatus
,
field
.
TypeString
,
value
)
_node
.
Status
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ExpiresAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldExpiresAt
,
field
.
TypeTime
,
value
)
_node
.
ExpiresAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
promocode
.
FieldNotes
,
field
.
TypeString
,
value
)
_node
.
Notes
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
_node
.
UpdatedAt
=
value
}
if
nodes
:=
_c
.
mutation
.
UsageRecordsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.PromoCode.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.PromoCodeUpsert) {
// SetCode(v+v).
// }).
// Exec(ctx)
func
(
_c
*
PromoCodeCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
PromoCodeUpsertOne
{
_c
.
conflict
=
opts
return
&
PromoCodeUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
PromoCodeCreate
)
OnConflictColumns
(
columns
...
string
)
*
PromoCodeUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
PromoCodeUpsertOne
{
create
:
_c
,
}
}
type
(
// PromoCodeUpsertOne is the builder for "upsert"-ing
// one PromoCode node.
PromoCodeUpsertOne
struct
{
create
*
PromoCodeCreate
}
// PromoCodeUpsert is the "OnConflict" setter.
PromoCodeUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetCode sets the "code" field.
func
(
u
*
PromoCodeUpsert
)
SetCode
(
v
string
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldCode
,
v
)
return
u
}
// UpdateCode sets the "code" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateCode
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldCode
)
return
u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUpsert
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldBonusAmount
,
v
)
return
u
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateBonusAmount
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldBonusAmount
)
return
u
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUpsert
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpsert
{
u
.
Add
(
promocode
.
FieldBonusAmount
,
v
)
return
u
}
// SetMaxUses sets the "max_uses" field.
func
(
u
*
PromoCodeUpsert
)
SetMaxUses
(
v
int
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldMaxUses
,
v
)
return
u
}
// UpdateMaxUses sets the "max_uses" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateMaxUses
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldMaxUses
)
return
u
}
// AddMaxUses adds v to the "max_uses" field.
func
(
u
*
PromoCodeUpsert
)
AddMaxUses
(
v
int
)
*
PromoCodeUpsert
{
u
.
Add
(
promocode
.
FieldMaxUses
,
v
)
return
u
}
// SetUsedCount sets the "used_count" field.
func
(
u
*
PromoCodeUpsert
)
SetUsedCount
(
v
int
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldUsedCount
,
v
)
return
u
}
// UpdateUsedCount sets the "used_count" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateUsedCount
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldUsedCount
)
return
u
}
// AddUsedCount adds v to the "used_count" field.
func
(
u
*
PromoCodeUpsert
)
AddUsedCount
(
v
int
)
*
PromoCodeUpsert
{
u
.
Add
(
promocode
.
FieldUsedCount
,
v
)
return
u
}
// SetStatus sets the "status" field.
func
(
u
*
PromoCodeUpsert
)
SetStatus
(
v
string
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldStatus
,
v
)
return
u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateStatus
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldStatus
)
return
u
}
// SetExpiresAt sets the "expires_at" field.
func
(
u
*
PromoCodeUpsert
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldExpiresAt
,
v
)
return
u
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateExpiresAt
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldExpiresAt
)
return
u
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
u
*
PromoCodeUpsert
)
ClearExpiresAt
()
*
PromoCodeUpsert
{
u
.
SetNull
(
promocode
.
FieldExpiresAt
)
return
u
}
// SetNotes sets the "notes" field.
func
(
u
*
PromoCodeUpsert
)
SetNotes
(
v
string
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldNotes
,
v
)
return
u
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateNotes
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldNotes
)
return
u
}
// ClearNotes clears the value of the "notes" field.
func
(
u
*
PromoCodeUpsert
)
ClearNotes
()
*
PromoCodeUpsert
{
u
.
SetNull
(
promocode
.
FieldNotes
)
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
PromoCodeUpsert
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldUpdatedAt
,
v
)
return
u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateUpdatedAt
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldUpdatedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertOne
)
UpdateNewValues
()
*
PromoCodeUpsertOne
{
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
(
promocode
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertOne
)
Ignore
()
*
PromoCodeUpsertOne
{
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
*
PromoCodeUpsertOne
)
DoNothing
()
*
PromoCodeUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the PromoCodeCreate.OnConflict
// documentation for more info.
func
(
u
*
PromoCodeUpsertOne
)
Update
(
set
func
(
*
PromoCodeUpsert
))
*
PromoCodeUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
PromoCodeUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetCode sets the "code" field.
func
(
u
*
PromoCodeUpsertOne
)
SetCode
(
v
string
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetCode
(
v
)
})
}
// UpdateCode sets the "code" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateCode
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateCode
()
})
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertOne
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetBonusAmount
(
v
)
})
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertOne
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddBonusAmount
(
v
)
})
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateBonusAmount
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateBonusAmount
()
})
}
// SetMaxUses sets the "max_uses" field.
func
(
u
*
PromoCodeUpsertOne
)
SetMaxUses
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetMaxUses
(
v
)
})
}
// AddMaxUses adds v to the "max_uses" field.
func
(
u
*
PromoCodeUpsertOne
)
AddMaxUses
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddMaxUses
(
v
)
})
}
// UpdateMaxUses sets the "max_uses" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateMaxUses
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateMaxUses
()
})
}
// SetUsedCount sets the "used_count" field.
func
(
u
*
PromoCodeUpsertOne
)
SetUsedCount
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUsedCount
(
v
)
})
}
// AddUsedCount adds v to the "used_count" field.
func
(
u
*
PromoCodeUpsertOne
)
AddUsedCount
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddUsedCount
(
v
)
})
}
// UpdateUsedCount sets the "used_count" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateUsedCount
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUsedCount
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
PromoCodeUpsertOne
)
SetStatus
(
v
string
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateStatus
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetExpiresAt sets the "expires_at" field.
func
(
u
*
PromoCodeUpsertOne
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetExpiresAt
(
v
)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateExpiresAt
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateExpiresAt
()
})
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
u
*
PromoCodeUpsertOne
)
ClearExpiresAt
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearExpiresAt
()
})
}
// SetNotes sets the "notes" field.
func
(
u
*
PromoCodeUpsertOne
)
SetNotes
(
v
string
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetNotes
(
v
)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateNotes
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateNotes
()
})
}
// ClearNotes clears the value of the "notes" field.
func
(
u
*
PromoCodeUpsertOne
)
ClearNotes
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearNotes
()
})
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
PromoCodeUpsertOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateUpdatedAt
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// Exec executes the query.
func
(
u
*
PromoCodeUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for PromoCodeCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
PromoCodeUpsertOne
)
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
*
PromoCodeUpsertOne
)
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
*
PromoCodeUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// PromoCodeCreateBulk is the builder for creating many PromoCode entities in bulk.
type
PromoCodeCreateBulk
struct
{
config
err
error
builders
[]
*
PromoCodeCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the PromoCode entities in the database.
func
(
_c
*
PromoCodeCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
PromoCode
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
PromoCode
,
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
.
(
*
PromoCodeMutation
)
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
*
PromoCodeCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
PromoCode
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
PromoCodeCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
PromoCodeCreateBulk
)
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.PromoCode.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.PromoCodeUpsert) {
// SetCode(v+v).
// }).
// Exec(ctx)
func
(
_c
*
PromoCodeCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
PromoCodeUpsertBulk
{
_c
.
conflict
=
opts
return
&
PromoCodeUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
PromoCodeCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
PromoCodeUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
PromoCodeUpsertBulk
{
create
:
_c
,
}
}
// PromoCodeUpsertBulk is the builder for "upsert"-ing
// a bulk of PromoCode nodes.
type
PromoCodeUpsertBulk
struct
{
create
*
PromoCodeCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertBulk
)
UpdateNewValues
()
*
PromoCodeUpsertBulk
{
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
(
promocode
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertBulk
)
Ignore
()
*
PromoCodeUpsertBulk
{
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
*
PromoCodeUpsertBulk
)
DoNothing
()
*
PromoCodeUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the PromoCodeCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
PromoCodeUpsertBulk
)
Update
(
set
func
(
*
PromoCodeUpsert
))
*
PromoCodeUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
PromoCodeUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetCode sets the "code" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetCode
(
v
string
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetCode
(
v
)
})
}
// UpdateCode sets the "code" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateCode
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateCode
()
})
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetBonusAmount
(
v
)
})
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertBulk
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddBonusAmount
(
v
)
})
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateBonusAmount
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateBonusAmount
()
})
}
// SetMaxUses sets the "max_uses" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetMaxUses
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetMaxUses
(
v
)
})
}
// AddMaxUses adds v to the "max_uses" field.
func
(
u
*
PromoCodeUpsertBulk
)
AddMaxUses
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddMaxUses
(
v
)
})
}
// UpdateMaxUses sets the "max_uses" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateMaxUses
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateMaxUses
()
})
}
// SetUsedCount sets the "used_count" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetUsedCount
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUsedCount
(
v
)
})
}
// AddUsedCount adds v to the "used_count" field.
func
(
u
*
PromoCodeUpsertBulk
)
AddUsedCount
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddUsedCount
(
v
)
})
}
// UpdateUsedCount sets the "used_count" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateUsedCount
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUsedCount
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetStatus
(
v
string
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateStatus
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetExpiresAt sets the "expires_at" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetExpiresAt
(
v
)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateExpiresAt
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateExpiresAt
()
})
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
u
*
PromoCodeUpsertBulk
)
ClearExpiresAt
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearExpiresAt
()
})
}
// SetNotes sets the "notes" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetNotes
(
v
string
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetNotes
(
v
)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateNotes
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateNotes
()
})
}
// ClearNotes clears the value of the "notes" field.
func
(
u
*
PromoCodeUpsertBulk
)
ClearNotes
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearNotes
()
})
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateUpdatedAt
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// Exec executes the query.
func
(
u
*
PromoCodeUpsertBulk
)
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 PromoCodeCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for PromoCodeCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
PromoCodeUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/promocode_delete.go
0 → 100644
View file @
1a641392
// 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/promocode"
)
// PromoCodeDelete is the builder for deleting a PromoCode entity.
type
PromoCodeDelete
struct
{
config
hooks
[]
Hook
mutation
*
PromoCodeMutation
}
// Where appends a list predicates to the PromoCodeDelete builder.
func
(
_d
*
PromoCodeDelete
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
PromoCodeDelete
)
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
*
PromoCodeDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
PromoCodeDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
promocode
.
Table
,
sqlgraph
.
NewFieldSpec
(
promocode
.
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
}
// PromoCodeDeleteOne is the builder for deleting a single PromoCode entity.
type
PromoCodeDeleteOne
struct
{
_d
*
PromoCodeDelete
}
// Where appends a list predicates to the PromoCodeDelete builder.
func
(
_d
*
PromoCodeDeleteOne
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
PromoCodeDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
promocode
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
PromoCodeDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/promocode_query.go
0 → 100644
View file @
1a641392
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"database/sql/driver"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
)
// PromoCodeQuery is the builder for querying PromoCode entities.
type
PromoCodeQuery
struct
{
config
ctx
*
QueryContext
order
[]
promocode
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
PromoCode
withUsageRecords
*
PromoCodeUsageQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the PromoCodeQuery builder.
func
(
_q
*
PromoCodeQuery
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
PromoCodeQuery
)
Limit
(
limit
int
)
*
PromoCodeQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
PromoCodeQuery
)
Offset
(
offset
int
)
*
PromoCodeQuery
{
_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
*
PromoCodeQuery
)
Unique
(
unique
bool
)
*
PromoCodeQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
PromoCodeQuery
)
Order
(
o
...
promocode
.
OrderOption
)
*
PromoCodeQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// QueryUsageRecords chains the current query on the "usage_records" edge.
func
(
_q
*
PromoCodeQuery
)
QueryUsageRecords
()
*
PromoCodeUsageQuery
{
query
:=
(
&
PromoCodeUsageClient
{
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
(
promocode
.
Table
,
promocode
.
FieldID
,
selector
),
sqlgraph
.
To
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
promocode
.
UsageRecordsTable
,
promocode
.
UsageRecordsColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// First returns the first PromoCode entity from the query.
// Returns a *NotFoundError when no PromoCode was found.
func
(
_q
*
PromoCodeQuery
)
First
(
ctx
context
.
Context
)
(
*
PromoCode
,
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
{
promocode
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
FirstX
(
ctx
context
.
Context
)
*
PromoCode
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first PromoCode ID from the query.
// Returns a *NotFoundError when no PromoCode ID was found.
func
(
_q
*
PromoCodeQuery
)
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
{
promocode
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single PromoCode entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one PromoCode entity is found.
// Returns a *NotFoundError when no PromoCode entities are found.
func
(
_q
*
PromoCodeQuery
)
Only
(
ctx
context
.
Context
)
(
*
PromoCode
,
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
{
promocode
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
promocode
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
OnlyX
(
ctx
context
.
Context
)
*
PromoCode
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only PromoCode ID in the query.
// Returns a *NotSingularError when more than one PromoCode ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
PromoCodeQuery
)
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
{
promocode
.
Label
}
default
:
err
=
&
NotSingularError
{
promocode
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
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 PromoCodes.
func
(
_q
*
PromoCodeQuery
)
All
(
ctx
context
.
Context
)
([]
*
PromoCode
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
PromoCode
,
*
PromoCodeQuery
]()
return
withInterceptors
[[]
*
PromoCode
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
PromoCode
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of PromoCode IDs.
func
(
_q
*
PromoCodeQuery
)
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
(
promocode
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
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
*
PromoCodeQuery
)
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
[
*
PromoCodeQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
PromoCodeQuery
)
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
*
PromoCodeQuery
)
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
*
PromoCodeQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the PromoCodeQuery 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
*
PromoCodeQuery
)
Clone
()
*
PromoCodeQuery
{
if
_q
==
nil
{
return
nil
}
return
&
PromoCodeQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
promocode
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
PromoCode
{},
_q
.
predicates
...
),
withUsageRecords
:
_q
.
withUsageRecords
.
Clone
(),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// WithUsageRecords tells the query-builder to eager-load the nodes that are connected to
// the "usage_records" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
PromoCodeQuery
)
WithUsageRecords
(
opts
...
func
(
*
PromoCodeUsageQuery
))
*
PromoCodeQuery
{
query
:=
(
&
PromoCodeUsageClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withUsageRecords
=
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.PromoCode.Query().
// GroupBy(promocode.FieldCode).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
PromoCodeQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
PromoCodeGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
PromoCodeGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
promocode
.
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.PromoCode.Query().
// Select(promocode.FieldCode).
// Scan(ctx, &v)
func
(
_q
*
PromoCodeQuery
)
Select
(
fields
...
string
)
*
PromoCodeSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
PromoCodeSelect
{
PromoCodeQuery
:
_q
}
sbuild
.
label
=
promocode
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a PromoCodeSelect configured with the given aggregations.
func
(
_q
*
PromoCodeQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
PromoCodeSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
PromoCodeQuery
)
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
!
promocode
.
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
*
PromoCodeQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
PromoCode
,
error
)
{
var
(
nodes
=
[]
*
PromoCode
{}
_spec
=
_q
.
querySpec
()
loadedTypes
=
[
1
]
bool
{
_q
.
withUsageRecords
!=
nil
,
}
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
PromoCode
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
PromoCode
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
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
.
withUsageRecords
;
query
!=
nil
{
if
err
:=
_q
.
loadUsageRecords
(
ctx
,
query
,
nodes
,
func
(
n
*
PromoCode
)
{
n
.
Edges
.
UsageRecords
=
[]
*
PromoCodeUsage
{}
},
func
(
n
*
PromoCode
,
e
*
PromoCodeUsage
)
{
n
.
Edges
.
UsageRecords
=
append
(
n
.
Edges
.
UsageRecords
,
e
)
});
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
func
(
_q
*
PromoCodeQuery
)
loadUsageRecords
(
ctx
context
.
Context
,
query
*
PromoCodeUsageQuery
,
nodes
[]
*
PromoCode
,
init
func
(
*
PromoCode
),
assign
func
(
*
PromoCode
,
*
PromoCodeUsage
))
error
{
fks
:=
make
([]
driver
.
Value
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
]
*
PromoCode
)
for
i
:=
range
nodes
{
fks
=
append
(
fks
,
nodes
[
i
]
.
ID
)
nodeids
[
nodes
[
i
]
.
ID
]
=
nodes
[
i
]
if
init
!=
nil
{
init
(
nodes
[
i
])
}
}
if
len
(
query
.
ctx
.
Fields
)
>
0
{
query
.
ctx
.
AppendFieldOnce
(
promocodeusage
.
FieldPromoCodeID
)
}
query
.
Where
(
predicate
.
PromoCodeUsage
(
func
(
s
*
sql
.
Selector
)
{
s
.
Where
(
sql
.
InValues
(
s
.
C
(
promocode
.
UsageRecordsColumn
),
fks
...
))
}))
neighbors
,
err
:=
query
.
All
(
ctx
)
if
err
!=
nil
{
return
err
}
for
_
,
n
:=
range
neighbors
{
fk
:=
n
.
PromoCodeID
node
,
ok
:=
nodeids
[
fk
]
if
!
ok
{
return
fmt
.
Errorf
(
`unexpected referenced foreign-key "promo_code_id" returned %v for node %v`
,
fk
,
n
.
ID
)
}
assign
(
node
,
n
)
}
return
nil
}
func
(
_q
*
PromoCodeQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_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
*
PromoCodeQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
promocode
.
Table
,
promocode
.
Columns
,
sqlgraph
.
NewFieldSpec
(
promocode
.
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
,
promocode
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
promocode
.
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
*
PromoCodeQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
promocode
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
promocode
.
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
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
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
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
PromoCodeQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
PromoCodeQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
PromoCodeQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
PromoCodeQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// PromoCodeGroupBy is the group-by builder for PromoCode entities.
type
PromoCodeGroupBy
struct
{
selector
build
*
PromoCodeQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
PromoCodeGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
PromoCodeGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
PromoCodeGroupBy
)
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
[
*
PromoCodeQuery
,
*
PromoCodeGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
PromoCodeGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
PromoCodeQuery
,
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
)
}
// PromoCodeSelect is the builder for selecting fields of PromoCode entities.
type
PromoCodeSelect
struct
{
*
PromoCodeQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
PromoCodeSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
PromoCodeSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
PromoCodeSelect
)
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
[
*
PromoCodeQuery
,
*
PromoCodeSelect
](
ctx
,
_s
.
PromoCodeQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
PromoCodeSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
PromoCodeQuery
,
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
)
}
backend/ent/promocode_update.go
0 → 100644
View file @
1a641392
// 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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
)
// PromoCodeUpdate is the builder for updating PromoCode entities.
type
PromoCodeUpdate
struct
{
config
hooks
[]
Hook
mutation
*
PromoCodeMutation
}
// Where appends a list predicates to the PromoCodeUpdate builder.
func
(
_u
*
PromoCodeUpdate
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeUpdate
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// SetCode sets the "code" field.
func
(
_u
*
PromoCodeUpdate
)
SetCode
(
v
string
)
*
PromoCodeUpdate
{
_u
.
mutation
.
SetCode
(
v
)
return
_u
}
// SetNillableCode sets the "code" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableCode
(
v
*
string
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetCode
(
*
v
)
}
return
_u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_u
*
PromoCodeUpdate
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpdate
{
_u
.
mutation
.
ResetBonusAmount
()
_u
.
mutation
.
SetBonusAmount
(
v
)
return
_u
}
// SetNillableBonusAmount sets the "bonus_amount" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableBonusAmount
(
v
*
float64
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetBonusAmount
(
*
v
)
}
return
_u
}
// AddBonusAmount adds value to the "bonus_amount" field.
func
(
_u
*
PromoCodeUpdate
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpdate
{
_u
.
mutation
.
AddBonusAmount
(
v
)
return
_u
}
// SetMaxUses sets the "max_uses" field.
func
(
_u
*
PromoCodeUpdate
)
SetMaxUses
(
v
int
)
*
PromoCodeUpdate
{
_u
.
mutation
.
ResetMaxUses
()
_u
.
mutation
.
SetMaxUses
(
v
)
return
_u
}
// SetNillableMaxUses sets the "max_uses" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableMaxUses
(
v
*
int
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetMaxUses
(
*
v
)
}
return
_u
}
// AddMaxUses adds value to the "max_uses" field.
func
(
_u
*
PromoCodeUpdate
)
AddMaxUses
(
v
int
)
*
PromoCodeUpdate
{
_u
.
mutation
.
AddMaxUses
(
v
)
return
_u
}
// SetUsedCount sets the "used_count" field.
func
(
_u
*
PromoCodeUpdate
)
SetUsedCount
(
v
int
)
*
PromoCodeUpdate
{
_u
.
mutation
.
ResetUsedCount
()
_u
.
mutation
.
SetUsedCount
(
v
)
return
_u
}
// SetNillableUsedCount sets the "used_count" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableUsedCount
(
v
*
int
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetUsedCount
(
*
v
)
}
return
_u
}
// AddUsedCount adds value to the "used_count" field.
func
(
_u
*
PromoCodeUpdate
)
AddUsedCount
(
v
int
)
*
PromoCodeUpdate
{
_u
.
mutation
.
AddUsedCount
(
v
)
return
_u
}
// SetStatus sets the "status" field.
func
(
_u
*
PromoCodeUpdate
)
SetStatus
(
v
string
)
*
PromoCodeUpdate
{
_u
.
mutation
.
SetStatus
(
v
)
return
_u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableStatus
(
v
*
string
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetStatus
(
*
v
)
}
return
_u
}
// SetExpiresAt sets the "expires_at" field.
func
(
_u
*
PromoCodeUpdate
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpdate
{
_u
.
mutation
.
SetExpiresAt
(
v
)
return
_u
}
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableExpiresAt
(
v
*
time
.
Time
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetExpiresAt
(
*
v
)
}
return
_u
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
_u
*
PromoCodeUpdate
)
ClearExpiresAt
()
*
PromoCodeUpdate
{
_u
.
mutation
.
ClearExpiresAt
()
return
_u
}
// SetNotes sets the "notes" field.
func
(
_u
*
PromoCodeUpdate
)
SetNotes
(
v
string
)
*
PromoCodeUpdate
{
_u
.
mutation
.
SetNotes
(
v
)
return
_u
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdate
)
SetNillableNotes
(
v
*
string
)
*
PromoCodeUpdate
{
if
v
!=
nil
{
_u
.
SetNotes
(
*
v
)
}
return
_u
}
// ClearNotes clears the value of the "notes" field.
func
(
_u
*
PromoCodeUpdate
)
ClearNotes
()
*
PromoCodeUpdate
{
_u
.
mutation
.
ClearNotes
()
return
_u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
PromoCodeUpdate
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpdate
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by IDs.
func
(
_u
*
PromoCodeUpdate
)
AddUsageRecordIDs
(
ids
...
int64
)
*
PromoCodeUpdate
{
_u
.
mutation
.
AddUsageRecordIDs
(
ids
...
)
return
_u
}
// AddUsageRecords adds the "usage_records" edges to the PromoCodeUsage entity.
func
(
_u
*
PromoCodeUpdate
)
AddUsageRecords
(
v
...*
PromoCodeUsage
)
*
PromoCodeUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddUsageRecordIDs
(
ids
...
)
}
// Mutation returns the PromoCodeMutation object of the builder.
func
(
_u
*
PromoCodeUpdate
)
Mutation
()
*
PromoCodeMutation
{
return
_u
.
mutation
}
// ClearUsageRecords clears all "usage_records" edges to the PromoCodeUsage entity.
func
(
_u
*
PromoCodeUpdate
)
ClearUsageRecords
()
*
PromoCodeUpdate
{
_u
.
mutation
.
ClearUsageRecords
()
return
_u
}
// RemoveUsageRecordIDs removes the "usage_records" edge to PromoCodeUsage entities by IDs.
func
(
_u
*
PromoCodeUpdate
)
RemoveUsageRecordIDs
(
ids
...
int64
)
*
PromoCodeUpdate
{
_u
.
mutation
.
RemoveUsageRecordIDs
(
ids
...
)
return
_u
}
// RemoveUsageRecords removes "usage_records" edges to PromoCodeUsage entities.
func
(
_u
*
PromoCodeUpdate
)
RemoveUsageRecords
(
v
...*
PromoCodeUsage
)
*
PromoCodeUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemoveUsageRecordIDs
(
ids
...
)
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
PromoCodeUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
PromoCodeUpdate
)
SaveX
(
ctx
context
.
Context
)
int
{
affected
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
affected
}
// Exec executes the query.
func
(
_u
*
PromoCodeUpdate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
PromoCodeUpdate
)
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
*
PromoCodeUpdate
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
promocode
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
PromoCodeUpdate
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Code
();
ok
{
if
err
:=
promocode
.
CodeValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"code"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.code": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
if
err
:=
promocode
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.status": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
PromoCodeUpdate
)
sqlSave
(
ctx
context
.
Context
)
(
_node
int
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
promocode
.
Table
,
promocode
.
Columns
,
sqlgraph
.
NewFieldSpec
(
promocode
.
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
(
promocode
.
FieldCode
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedBonusAmount
();
ok
{
_spec
.
AddField
(
promocode
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
MaxUses
();
ok
{
_spec
.
SetField
(
promocode
.
FieldMaxUses
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedMaxUses
();
ok
{
_spec
.
AddField
(
promocode
.
FieldMaxUses
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
UsedCount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUsedCount
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedUsedCount
();
ok
{
_spec
.
AddField
(
promocode
.
FieldUsedCount
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
promocode
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ExpiresAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldExpiresAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
ExpiresAtCleared
()
{
_spec
.
ClearField
(
promocode
.
FieldExpiresAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
promocode
.
FieldNotes
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
NotesCleared
()
{
_spec
.
ClearField
(
promocode
.
FieldNotes
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
UsageRecordsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedUsageRecordsIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
UsageRecordsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
UsageRecordsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
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
{
promocode
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
0
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
// PromoCodeUpdateOne is the builder for updating a single PromoCode entity.
type
PromoCodeUpdateOne
struct
{
config
fields
[]
string
hooks
[]
Hook
mutation
*
PromoCodeMutation
}
// SetCode sets the "code" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetCode
(
v
string
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
SetCode
(
v
)
return
_u
}
// SetNillableCode sets the "code" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableCode
(
v
*
string
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetCode
(
*
v
)
}
return
_u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
ResetBonusAmount
()
_u
.
mutation
.
SetBonusAmount
(
v
)
return
_u
}
// SetNillableBonusAmount sets the "bonus_amount" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableBonusAmount
(
v
*
float64
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetBonusAmount
(
*
v
)
}
return
_u
}
// AddBonusAmount adds value to the "bonus_amount" field.
func
(
_u
*
PromoCodeUpdateOne
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
AddBonusAmount
(
v
)
return
_u
}
// SetMaxUses sets the "max_uses" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetMaxUses
(
v
int
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
ResetMaxUses
()
_u
.
mutation
.
SetMaxUses
(
v
)
return
_u
}
// SetNillableMaxUses sets the "max_uses" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableMaxUses
(
v
*
int
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetMaxUses
(
*
v
)
}
return
_u
}
// AddMaxUses adds value to the "max_uses" field.
func
(
_u
*
PromoCodeUpdateOne
)
AddMaxUses
(
v
int
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
AddMaxUses
(
v
)
return
_u
}
// SetUsedCount sets the "used_count" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetUsedCount
(
v
int
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
ResetUsedCount
()
_u
.
mutation
.
SetUsedCount
(
v
)
return
_u
}
// SetNillableUsedCount sets the "used_count" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableUsedCount
(
v
*
int
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetUsedCount
(
*
v
)
}
return
_u
}
// AddUsedCount adds value to the "used_count" field.
func
(
_u
*
PromoCodeUpdateOne
)
AddUsedCount
(
v
int
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
AddUsedCount
(
v
)
return
_u
}
// SetStatus sets the "status" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetStatus
(
v
string
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
SetStatus
(
v
)
return
_u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableStatus
(
v
*
string
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetStatus
(
*
v
)
}
return
_u
}
// SetExpiresAt sets the "expires_at" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
SetExpiresAt
(
v
)
return
_u
}
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableExpiresAt
(
v
*
time
.
Time
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetExpiresAt
(
*
v
)
}
return
_u
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
_u
*
PromoCodeUpdateOne
)
ClearExpiresAt
()
*
PromoCodeUpdateOne
{
_u
.
mutation
.
ClearExpiresAt
()
return
_u
}
// SetNotes sets the "notes" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetNotes
(
v
string
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
SetNotes
(
v
)
return
_u
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func
(
_u
*
PromoCodeUpdateOne
)
SetNillableNotes
(
v
*
string
)
*
PromoCodeUpdateOne
{
if
v
!=
nil
{
_u
.
SetNotes
(
*
v
)
}
return
_u
}
// ClearNotes clears the value of the "notes" field.
func
(
_u
*
PromoCodeUpdateOne
)
ClearNotes
()
*
PromoCodeUpdateOne
{
_u
.
mutation
.
ClearNotes
()
return
_u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
PromoCodeUpdateOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by IDs.
func
(
_u
*
PromoCodeUpdateOne
)
AddUsageRecordIDs
(
ids
...
int64
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
AddUsageRecordIDs
(
ids
...
)
return
_u
}
// AddUsageRecords adds the "usage_records" edges to the PromoCodeUsage entity.
func
(
_u
*
PromoCodeUpdateOne
)
AddUsageRecords
(
v
...*
PromoCodeUsage
)
*
PromoCodeUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddUsageRecordIDs
(
ids
...
)
}
// Mutation returns the PromoCodeMutation object of the builder.
func
(
_u
*
PromoCodeUpdateOne
)
Mutation
()
*
PromoCodeMutation
{
return
_u
.
mutation
}
// ClearUsageRecords clears all "usage_records" edges to the PromoCodeUsage entity.
func
(
_u
*
PromoCodeUpdateOne
)
ClearUsageRecords
()
*
PromoCodeUpdateOne
{
_u
.
mutation
.
ClearUsageRecords
()
return
_u
}
// RemoveUsageRecordIDs removes the "usage_records" edge to PromoCodeUsage entities by IDs.
func
(
_u
*
PromoCodeUpdateOne
)
RemoveUsageRecordIDs
(
ids
...
int64
)
*
PromoCodeUpdateOne
{
_u
.
mutation
.
RemoveUsageRecordIDs
(
ids
...
)
return
_u
}
// RemoveUsageRecords removes "usage_records" edges to PromoCodeUsage entities.
func
(
_u
*
PromoCodeUpdateOne
)
RemoveUsageRecords
(
v
...*
PromoCodeUsage
)
*
PromoCodeUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemoveUsageRecordIDs
(
ids
...
)
}
// Where appends a list predicates to the PromoCodeUpdate builder.
func
(
_u
*
PromoCodeUpdateOne
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeUpdateOne
{
_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
*
PromoCodeUpdateOne
)
Select
(
field
string
,
fields
...
string
)
*
PromoCodeUpdateOne
{
_u
.
fields
=
append
([]
string
{
field
},
fields
...
)
return
_u
}
// Save executes the query and returns the updated PromoCode entity.
func
(
_u
*
PromoCodeUpdateOne
)
Save
(
ctx
context
.
Context
)
(
*
PromoCode
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
PromoCodeUpdateOne
)
SaveX
(
ctx
context
.
Context
)
*
PromoCode
{
node
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// Exec executes the query on the entity.
func
(
_u
*
PromoCodeUpdateOne
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
PromoCodeUpdateOne
)
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
*
PromoCodeUpdateOne
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
promocode
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
PromoCodeUpdateOne
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Code
();
ok
{
if
err
:=
promocode
.
CodeValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"code"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.code": %w`
,
err
)}
}
}
if
v
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
if
err
:=
promocode
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.status": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
PromoCodeUpdateOne
)
sqlSave
(
ctx
context
.
Context
)
(
_node
*
PromoCode
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
promocode
.
Table
,
promocode
.
Columns
,
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
))
id
,
ok
:=
_u
.
mutation
.
ID
()
if
!
ok
{
return
nil
,
&
ValidationError
{
Name
:
"id"
,
err
:
errors
.
New
(
`ent: missing "PromoCode.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
,
promocode
.
FieldID
)
for
_
,
f
:=
range
fields
{
if
!
promocode
.
ValidColumn
(
f
)
{
return
nil
,
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
if
f
!=
promocode
.
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
(
promocode
.
FieldCode
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedBonusAmount
();
ok
{
_spec
.
AddField
(
promocode
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
MaxUses
();
ok
{
_spec
.
SetField
(
promocode
.
FieldMaxUses
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedMaxUses
();
ok
{
_spec
.
AddField
(
promocode
.
FieldMaxUses
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
UsedCount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUsedCount
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedUsedCount
();
ok
{
_spec
.
AddField
(
promocode
.
FieldUsedCount
,
field
.
TypeInt
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
promocode
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ExpiresAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldExpiresAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
ExpiresAtCleared
()
{
_spec
.
ClearField
(
promocode
.
FieldExpiresAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
promocode
.
FieldNotes
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
NotesCleared
()
{
_spec
.
ClearField
(
promocode
.
FieldNotes
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
UsageRecordsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedUsageRecordsIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
UsageRecordsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
UsageRecordsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
_node
=
&
PromoCode
{
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
{
promocode
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
backend/ent/promocodeusage.go
0 → 100644
View file @
1a641392
// 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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// PromoCodeUsage is the model entity for the PromoCodeUsage schema.
type
PromoCodeUsage
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// 优惠码ID
PromoCodeID
int64
`json:"promo_code_id,omitempty"`
// 使用用户ID
UserID
int64
`json:"user_id,omitempty"`
// 实际赠送金额
BonusAmount
float64
`json:"bonus_amount,omitempty"`
// 使用时间
UsedAt
time
.
Time
`json:"used_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PromoCodeUsageQuery when eager-loading is set.
Edges
PromoCodeUsageEdges
`json:"edges"`
selectValues
sql
.
SelectValues
}
// PromoCodeUsageEdges holds the relations/edges for other nodes in the graph.
type
PromoCodeUsageEdges
struct
{
// PromoCode holds the value of the promo_code edge.
PromoCode
*
PromoCode
`json:"promo_code,omitempty"`
// User holds the value of the user edge.
User
*
User
`json:"user,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes
[
2
]
bool
}
// PromoCodeOrErr returns the PromoCode value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func
(
e
PromoCodeUsageEdges
)
PromoCodeOrErr
()
(
*
PromoCode
,
error
)
{
if
e
.
PromoCode
!=
nil
{
return
e
.
PromoCode
,
nil
}
else
if
e
.
loadedTypes
[
0
]
{
return
nil
,
&
NotFoundError
{
label
:
promocode
.
Label
}
}
return
nil
,
&
NotLoadedError
{
edge
:
"promo_code"
}
}
// 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
PromoCodeUsageEdges
)
UserOrErr
()
(
*
User
,
error
)
{
if
e
.
User
!=
nil
{
return
e
.
User
,
nil
}
else
if
e
.
loadedTypes
[
1
]
{
return
nil
,
&
NotFoundError
{
label
:
user
.
Label
}
}
return
nil
,
&
NotLoadedError
{
edge
:
"user"
}
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
PromoCodeUsage
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
promocodeusage
.
FieldBonusAmount
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
promocodeusage
.
FieldID
,
promocodeusage
.
FieldPromoCodeID
,
promocodeusage
.
FieldUserID
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
promocodeusage
.
FieldUsedAt
:
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 PromoCodeUsage fields.
func
(
_m
*
PromoCodeUsage
)
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
promocodeusage
.
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
promocodeusage
.
FieldPromoCodeID
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field promo_code_id"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
PromoCodeID
=
value
.
Int64
}
case
promocodeusage
.
FieldUserID
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field user_id"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UserID
=
value
.
Int64
}
case
promocodeusage
.
FieldBonusAmount
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullFloat64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field bonus_amount"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
BonusAmount
=
value
.
Float64
}
case
promocodeusage
.
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
=
value
.
Time
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
}
return
nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the PromoCodeUsage.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
PromoCodeUsage
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// QueryPromoCode queries the "promo_code" edge of the PromoCodeUsage entity.
func
(
_m
*
PromoCodeUsage
)
QueryPromoCode
()
*
PromoCodeQuery
{
return
NewPromoCodeUsageClient
(
_m
.
config
)
.
QueryPromoCode
(
_m
)
}
// QueryUser queries the "user" edge of the PromoCodeUsage entity.
func
(
_m
*
PromoCodeUsage
)
QueryUser
()
*
UserQuery
{
return
NewPromoCodeUsageClient
(
_m
.
config
)
.
QueryUser
(
_m
)
}
// Update returns a builder for updating this PromoCodeUsage.
// Note that you need to call PromoCodeUsage.Unwrap() before calling this method if this PromoCodeUsage
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
PromoCodeUsage
)
Update
()
*
PromoCodeUsageUpdateOne
{
return
NewPromoCodeUsageClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the PromoCodeUsage 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
*
PromoCodeUsage
)
Unwrap
()
*
PromoCodeUsage
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: PromoCodeUsage is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
PromoCodeUsage
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"PromoCodeUsage("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"promo_code_id="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
PromoCodeID
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"user_id="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
UserID
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"bonus_amount="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
BonusAmount
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"used_at="
)
builder
.
WriteString
(
_m
.
UsedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// PromoCodeUsages is a parsable slice of PromoCodeUsage.
type
PromoCodeUsages
[]
*
PromoCodeUsage
backend/ent/promocodeusage/promocodeusage.go
0 → 100644
View file @
1a641392
// Code generated by ent, DO NOT EDIT.
package
promocodeusage
import
(
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const
(
// Label holds the string label denoting the promocodeusage type in the database.
Label
=
"promo_code_usage"
// FieldID holds the string denoting the id field in the database.
FieldID
=
"id"
// FieldPromoCodeID holds the string denoting the promo_code_id field in the database.
FieldPromoCodeID
=
"promo_code_id"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID
=
"user_id"
// FieldBonusAmount holds the string denoting the bonus_amount field in the database.
FieldBonusAmount
=
"bonus_amount"
// FieldUsedAt holds the string denoting the used_at field in the database.
FieldUsedAt
=
"used_at"
// EdgePromoCode holds the string denoting the promo_code edge name in mutations.
EdgePromoCode
=
"promo_code"
// EdgeUser holds the string denoting the user edge name in mutations.
EdgeUser
=
"user"
// Table holds the table name of the promocodeusage in the database.
Table
=
"promo_code_usages"
// PromoCodeTable is the table that holds the promo_code relation/edge.
PromoCodeTable
=
"promo_code_usages"
// PromoCodeInverseTable is the table name for the PromoCode entity.
// It exists in this package in order to avoid circular dependency with the "promocode" package.
PromoCodeInverseTable
=
"promo_codes"
// PromoCodeColumn is the table column denoting the promo_code relation/edge.
PromoCodeColumn
=
"promo_code_id"
// UserTable is the table that holds the user relation/edge.
UserTable
=
"promo_code_usages"
// 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
=
"user_id"
)
// Columns holds all SQL columns for promocodeusage fields.
var
Columns
=
[]
string
{
FieldID
,
FieldPromoCodeID
,
FieldUserID
,
FieldBonusAmount
,
FieldUsedAt
,
}
// 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
(
// DefaultUsedAt holds the default value on creation for the "used_at" field.
DefaultUsedAt
func
()
time
.
Time
)
// OrderOption defines the ordering options for the PromoCodeUsage 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
()
}
// ByPromoCodeID orders the results by the promo_code_id field.
func
ByPromoCodeID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldPromoCodeID
,
opts
...
)
.
ToFunc
()
}
// ByUserID orders the results by the user_id field.
func
ByUserID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUserID
,
opts
...
)
.
ToFunc
()
}
// ByBonusAmount orders the results by the bonus_amount field.
func
ByBonusAmount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldBonusAmount
,
opts
...
)
.
ToFunc
()
}
// ByUsedAt orders the results by the used_at field.
func
ByUsedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUsedAt
,
opts
...
)
.
ToFunc
()
}
// ByPromoCodeField orders the results by promo_code field.
func
ByPromoCodeField
(
field
string
,
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborTerms
(
s
,
newPromoCodeStep
(),
sql
.
OrderByField
(
field
,
opts
...
))
}
}
// 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
...
))
}
}
func
newPromoCodeStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
PromoCodeInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
PromoCodeTable
,
PromoCodeColumn
),
)
}
func
newUserStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
UserInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
UserTable
,
UserColumn
),
)
}
backend/ent/promocodeusage/where.go
0 → 100644
View file @
1a641392
// Code generated by ent, DO NOT EDIT.
package
promocodeusage
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
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// PromoCodeID applies equality check predicate on the "promo_code_id" field. It's identical to PromoCodeIDEQ.
func
PromoCodeID
(
v
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldPromoCodeID
,
v
))
}
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
func
UserID
(
v
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldUserID
,
v
))
}
// BonusAmount applies equality check predicate on the "bonus_amount" field. It's identical to BonusAmountEQ.
func
BonusAmount
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldBonusAmount
,
v
))
}
// UsedAt applies equality check predicate on the "used_at" field. It's identical to UsedAtEQ.
func
UsedAt
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldUsedAt
,
v
))
}
// PromoCodeIDEQ applies the EQ predicate on the "promo_code_id" field.
func
PromoCodeIDEQ
(
v
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldPromoCodeID
,
v
))
}
// PromoCodeIDNEQ applies the NEQ predicate on the "promo_code_id" field.
func
PromoCodeIDNEQ
(
v
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNEQ
(
FieldPromoCodeID
,
v
))
}
// PromoCodeIDIn applies the In predicate on the "promo_code_id" field.
func
PromoCodeIDIn
(
vs
...
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldIn
(
FieldPromoCodeID
,
vs
...
))
}
// PromoCodeIDNotIn applies the NotIn predicate on the "promo_code_id" field.
func
PromoCodeIDNotIn
(
vs
...
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNotIn
(
FieldPromoCodeID
,
vs
...
))
}
// UserIDEQ applies the EQ predicate on the "user_id" field.
func
UserIDEQ
(
v
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldUserID
,
v
))
}
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
func
UserIDNEQ
(
v
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNEQ
(
FieldUserID
,
v
))
}
// UserIDIn applies the In predicate on the "user_id" field.
func
UserIDIn
(
vs
...
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldIn
(
FieldUserID
,
vs
...
))
}
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
func
UserIDNotIn
(
vs
...
int64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNotIn
(
FieldUserID
,
vs
...
))
}
// BonusAmountEQ applies the EQ predicate on the "bonus_amount" field.
func
BonusAmountEQ
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldBonusAmount
,
v
))
}
// BonusAmountNEQ applies the NEQ predicate on the "bonus_amount" field.
func
BonusAmountNEQ
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNEQ
(
FieldBonusAmount
,
v
))
}
// BonusAmountIn applies the In predicate on the "bonus_amount" field.
func
BonusAmountIn
(
vs
...
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldIn
(
FieldBonusAmount
,
vs
...
))
}
// BonusAmountNotIn applies the NotIn predicate on the "bonus_amount" field.
func
BonusAmountNotIn
(
vs
...
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNotIn
(
FieldBonusAmount
,
vs
...
))
}
// BonusAmountGT applies the GT predicate on the "bonus_amount" field.
func
BonusAmountGT
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldGT
(
FieldBonusAmount
,
v
))
}
// BonusAmountGTE applies the GTE predicate on the "bonus_amount" field.
func
BonusAmountGTE
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldGTE
(
FieldBonusAmount
,
v
))
}
// BonusAmountLT applies the LT predicate on the "bonus_amount" field.
func
BonusAmountLT
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldLT
(
FieldBonusAmount
,
v
))
}
// BonusAmountLTE applies the LTE predicate on the "bonus_amount" field.
func
BonusAmountLTE
(
v
float64
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldLTE
(
FieldBonusAmount
,
v
))
}
// UsedAtEQ applies the EQ predicate on the "used_at" field.
func
UsedAtEQ
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldEQ
(
FieldUsedAt
,
v
))
}
// UsedAtNEQ applies the NEQ predicate on the "used_at" field.
func
UsedAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNEQ
(
FieldUsedAt
,
v
))
}
// UsedAtIn applies the In predicate on the "used_at" field.
func
UsedAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldIn
(
FieldUsedAt
,
vs
...
))
}
// UsedAtNotIn applies the NotIn predicate on the "used_at" field.
func
UsedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldNotIn
(
FieldUsedAt
,
vs
...
))
}
// UsedAtGT applies the GT predicate on the "used_at" field.
func
UsedAtGT
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldGT
(
FieldUsedAt
,
v
))
}
// UsedAtGTE applies the GTE predicate on the "used_at" field.
func
UsedAtGTE
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldGTE
(
FieldUsedAt
,
v
))
}
// UsedAtLT applies the LT predicate on the "used_at" field.
func
UsedAtLT
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldLT
(
FieldUsedAt
,
v
))
}
// UsedAtLTE applies the LTE predicate on the "used_at" field.
func
UsedAtLTE
(
v
time
.
Time
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
FieldLTE
(
FieldUsedAt
,
v
))
}
// HasPromoCode applies the HasEdge predicate on the "promo_code" edge.
func
HasPromoCode
()
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
func
(
s
*
sql
.
Selector
)
{
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
PromoCodeTable
,
PromoCodeColumn
),
)
sqlgraph
.
HasNeighbors
(
s
,
step
)
})
}
// HasPromoCodeWith applies the HasEdge predicate on the "promo_code" edge with a given conditions (other predicates).
func
HasPromoCodeWith
(
preds
...
predicate
.
PromoCode
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newPromoCodeStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
for
_
,
p
:=
range
preds
{
p
(
s
)
}
})
})
}
// HasUser applies the HasEdge predicate on the "user" edge.
func
HasUser
()
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
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
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newUserStep
()
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
.
PromoCodeUsage
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
PromoCodeUsage
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
PromoCodeUsage
)
predicate
.
PromoCodeUsage
{
return
predicate
.
PromoCodeUsage
(
sql
.
NotPredicates
(
p
))
}
backend/ent/promocodeusage_create.go
0 → 100644
View file @
1a641392
// 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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// PromoCodeUsageCreate is the builder for creating a PromoCodeUsage entity.
type
PromoCodeUsageCreate
struct
{
config
mutation
*
PromoCodeUsageMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetPromoCodeID sets the "promo_code_id" field.
func
(
_c
*
PromoCodeUsageCreate
)
SetPromoCodeID
(
v
int64
)
*
PromoCodeUsageCreate
{
_c
.
mutation
.
SetPromoCodeID
(
v
)
return
_c
}
// SetUserID sets the "user_id" field.
func
(
_c
*
PromoCodeUsageCreate
)
SetUserID
(
v
int64
)
*
PromoCodeUsageCreate
{
_c
.
mutation
.
SetUserID
(
v
)
return
_c
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_c
*
PromoCodeUsageCreate
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUsageCreate
{
_c
.
mutation
.
SetBonusAmount
(
v
)
return
_c
}
// SetUsedAt sets the "used_at" field.
func
(
_c
*
PromoCodeUsageCreate
)
SetUsedAt
(
v
time
.
Time
)
*
PromoCodeUsageCreate
{
_c
.
mutation
.
SetUsedAt
(
v
)
return
_c
}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.
func
(
_c
*
PromoCodeUsageCreate
)
SetNillableUsedAt
(
v
*
time
.
Time
)
*
PromoCodeUsageCreate
{
if
v
!=
nil
{
_c
.
SetUsedAt
(
*
v
)
}
return
_c
}
// SetPromoCode sets the "promo_code" edge to the PromoCode entity.
func
(
_c
*
PromoCodeUsageCreate
)
SetPromoCode
(
v
*
PromoCode
)
*
PromoCodeUsageCreate
{
return
_c
.
SetPromoCodeID
(
v
.
ID
)
}
// SetUser sets the "user" edge to the User entity.
func
(
_c
*
PromoCodeUsageCreate
)
SetUser
(
v
*
User
)
*
PromoCodeUsageCreate
{
return
_c
.
SetUserID
(
v
.
ID
)
}
// Mutation returns the PromoCodeUsageMutation object of the builder.
func
(
_c
*
PromoCodeUsageCreate
)
Mutation
()
*
PromoCodeUsageMutation
{
return
_c
.
mutation
}
// Save creates the PromoCodeUsage in the database.
func
(
_c
*
PromoCodeUsageCreate
)
Save
(
ctx
context
.
Context
)
(
*
PromoCodeUsage
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
PromoCodeUsageCreate
)
SaveX
(
ctx
context
.
Context
)
*
PromoCodeUsage
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
PromoCodeUsageCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
PromoCodeUsageCreate
)
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
*
PromoCodeUsageCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
UsedAt
();
!
ok
{
v
:=
promocodeusage
.
DefaultUsedAt
()
_c
.
mutation
.
SetUsedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
PromoCodeUsageCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
PromoCodeID
();
!
ok
{
return
&
ValidationError
{
Name
:
"promo_code_id"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCodeUsage.promo_code_id"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UserID
();
!
ok
{
return
&
ValidationError
{
Name
:
"user_id"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCodeUsage.user_id"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
BonusAmount
();
!
ok
{
return
&
ValidationError
{
Name
:
"bonus_amount"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCodeUsage.bonus_amount"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UsedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"used_at"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCodeUsage.used_at"`
)}
}
if
len
(
_c
.
mutation
.
PromoCodeIDs
())
==
0
{
return
&
ValidationError
{
Name
:
"promo_code"
,
err
:
errors
.
New
(
`ent: missing required edge "PromoCodeUsage.promo_code"`
)}
}
if
len
(
_c
.
mutation
.
UserIDs
())
==
0
{
return
&
ValidationError
{
Name
:
"user"
,
err
:
errors
.
New
(
`ent: missing required edge "PromoCodeUsage.user"`
)}
}
return
nil
}
func
(
_c
*
PromoCodeUsageCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
PromoCodeUsage
,
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
*
PromoCodeUsageCreate
)
createSpec
()
(
*
PromoCodeUsage
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
PromoCodeUsage
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
promocodeusage
.
Table
,
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocodeusage
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
_node
.
BonusAmount
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UsedAt
();
ok
{
_spec
.
SetField
(
promocodeusage
.
FieldUsedAt
,
field
.
TypeTime
,
value
)
_node
.
UsedAt
=
value
}
if
nodes
:=
_c
.
mutation
.
PromoCodeIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
PromoCodeTable
,
Columns
:
[]
string
{
promocodeusage
.
PromoCodeColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_node
.
PromoCodeID
=
nodes
[
0
]
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
if
nodes
:=
_c
.
mutation
.
UserIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
UserTable
,
Columns
:
[]
string
{
promocodeusage
.
UserColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
user
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_node
.
UserID
=
nodes
[
0
]
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.PromoCodeUsage.Create().
// SetPromoCodeID(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.PromoCodeUsageUpsert) {
// SetPromoCodeID(v+v).
// }).
// Exec(ctx)
func
(
_c
*
PromoCodeUsageCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
PromoCodeUsageUpsertOne
{
_c
.
conflict
=
opts
return
&
PromoCodeUsageUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.PromoCodeUsage.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
PromoCodeUsageCreate
)
OnConflictColumns
(
columns
...
string
)
*
PromoCodeUsageUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
PromoCodeUsageUpsertOne
{
create
:
_c
,
}
}
type
(
// PromoCodeUsageUpsertOne is the builder for "upsert"-ing
// one PromoCodeUsage node.
PromoCodeUsageUpsertOne
struct
{
create
*
PromoCodeUsageCreate
}
// PromoCodeUsageUpsert is the "OnConflict" setter.
PromoCodeUsageUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetPromoCodeID sets the "promo_code_id" field.
func
(
u
*
PromoCodeUsageUpsert
)
SetPromoCodeID
(
v
int64
)
*
PromoCodeUsageUpsert
{
u
.
Set
(
promocodeusage
.
FieldPromoCodeID
,
v
)
return
u
}
// UpdatePromoCodeID sets the "promo_code_id" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsert
)
UpdatePromoCodeID
()
*
PromoCodeUsageUpsert
{
u
.
SetExcluded
(
promocodeusage
.
FieldPromoCodeID
)
return
u
}
// SetUserID sets the "user_id" field.
func
(
u
*
PromoCodeUsageUpsert
)
SetUserID
(
v
int64
)
*
PromoCodeUsageUpsert
{
u
.
Set
(
promocodeusage
.
FieldUserID
,
v
)
return
u
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsert
)
UpdateUserID
()
*
PromoCodeUsageUpsert
{
u
.
SetExcluded
(
promocodeusage
.
FieldUserID
)
return
u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUsageUpsert
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUsageUpsert
{
u
.
Set
(
promocodeusage
.
FieldBonusAmount
,
v
)
return
u
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsert
)
UpdateBonusAmount
()
*
PromoCodeUsageUpsert
{
u
.
SetExcluded
(
promocodeusage
.
FieldBonusAmount
)
return
u
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUsageUpsert
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUsageUpsert
{
u
.
Add
(
promocodeusage
.
FieldBonusAmount
,
v
)
return
u
}
// SetUsedAt sets the "used_at" field.
func
(
u
*
PromoCodeUsageUpsert
)
SetUsedAt
(
v
time
.
Time
)
*
PromoCodeUsageUpsert
{
u
.
Set
(
promocodeusage
.
FieldUsedAt
,
v
)
return
u
}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsert
)
UpdateUsedAt
()
*
PromoCodeUsageUpsert
{
u
.
SetExcluded
(
promocodeusage
.
FieldUsedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.PromoCodeUsage.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
PromoCodeUsageUpsertOne
)
UpdateNewValues
()
*
PromoCodeUsageUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.PromoCodeUsage.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
PromoCodeUsageUpsertOne
)
Ignore
()
*
PromoCodeUsageUpsertOne
{
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
*
PromoCodeUsageUpsertOne
)
DoNothing
()
*
PromoCodeUsageUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the PromoCodeUsageCreate.OnConflict
// documentation for more info.
func
(
u
*
PromoCodeUsageUpsertOne
)
Update
(
set
func
(
*
PromoCodeUsageUpsert
))
*
PromoCodeUsageUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
PromoCodeUsageUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetPromoCodeID sets the "promo_code_id" field.
func
(
u
*
PromoCodeUsageUpsertOne
)
SetPromoCodeID
(
v
int64
)
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetPromoCodeID
(
v
)
})
}
// UpdatePromoCodeID sets the "promo_code_id" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertOne
)
UpdatePromoCodeID
()
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdatePromoCodeID
()
})
}
// SetUserID sets the "user_id" field.
func
(
u
*
PromoCodeUsageUpsertOne
)
SetUserID
(
v
int64
)
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetUserID
(
v
)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertOne
)
UpdateUserID
()
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdateUserID
()
})
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUsageUpsertOne
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetBonusAmount
(
v
)
})
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUsageUpsertOne
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
AddBonusAmount
(
v
)
})
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertOne
)
UpdateBonusAmount
()
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdateBonusAmount
()
})
}
// SetUsedAt sets the "used_at" field.
func
(
u
*
PromoCodeUsageUpsertOne
)
SetUsedAt
(
v
time
.
Time
)
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetUsedAt
(
v
)
})
}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertOne
)
UpdateUsedAt
()
*
PromoCodeUsageUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdateUsedAt
()
})
}
// Exec executes the query.
func
(
u
*
PromoCodeUsageUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for PromoCodeUsageCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
PromoCodeUsageUpsertOne
)
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
*
PromoCodeUsageUpsertOne
)
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
*
PromoCodeUsageUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// PromoCodeUsageCreateBulk is the builder for creating many PromoCodeUsage entities in bulk.
type
PromoCodeUsageCreateBulk
struct
{
config
err
error
builders
[]
*
PromoCodeUsageCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the PromoCodeUsage entities in the database.
func
(
_c
*
PromoCodeUsageCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
PromoCodeUsage
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
PromoCodeUsage
,
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
.
(
*
PromoCodeUsageMutation
)
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
*
PromoCodeUsageCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
PromoCodeUsage
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
PromoCodeUsageCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
PromoCodeUsageCreateBulk
)
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.PromoCodeUsage.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.PromoCodeUsageUpsert) {
// SetPromoCodeID(v+v).
// }).
// Exec(ctx)
func
(
_c
*
PromoCodeUsageCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
PromoCodeUsageUpsertBulk
{
_c
.
conflict
=
opts
return
&
PromoCodeUsageUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.PromoCodeUsage.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
PromoCodeUsageCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
PromoCodeUsageUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
PromoCodeUsageUpsertBulk
{
create
:
_c
,
}
}
// PromoCodeUsageUpsertBulk is the builder for "upsert"-ing
// a bulk of PromoCodeUsage nodes.
type
PromoCodeUsageUpsertBulk
struct
{
create
*
PromoCodeUsageCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.PromoCodeUsage.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
PromoCodeUsageUpsertBulk
)
UpdateNewValues
()
*
PromoCodeUsageUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.PromoCodeUsage.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
PromoCodeUsageUpsertBulk
)
Ignore
()
*
PromoCodeUsageUpsertBulk
{
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
*
PromoCodeUsageUpsertBulk
)
DoNothing
()
*
PromoCodeUsageUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the PromoCodeUsageCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
PromoCodeUsageUpsertBulk
)
Update
(
set
func
(
*
PromoCodeUsageUpsert
))
*
PromoCodeUsageUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
PromoCodeUsageUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetPromoCodeID sets the "promo_code_id" field.
func
(
u
*
PromoCodeUsageUpsertBulk
)
SetPromoCodeID
(
v
int64
)
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetPromoCodeID
(
v
)
})
}
// UpdatePromoCodeID sets the "promo_code_id" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertBulk
)
UpdatePromoCodeID
()
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdatePromoCodeID
()
})
}
// SetUserID sets the "user_id" field.
func
(
u
*
PromoCodeUsageUpsertBulk
)
SetUserID
(
v
int64
)
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetUserID
(
v
)
})
}
// UpdateUserID sets the "user_id" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertBulk
)
UpdateUserID
()
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdateUserID
()
})
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUsageUpsertBulk
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetBonusAmount
(
v
)
})
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUsageUpsertBulk
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
AddBonusAmount
(
v
)
})
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertBulk
)
UpdateBonusAmount
()
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdateBonusAmount
()
})
}
// SetUsedAt sets the "used_at" field.
func
(
u
*
PromoCodeUsageUpsertBulk
)
SetUsedAt
(
v
time
.
Time
)
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
SetUsedAt
(
v
)
})
}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUsageUpsertBulk
)
UpdateUsedAt
()
*
PromoCodeUsageUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUsageUpsert
)
{
s
.
UpdateUsedAt
()
})
}
// Exec executes the query.
func
(
u
*
PromoCodeUsageUpsertBulk
)
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 PromoCodeUsageCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for PromoCodeUsageCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
PromoCodeUsageUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/promocodeusage_delete.go
0 → 100644
View file @
1a641392
// 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/promocodeusage"
)
// PromoCodeUsageDelete is the builder for deleting a PromoCodeUsage entity.
type
PromoCodeUsageDelete
struct
{
config
hooks
[]
Hook
mutation
*
PromoCodeUsageMutation
}
// Where appends a list predicates to the PromoCodeUsageDelete builder.
func
(
_d
*
PromoCodeUsageDelete
)
Where
(
ps
...
predicate
.
PromoCodeUsage
)
*
PromoCodeUsageDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
PromoCodeUsageDelete
)
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
*
PromoCodeUsageDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
PromoCodeUsageDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
promocodeusage
.
Table
,
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
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
}
// PromoCodeUsageDeleteOne is the builder for deleting a single PromoCodeUsage entity.
type
PromoCodeUsageDeleteOne
struct
{
_d
*
PromoCodeUsageDelete
}
// Where appends a list predicates to the PromoCodeUsageDelete builder.
func
(
_d
*
PromoCodeUsageDeleteOne
)
Where
(
ps
...
predicate
.
PromoCodeUsage
)
*
PromoCodeUsageDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
PromoCodeUsageDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
promocodeusage
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
PromoCodeUsageDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/promocodeusage_query.go
0 → 100644
View file @
1a641392
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// PromoCodeUsageQuery is the builder for querying PromoCodeUsage entities.
type
PromoCodeUsageQuery
struct
{
config
ctx
*
QueryContext
order
[]
promocodeusage
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
PromoCodeUsage
withPromoCode
*
PromoCodeQuery
withUser
*
UserQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the PromoCodeUsageQuery builder.
func
(
_q
*
PromoCodeUsageQuery
)
Where
(
ps
...
predicate
.
PromoCodeUsage
)
*
PromoCodeUsageQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
PromoCodeUsageQuery
)
Limit
(
limit
int
)
*
PromoCodeUsageQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
PromoCodeUsageQuery
)
Offset
(
offset
int
)
*
PromoCodeUsageQuery
{
_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
*
PromoCodeUsageQuery
)
Unique
(
unique
bool
)
*
PromoCodeUsageQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
PromoCodeUsageQuery
)
Order
(
o
...
promocodeusage
.
OrderOption
)
*
PromoCodeUsageQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// QueryPromoCode chains the current query on the "promo_code" edge.
func
(
_q
*
PromoCodeUsageQuery
)
QueryPromoCode
()
*
PromoCodeQuery
{
query
:=
(
&
PromoCodeClient
{
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
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
,
selector
),
sqlgraph
.
To
(
promocode
.
Table
,
promocode
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
promocodeusage
.
PromoCodeTable
,
promocodeusage
.
PromoCodeColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// QueryUser chains the current query on the "user" edge.
func
(
_q
*
PromoCodeUsageQuery
)
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
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
,
selector
),
sqlgraph
.
To
(
user
.
Table
,
user
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
promocodeusage
.
UserTable
,
promocodeusage
.
UserColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// First returns the first PromoCodeUsage entity from the query.
// Returns a *NotFoundError when no PromoCodeUsage was found.
func
(
_q
*
PromoCodeUsageQuery
)
First
(
ctx
context
.
Context
)
(
*
PromoCodeUsage
,
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
{
promocodeusage
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
FirstX
(
ctx
context
.
Context
)
*
PromoCodeUsage
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first PromoCodeUsage ID from the query.
// Returns a *NotFoundError when no PromoCodeUsage ID was found.
func
(
_q
*
PromoCodeUsageQuery
)
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
{
promocodeusage
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single PromoCodeUsage entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one PromoCodeUsage entity is found.
// Returns a *NotFoundError when no PromoCodeUsage entities are found.
func
(
_q
*
PromoCodeUsageQuery
)
Only
(
ctx
context
.
Context
)
(
*
PromoCodeUsage
,
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
{
promocodeusage
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
promocodeusage
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
OnlyX
(
ctx
context
.
Context
)
*
PromoCodeUsage
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only PromoCodeUsage ID in the query.
// Returns a *NotSingularError when more than one PromoCodeUsage ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
PromoCodeUsageQuery
)
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
{
promocodeusage
.
Label
}
default
:
err
=
&
NotSingularError
{
promocodeusage
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
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 PromoCodeUsages.
func
(
_q
*
PromoCodeUsageQuery
)
All
(
ctx
context
.
Context
)
([]
*
PromoCodeUsage
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
PromoCodeUsage
,
*
PromoCodeUsageQuery
]()
return
withInterceptors
[[]
*
PromoCodeUsage
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
PromoCodeUsage
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of PromoCodeUsage IDs.
func
(
_q
*
PromoCodeUsageQuery
)
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
(
promocodeusage
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
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
*
PromoCodeUsageQuery
)
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
[
*
PromoCodeUsageQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
PromoCodeUsageQuery
)
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
*
PromoCodeUsageQuery
)
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
*
PromoCodeUsageQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the PromoCodeUsageQuery 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
*
PromoCodeUsageQuery
)
Clone
()
*
PromoCodeUsageQuery
{
if
_q
==
nil
{
return
nil
}
return
&
PromoCodeUsageQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
promocodeusage
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
PromoCodeUsage
{},
_q
.
predicates
...
),
withPromoCode
:
_q
.
withPromoCode
.
Clone
(),
withUser
:
_q
.
withUser
.
Clone
(),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// WithPromoCode tells the query-builder to eager-load the nodes that are connected to
// the "promo_code" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
PromoCodeUsageQuery
)
WithPromoCode
(
opts
...
func
(
*
PromoCodeQuery
))
*
PromoCodeUsageQuery
{
query
:=
(
&
PromoCodeClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withPromoCode
=
query
return
_q
}
// 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
*
PromoCodeUsageQuery
)
WithUser
(
opts
...
func
(
*
UserQuery
))
*
PromoCodeUsageQuery
{
query
:=
(
&
UserClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withUser
=
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 {
// PromoCodeID int64 `json:"promo_code_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.PromoCodeUsage.Query().
// GroupBy(promocodeusage.FieldPromoCodeID).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
PromoCodeUsageQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
PromoCodeUsageGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
PromoCodeUsageGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
promocodeusage
.
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 {
// PromoCodeID int64 `json:"promo_code_id,omitempty"`
// }
//
// client.PromoCodeUsage.Query().
// Select(promocodeusage.FieldPromoCodeID).
// Scan(ctx, &v)
func
(
_q
*
PromoCodeUsageQuery
)
Select
(
fields
...
string
)
*
PromoCodeUsageSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
PromoCodeUsageSelect
{
PromoCodeUsageQuery
:
_q
}
sbuild
.
label
=
promocodeusage
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a PromoCodeUsageSelect configured with the given aggregations.
func
(
_q
*
PromoCodeUsageQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
PromoCodeUsageSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
PromoCodeUsageQuery
)
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
!
promocodeusage
.
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
*
PromoCodeUsageQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
PromoCodeUsage
,
error
)
{
var
(
nodes
=
[]
*
PromoCodeUsage
{}
_spec
=
_q
.
querySpec
()
loadedTypes
=
[
2
]
bool
{
_q
.
withPromoCode
!=
nil
,
_q
.
withUser
!=
nil
,
}
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
PromoCodeUsage
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
PromoCodeUsage
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
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
.
withPromoCode
;
query
!=
nil
{
if
err
:=
_q
.
loadPromoCode
(
ctx
,
query
,
nodes
,
nil
,
func
(
n
*
PromoCodeUsage
,
e
*
PromoCode
)
{
n
.
Edges
.
PromoCode
=
e
});
err
!=
nil
{
return
nil
,
err
}
}
if
query
:=
_q
.
withUser
;
query
!=
nil
{
if
err
:=
_q
.
loadUser
(
ctx
,
query
,
nodes
,
nil
,
func
(
n
*
PromoCodeUsage
,
e
*
User
)
{
n
.
Edges
.
User
=
e
});
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
func
(
_q
*
PromoCodeUsageQuery
)
loadPromoCode
(
ctx
context
.
Context
,
query
*
PromoCodeQuery
,
nodes
[]
*
PromoCodeUsage
,
init
func
(
*
PromoCodeUsage
),
assign
func
(
*
PromoCodeUsage
,
*
PromoCode
))
error
{
ids
:=
make
([]
int64
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
][]
*
PromoCodeUsage
)
for
i
:=
range
nodes
{
fk
:=
nodes
[
i
]
.
PromoCodeID
if
_
,
ok
:=
nodeids
[
fk
];
!
ok
{
ids
=
append
(
ids
,
fk
)
}
nodeids
[
fk
]
=
append
(
nodeids
[
fk
],
nodes
[
i
])
}
if
len
(
ids
)
==
0
{
return
nil
}
query
.
Where
(
promocode
.
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 "promo_code_id" returned %v`
,
n
.
ID
)
}
for
i
:=
range
nodes
{
assign
(
nodes
[
i
],
n
)
}
}
return
nil
}
func
(
_q
*
PromoCodeUsageQuery
)
loadUser
(
ctx
context
.
Context
,
query
*
UserQuery
,
nodes
[]
*
PromoCodeUsage
,
init
func
(
*
PromoCodeUsage
),
assign
func
(
*
PromoCodeUsage
,
*
User
))
error
{
ids
:=
make
([]
int64
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
][]
*
PromoCodeUsage
)
for
i
:=
range
nodes
{
fk
:=
nodes
[
i
]
.
UserID
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 "user_id" returned %v`
,
n
.
ID
)
}
for
i
:=
range
nodes
{
assign
(
nodes
[
i
],
n
)
}
}
return
nil
}
func
(
_q
*
PromoCodeUsageQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_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
*
PromoCodeUsageQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
promocodeusage
.
Table
,
promocodeusage
.
Columns
,
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
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
,
promocodeusage
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
promocodeusage
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
if
_q
.
withPromoCode
!=
nil
{
_spec
.
Node
.
AddColumnOnce
(
promocodeusage
.
FieldPromoCodeID
)
}
if
_q
.
withUser
!=
nil
{
_spec
.
Node
.
AddColumnOnce
(
promocodeusage
.
FieldUserID
)
}
}
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
*
PromoCodeUsageQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
promocodeusage
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
promocodeusage
.
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
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
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
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
PromoCodeUsageQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
PromoCodeUsageQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
PromoCodeUsageQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
PromoCodeUsageQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// PromoCodeUsageGroupBy is the group-by builder for PromoCodeUsage entities.
type
PromoCodeUsageGroupBy
struct
{
selector
build
*
PromoCodeUsageQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
PromoCodeUsageGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
PromoCodeUsageGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
PromoCodeUsageGroupBy
)
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
[
*
PromoCodeUsageQuery
,
*
PromoCodeUsageGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
PromoCodeUsageGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
PromoCodeUsageQuery
,
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
)
}
// PromoCodeUsageSelect is the builder for selecting fields of PromoCodeUsage entities.
type
PromoCodeUsageSelect
struct
{
*
PromoCodeUsageQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
PromoCodeUsageSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
PromoCodeUsageSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
PromoCodeUsageSelect
)
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
[
*
PromoCodeUsageQuery
,
*
PromoCodeUsageSelect
](
ctx
,
_s
.
PromoCodeUsageQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
PromoCodeUsageSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
PromoCodeUsageQuery
,
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
)
}
backend/ent/promocodeusage_update.go
0 → 100644
View file @
1a641392
// 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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/user"
)
// PromoCodeUsageUpdate is the builder for updating PromoCodeUsage entities.
type
PromoCodeUsageUpdate
struct
{
config
hooks
[]
Hook
mutation
*
PromoCodeUsageMutation
}
// Where appends a list predicates to the PromoCodeUsageUpdate builder.
func
(
_u
*
PromoCodeUsageUpdate
)
Where
(
ps
...
predicate
.
PromoCodeUsage
)
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// SetPromoCodeID sets the "promo_code_id" field.
func
(
_u
*
PromoCodeUsageUpdate
)
SetPromoCodeID
(
v
int64
)
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
SetPromoCodeID
(
v
)
return
_u
}
// SetNillablePromoCodeID sets the "promo_code_id" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdate
)
SetNillablePromoCodeID
(
v
*
int64
)
*
PromoCodeUsageUpdate
{
if
v
!=
nil
{
_u
.
SetPromoCodeID
(
*
v
)
}
return
_u
}
// SetUserID sets the "user_id" field.
func
(
_u
*
PromoCodeUsageUpdate
)
SetUserID
(
v
int64
)
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
SetUserID
(
v
)
return
_u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdate
)
SetNillableUserID
(
v
*
int64
)
*
PromoCodeUsageUpdate
{
if
v
!=
nil
{
_u
.
SetUserID
(
*
v
)
}
return
_u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_u
*
PromoCodeUsageUpdate
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
ResetBonusAmount
()
_u
.
mutation
.
SetBonusAmount
(
v
)
return
_u
}
// SetNillableBonusAmount sets the "bonus_amount" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdate
)
SetNillableBonusAmount
(
v
*
float64
)
*
PromoCodeUsageUpdate
{
if
v
!=
nil
{
_u
.
SetBonusAmount
(
*
v
)
}
return
_u
}
// AddBonusAmount adds value to the "bonus_amount" field.
func
(
_u
*
PromoCodeUsageUpdate
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
AddBonusAmount
(
v
)
return
_u
}
// SetUsedAt sets the "used_at" field.
func
(
_u
*
PromoCodeUsageUpdate
)
SetUsedAt
(
v
time
.
Time
)
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
SetUsedAt
(
v
)
return
_u
}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdate
)
SetNillableUsedAt
(
v
*
time
.
Time
)
*
PromoCodeUsageUpdate
{
if
v
!=
nil
{
_u
.
SetUsedAt
(
*
v
)
}
return
_u
}
// SetPromoCode sets the "promo_code" edge to the PromoCode entity.
func
(
_u
*
PromoCodeUsageUpdate
)
SetPromoCode
(
v
*
PromoCode
)
*
PromoCodeUsageUpdate
{
return
_u
.
SetPromoCodeID
(
v
.
ID
)
}
// SetUser sets the "user" edge to the User entity.
func
(
_u
*
PromoCodeUsageUpdate
)
SetUser
(
v
*
User
)
*
PromoCodeUsageUpdate
{
return
_u
.
SetUserID
(
v
.
ID
)
}
// Mutation returns the PromoCodeUsageMutation object of the builder.
func
(
_u
*
PromoCodeUsageUpdate
)
Mutation
()
*
PromoCodeUsageMutation
{
return
_u
.
mutation
}
// ClearPromoCode clears the "promo_code" edge to the PromoCode entity.
func
(
_u
*
PromoCodeUsageUpdate
)
ClearPromoCode
()
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
ClearPromoCode
()
return
_u
}
// ClearUser clears the "user" edge to the User entity.
func
(
_u
*
PromoCodeUsageUpdate
)
ClearUser
()
*
PromoCodeUsageUpdate
{
_u
.
mutation
.
ClearUser
()
return
_u
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
PromoCodeUsageUpdate
)
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
*
PromoCodeUsageUpdate
)
SaveX
(
ctx
context
.
Context
)
int
{
affected
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
affected
}
// Exec executes the query.
func
(
_u
*
PromoCodeUsageUpdate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
PromoCodeUsageUpdate
)
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
*
PromoCodeUsageUpdate
)
check
()
error
{
if
_u
.
mutation
.
PromoCodeCleared
()
&&
len
(
_u
.
mutation
.
PromoCodeIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "PromoCodeUsage.promo_code"`
)
}
if
_u
.
mutation
.
UserCleared
()
&&
len
(
_u
.
mutation
.
UserIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "PromoCodeUsage.user"`
)
}
return
nil
}
func
(
_u
*
PromoCodeUsageUpdate
)
sqlSave
(
ctx
context
.
Context
)
(
_node
int
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
promocodeusage
.
Table
,
promocodeusage
.
Columns
,
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
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
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocodeusage
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedBonusAmount
();
ok
{
_spec
.
AddField
(
promocodeusage
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
UsedAt
();
ok
{
_spec
.
SetField
(
promocodeusage
.
FieldUsedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
PromoCodeCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
PromoCodeTable
,
Columns
:
[]
string
{
promocodeusage
.
PromoCodeColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
PromoCodeIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
PromoCodeTable
,
Columns
:
[]
string
{
promocodeusage
.
PromoCodeColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocode
.
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
.
UserCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
UserTable
,
Columns
:
[]
string
{
promocodeusage
.
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
:
promocodeusage
.
UserTable
,
Columns
:
[]
string
{
promocodeusage
.
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
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
promocodeusage
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
0
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
// PromoCodeUsageUpdateOne is the builder for updating a single PromoCodeUsage entity.
type
PromoCodeUsageUpdateOne
struct
{
config
fields
[]
string
hooks
[]
Hook
mutation
*
PromoCodeUsageMutation
}
// SetPromoCodeID sets the "promo_code_id" field.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetPromoCodeID
(
v
int64
)
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
SetPromoCodeID
(
v
)
return
_u
}
// SetNillablePromoCodeID sets the "promo_code_id" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetNillablePromoCodeID
(
v
*
int64
)
*
PromoCodeUsageUpdateOne
{
if
v
!=
nil
{
_u
.
SetPromoCodeID
(
*
v
)
}
return
_u
}
// SetUserID sets the "user_id" field.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetUserID
(
v
int64
)
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
SetUserID
(
v
)
return
_u
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetNillableUserID
(
v
*
int64
)
*
PromoCodeUsageUpdateOne
{
if
v
!=
nil
{
_u
.
SetUserID
(
*
v
)
}
return
_u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
ResetBonusAmount
()
_u
.
mutation
.
SetBonusAmount
(
v
)
return
_u
}
// SetNillableBonusAmount sets the "bonus_amount" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetNillableBonusAmount
(
v
*
float64
)
*
PromoCodeUsageUpdateOne
{
if
v
!=
nil
{
_u
.
SetBonusAmount
(
*
v
)
}
return
_u
}
// AddBonusAmount adds value to the "bonus_amount" field.
func
(
_u
*
PromoCodeUsageUpdateOne
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
AddBonusAmount
(
v
)
return
_u
}
// SetUsedAt sets the "used_at" field.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetUsedAt
(
v
time
.
Time
)
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
SetUsedAt
(
v
)
return
_u
}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetNillableUsedAt
(
v
*
time
.
Time
)
*
PromoCodeUsageUpdateOne
{
if
v
!=
nil
{
_u
.
SetUsedAt
(
*
v
)
}
return
_u
}
// SetPromoCode sets the "promo_code" edge to the PromoCode entity.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetPromoCode
(
v
*
PromoCode
)
*
PromoCodeUsageUpdateOne
{
return
_u
.
SetPromoCodeID
(
v
.
ID
)
}
// SetUser sets the "user" edge to the User entity.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SetUser
(
v
*
User
)
*
PromoCodeUsageUpdateOne
{
return
_u
.
SetUserID
(
v
.
ID
)
}
// Mutation returns the PromoCodeUsageMutation object of the builder.
func
(
_u
*
PromoCodeUsageUpdateOne
)
Mutation
()
*
PromoCodeUsageMutation
{
return
_u
.
mutation
}
// ClearPromoCode clears the "promo_code" edge to the PromoCode entity.
func
(
_u
*
PromoCodeUsageUpdateOne
)
ClearPromoCode
()
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
ClearPromoCode
()
return
_u
}
// ClearUser clears the "user" edge to the User entity.
func
(
_u
*
PromoCodeUsageUpdateOne
)
ClearUser
()
*
PromoCodeUsageUpdateOne
{
_u
.
mutation
.
ClearUser
()
return
_u
}
// Where appends a list predicates to the PromoCodeUsageUpdate builder.
func
(
_u
*
PromoCodeUsageUpdateOne
)
Where
(
ps
...
predicate
.
PromoCodeUsage
)
*
PromoCodeUsageUpdateOne
{
_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
*
PromoCodeUsageUpdateOne
)
Select
(
field
string
,
fields
...
string
)
*
PromoCodeUsageUpdateOne
{
_u
.
fields
=
append
([]
string
{
field
},
fields
...
)
return
_u
}
// Save executes the query and returns the updated PromoCodeUsage entity.
func
(
_u
*
PromoCodeUsageUpdateOne
)
Save
(
ctx
context
.
Context
)
(
*
PromoCodeUsage
,
error
)
{
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
PromoCodeUsageUpdateOne
)
SaveX
(
ctx
context
.
Context
)
*
PromoCodeUsage
{
node
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// Exec executes the query on the entity.
func
(
_u
*
PromoCodeUsageUpdateOne
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
PromoCodeUsageUpdateOne
)
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
*
PromoCodeUsageUpdateOne
)
check
()
error
{
if
_u
.
mutation
.
PromoCodeCleared
()
&&
len
(
_u
.
mutation
.
PromoCodeIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "PromoCodeUsage.promo_code"`
)
}
if
_u
.
mutation
.
UserCleared
()
&&
len
(
_u
.
mutation
.
UserIDs
())
>
0
{
return
errors
.
New
(
`ent: clearing a required unique edge "PromoCodeUsage.user"`
)
}
return
nil
}
func
(
_u
*
PromoCodeUsageUpdateOne
)
sqlSave
(
ctx
context
.
Context
)
(
_node
*
PromoCodeUsage
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
promocodeusage
.
Table
,
promocodeusage
.
Columns
,
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
))
id
,
ok
:=
_u
.
mutation
.
ID
()
if
!
ok
{
return
nil
,
&
ValidationError
{
Name
:
"id"
,
err
:
errors
.
New
(
`ent: missing "PromoCodeUsage.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
,
promocodeusage
.
FieldID
)
for
_
,
f
:=
range
fields
{
if
!
promocodeusage
.
ValidColumn
(
f
)
{
return
nil
,
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
if
f
!=
promocodeusage
.
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
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocodeusage
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedBonusAmount
();
ok
{
_spec
.
AddField
(
promocodeusage
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
UsedAt
();
ok
{
_spec
.
SetField
(
promocodeusage
.
FieldUsedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
PromoCodeCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
PromoCodeTable
,
Columns
:
[]
string
{
promocodeusage
.
PromoCodeColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
PromoCodeIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
PromoCodeTable
,
Columns
:
[]
string
{
promocodeusage
.
PromoCodeColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocode
.
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
.
UserCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
Inverse
:
true
,
Table
:
promocodeusage
.
UserTable
,
Columns
:
[]
string
{
promocodeusage
.
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
:
promocodeusage
.
UserTable
,
Columns
:
[]
string
{
promocodeusage
.
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
)
}
_node
=
&
PromoCodeUsage
{
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
{
promocodeusage
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
backend/ent/proxy_query.go
View file @
1a641392
...
...
@@ -9,6 +9,7 @@ import (
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
...
...
@@ -25,6 +26,7 @@ type ProxyQuery struct {
inters
[]
Interceptor
predicates
[]
predicate
.
Proxy
withAccounts
*
AccountQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
...
@@ -384,6 +386,9 @@ func (_q *ProxyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Proxy,
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
...
...
@@ -439,6 +444,9 @@ func (_q *ProxyQuery) loadAccounts(ctx context.Context, query *AccountQuery, nod
func
(
_q
*
ProxyQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
...
...
@@ -501,6 +509,9 @@ func (_q *ProxyQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
...
...
@@ -518,6 +529,32 @@ func (_q *ProxyQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
ProxyQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
ProxyQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
ProxyQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
ProxyQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// ProxyGroupBy is the group-by builder for Proxy entities.
type
ProxyGroupBy
struct
{
selector
...
...
backend/ent/redeemcode_query.go
View file @
1a641392
...
...
@@ -8,6 +8,7 @@ import (
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
...
...
@@ -26,6 +27,7 @@ type RedeemCodeQuery struct {
predicates
[]
predicate
.
RedeemCode
withUser
*
UserQuery
withGroup
*
GroupQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
...
@@ -420,6 +422,9 @@ func (_q *RedeemCodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*R
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
...
...
@@ -511,6 +516,9 @@ func (_q *RedeemCodeQuery) loadGroup(ctx context.Context, query *GroupQuery, nod
func
(
_q
*
RedeemCodeQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
...
...
@@ -579,6 +587,9 @@ func (_q *RedeemCodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
...
...
@@ -596,6 +607,32 @@ func (_q *RedeemCodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
RedeemCodeQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
RedeemCodeQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
RedeemCodeQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
RedeemCodeQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// RedeemCodeGroupBy is the group-by builder for RedeemCode entities.
type
RedeemCodeGroupBy
struct
{
selector
...
...
backend/ent/runtime/runtime.go
View file @
1a641392
...
...
@@ -9,6 +9,8 @@ import (
"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/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/schema"
...
...
@@ -274,6 +276,60 @@ func init() {
groupDescClaudeCodeOnly
:=
groupFields
[
14
]
.
Descriptor
()
// group.DefaultClaudeCodeOnly holds the default value on creation for the claude_code_only field.
group
.
DefaultClaudeCodeOnly
=
groupDescClaudeCodeOnly
.
Default
.
(
bool
)
promocodeFields
:=
schema
.
PromoCode
{}
.
Fields
()
_
=
promocodeFields
// promocodeDescCode is the schema descriptor for code field.
promocodeDescCode
:=
promocodeFields
[
0
]
.
Descriptor
()
// promocode.CodeValidator is a validator for the "code" field. It is called by the builders before save.
promocode
.
CodeValidator
=
func
()
func
(
string
)
error
{
validators
:=
promocodeDescCode
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
code
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
code
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// promocodeDescBonusAmount is the schema descriptor for bonus_amount field.
promocodeDescBonusAmount
:=
promocodeFields
[
1
]
.
Descriptor
()
// promocode.DefaultBonusAmount holds the default value on creation for the bonus_amount field.
promocode
.
DefaultBonusAmount
=
promocodeDescBonusAmount
.
Default
.
(
float64
)
// promocodeDescMaxUses is the schema descriptor for max_uses field.
promocodeDescMaxUses
:=
promocodeFields
[
2
]
.
Descriptor
()
// promocode.DefaultMaxUses holds the default value on creation for the max_uses field.
promocode
.
DefaultMaxUses
=
promocodeDescMaxUses
.
Default
.
(
int
)
// promocodeDescUsedCount is the schema descriptor for used_count field.
promocodeDescUsedCount
:=
promocodeFields
[
3
]
.
Descriptor
()
// promocode.DefaultUsedCount holds the default value on creation for the used_count field.
promocode
.
DefaultUsedCount
=
promocodeDescUsedCount
.
Default
.
(
int
)
// promocodeDescStatus is the schema descriptor for status field.
promocodeDescStatus
:=
promocodeFields
[
4
]
.
Descriptor
()
// promocode.DefaultStatus holds the default value on creation for the status field.
promocode
.
DefaultStatus
=
promocodeDescStatus
.
Default
.
(
string
)
// promocode.StatusValidator is a validator for the "status" field. It is called by the builders before save.
promocode
.
StatusValidator
=
promocodeDescStatus
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// promocodeDescCreatedAt is the schema descriptor for created_at field.
promocodeDescCreatedAt
:=
promocodeFields
[
7
]
.
Descriptor
()
// promocode.DefaultCreatedAt holds the default value on creation for the created_at field.
promocode
.
DefaultCreatedAt
=
promocodeDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// promocodeDescUpdatedAt is the schema descriptor for updated_at field.
promocodeDescUpdatedAt
:=
promocodeFields
[
8
]
.
Descriptor
()
// promocode.DefaultUpdatedAt holds the default value on creation for the updated_at field.
promocode
.
DefaultUpdatedAt
=
promocodeDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// promocode.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
promocode
.
UpdateDefaultUpdatedAt
=
promocodeDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
promocodeusageFields
:=
schema
.
PromoCodeUsage
{}
.
Fields
()
_
=
promocodeusageFields
// promocodeusageDescUsedAt is the schema descriptor for used_at field.
promocodeusageDescUsedAt
:=
promocodeusageFields
[
3
]
.
Descriptor
()
// promocodeusage.DefaultUsedAt holds the default value on creation for the used_at field.
promocodeusage
.
DefaultUsedAt
=
promocodeusageDescUsedAt
.
Default
.
(
func
()
time
.
Time
)
proxyMixin
:=
schema
.
Proxy
{}
.
Mixin
()
proxyMixinHooks1
:=
proxyMixin
[
1
]
.
Hooks
()
proxy
.
Hooks
[
0
]
=
proxyMixinHooks1
[
0
]
...
...
@@ -533,16 +589,20 @@ func init() {
usagelogDescUserAgent
:=
usagelogFields
[
24
]
.
Descriptor
()
// usagelog.UserAgentValidator is a validator for the "user_agent" field. It is called by the builders before save.
usagelog
.
UserAgentValidator
=
usagelogDescUserAgent
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescIPAddress is the schema descriptor for ip_address field.
usagelogDescIPAddress
:=
usagelogFields
[
25
]
.
Descriptor
()
// usagelog.IPAddressValidator is a validator for the "ip_address" field. It is called by the builders before save.
usagelog
.
IPAddressValidator
=
usagelogDescIPAddress
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescImageCount is the schema descriptor for image_count field.
usagelogDescImageCount
:=
usagelogFields
[
2
5
]
.
Descriptor
()
usagelogDescImageCount
:=
usagelogFields
[
2
6
]
.
Descriptor
()
// usagelog.DefaultImageCount holds the default value on creation for the image_count field.
usagelog
.
DefaultImageCount
=
usagelogDescImageCount
.
Default
.
(
int
)
// usagelogDescImageSize is the schema descriptor for image_size field.
usagelogDescImageSize
:=
usagelogFields
[
2
6
]
.
Descriptor
()
usagelogDescImageSize
:=
usagelogFields
[
2
7
]
.
Descriptor
()
// usagelog.ImageSizeValidator is a validator for the "image_size" field. It is called by the builders before save.
usagelog
.
ImageSizeValidator
=
usagelogDescImageSize
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// usagelogDescCreatedAt is the schema descriptor for created_at field.
usagelogDescCreatedAt
:=
usagelogFields
[
2
7
]
.
Descriptor
()
usagelogDescCreatedAt
:=
usagelogFields
[
2
8
]
.
Descriptor
()
// usagelog.DefaultCreatedAt holds the default value on creation for the created_at field.
usagelog
.
DefaultCreatedAt
=
usagelogDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
userMixin
:=
schema
.
User
{}
.
Mixin
()
...
...
backend/ent/schema/api_key.go
View file @
1a641392
...
...
@@ -46,6 +46,12 @@ func (APIKey) Fields() []ent.Field {
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
StatusActive
),
field
.
JSON
(
"ip_whitelist"
,
[]
string
{})
.
Optional
()
.
Comment
(
"Allowed IPs/CIDRs, e.g. [
\"
192.168.1.100
\"
,
\"
10.0.0.0/8
\"
]"
),
field
.
JSON
(
"ip_blacklist"
,
[]
string
{})
.
Optional
()
.
Comment
(
"Blocked IPs/CIDRs"
),
}
}
...
...
Prev
1
2
3
4
5
6
…
9
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment