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
e79dbad6
Commit
e79dbad6
authored
Jan 10, 2026
by
yangjianbo
Browse files
Merge branch 'main' into test
parents
6a9cc13e
d1a6d6b1
Changes
83
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
e79dbad6
...
@@ -14,6 +14,9 @@ backend/server
...
@@ -14,6 +14,9 @@ backend/server
backend/sub2api
backend/sub2api
backend/main
backend/main
# Go 测试二进制
*.test
# 测试覆盖率
# 测试覆盖率
*.out
*.out
coverage.html
coverage.html
...
...
backend/cmd/jwtgen/main.go
View file @
e79dbad6
...
@@ -33,7 +33,7 @@ func main() {
...
@@ -33,7 +33,7 @@ func main() {
}()
}()
userRepo
:=
repository
.
NewUserRepository
(
client
,
sqlDB
)
userRepo
:=
repository
.
NewUserRepository
(
client
,
sqlDB
)
authService
:=
service
.
NewAuthService
(
userRepo
,
cfg
,
nil
,
nil
,
nil
,
nil
)
authService
:=
service
.
NewAuthService
(
userRepo
,
cfg
,
nil
,
nil
,
nil
,
nil
,
nil
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
defer
cancel
()
defer
cancel
()
...
...
backend/cmd/server/wire_gen.go
View file @
e79dbad6
...
@@ -51,13 +51,17 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -51,13 +51,17 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
turnstileVerifier
:=
repository
.
NewTurnstileVerifier
()
turnstileVerifier
:=
repository
.
NewTurnstileVerifier
()
turnstileService
:=
service
.
NewTurnstileService
(
settingService
,
turnstileVerifier
)
turnstileService
:=
service
.
NewTurnstileService
(
settingService
,
turnstileVerifier
)
emailQueueService
:=
service
.
ProvideEmailQueueService
(
emailService
)
emailQueueService
:=
service
.
ProvideEmailQueueService
(
emailService
)
authService
:=
service
.
NewAuthService
(
userRepository
,
configConfig
,
settingService
,
emailService
,
turnstileService
,
emailQueueService
)
promoCodeRepository
:=
repository
.
NewPromoCodeRepository
(
client
)
billingCache
:=
repository
.
NewBillingCache
(
redisClient
)
userSubscriptionRepository
:=
repository
.
NewUserSubscriptionRepository
(
client
)
billingCacheService
:=
service
.
NewBillingCacheService
(
billingCache
,
userRepository
,
userSubscriptionRepository
,
configConfig
)
promoService
:=
service
.
NewPromoService
(
promoCodeRepository
,
userRepository
,
billingCacheService
,
client
)
authService
:=
service
.
NewAuthService
(
userRepository
,
configConfig
,
settingService
,
emailService
,
turnstileService
,
emailQueueService
,
promoService
)
userService
:=
service
.
NewUserService
(
userRepository
)
userService
:=
service
.
NewUserService
(
userRepository
)
authHandler
:=
handler
.
NewAuthHandler
(
configConfig
,
authService
,
userService
,
settingService
)
authHandler
:=
handler
.
NewAuthHandler
(
configConfig
,
authService
,
userService
,
settingService
,
promoService
)
userHandler
:=
handler
.
NewUserHandler
(
userService
)
userHandler
:=
handler
.
NewUserHandler
(
userService
)
apiKeyRepository
:=
repository
.
NewAPIKeyRepository
(
client
)
apiKeyRepository
:=
repository
.
NewAPIKeyRepository
(
client
)
groupRepository
:=
repository
.
NewGroupRepository
(
client
,
db
)
groupRepository
:=
repository
.
NewGroupRepository
(
client
,
db
)
userSubscriptionRepository
:=
repository
.
NewUserSubscriptionRepository
(
client
)
apiKeyCache
:=
repository
.
NewAPIKeyCache
(
redisClient
)
apiKeyCache
:=
repository
.
NewAPIKeyCache
(
redisClient
)
apiKeyService
:=
service
.
NewAPIKeyService
(
apiKeyRepository
,
userRepository
,
groupRepository
,
userSubscriptionRepository
,
apiKeyCache
,
configConfig
)
apiKeyService
:=
service
.
NewAPIKeyService
(
apiKeyRepository
,
userRepository
,
groupRepository
,
userSubscriptionRepository
,
apiKeyCache
,
configConfig
)
apiKeyHandler
:=
handler
.
NewAPIKeyHandler
(
apiKeyService
)
apiKeyHandler
:=
handler
.
NewAPIKeyHandler
(
apiKeyService
)
...
@@ -65,8 +69,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -65,8 +69,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
usageService
:=
service
.
NewUsageService
(
usageLogRepository
,
userRepository
,
client
)
usageService
:=
service
.
NewUsageService
(
usageLogRepository
,
userRepository
,
client
)
usageHandler
:=
handler
.
NewUsageHandler
(
usageService
,
apiKeyService
)
usageHandler
:=
handler
.
NewUsageHandler
(
usageService
,
apiKeyService
)
redeemCodeRepository
:=
repository
.
NewRedeemCodeRepository
(
client
)
redeemCodeRepository
:=
repository
.
NewRedeemCodeRepository
(
client
)
billingCache
:=
repository
.
NewBillingCache
(
redisClient
)
billingCacheService
:=
service
.
NewBillingCacheService
(
billingCache
,
userRepository
,
userSubscriptionRepository
,
configConfig
)
subscriptionService
:=
service
.
NewSubscriptionService
(
groupRepository
,
userSubscriptionRepository
,
billingCacheService
)
subscriptionService
:=
service
.
NewSubscriptionService
(
groupRepository
,
userSubscriptionRepository
,
billingCacheService
)
redeemCache
:=
repository
.
NewRedeemCache
(
redisClient
)
redeemCache
:=
repository
.
NewRedeemCache
(
redisClient
)
redeemService
:=
service
.
NewRedeemService
(
redeemCodeRepository
,
userRepository
,
subscriptionService
,
redeemCache
,
billingCacheService
,
client
)
redeemService
:=
service
.
NewRedeemService
(
redeemCodeRepository
,
userRepository
,
subscriptionService
,
redeemCache
,
billingCacheService
,
client
)
...
@@ -112,6 +114,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -112,6 +114,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
antigravityOAuthHandler
:=
admin
.
NewAntigravityOAuthHandler
(
antigravityOAuthService
)
antigravityOAuthHandler
:=
admin
.
NewAntigravityOAuthHandler
(
antigravityOAuthService
)
proxyHandler
:=
admin
.
NewProxyHandler
(
adminService
)
proxyHandler
:=
admin
.
NewProxyHandler
(
adminService
)
adminRedeemHandler
:=
admin
.
NewRedeemHandler
(
adminService
)
adminRedeemHandler
:=
admin
.
NewRedeemHandler
(
adminService
)
promoHandler
:=
admin
.
NewPromoHandler
(
promoService
)
settingHandler
:=
admin
.
NewSettingHandler
(
settingService
,
emailService
,
turnstileService
)
settingHandler
:=
admin
.
NewSettingHandler
(
settingService
,
emailService
,
turnstileService
)
updateCache
:=
repository
.
NewUpdateCache
(
redisClient
)
updateCache
:=
repository
.
NewUpdateCache
(
redisClient
)
gitHubReleaseClient
:=
repository
.
ProvideGitHubReleaseClient
(
configConfig
)
gitHubReleaseClient
:=
repository
.
ProvideGitHubReleaseClient
(
configConfig
)
...
@@ -124,7 +127,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -124,7 +127,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
userAttributeValueRepository
:=
repository
.
NewUserAttributeValueRepository
(
client
)
userAttributeValueRepository
:=
repository
.
NewUserAttributeValueRepository
(
client
)
userAttributeService
:=
service
.
NewUserAttributeService
(
userAttributeDefinitionRepository
,
userAttributeValueRepository
)
userAttributeService
:=
service
.
NewUserAttributeService
(
userAttributeDefinitionRepository
,
userAttributeValueRepository
)
userAttributeHandler
:=
admin
.
NewUserAttributeHandler
(
userAttributeService
)
userAttributeHandler
:=
admin
.
NewUserAttributeHandler
(
userAttributeService
)
adminHandlers
:=
handler
.
ProvideAdminHandlers
(
dashboardHandler
,
adminUserHandler
,
groupHandler
,
accountHandler
,
oAuthHandler
,
openAIOAuthHandler
,
geminiOAuthHandler
,
antigravityOAuthHandler
,
proxyHandler
,
adminRedeemHandler
,
settingHandler
,
systemHandler
,
adminSubscriptionHandler
,
adminUsageHandler
,
userAttributeHandler
)
adminHandlers
:=
handler
.
ProvideAdminHandlers
(
dashboardHandler
,
adminUserHandler
,
groupHandler
,
accountHandler
,
oAuthHandler
,
openAIOAuthHandler
,
geminiOAuthHandler
,
antigravityOAuthHandler
,
proxyHandler
,
adminRedeemHandler
,
promoHandler
,
settingHandler
,
systemHandler
,
adminSubscriptionHandler
,
adminUsageHandler
,
userAttributeHandler
)
pricingRemoteClient
:=
repository
.
ProvidePricingRemoteClient
(
configConfig
)
pricingRemoteClient
:=
repository
.
ProvidePricingRemoteClient
(
configConfig
)
pricingService
,
err
:=
service
.
ProvidePricingService
(
configConfig
,
pricingRemoteClient
)
pricingService
,
err
:=
service
.
ProvidePricingService
(
configConfig
,
pricingRemoteClient
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -145,7 +148,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
...
@@ -145,7 +148,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
jwtAuthMiddleware
:=
middleware
.
NewJWTAuthMiddleware
(
authService
,
userService
)
jwtAuthMiddleware
:=
middleware
.
NewJWTAuthMiddleware
(
authService
,
userService
)
adminAuthMiddleware
:=
middleware
.
NewAdminAuthMiddleware
(
authService
,
userService
,
settingService
)
adminAuthMiddleware
:=
middleware
.
NewAdminAuthMiddleware
(
authService
,
userService
,
settingService
)
apiKeyAuthMiddleware
:=
middleware
.
NewAPIKeyAuthMiddleware
(
apiKeyService
,
subscriptionService
,
configConfig
)
apiKeyAuthMiddleware
:=
middleware
.
NewAPIKeyAuthMiddleware
(
apiKeyService
,
subscriptionService
,
configConfig
)
engine
:=
server
.
ProvideRouter
(
configConfig
,
handlers
,
jwtAuthMiddleware
,
adminAuthMiddleware
,
apiKeyAuthMiddleware
,
apiKeyService
,
subscriptionService
)
engine
:=
server
.
ProvideRouter
(
configConfig
,
handlers
,
jwtAuthMiddleware
,
adminAuthMiddleware
,
apiKeyAuthMiddleware
,
apiKeyService
,
subscriptionService
,
redisClient
)
httpServer
:=
server
.
ProvideHTTPServer
(
configConfig
,
engine
)
httpServer
:=
server
.
ProvideHTTPServer
(
configConfig
,
engine
)
tokenRefreshService
:=
service
.
ProvideTokenRefreshService
(
accountRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
configConfig
)
tokenRefreshService
:=
service
.
ProvideTokenRefreshService
(
accountRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
configConfig
)
accountExpiryService
:=
service
.
ProvideAccountExpiryService
(
accountRepository
)
accountExpiryService
:=
service
.
ProvideAccountExpiryService
(
accountRepository
)
...
...
backend/ent/account_query.go
View file @
e79dbad6
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"math"
"math"
"entgo.io/ent"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/field"
...
@@ -31,6 +32,7 @@ type AccountQuery struct {
...
@@ -31,6 +32,7 @@ type AccountQuery struct {
withProxy
*
ProxyQuery
withProxy
*
ProxyQuery
withUsageLogs
*
UsageLogQuery
withUsageLogs
*
UsageLogQuery
withAccountGroups
*
AccountGroupQuery
withAccountGroups
*
AccountGroupQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
@@ -495,6 +497,9 @@ func (_q *AccountQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Acco
...
@@ -495,6 +497,9 @@ func (_q *AccountQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Acco
node
.
Edges
.
loadedTypes
=
loadedTypes
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
return
node
.
assignValues
(
columns
,
values
)
}
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
hooks
[
i
](
ctx
,
_spec
)
}
}
...
@@ -690,6 +695,9 @@ func (_q *AccountQuery) loadAccountGroups(ctx context.Context, query *AccountGro
...
@@ -690,6 +695,9 @@ func (_q *AccountQuery) loadAccountGroups(ctx context.Context, query *AccountGro
func
(
_q
*
AccountQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
func
(
_q
*
AccountQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
...
@@ -755,6 +763,9 @@ func (_q *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -755,6 +763,9 @@ func (_q *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
selector
.
Distinct
()
}
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
p
(
selector
)
}
}
...
@@ -772,6 +783,32 @@ func (_q *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -772,6 +783,32 @@ func (_q *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
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
*
AccountQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
AccountQuery
{
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
*
AccountQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
AccountQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// AccountGroupBy is the group-by builder for Account entities.
// AccountGroupBy is the group-by builder for Account entities.
type
AccountGroupBy
struct
{
type
AccountGroupBy
struct
{
selector
selector
...
...
backend/ent/accountgroup_query.go
View file @
e79dbad6
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"math"
"math"
"entgo.io/ent"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/account"
"github.com/Wei-Shaw/sub2api/ent/account"
...
@@ -25,6 +26,7 @@ type AccountGroupQuery struct {
...
@@ -25,6 +26,7 @@ type AccountGroupQuery struct {
predicates
[]
predicate
.
AccountGroup
predicates
[]
predicate
.
AccountGroup
withAccount
*
AccountQuery
withAccount
*
AccountQuery
withGroup
*
GroupQuery
withGroup
*
GroupQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
@@ -347,6 +349,9 @@ func (_q *AccountGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]
...
@@ -347,6 +349,9 @@ func (_q *AccountGroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]
node
.
Edges
.
loadedTypes
=
loadedTypes
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
return
node
.
assignValues
(
columns
,
values
)
}
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
hooks
[
i
](
ctx
,
_spec
)
}
}
...
@@ -432,6 +437,9 @@ func (_q *AccountGroupQuery) loadGroup(ctx context.Context, query *GroupQuery, n
...
@@ -432,6 +437,9 @@ func (_q *AccountGroupQuery) loadGroup(ctx context.Context, query *GroupQuery, n
func
(
_q
*
AccountGroupQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
func
(
_q
*
AccountGroupQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Unique
=
false
_spec
.
Unique
=
false
_spec
.
Node
.
Columns
=
nil
_spec
.
Node
.
Columns
=
nil
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
...
@@ -495,6 +503,9 @@ func (_q *AccountGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -495,6 +503,9 @@ func (_q *AccountGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
selector
.
Distinct
()
}
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
p
(
selector
)
}
}
...
@@ -512,6 +523,32 @@ func (_q *AccountGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -512,6 +523,32 @@ func (_q *AccountGroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
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
*
AccountGroupQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
AccountGroupQuery
{
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
*
AccountGroupQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
AccountGroupQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// AccountGroupGroupBy is the group-by builder for AccountGroup entities.
// AccountGroupGroupBy is the group-by builder for AccountGroup entities.
type
AccountGroupGroupBy
struct
{
type
AccountGroupGroupBy
struct
{
selector
selector
...
...
backend/ent/apikey_query.go
View file @
e79dbad6
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"math"
"math"
"entgo.io/ent"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/field"
...
@@ -29,6 +30,7 @@ type APIKeyQuery struct {
...
@@ -29,6 +30,7 @@ type APIKeyQuery struct {
withUser
*
UserQuery
withUser
*
UserQuery
withGroup
*
GroupQuery
withGroup
*
GroupQuery
withUsageLogs
*
UsageLogQuery
withUsageLogs
*
UsageLogQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
@@ -458,6 +460,9 @@ func (_q *APIKeyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*APIKe
...
@@ -458,6 +460,9 @@ func (_q *APIKeyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*APIKe
node
.
Edges
.
loadedTypes
=
loadedTypes
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
return
node
.
assignValues
(
columns
,
values
)
}
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
hooks
[
i
](
ctx
,
_spec
)
}
}
...
@@ -583,6 +588,9 @@ func (_q *APIKeyQuery) loadUsageLogs(ctx context.Context, query *UsageLogQuery,
...
@@ -583,6 +588,9 @@ func (_q *APIKeyQuery) loadUsageLogs(ctx context.Context, query *UsageLogQuery,
func
(
_q
*
APIKeyQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
func
(
_q
*
APIKeyQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
...
@@ -651,6 +659,9 @@ func (_q *APIKeyQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -651,6 +659,9 @@ func (_q *APIKeyQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
selector
.
Distinct
()
}
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
p
(
selector
)
}
}
...
@@ -668,6 +679,32 @@ func (_q *APIKeyQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -668,6 +679,32 @@ func (_q *APIKeyQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
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
*
APIKeyQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
APIKeyQuery
{
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
*
APIKeyQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
APIKeyQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// APIKeyGroupBy is the group-by builder for APIKey entities.
// APIKeyGroupBy is the group-by builder for APIKey entities.
type
APIKeyGroupBy
struct
{
type
APIKeyGroupBy
struct
{
selector
selector
...
...
backend/ent/client.go
View file @
e79dbad6
...
@@ -19,6 +19,8 @@ import (
...
@@ -19,6 +19,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"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/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
@@ -45,6 +47,10 @@ type Client struct {
...
@@ -45,6 +47,10 @@ type Client struct {
AccountGroup
*
AccountGroupClient
AccountGroup
*
AccountGroupClient
// Group is the client for interacting with the Group builders.
// Group is the client for interacting with the Group builders.
Group
*
GroupClient
Group
*
GroupClient
// PromoCode is the client for interacting with the PromoCode builders.
PromoCode
*
PromoCodeClient
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
PromoCodeUsage
*
PromoCodeUsageClient
// Proxy is the client for interacting with the Proxy builders.
// Proxy is the client for interacting with the Proxy builders.
Proxy
*
ProxyClient
Proxy
*
ProxyClient
// RedeemCode is the client for interacting with the RedeemCode builders.
// RedeemCode is the client for interacting with the RedeemCode builders.
...
@@ -78,6 +84,8 @@ func (c *Client) init() {
...
@@ -78,6 +84,8 @@ func (c *Client) init() {
c
.
Account
=
NewAccountClient
(
c
.
config
)
c
.
Account
=
NewAccountClient
(
c
.
config
)
c
.
AccountGroup
=
NewAccountGroupClient
(
c
.
config
)
c
.
AccountGroup
=
NewAccountGroupClient
(
c
.
config
)
c
.
Group
=
NewGroupClient
(
c
.
config
)
c
.
Group
=
NewGroupClient
(
c
.
config
)
c
.
PromoCode
=
NewPromoCodeClient
(
c
.
config
)
c
.
PromoCodeUsage
=
NewPromoCodeUsageClient
(
c
.
config
)
c
.
Proxy
=
NewProxyClient
(
c
.
config
)
c
.
Proxy
=
NewProxyClient
(
c
.
config
)
c
.
RedeemCode
=
NewRedeemCodeClient
(
c
.
config
)
c
.
RedeemCode
=
NewRedeemCodeClient
(
c
.
config
)
c
.
Setting
=
NewSettingClient
(
c
.
config
)
c
.
Setting
=
NewSettingClient
(
c
.
config
)
...
@@ -183,6 +191,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
...
@@ -183,6 +191,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
Account
:
NewAccountClient
(
cfg
),
Account
:
NewAccountClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
PromoCode
:
NewPromoCodeClient
(
cfg
),
PromoCodeUsage
:
NewPromoCodeUsageClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
...
@@ -215,6 +225,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
...
@@ -215,6 +225,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
Account
:
NewAccountClient
(
cfg
),
Account
:
NewAccountClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
PromoCode
:
NewPromoCodeClient
(
cfg
),
PromoCodeUsage
:
NewPromoCodeUsageClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
...
@@ -253,9 +265,9 @@ func (c *Client) Close() error {
...
@@ -253,9 +265,9 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func
(
c
*
Client
)
Use
(
hooks
...
Hook
)
{
func
(
c
*
Client
)
Use
(
hooks
...
Hook
)
{
for
_
,
n
:=
range
[]
interface
{
Use
(
...
Hook
)
}{
for
_
,
n
:=
range
[]
interface
{
Use
(
...
Hook
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
xy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
moCode
,
c
.
PromoCodeUsage
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
}
{
n
.
Use
(
hooks
...
)
n
.
Use
(
hooks
...
)
}
}
...
@@ -265,9 +277,9 @@ func (c *Client) Use(hooks ...Hook) {
...
@@ -265,9 +277,9 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func
(
c
*
Client
)
Intercept
(
interceptors
...
Interceptor
)
{
func
(
c
*
Client
)
Intercept
(
interceptors
...
Interceptor
)
{
for
_
,
n
:=
range
[]
interface
{
Intercept
(
...
Interceptor
)
}{
for
_
,
n
:=
range
[]
interface
{
Intercept
(
...
Interceptor
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
xy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
moCode
,
c
.
PromoCodeUsage
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
}
{
n
.
Intercept
(
interceptors
...
)
n
.
Intercept
(
interceptors
...
)
}
}
...
@@ -284,6 +296,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
...
@@ -284,6 +296,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return
c
.
AccountGroup
.
mutate
(
ctx
,
m
)
return
c
.
AccountGroup
.
mutate
(
ctx
,
m
)
case
*
GroupMutation
:
case
*
GroupMutation
:
return
c
.
Group
.
mutate
(
ctx
,
m
)
return
c
.
Group
.
mutate
(
ctx
,
m
)
case
*
PromoCodeMutation
:
return
c
.
PromoCode
.
mutate
(
ctx
,
m
)
case
*
PromoCodeUsageMutation
:
return
c
.
PromoCodeUsage
.
mutate
(
ctx
,
m
)
case
*
ProxyMutation
:
case
*
ProxyMutation
:
return
c
.
Proxy
.
mutate
(
ctx
,
m
)
return
c
.
Proxy
.
mutate
(
ctx
,
m
)
case
*
RedeemCodeMutation
:
case
*
RedeemCodeMutation
:
...
@@ -1068,6 +1084,320 @@ func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, erro
...
@@ -1068,6 +1084,320 @@ func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, erro
}
}
}
}
// PromoCodeClient is a client for the PromoCode schema.
type
PromoCodeClient
struct
{
config
}
// NewPromoCodeClient returns a client for the PromoCode from the given config.
func
NewPromoCodeClient
(
c
config
)
*
PromoCodeClient
{
return
&
PromoCodeClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `promocode.Hooks(f(g(h())))`.
func
(
c
*
PromoCodeClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
PromoCode
=
append
(
c
.
hooks
.
PromoCode
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `promocode.Intercept(f(g(h())))`.
func
(
c
*
PromoCodeClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
PromoCode
=
append
(
c
.
inters
.
PromoCode
,
interceptors
...
)
}
// Create returns a builder for creating a PromoCode entity.
func
(
c
*
PromoCodeClient
)
Create
()
*
PromoCodeCreate
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpCreate
)
return
&
PromoCodeCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of PromoCode entities.
func
(
c
*
PromoCodeClient
)
CreateBulk
(
builders
...*
PromoCodeCreate
)
*
PromoCodeCreateBulk
{
return
&
PromoCodeCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func
(
c
*
PromoCodeClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
PromoCodeCreate
,
int
))
*
PromoCodeCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
PromoCodeCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to PromoCodeClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
PromoCodeCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
PromoCodeCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for PromoCode.
func
(
c
*
PromoCodeClient
)
Update
()
*
PromoCodeUpdate
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpUpdate
)
return
&
PromoCodeUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
PromoCodeClient
)
UpdateOne
(
_m
*
PromoCode
)
*
PromoCodeUpdateOne
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCode
(
_m
))
return
&
PromoCodeUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
PromoCodeClient
)
UpdateOneID
(
id
int64
)
*
PromoCodeUpdateOne
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCodeID
(
id
))
return
&
PromoCodeUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for PromoCode.
func
(
c
*
PromoCodeClient
)
Delete
()
*
PromoCodeDelete
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpDelete
)
return
&
PromoCodeDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
PromoCodeClient
)
DeleteOne
(
_m
*
PromoCode
)
*
PromoCodeDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
PromoCodeClient
)
DeleteOneID
(
id
int64
)
*
PromoCodeDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
promocode
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
PromoCodeDeleteOne
{
builder
}
}
// Query returns a query builder for PromoCode.
func
(
c
*
PromoCodeClient
)
Query
()
*
PromoCodeQuery
{
return
&
PromoCodeQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypePromoCode
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a PromoCode entity by its id.
func
(
c
*
PromoCodeClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
PromoCode
,
error
)
{
return
c
.
Query
()
.
Where
(
promocode
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
PromoCodeClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
PromoCode
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// QueryUsageRecords queries the usage_records edge of a PromoCode.
func
(
c
*
PromoCodeClient
)
QueryUsageRecords
(
_m
*
PromoCode
)
*
PromoCodeUsageQuery
{
query
:=
(
&
PromoCodeUsageClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
promocode
.
Table
,
promocode
.
FieldID
,
id
),
sqlgraph
.
To
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
promocode
.
UsageRecordsTable
,
promocode
.
UsageRecordsColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// Hooks returns the client hooks.
func
(
c
*
PromoCodeClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
PromoCode
}
// Interceptors returns the client interceptors.
func
(
c
*
PromoCodeClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
PromoCode
}
func
(
c
*
PromoCodeClient
)
mutate
(
ctx
context
.
Context
,
m
*
PromoCodeMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
PromoCodeCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
PromoCodeUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
PromoCodeUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
PromoCodeDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown PromoCode mutation op: %q"
,
m
.
Op
())
}
}
// PromoCodeUsageClient is a client for the PromoCodeUsage schema.
type
PromoCodeUsageClient
struct
{
config
}
// NewPromoCodeUsageClient returns a client for the PromoCodeUsage from the given config.
func
NewPromoCodeUsageClient
(
c
config
)
*
PromoCodeUsageClient
{
return
&
PromoCodeUsageClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `promocodeusage.Hooks(f(g(h())))`.
func
(
c
*
PromoCodeUsageClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
PromoCodeUsage
=
append
(
c
.
hooks
.
PromoCodeUsage
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `promocodeusage.Intercept(f(g(h())))`.
func
(
c
*
PromoCodeUsageClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
PromoCodeUsage
=
append
(
c
.
inters
.
PromoCodeUsage
,
interceptors
...
)
}
// Create returns a builder for creating a PromoCodeUsage entity.
func
(
c
*
PromoCodeUsageClient
)
Create
()
*
PromoCodeUsageCreate
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpCreate
)
return
&
PromoCodeUsageCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of PromoCodeUsage entities.
func
(
c
*
PromoCodeUsageClient
)
CreateBulk
(
builders
...*
PromoCodeUsageCreate
)
*
PromoCodeUsageCreateBulk
{
return
&
PromoCodeUsageCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func
(
c
*
PromoCodeUsageClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
PromoCodeUsageCreate
,
int
))
*
PromoCodeUsageCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
PromoCodeUsageCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to PromoCodeUsageClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
PromoCodeUsageCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
PromoCodeUsageCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
Update
()
*
PromoCodeUsageUpdate
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpUpdate
)
return
&
PromoCodeUsageUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
PromoCodeUsageClient
)
UpdateOne
(
_m
*
PromoCodeUsage
)
*
PromoCodeUsageUpdateOne
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCodeUsage
(
_m
))
return
&
PromoCodeUsageUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
PromoCodeUsageClient
)
UpdateOneID
(
id
int64
)
*
PromoCodeUsageUpdateOne
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCodeUsageID
(
id
))
return
&
PromoCodeUsageUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
Delete
()
*
PromoCodeUsageDelete
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpDelete
)
return
&
PromoCodeUsageDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
PromoCodeUsageClient
)
DeleteOne
(
_m
*
PromoCodeUsage
)
*
PromoCodeUsageDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
PromoCodeUsageClient
)
DeleteOneID
(
id
int64
)
*
PromoCodeUsageDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
promocodeusage
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
PromoCodeUsageDeleteOne
{
builder
}
}
// Query returns a query builder for PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
Query
()
*
PromoCodeUsageQuery
{
return
&
PromoCodeUsageQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypePromoCodeUsage
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a PromoCodeUsage entity by its id.
func
(
c
*
PromoCodeUsageClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
PromoCodeUsage
,
error
)
{
return
c
.
Query
()
.
Where
(
promocodeusage
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
PromoCodeUsageClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
PromoCodeUsage
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// QueryPromoCode queries the promo_code edge of a PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
QueryPromoCode
(
_m
*
PromoCodeUsage
)
*
PromoCodeQuery
{
query
:=
(
&
PromoCodeClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
,
id
),
sqlgraph
.
To
(
promocode
.
Table
,
promocode
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
promocodeusage
.
PromoCodeTable
,
promocodeusage
.
PromoCodeColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// QueryUser queries the user edge of a PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
QueryUser
(
_m
*
PromoCodeUsage
)
*
UserQuery
{
query
:=
(
&
UserClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
,
id
),
sqlgraph
.
To
(
user
.
Table
,
user
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
promocodeusage
.
UserTable
,
promocodeusage
.
UserColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// Hooks returns the client hooks.
func
(
c
*
PromoCodeUsageClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
PromoCodeUsage
}
// Interceptors returns the client interceptors.
func
(
c
*
PromoCodeUsageClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
PromoCodeUsage
}
func
(
c
*
PromoCodeUsageClient
)
mutate
(
ctx
context
.
Context
,
m
*
PromoCodeUsageMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
PromoCodeUsageCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
PromoCodeUsageUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
PromoCodeUsageUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
PromoCodeUsageDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown PromoCodeUsage mutation op: %q"
,
m
.
Op
())
}
}
// ProxyClient is a client for the Proxy schema.
// ProxyClient is a client for the Proxy schema.
type
ProxyClient
struct
{
type
ProxyClient
struct
{
config
config
...
@@ -1950,6 +2280,22 @@ func (c *UserClient) QueryAttributeValues(_m *User) *UserAttributeValueQuery {
...
@@ -1950,6 +2280,22 @@ func (c *UserClient) QueryAttributeValues(_m *User) *UserAttributeValueQuery {
return
query
return
query
}
}
// QueryPromoCodeUsages queries the promo_code_usages edge of a User.
func
(
c
*
UserClient
)
QueryPromoCodeUsages
(
_m
*
User
)
*
PromoCodeUsageQuery
{
query
:=
(
&
PromoCodeUsageClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
user
.
Table
,
user
.
FieldID
,
id
),
sqlgraph
.
To
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
user
.
PromoCodeUsagesTable
,
user
.
PromoCodeUsagesColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// QueryUserAllowedGroups queries the user_allowed_groups edge of a User.
// QueryUserAllowedGroups queries the user_allowed_groups edge of a User.
func
(
c
*
UserClient
)
QueryUserAllowedGroups
(
_m
*
User
)
*
UserAllowedGroupQuery
{
func
(
c
*
UserClient
)
QueryUserAllowedGroups
(
_m
*
User
)
*
UserAllowedGroupQuery
{
query
:=
(
&
UserAllowedGroupClient
{
config
:
c
.
config
})
.
Query
()
query
:=
(
&
UserAllowedGroupClient
{
config
:
c
.
config
})
.
Query
()
...
@@ -2627,14 +2973,14 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
...
@@ -2627,14 +2973,14 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
// hooks and interceptors per client, for fast access.
// hooks and interceptors per client, for fast access.
type
(
type
(
hooks
struct
{
hooks
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
xy
,
RedeemCode
,
Setting
,
UsageLog
,
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
moCode
,
PromoCodeUsage
,
Proxy
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserSubscription
[]
ent
.
Hook
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
}
}
inters
struct
{
inters
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
xy
,
RedeemCode
,
Setting
,
UsageLog
,
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
moCode
,
PromoCodeUsage
,
Proxy
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserSubscription
[]
ent
.
Interceptor
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
}
}
)
)
...
...
backend/ent/ent.go
View file @
e79dbad6
...
@@ -16,6 +16,8 @@ import (
...
@@ -16,6 +16,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"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/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
@@ -89,6 +91,8 @@ func checkColumn(t, c string) error {
...
@@ -89,6 +91,8 @@ func checkColumn(t, c string) error {
account
.
Table
:
account
.
ValidColumn
,
account
.
Table
:
account
.
ValidColumn
,
accountgroup
.
Table
:
accountgroup
.
ValidColumn
,
accountgroup
.
Table
:
accountgroup
.
ValidColumn
,
group
.
Table
:
group
.
ValidColumn
,
group
.
Table
:
group
.
ValidColumn
,
promocode
.
Table
:
promocode
.
ValidColumn
,
promocodeusage
.
Table
:
promocodeusage
.
ValidColumn
,
proxy
.
Table
:
proxy
.
ValidColumn
,
proxy
.
Table
:
proxy
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
...
...
backend/ent/generate.go
View file @
e79dbad6
...
@@ -2,4 +2,5 @@
...
@@ -2,4 +2,5 @@
package
ent
package
ent
// 启用 sql/execquery 以生成 ExecContext/QueryContext 的透传接口,便于事务内执行原生 SQL。
// 启用 sql/execquery 以生成 ExecContext/QueryContext 的透传接口,便于事务内执行原生 SQL。
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert,intercept,sql/execquery --idtype int64 ./schema
// 启用 sql/lock 以支持 FOR UPDATE 行锁。
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert,intercept,sql/execquery,sql/lock --idtype int64 ./schema
backend/ent/group_query.go
View file @
e79dbad6
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"math"
"math"
"entgo.io/ent"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/field"
...
@@ -39,6 +40,7 @@ type GroupQuery struct {
...
@@ -39,6 +40,7 @@ type GroupQuery struct {
withAllowedUsers
*
UserQuery
withAllowedUsers
*
UserQuery
withAccountGroups
*
AccountGroupQuery
withAccountGroups
*
AccountGroupQuery
withUserAllowedGroups
*
UserAllowedGroupQuery
withUserAllowedGroups
*
UserAllowedGroupQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
@@ -643,6 +645,9 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
...
@@ -643,6 +645,9 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
node
.
Edges
.
loadedTypes
=
loadedTypes
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
return
node
.
assignValues
(
columns
,
values
)
}
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
hooks
[
i
](
ctx
,
_spec
)
}
}
...
@@ -1025,6 +1030,9 @@ func (_q *GroupQuery) loadUserAllowedGroups(ctx context.Context, query *UserAllo
...
@@ -1025,6 +1030,9 @@ func (_q *GroupQuery) loadUserAllowedGroups(ctx context.Context, query *UserAllo
func
(
_q
*
GroupQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
func
(
_q
*
GroupQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
...
@@ -1087,6 +1095,9 @@ func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -1087,6 +1095,9 @@ func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
selector
.
Distinct
()
}
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
p
(
selector
)
}
}
...
@@ -1104,6 +1115,32 @@ func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
...
@@ -1104,6 +1115,32 @@ func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
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
*
GroupQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
GroupQuery
{
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
*
GroupQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
GroupQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// GroupGroupBy is the group-by builder for Group entities.
// GroupGroupBy is the group-by builder for Group entities.
type
GroupGroupBy
struct
{
type
GroupGroupBy
struct
{
selector
selector
...
...
backend/ent/hook/hook.go
View file @
e79dbad6
...
@@ -57,6 +57,30 @@ func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
...
@@ -57,6 +57,30 @@ func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.GroupMutation"
,
m
)
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.GroupMutation"
,
m
)
}
}
// The PromoCodeFunc type is an adapter to allow the use of ordinary
// function as PromoCode mutator.
type
PromoCodeFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
PromoCodeFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
PromoCodeMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.PromoCodeMutation"
,
m
)
}
// The PromoCodeUsageFunc type is an adapter to allow the use of ordinary
// function as PromoCodeUsage mutator.
type
PromoCodeUsageFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeUsageMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
PromoCodeUsageFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
PromoCodeUsageMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.PromoCodeUsageMutation"
,
m
)
}
// The ProxyFunc type is an adapter to allow the use of ordinary
// The ProxyFunc type is an adapter to allow the use of ordinary
// function as Proxy mutator.
// function as Proxy mutator.
type
ProxyFunc
func
(
context
.
Context
,
*
ent
.
ProxyMutation
)
(
ent
.
Value
,
error
)
type
ProxyFunc
func
(
context
.
Context
,
*
ent
.
ProxyMutation
)
(
ent
.
Value
,
error
)
...
...
backend/ent/intercept/intercept.go
View file @
e79dbad6
...
@@ -13,6 +13,8 @@ import (
...
@@ -13,6 +13,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"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/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
@@ -188,6 +190,60 @@ func (f TraverseGroup) Traverse(ctx context.Context, q ent.Query) error {
...
@@ -188,6 +190,60 @@ func (f TraverseGroup) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.GroupQuery"
,
q
)
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.GroupQuery"
,
q
)
}
}
// The PromoCodeFunc type is an adapter to allow the use of ordinary function as a Querier.
type
PromoCodeFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
PromoCodeFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeQuery"
,
q
)
}
// The TraversePromoCode type is an adapter to allow the use of ordinary function as Traverser.
type
TraversePromoCode
func
(
context
.
Context
,
*
ent
.
PromoCodeQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraversePromoCode
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraversePromoCode
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeQuery"
,
q
)
}
// The PromoCodeUsageFunc type is an adapter to allow the use of ordinary function as a Querier.
type
PromoCodeUsageFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeUsageQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
PromoCodeUsageFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeUsageQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeUsageQuery"
,
q
)
}
// The TraversePromoCodeUsage type is an adapter to allow the use of ordinary function as Traverser.
type
TraversePromoCodeUsage
func
(
context
.
Context
,
*
ent
.
PromoCodeUsageQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraversePromoCodeUsage
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraversePromoCodeUsage
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeUsageQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeUsageQuery"
,
q
)
}
// The ProxyFunc type is an adapter to allow the use of ordinary function as a Querier.
// The ProxyFunc type is an adapter to allow the use of ordinary function as a Querier.
type
ProxyFunc
func
(
context
.
Context
,
*
ent
.
ProxyQuery
)
(
ent
.
Value
,
error
)
type
ProxyFunc
func
(
context
.
Context
,
*
ent
.
ProxyQuery
)
(
ent
.
Value
,
error
)
...
@@ -442,6 +498,10 @@ func NewQuery(q ent.Query) (Query, error) {
...
@@ -442,6 +498,10 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
AccountGroupQuery
,
predicate
.
AccountGroup
,
accountgroup
.
OrderOption
]{
typ
:
ent
.
TypeAccountGroup
,
tq
:
q
},
nil
return
&
query
[
*
ent
.
AccountGroupQuery
,
predicate
.
AccountGroup
,
accountgroup
.
OrderOption
]{
typ
:
ent
.
TypeAccountGroup
,
tq
:
q
},
nil
case
*
ent
.
GroupQuery
:
case
*
ent
.
GroupQuery
:
return
&
query
[
*
ent
.
GroupQuery
,
predicate
.
Group
,
group
.
OrderOption
]{
typ
:
ent
.
TypeGroup
,
tq
:
q
},
nil
return
&
query
[
*
ent
.
GroupQuery
,
predicate
.
Group
,
group
.
OrderOption
]{
typ
:
ent
.
TypeGroup
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeQuery
:
return
&
query
[
*
ent
.
PromoCodeQuery
,
predicate
.
PromoCode
,
promocode
.
OrderOption
]{
typ
:
ent
.
TypePromoCode
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeUsageQuery
:
return
&
query
[
*
ent
.
PromoCodeUsageQuery
,
predicate
.
PromoCodeUsage
,
promocodeusage
.
OrderOption
]{
typ
:
ent
.
TypePromoCodeUsage
,
tq
:
q
},
nil
case
*
ent
.
ProxyQuery
:
case
*
ent
.
ProxyQuery
:
return
&
query
[
*
ent
.
ProxyQuery
,
predicate
.
Proxy
,
proxy
.
OrderOption
]{
typ
:
ent
.
TypeProxy
,
tq
:
q
},
nil
return
&
query
[
*
ent
.
ProxyQuery
,
predicate
.
Proxy
,
proxy
.
OrderOption
]{
typ
:
ent
.
TypeProxy
,
tq
:
q
},
nil
case
*
ent
.
RedeemCodeQuery
:
case
*
ent
.
RedeemCodeQuery
:
...
...
backend/ent/migrate/schema.go
View file @
e79dbad6
...
@@ -259,6 +259,82 @@ var (
...
@@ -259,6 +259,82 @@ var (
},
},
},
},
}
}
// PromoCodesColumns holds the columns for the "promo_codes" table.
PromoCodesColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"code"
,
Type
:
field
.
TypeString
,
Unique
:
true
,
Size
:
32
},
{
Name
:
"bonus_amount"
,
Type
:
field
.
TypeFloat64
,
Default
:
0
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"max_uses"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"used_count"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"expires_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"notes"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"updated_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
}
// PromoCodesTable holds the schema information for the "promo_codes" table.
PromoCodesTable
=
&
schema
.
Table
{
Name
:
"promo_codes"
,
Columns
:
PromoCodesColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"promocode_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
5
]},
},
{
Name
:
"promocode_expires_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
6
]},
},
},
}
// PromoCodeUsagesColumns holds the columns for the "promo_code_usages" table.
PromoCodeUsagesColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"bonus_amount"
,
Type
:
field
.
TypeFloat64
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"used_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"promo_code_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
}
// PromoCodeUsagesTable holds the schema information for the "promo_code_usages" table.
PromoCodeUsagesTable
=
&
schema
.
Table
{
Name
:
"promo_code_usages"
,
Columns
:
PromoCodeUsagesColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"promo_code_usages_promo_codes_usage_records"
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
3
]},
RefColumns
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"promo_code_usages_users_promo_code_usages"
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
4
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"promocodeusage_promo_code_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
3
]},
},
{
Name
:
"promocodeusage_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
4
]},
},
{
Name
:
"promocodeusage_promo_code_id_user_id"
,
Unique
:
true
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
3
],
PromoCodeUsagesColumns
[
4
]},
},
},
}
// ProxiesColumns holds the columns for the "proxies" table.
// ProxiesColumns holds the columns for the "proxies" table.
ProxiesColumns
=
[]
*
schema
.
Column
{
ProxiesColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
@@ -720,6 +796,8 @@ var (
...
@@ -720,6 +796,8 @@ var (
AccountsTable
,
AccountsTable
,
AccountGroupsTable
,
AccountGroupsTable
,
GroupsTable
,
GroupsTable
,
PromoCodesTable
,
PromoCodeUsagesTable
,
ProxiesTable
,
ProxiesTable
,
RedeemCodesTable
,
RedeemCodesTable
,
SettingsTable
,
SettingsTable
,
...
@@ -750,6 +828,14 @@ func init() {
...
@@ -750,6 +828,14 @@ func init() {
GroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
GroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"groups"
,
Table
:
"groups"
,
}
}
PromoCodesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"promo_codes"
,
}
PromoCodeUsagesTable
.
ForeignKeys
[
0
]
.
RefTable
=
PromoCodesTable
PromoCodeUsagesTable
.
ForeignKeys
[
1
]
.
RefTable
=
UsersTable
PromoCodeUsagesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"promo_code_usages"
,
}
ProxiesTable
.
Annotation
=
&
entsql
.
Annotation
{
ProxiesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"proxies"
,
Table
:
"proxies"
,
}
}
...
...
backend/ent/mutation.go
View file @
e79dbad6
...
@@ -16,6 +16,8 @@ import (
...
@@ -16,6 +16,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"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/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
@@ -40,6 +42,8 @@ const (
...
@@ -40,6 +42,8 @@ const (
TypeAccount = "Account"
TypeAccount = "Account"
TypeAccountGroup = "AccountGroup"
TypeAccountGroup = "AccountGroup"
TypeGroup = "Group"
TypeGroup = "Group"
TypePromoCode = "PromoCode"
TypePromoCodeUsage = "PromoCodeUsage"
TypeProxy = "Proxy"
TypeProxy = "Proxy"
TypeRedeemCode = "RedeemCode"
TypeRedeemCode = "RedeemCode"
TypeSetting = "Setting"
TypeSetting = "Setting"
...
@@ -6026,6 +6030,1624 @@ func (m *GroupMutation) ResetEdge(name string) error {
...
@@ -6026,6 +6030,1624 @@ func (m *GroupMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Group edge %s", name)
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 promocodeusage.FieldBonusAmount:
m.ResetBonusAmount()
return nil
case promocodeusage.FieldUsedAt:
m.ResetUsedAt()
return nil
}
return fmt.Errorf("unknown PromoCodeUsage field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PromoCodeUsageMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.promo_code != nil {
edges = append(edges, promocodeusage.EdgePromoCode)
}
if m.user != nil {
edges = append(edges, promocodeusage.EdgeUser)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PromoCodeUsageMutation) AddedIDs(name string) []ent.Value {
switch name {
case promocodeusage.EdgePromoCode:
if id := m.promo_code; id != nil {
return []ent.Value{*id}
}
case promocodeusage.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
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 *PromoCodeUsageMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PromoCodeUsageMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.clearedpromo_code {
edges = append(edges, promocodeusage.EdgePromoCode)
}
if m.cleareduser {
edges = append(edges, promocodeusage.EdgeUser)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PromoCodeUsageMutation) EdgeCleared(name string) bool {
switch name {
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 *PromoCodeUsageMutation) ClearEdge(name string) error {
switch name {
case promocodeusage.EdgePromoCode:
m.ClearPromoCode()
return nil
case promocodeusage.EdgeUser:
m.ClearUser()
return nil
}
return fmt.Errorf("unknown PromoCodeUsage 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 *PromoCodeUsageMutation) ResetEdge(name string) error {
switch name {
case promocodeusage.EdgePromoCode:
m.ResetPromoCode()
return nil
case promocodeusage.EdgeUser:
m.ResetUser()
return nil
}
return fmt.Errorf("unknown PromoCodeUsage edge %s", name)
}
// ProxyMutation represents an operation that mutates the Proxy nodes in the graph.
// ProxyMutation represents an operation that mutates the Proxy nodes in the graph.
type ProxyMutation struct {
type ProxyMutation struct {
config
config
...
@@ -11353,6 +12975,9 @@ type UserMutation struct {
...
@@ -11353,6 +12975,9 @@ type UserMutation struct {
attribute_values map[int64]struct{}
attribute_values map[int64]struct{}
removedattribute_values map[int64]struct{}
removedattribute_values map[int64]struct{}
clearedattribute_values bool
clearedattribute_values bool
promo_code_usages map[int64]struct{}
removedpromo_code_usages map[int64]struct{}
clearedpromo_code_usages bool
done bool
done bool
oldValue func(context.Context) (*User, error)
oldValue func(context.Context) (*User, error)
predicates []predicate.User
predicates []predicate.User
...
@@ -12283,6 +13908,60 @@ func (m *UserMutation) ResetAttributeValues() {
...
@@ -12283,6 +13908,60 @@ func (m *UserMutation) ResetAttributeValues() {
m.removedattribute_values = nil
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.
// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
func (m *UserMutation) Where(ps ...predicate.User) {
m.predicates = append(m.predicates, ps...)
m.predicates = append(m.predicates, ps...)
...
@@ -12622,7 +14301,7 @@ func (m *UserMutation) ResetField(name string) error {
...
@@ -12622,7 +14301,7 @@ func (m *UserMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
func (m *UserMutation) AddedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.api_keys != nil {
if m.api_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
edges = append(edges, user.EdgeAPIKeys)
}
}
...
@@ -12644,6 +14323,9 @@ func (m *UserMutation) AddedEdges() []string {
...
@@ -12644,6 +14323,9 @@ func (m *UserMutation) AddedEdges() []string {
if m.attribute_values != nil {
if m.attribute_values != nil {
edges = append(edges, user.EdgeAttributeValues)
edges = append(edges, user.EdgeAttributeValues)
}
}
if m.promo_code_usages != nil {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
return edges
}
}
...
@@ -12693,13 +14375,19 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value {
...
@@ -12693,13 +14375,19 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
ids = append(ids, id)
}
}
return ids
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
return nil
}
}
// RemovedEdges returns all edge names that were removed in this mutation.
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.removedapi_keys != nil {
if m.removedapi_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
edges = append(edges, user.EdgeAPIKeys)
}
}
...
@@ -12721,6 +14409,9 @@ func (m *UserMutation) RemovedEdges() []string {
...
@@ -12721,6 +14409,9 @@ func (m *UserMutation) RemovedEdges() []string {
if m.removedattribute_values != nil {
if m.removedattribute_values != nil {
edges = append(edges, user.EdgeAttributeValues)
edges = append(edges, user.EdgeAttributeValues)
}
}
if m.removedpromo_code_usages != nil {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
return edges
}
}
...
@@ -12770,13 +14461,19 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value {
...
@@ -12770,13 +14461,19 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
ids = append(ids, id)
}
}
return ids
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
return nil
}
}
// ClearedEdges returns all edge names that were cleared in this mutation.
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
func (m *UserMutation) ClearedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.clearedapi_keys {
if m.clearedapi_keys {
edges = append(edges, user.EdgeAPIKeys)
edges = append(edges, user.EdgeAPIKeys)
}
}
...
@@ -12798,6 +14495,9 @@ func (m *UserMutation) ClearedEdges() []string {
...
@@ -12798,6 +14495,9 @@ func (m *UserMutation) ClearedEdges() []string {
if m.clearedattribute_values {
if m.clearedattribute_values {
edges = append(edges, user.EdgeAttributeValues)
edges = append(edges, user.EdgeAttributeValues)
}
}
if m.clearedpromo_code_usages {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
return edges
}
}
...
@@ -12819,6 +14519,8 @@ func (m *UserMutation) EdgeCleared(name string) bool {
...
@@ -12819,6 +14519,8 @@ func (m *UserMutation) EdgeCleared(name string) bool {
return m.clearedusage_logs
return m.clearedusage_logs
case user.EdgeAttributeValues:
case user.EdgeAttributeValues:
return m.clearedattribute_values
return m.clearedattribute_values
case user.EdgePromoCodeUsages:
return m.clearedpromo_code_usages
}
}
return false
return false
}
}
...
@@ -12856,6 +14558,9 @@ func (m *UserMutation) ResetEdge(name string) error {
...
@@ -12856,6 +14558,9 @@ func (m *UserMutation) ResetEdge(name string) error {
case user.EdgeAttributeValues:
case user.EdgeAttributeValues:
m.ResetAttributeValues()
m.ResetAttributeValues()
return nil
return nil
case user.EdgePromoCodeUsages:
m.ResetPromoCodeUsages()
return nil
}
}
return fmt.Errorf("unknown User edge %s", name)
return fmt.Errorf("unknown User edge %s", name)
}
}
...
...
backend/ent/predicate/predicate.go
View file @
e79dbad6
...
@@ -18,6 +18,12 @@ type AccountGroup func(*sql.Selector)
...
@@ -18,6 +18,12 @@ type AccountGroup func(*sql.Selector)
// Group is the predicate function for group builders.
// Group is the predicate function for group builders.
type
Group
func
(
*
sql
.
Selector
)
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.
// Proxy is the predicate function for proxy builders.
type
Proxy
func
(
*
sql
.
Selector
)
type
Proxy
func
(
*
sql
.
Selector
)
...
...
backend/ent/promocode.go
0 → 100644
View file @
e79dbad6
// 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 @
e79dbad6
// 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 @
e79dbad6
// 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 @
e79dbad6
// 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 @
e79dbad6
// 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
)
}
}
Prev
1
2
3
4
5
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