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
c8e2f614
Commit
c8e2f614
authored
Jan 20, 2026
by
cyhhao
Browse files
Merge branch 'main' of github.com:Wei-Shaw/sub2api
parents
c0347cde
c95a8649
Changes
167
Hide whitespace changes
Inline
Side-by-side
backend/cmd/server/main.go
View file @
c8e2f614
...
...
@@ -8,6 +8,7 @@ import (
"errors"
"flag"
"log"
"log/slog"
"net/http"
"os"
"os/signal"
...
...
@@ -44,7 +45,25 @@ func init() {
}
}
// initLogger configures the default slog handler based on gin.Mode().
// In non-release mode, Debug level logs are enabled.
func
initLogger
()
{
var
level
slog
.
Level
if
gin
.
Mode
()
==
gin
.
ReleaseMode
{
level
=
slog
.
LevelInfo
}
else
{
level
=
slog
.
LevelDebug
}
handler
:=
slog
.
NewTextHandler
(
os
.
Stderr
,
&
slog
.
HandlerOptions
{
Level
:
level
,
})
slog
.
SetDefault
(
slog
.
New
(
handler
))
}
func
main
()
{
// Initialize slog logger based on gin mode
initLogger
()
// Parse command line flags
setupMode
:=
flag
.
Bool
(
"setup"
,
false
,
"Run setup wizard in CLI mode"
)
showVersion
:=
flag
.
Bool
(
"version"
,
false
,
"Show version information"
)
...
...
backend/cmd/server/wire.go
View file @
c8e2f614
...
...
@@ -70,6 +70,7 @@ func provideCleanup(
schedulerSnapshot
*
service
.
SchedulerSnapshotService
,
tokenRefresh
*
service
.
TokenRefreshService
,
accountExpiry
*
service
.
AccountExpiryService
,
usageCleanup
*
service
.
UsageCleanupService
,
pricing
*
service
.
PricingService
,
emailQueue
*
service
.
EmailQueueService
,
billingCache
*
service
.
BillingCacheService
,
...
...
@@ -123,6 +124,12 @@ func provideCleanup(
}
return
nil
}},
{
"UsageCleanupService"
,
func
()
error
{
if
usageCleanup
!=
nil
{
usageCleanup
.
Stop
()
}
return
nil
}},
{
"TokenRefreshService"
,
func
()
error
{
tokenRefresh
.
Stop
()
return
nil
...
...
backend/cmd/server/wire_gen.go
View file @
c8e2f614
...
...
@@ -105,21 +105,22 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
geminiTokenCache
:=
repository
.
NewGeminiTokenCache
(
redisClient
)
compositeTokenCacheInvalidator
:=
service
.
NewCompositeTokenCacheInvalidator
(
geminiTokenCache
)
rateLimitService
:=
service
.
ProvideRateLimitService
(
accountRepository
,
usageLogRepository
,
configConfig
,
geminiQuotaService
,
tempUnschedCache
,
timeoutCounterCache
,
settingService
,
compositeTokenCacheInvalidator
)
claudeUsageFetcher
:=
repository
.
NewClaudeUsageFetcher
()
httpUpstream
:=
repository
.
NewHTTPUpstream
(
configConfig
)
claudeUsageFetcher
:=
repository
.
NewClaudeUsageFetcher
(
httpUpstream
)
antigravityQuotaFetcher
:=
service
.
NewAntigravityQuotaFetcher
(
proxyRepository
)
usageCache
:=
service
.
NewUsageCache
()
accountUsageService
:=
service
.
NewAccountUsageService
(
accountRepository
,
usageLogRepository
,
claudeUsageFetcher
,
geminiQuotaService
,
antigravityQuotaFetcher
,
usageCache
)
identityCache
:=
repository
.
NewIdentityCache
(
redisClient
)
accountUsageService
:=
service
.
NewAccountUsageService
(
accountRepository
,
usageLogRepository
,
claudeUsageFetcher
,
geminiQuotaService
,
antigravityQuotaFetcher
,
usageCache
,
identityCache
)
geminiTokenProvider
:=
service
.
NewGeminiTokenProvider
(
accountRepository
,
geminiTokenCache
,
geminiOAuthService
)
gatewayCache
:=
repository
.
NewGatewayCache
(
redisClient
)
antigravityTokenProvider
:=
service
.
NewAntigravityTokenProvider
(
accountRepository
,
geminiTokenCache
,
antigravityOAuthService
)
httpUpstream
:=
repository
.
NewHTTPUpstream
(
configConfig
)
antigravityGatewayService
:=
service
.
NewAntigravityGatewayService
(
accountRepository
,
gatewayCache
,
antigravityTokenProvider
,
rateLimitService
,
httpUpstream
,
settingService
)
accountTestService
:=
service
.
NewAccountTestService
(
accountRepository
,
geminiTokenProvider
,
antigravityGatewayService
,
httpUpstream
,
configConfig
)
concurrencyCache
:=
repository
.
ProvideConcurrencyCache
(
redisClient
,
configConfig
)
concurrencyService
:=
service
.
ProvideConcurrencyService
(
concurrencyCache
,
accountRepository
,
configConfig
)
crsSyncService
:=
service
.
NewCRSSyncService
(
accountRepository
,
proxyRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
configConfig
)
sessionLimitCache
:=
repository
.
ProvideSessionLimitCache
(
redisClient
,
configConfig
)
accountHandler
:=
admin
.
NewAccountHandler
(
adminService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
rateLimitService
,
accountUsageService
,
accountTestService
,
concurrencyService
,
crsSyncService
,
sessionLimitCache
)
accountHandler
:=
admin
.
NewAccountHandler
(
adminService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
rateLimitService
,
accountUsageService
,
accountTestService
,
concurrencyService
,
crsSyncService
,
sessionLimitCache
,
compositeTokenCacheInvalidator
)
oAuthHandler
:=
admin
.
NewOAuthHandler
(
oAuthService
)
openAIOAuthHandler
:=
admin
.
NewOpenAIOAuthHandler
(
openAIOAuthService
,
adminService
)
geminiOAuthHandler
:=
admin
.
NewGeminiOAuthHandler
(
geminiOAuthService
)
...
...
@@ -137,7 +138,6 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
return
nil
,
err
}
billingService
:=
service
.
NewBillingService
(
configConfig
,
pricingService
)
identityCache
:=
repository
.
NewIdentityCache
(
redisClient
)
identityService
:=
service
.
NewIdentityService
(
identityCache
)
deferredService
:=
service
.
ProvideDeferredService
(
accountRepository
,
timingWheelService
)
claudeTokenProvider
:=
service
.
NewClaudeTokenProvider
(
accountRepository
,
geminiTokenCache
,
oAuthService
)
...
...
@@ -154,7 +154,9 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
updateService
:=
service
.
ProvideUpdateService
(
updateCache
,
gitHubReleaseClient
,
serviceBuildInfo
)
systemHandler
:=
handler
.
ProvideSystemHandler
(
updateService
)
adminSubscriptionHandler
:=
admin
.
NewSubscriptionHandler
(
subscriptionService
)
adminUsageHandler
:=
admin
.
NewUsageHandler
(
usageService
,
apiKeyService
,
adminService
)
usageCleanupRepository
:=
repository
.
NewUsageCleanupRepository
(
client
,
db
)
usageCleanupService
:=
service
.
ProvideUsageCleanupService
(
usageCleanupRepository
,
timingWheelService
,
dashboardAggregationService
,
configConfig
)
adminUsageHandler
:=
admin
.
NewUsageHandler
(
usageService
,
apiKeyService
,
adminService
,
usageCleanupService
)
userAttributeDefinitionRepository
:=
repository
.
NewUserAttributeDefinitionRepository
(
client
)
userAttributeValueRepository
:=
repository
.
NewUserAttributeValueRepository
(
client
)
userAttributeService
:=
service
.
NewUserAttributeService
(
userAttributeDefinitionRepository
,
userAttributeValueRepository
)
...
...
@@ -176,7 +178,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
opsScheduledReportService
:=
service
.
ProvideOpsScheduledReportService
(
opsService
,
userService
,
emailService
,
redisClient
,
configConfig
)
tokenRefreshService
:=
service
.
ProvideTokenRefreshService
(
accountRepository
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
,
compositeTokenCacheInvalidator
,
configConfig
)
accountExpiryService
:=
service
.
ProvideAccountExpiryService
(
accountRepository
)
v
:=
provideCleanup
(
client
,
redisClient
,
opsMetricsCollector
,
opsAggregationService
,
opsAlertEvaluatorService
,
opsCleanupService
,
opsScheduledReportService
,
schedulerSnapshotService
,
tokenRefreshService
,
accountExpiryService
,
pricingService
,
emailQueueService
,
billingCacheService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
)
v
:=
provideCleanup
(
client
,
redisClient
,
opsMetricsCollector
,
opsAggregationService
,
opsAlertEvaluatorService
,
opsCleanupService
,
opsScheduledReportService
,
schedulerSnapshotService
,
tokenRefreshService
,
accountExpiryService
,
usageCleanupService
,
pricingService
,
emailQueueService
,
billingCacheService
,
oAuthService
,
openAIOAuthService
,
geminiOAuthService
,
antigravityOAuthService
)
application
:=
&
Application
{
Server
:
httpServer
,
Cleanup
:
v
,
...
...
@@ -209,6 +211,7 @@ func provideCleanup(
schedulerSnapshot
*
service
.
SchedulerSnapshotService
,
tokenRefresh
*
service
.
TokenRefreshService
,
accountExpiry
*
service
.
AccountExpiryService
,
usageCleanup
*
service
.
UsageCleanupService
,
pricing
*
service
.
PricingService
,
emailQueue
*
service
.
EmailQueueService
,
billingCache
*
service
.
BillingCacheService
,
...
...
@@ -261,6 +264,12 @@ func provideCleanup(
}
return
nil
}},
{
"UsageCleanupService"
,
func
()
error
{
if
usageCleanup
!=
nil
{
usageCleanup
.
Stop
()
}
return
nil
}},
{
"TokenRefreshService"
,
func
()
error
{
tokenRefresh
.
Stop
()
return
nil
...
...
backend/ent/client.go
View file @
c8e2f614
...
...
@@ -24,6 +24,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -57,6 +58,8 @@ type Client struct {
RedeemCode
*
RedeemCodeClient
// Setting is the client for interacting with the Setting builders.
Setting
*
SettingClient
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
UsageCleanupTask
*
UsageCleanupTaskClient
// UsageLog is the client for interacting with the UsageLog builders.
UsageLog
*
UsageLogClient
// User is the client for interacting with the User builders.
...
...
@@ -89,6 +92,7 @@ func (c *Client) init() {
c
.
Proxy
=
NewProxyClient
(
c
.
config
)
c
.
RedeemCode
=
NewRedeemCodeClient
(
c
.
config
)
c
.
Setting
=
NewSettingClient
(
c
.
config
)
c
.
UsageCleanupTask
=
NewUsageCleanupTaskClient
(
c
.
config
)
c
.
UsageLog
=
NewUsageLogClient
(
c
.
config
)
c
.
User
=
NewUserClient
(
c
.
config
)
c
.
UserAllowedGroup
=
NewUserAllowedGroupClient
(
c
.
config
)
...
...
@@ -196,6 +200,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
UsageCleanupTask
:
NewUsageCleanupTaskClient
(
cfg
),
UsageLog
:
NewUsageLogClient
(
cfg
),
User
:
NewUserClient
(
cfg
),
UserAllowedGroup
:
NewUserAllowedGroupClient
(
cfg
),
...
...
@@ -230,6 +235,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
UsageCleanupTask
:
NewUsageCleanupTaskClient
(
cfg
),
UsageLog
:
NewUsageLogClient
(
cfg
),
User
:
NewUserClient
(
cfg
),
UserAllowedGroup
:
NewUserAllowedGroupClient
(
cfg
),
...
...
@@ -266,8 +272,9 @@ func (c *Client) Close() error {
func
(
c
*
Client
)
Use
(
hooks
...
Hook
)
{
for
_
,
n
:=
range
[]
interface
{
Use
(
...
Hook
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
PromoCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageCleanupTask
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
n
.
Use
(
hooks
...
)
}
...
...
@@ -278,8 +285,9 @@ func (c *Client) Use(hooks ...Hook) {
func
(
c
*
Client
)
Intercept
(
interceptors
...
Interceptor
)
{
for
_
,
n
:=
range
[]
interface
{
Intercept
(
...
Interceptor
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
PromoCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageCleanupTask
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
n
.
Intercept
(
interceptors
...
)
}
...
...
@@ -306,6 +314,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return
c
.
RedeemCode
.
mutate
(
ctx
,
m
)
case
*
SettingMutation
:
return
c
.
Setting
.
mutate
(
ctx
,
m
)
case
*
UsageCleanupTaskMutation
:
return
c
.
UsageCleanupTask
.
mutate
(
ctx
,
m
)
case
*
UsageLogMutation
:
return
c
.
UsageLog
.
mutate
(
ctx
,
m
)
case
*
UserMutation
:
...
...
@@ -1847,6 +1857,139 @@ func (c *SettingClient) mutate(ctx context.Context, m *SettingMutation) (Value,
}
}
// UsageCleanupTaskClient is a client for the UsageCleanupTask schema.
type
UsageCleanupTaskClient
struct
{
config
}
// NewUsageCleanupTaskClient returns a client for the UsageCleanupTask from the given config.
func
NewUsageCleanupTaskClient
(
c
config
)
*
UsageCleanupTaskClient
{
return
&
UsageCleanupTaskClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `usagecleanuptask.Hooks(f(g(h())))`.
func
(
c
*
UsageCleanupTaskClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
UsageCleanupTask
=
append
(
c
.
hooks
.
UsageCleanupTask
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `usagecleanuptask.Intercept(f(g(h())))`.
func
(
c
*
UsageCleanupTaskClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
UsageCleanupTask
=
append
(
c
.
inters
.
UsageCleanupTask
,
interceptors
...
)
}
// Create returns a builder for creating a UsageCleanupTask entity.
func
(
c
*
UsageCleanupTaskClient
)
Create
()
*
UsageCleanupTaskCreate
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpCreate
)
return
&
UsageCleanupTaskCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of UsageCleanupTask entities.
func
(
c
*
UsageCleanupTaskClient
)
CreateBulk
(
builders
...*
UsageCleanupTaskCreate
)
*
UsageCleanupTaskCreateBulk
{
return
&
UsageCleanupTaskCreateBulk
{
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
*
UsageCleanupTaskClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
UsageCleanupTaskCreate
,
int
))
*
UsageCleanupTaskCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
UsageCleanupTaskCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to UsageCleanupTaskClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
UsageCleanupTaskCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
UsageCleanupTaskCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for UsageCleanupTask.
func
(
c
*
UsageCleanupTaskClient
)
Update
()
*
UsageCleanupTaskUpdate
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpUpdate
)
return
&
UsageCleanupTaskUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
UsageCleanupTaskClient
)
UpdateOne
(
_m
*
UsageCleanupTask
)
*
UsageCleanupTaskUpdateOne
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpUpdateOne
,
withUsageCleanupTask
(
_m
))
return
&
UsageCleanupTaskUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
UsageCleanupTaskClient
)
UpdateOneID
(
id
int64
)
*
UsageCleanupTaskUpdateOne
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpUpdateOne
,
withUsageCleanupTaskID
(
id
))
return
&
UsageCleanupTaskUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for UsageCleanupTask.
func
(
c
*
UsageCleanupTaskClient
)
Delete
()
*
UsageCleanupTaskDelete
{
mutation
:=
newUsageCleanupTaskMutation
(
c
.
config
,
OpDelete
)
return
&
UsageCleanupTaskDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
UsageCleanupTaskClient
)
DeleteOne
(
_m
*
UsageCleanupTask
)
*
UsageCleanupTaskDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
UsageCleanupTaskClient
)
DeleteOneID
(
id
int64
)
*
UsageCleanupTaskDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
usagecleanuptask
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
UsageCleanupTaskDeleteOne
{
builder
}
}
// Query returns a query builder for UsageCleanupTask.
func
(
c
*
UsageCleanupTaskClient
)
Query
()
*
UsageCleanupTaskQuery
{
return
&
UsageCleanupTaskQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypeUsageCleanupTask
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a UsageCleanupTask entity by its id.
func
(
c
*
UsageCleanupTaskClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
UsageCleanupTask
,
error
)
{
return
c
.
Query
()
.
Where
(
usagecleanuptask
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
UsageCleanupTaskClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
UsageCleanupTask
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// Hooks returns the client hooks.
func
(
c
*
UsageCleanupTaskClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
UsageCleanupTask
}
// Interceptors returns the client interceptors.
func
(
c
*
UsageCleanupTaskClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
UsageCleanupTask
}
func
(
c
*
UsageCleanupTaskClient
)
mutate
(
ctx
context
.
Context
,
m
*
UsageCleanupTaskMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
UsageCleanupTaskCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
UsageCleanupTaskUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
UsageCleanupTaskUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
UsageCleanupTaskDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown UsageCleanupTask mutation op: %q"
,
m
.
Op
())
}
}
// UsageLogClient is a client for the UsageLog schema.
type
UsageLogClient
struct
{
config
...
...
@@ -2974,13 +3117,13 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
type
(
hooks
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
PromoCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
RedeemCode
,
Setting
,
UsageCleanupTask
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
}
inters
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
PromoCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
RedeemCode
,
Setting
,
UsageCleanupTask
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
}
)
...
...
backend/ent/ent.go
View file @
c8e2f614
...
...
@@ -21,6 +21,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -96,6 +97,7 @@ func checkColumn(t, c string) error {
proxy
.
Table
:
proxy
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
usagecleanuptask
.
Table
:
usagecleanuptask
.
ValidColumn
,
usagelog
.
Table
:
usagelog
.
ValidColumn
,
user
.
Table
:
user
.
ValidColumn
,
userallowedgroup
.
Table
:
userallowedgroup
.
ValidColumn
,
...
...
backend/ent/hook/hook.go
View file @
c8e2f614
...
...
@@ -117,6 +117,18 @@ func (f SettingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, err
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.SettingMutation"
,
m
)
}
// The UsageCleanupTaskFunc type is an adapter to allow the use of ordinary
// function as UsageCleanupTask mutator.
type
UsageCleanupTaskFunc
func
(
context
.
Context
,
*
ent
.
UsageCleanupTaskMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
UsageCleanupTaskFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
UsageCleanupTaskMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.UsageCleanupTaskMutation"
,
m
)
}
// The UsageLogFunc type is an adapter to allow the use of ordinary
// function as UsageLog mutator.
type
UsageLogFunc
func
(
context
.
Context
,
*
ent
.
UsageLogMutation
)
(
ent
.
Value
,
error
)
...
...
backend/ent/intercept/intercept.go
View file @
c8e2f614
...
...
@@ -18,6 +18,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -325,6 +326,33 @@ func (f TraverseSetting) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.SettingQuery"
,
q
)
}
// The UsageCleanupTaskFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UsageCleanupTaskFunc
func
(
context
.
Context
,
*
ent
.
UsageCleanupTaskQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
UsageCleanupTaskFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
UsageCleanupTaskQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UsageCleanupTaskQuery"
,
q
)
}
// The TraverseUsageCleanupTask type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseUsageCleanupTask
func
(
context
.
Context
,
*
ent
.
UsageCleanupTaskQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseUsageCleanupTask
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseUsageCleanupTask
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
UsageCleanupTaskQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.UsageCleanupTaskQuery"
,
q
)
}
// The UsageLogFunc type is an adapter to allow the use of ordinary function as a Querier.
type
UsageLogFunc
func
(
context
.
Context
,
*
ent
.
UsageLogQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -508,6 +536,8 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
RedeemCodeQuery
,
predicate
.
RedeemCode
,
redeemcode
.
OrderOption
]{
typ
:
ent
.
TypeRedeemCode
,
tq
:
q
},
nil
case
*
ent
.
SettingQuery
:
return
&
query
[
*
ent
.
SettingQuery
,
predicate
.
Setting
,
setting
.
OrderOption
]{
typ
:
ent
.
TypeSetting
,
tq
:
q
},
nil
case
*
ent
.
UsageCleanupTaskQuery
:
return
&
query
[
*
ent
.
UsageCleanupTaskQuery
,
predicate
.
UsageCleanupTask
,
usagecleanuptask
.
OrderOption
]{
typ
:
ent
.
TypeUsageCleanupTask
,
tq
:
q
},
nil
case
*
ent
.
UsageLogQuery
:
return
&
query
[
*
ent
.
UsageLogQuery
,
predicate
.
UsageLog
,
usagelog
.
OrderOption
]{
typ
:
ent
.
TypeUsageLog
,
tq
:
q
},
nil
case
*
ent
.
UserQuery
:
...
...
backend/ent/migrate/schema.go
View file @
c8e2f614
...
...
@@ -434,6 +434,44 @@ var (
Columns
:
SettingsColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
SettingsColumns
[
0
]},
}
// UsageCleanupTasksColumns holds the columns for the "usage_cleanup_tasks" table.
UsageCleanupTasksColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"updated_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
},
{
Name
:
"filters"
,
Type
:
field
.
TypeJSON
},
{
Name
:
"created_by"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"deleted_rows"
,
Type
:
field
.
TypeInt64
,
Default
:
0
},
{
Name
:
"error_message"
,
Type
:
field
.
TypeString
,
Nullable
:
true
},
{
Name
:
"canceled_by"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"canceled_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"started_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"finished_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
}
// UsageCleanupTasksTable holds the schema information for the "usage_cleanup_tasks" table.
UsageCleanupTasksTable
=
&
schema
.
Table
{
Name
:
"usage_cleanup_tasks"
,
Columns
:
UsageCleanupTasksColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"usagecleanuptask_status_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
3
],
UsageCleanupTasksColumns
[
1
]},
},
{
Name
:
"usagecleanuptask_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
1
]},
},
{
Name
:
"usagecleanuptask_canceled_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageCleanupTasksColumns
[
9
]},
},
},
}
// UsageLogsColumns holds the columns for the "usage_logs" table.
UsageLogsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -805,6 +843,7 @@ var (
ProxiesTable
,
RedeemCodesTable
,
SettingsTable
,
UsageCleanupTasksTable
,
UsageLogsTable
,
UsersTable
,
UserAllowedGroupsTable
,
...
...
@@ -851,6 +890,9 @@ func init() {
SettingsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"settings"
,
}
UsageCleanupTasksTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"usage_cleanup_tasks"
,
}
UsageLogsTable
.
ForeignKeys
[
0
]
.
RefTable
=
APIKeysTable
UsageLogsTable
.
ForeignKeys
[
1
]
.
RefTable
=
AccountsTable
UsageLogsTable
.
ForeignKeys
[
2
]
.
RefTable
=
GroupsTable
...
...
backend/ent/mutation.go
View file @
c8e2f614
...
...
@@ -4,6 +4,7 @@ package ent
import (
"context"
"encoding/json"
"errors"
"fmt"
"sync"
...
...
@@ -21,6 +22,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -47,6 +49,7 @@ const (
TypeProxy = "Proxy"
TypeRedeemCode = "RedeemCode"
TypeSetting = "Setting"
TypeUsageCleanupTask = "UsageCleanupTask"
TypeUsageLog = "UsageLog"
TypeUser = "User"
TypeUserAllowedGroup = "UserAllowedGroup"
...
...
@@ -10370,6 +10373,1089 @@ func (m *SettingMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Setting edge %s", name)
}
// UsageCleanupTaskMutation represents an operation that mutates the UsageCleanupTask nodes in the graph.
type UsageCleanupTaskMutation struct {
config
op Op
typ string
id *int64
created_at *time.Time
updated_at *time.Time
status *string
filters *json.RawMessage
appendfilters json.RawMessage
created_by *int64
addcreated_by *int64
deleted_rows *int64
adddeleted_rows *int64
error_message *string
canceled_by *int64
addcanceled_by *int64
canceled_at *time.Time
started_at *time.Time
finished_at *time.Time
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*UsageCleanupTask, error)
predicates []predicate.UsageCleanupTask
}
var _ ent.Mutation = (*UsageCleanupTaskMutation)(nil)
// usagecleanuptaskOption allows management of the mutation configuration using functional options.
type usagecleanuptaskOption func(*UsageCleanupTaskMutation)
// newUsageCleanupTaskMutation creates new mutation for the UsageCleanupTask entity.
func newUsageCleanupTaskMutation(c config, op Op, opts ...usagecleanuptaskOption) *UsageCleanupTaskMutation {
m := &UsageCleanupTaskMutation{
config: c,
op: op,
typ: TypeUsageCleanupTask,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUsageCleanupTaskID sets the ID field of the mutation.
func withUsageCleanupTaskID(id int64) usagecleanuptaskOption {
return func(m *UsageCleanupTaskMutation) {
var (
err error
once sync.Once
value *UsageCleanupTask
)
m.oldValue = func(ctx context.Context) (*UsageCleanupTask, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().UsageCleanupTask.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUsageCleanupTask sets the old UsageCleanupTask of the mutation.
func withUsageCleanupTask(node *UsageCleanupTask) usagecleanuptaskOption {
return func(m *UsageCleanupTaskMutation) {
m.oldValue = func(context.Context) (*UsageCleanupTask, 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 UsageCleanupTaskMutation) 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 UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) 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().UsageCleanupTask.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreatedAt sets the "created_at" field.
func (m *UsageCleanupTaskMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UsageCleanupTaskMutation) 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 UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *UsageCleanupTaskMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UsageCleanupTaskMutation) 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 UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetStatus sets the "status" field.
func (m *UsageCleanupTaskMutation) SetStatus(s string) {
m.status = &s
}
// Status returns the value of the "status" field in the mutation.
func (m *UsageCleanupTaskMutation) 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 UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ResetStatus() {
m.status = nil
}
// SetFilters sets the "filters" field.
func (m *UsageCleanupTaskMutation) SetFilters(jm json.RawMessage) {
m.filters = &jm
m.appendfilters = nil
}
// Filters returns the value of the "filters" field in the mutation.
func (m *UsageCleanupTaskMutation) Filters() (r json.RawMessage, exists bool) {
v := m.filters
if v == nil {
return
}
return *v, true
}
// OldFilters returns the old "filters" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldFilters(ctx context.Context) (v json.RawMessage, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFilters is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFilters requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFilters: %w", err)
}
return oldValue.Filters, nil
}
// AppendFilters adds jm to the "filters" field.
func (m *UsageCleanupTaskMutation) AppendFilters(jm json.RawMessage) {
m.appendfilters = append(m.appendfilters, jm...)
}
// AppendedFilters returns the list of values that were appended to the "filters" field in this mutation.
func (m *UsageCleanupTaskMutation) AppendedFilters() (json.RawMessage, bool) {
if len(m.appendfilters) == 0 {
return nil, false
}
return m.appendfilters, true
}
// ResetFilters resets all changes to the "filters" field.
func (m *UsageCleanupTaskMutation) ResetFilters() {
m.filters = nil
m.appendfilters = nil
}
// SetCreatedBy sets the "created_by" field.
func (m *UsageCleanupTaskMutation) SetCreatedBy(i int64) {
m.created_by = &i
m.addcreated_by = nil
}
// CreatedBy returns the value of the "created_by" field in the mutation.
func (m *UsageCleanupTaskMutation) CreatedBy() (r int64, exists bool) {
v := m.created_by
if v == nil {
return
}
return *v, true
}
// OldCreatedBy returns the old "created_by" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldCreatedBy(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedBy is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedBy requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedBy: %w", err)
}
return oldValue.CreatedBy, nil
}
// AddCreatedBy adds i to the "created_by" field.
func (m *UsageCleanupTaskMutation) AddCreatedBy(i int64) {
if m.addcreated_by != nil {
*m.addcreated_by += i
} else {
m.addcreated_by = &i
}
}
// AddedCreatedBy returns the value that was added to the "created_by" field in this mutation.
func (m *UsageCleanupTaskMutation) AddedCreatedBy() (r int64, exists bool) {
v := m.addcreated_by
if v == nil {
return
}
return *v, true
}
// ResetCreatedBy resets all changes to the "created_by" field.
func (m *UsageCleanupTaskMutation) ResetCreatedBy() {
m.created_by = nil
m.addcreated_by = nil
}
// SetDeletedRows sets the "deleted_rows" field.
func (m *UsageCleanupTaskMutation) SetDeletedRows(i int64) {
m.deleted_rows = &i
m.adddeleted_rows = nil
}
// DeletedRows returns the value of the "deleted_rows" field in the mutation.
func (m *UsageCleanupTaskMutation) DeletedRows() (r int64, exists bool) {
v := m.deleted_rows
if v == nil {
return
}
return *v, true
}
// OldDeletedRows returns the old "deleted_rows" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldDeletedRows(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedRows is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedRows requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedRows: %w", err)
}
return oldValue.DeletedRows, nil
}
// AddDeletedRows adds i to the "deleted_rows" field.
func (m *UsageCleanupTaskMutation) AddDeletedRows(i int64) {
if m.adddeleted_rows != nil {
*m.adddeleted_rows += i
} else {
m.adddeleted_rows = &i
}
}
// AddedDeletedRows returns the value that was added to the "deleted_rows" field in this mutation.
func (m *UsageCleanupTaskMutation) AddedDeletedRows() (r int64, exists bool) {
v := m.adddeleted_rows
if v == nil {
return
}
return *v, true
}
// ResetDeletedRows resets all changes to the "deleted_rows" field.
func (m *UsageCleanupTaskMutation) ResetDeletedRows() {
m.deleted_rows = nil
m.adddeleted_rows = nil
}
// SetErrorMessage sets the "error_message" field.
func (m *UsageCleanupTaskMutation) SetErrorMessage(s string) {
m.error_message = &s
}
// ErrorMessage returns the value of the "error_message" field in the mutation.
func (m *UsageCleanupTaskMutation) ErrorMessage() (r string, exists bool) {
v := m.error_message
if v == nil {
return
}
return *v, true
}
// OldErrorMessage returns the old "error_message" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldErrorMessage(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldErrorMessage is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldErrorMessage requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err)
}
return oldValue.ErrorMessage, nil
}
// ClearErrorMessage clears the value of the "error_message" field.
func (m *UsageCleanupTaskMutation) ClearErrorMessage() {
m.error_message = nil
m.clearedFields[usagecleanuptask.FieldErrorMessage] = struct{}{}
}
// ErrorMessageCleared returns if the "error_message" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) ErrorMessageCleared() bool {
_, ok := m.clearedFields[usagecleanuptask.FieldErrorMessage]
return ok
}
// ResetErrorMessage resets all changes to the "error_message" field.
func (m *UsageCleanupTaskMutation) ResetErrorMessage() {
m.error_message = nil
delete(m.clearedFields, usagecleanuptask.FieldErrorMessage)
}
// SetCanceledBy sets the "canceled_by" field.
func (m *UsageCleanupTaskMutation) SetCanceledBy(i int64) {
m.canceled_by = &i
m.addcanceled_by = nil
}
// CanceledBy returns the value of the "canceled_by" field in the mutation.
func (m *UsageCleanupTaskMutation) CanceledBy() (r int64, exists bool) {
v := m.canceled_by
if v == nil {
return
}
return *v, true
}
// OldCanceledBy returns the old "canceled_by" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldCanceledBy(ctx context.Context) (v *int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCanceledBy is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCanceledBy requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCanceledBy: %w", err)
}
return oldValue.CanceledBy, nil
}
// AddCanceledBy adds i to the "canceled_by" field.
func (m *UsageCleanupTaskMutation) AddCanceledBy(i int64) {
if m.addcanceled_by != nil {
*m.addcanceled_by += i
} else {
m.addcanceled_by = &i
}
}
// AddedCanceledBy returns the value that was added to the "canceled_by" field in this mutation.
func (m *UsageCleanupTaskMutation) AddedCanceledBy() (r int64, exists bool) {
v := m.addcanceled_by
if v == nil {
return
}
return *v, true
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func (m *UsageCleanupTaskMutation) ClearCanceledBy() {
m.canceled_by = nil
m.addcanceled_by = nil
m.clearedFields[usagecleanuptask.FieldCanceledBy] = struct{}{}
}
// CanceledByCleared returns if the "canceled_by" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) CanceledByCleared() bool {
_, ok := m.clearedFields[usagecleanuptask.FieldCanceledBy]
return ok
}
// ResetCanceledBy resets all changes to the "canceled_by" field.
func (m *UsageCleanupTaskMutation) ResetCanceledBy() {
m.canceled_by = nil
m.addcanceled_by = nil
delete(m.clearedFields, usagecleanuptask.FieldCanceledBy)
}
// SetCanceledAt sets the "canceled_at" field.
func (m *UsageCleanupTaskMutation) SetCanceledAt(t time.Time) {
m.canceled_at = &t
}
// CanceledAt returns the value of the "canceled_at" field in the mutation.
func (m *UsageCleanupTaskMutation) CanceledAt() (r time.Time, exists bool) {
v := m.canceled_at
if v == nil {
return
}
return *v, true
}
// OldCanceledAt returns the old "canceled_at" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldCanceledAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCanceledAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCanceledAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCanceledAt: %w", err)
}
return oldValue.CanceledAt, nil
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func (m *UsageCleanupTaskMutation) ClearCanceledAt() {
m.canceled_at = nil
m.clearedFields[usagecleanuptask.FieldCanceledAt] = struct{}{}
}
// CanceledAtCleared returns if the "canceled_at" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) CanceledAtCleared() bool {
_, ok := m.clearedFields[usagecleanuptask.FieldCanceledAt]
return ok
}
// ResetCanceledAt resets all changes to the "canceled_at" field.
func (m *UsageCleanupTaskMutation) ResetCanceledAt() {
m.canceled_at = nil
delete(m.clearedFields, usagecleanuptask.FieldCanceledAt)
}
// SetStartedAt sets the "started_at" field.
func (m *UsageCleanupTaskMutation) SetStartedAt(t time.Time) {
m.started_at = &t
}
// StartedAt returns the value of the "started_at" field in the mutation.
func (m *UsageCleanupTaskMutation) StartedAt() (r time.Time, exists bool) {
v := m.started_at
if v == nil {
return
}
return *v, true
}
// OldStartedAt returns the old "started_at" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldStartedAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStartedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStartedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStartedAt: %w", err)
}
return oldValue.StartedAt, nil
}
// ClearStartedAt clears the value of the "started_at" field.
func (m *UsageCleanupTaskMutation) ClearStartedAt() {
m.started_at = nil
m.clearedFields[usagecleanuptask.FieldStartedAt] = struct{}{}
}
// StartedAtCleared returns if the "started_at" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) StartedAtCleared() bool {
_, ok := m.clearedFields[usagecleanuptask.FieldStartedAt]
return ok
}
// ResetStartedAt resets all changes to the "started_at" field.
func (m *UsageCleanupTaskMutation) ResetStartedAt() {
m.started_at = nil
delete(m.clearedFields, usagecleanuptask.FieldStartedAt)
}
// SetFinishedAt sets the "finished_at" field.
func (m *UsageCleanupTaskMutation) SetFinishedAt(t time.Time) {
m.finished_at = &t
}
// FinishedAt returns the value of the "finished_at" field in the mutation.
func (m *UsageCleanupTaskMutation) FinishedAt() (r time.Time, exists bool) {
v := m.finished_at
if v == nil {
return
}
return *v, true
}
// OldFinishedAt returns the old "finished_at" field's value of the UsageCleanupTask entity.
// If the UsageCleanupTask 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 *UsageCleanupTaskMutation) OldFinishedAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldFinishedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldFinishedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldFinishedAt: %w", err)
}
return oldValue.FinishedAt, nil
}
// ClearFinishedAt clears the value of the "finished_at" field.
func (m *UsageCleanupTaskMutation) ClearFinishedAt() {
m.finished_at = nil
m.clearedFields[usagecleanuptask.FieldFinishedAt] = struct{}{}
}
// FinishedAtCleared returns if the "finished_at" field was cleared in this mutation.
func (m *UsageCleanupTaskMutation) FinishedAtCleared() bool {
_, ok := m.clearedFields[usagecleanuptask.FieldFinishedAt]
return ok
}
// ResetFinishedAt resets all changes to the "finished_at" field.
func (m *UsageCleanupTaskMutation) ResetFinishedAt() {
m.finished_at = nil
delete(m.clearedFields, usagecleanuptask.FieldFinishedAt)
}
// Where appends a list predicates to the UsageCleanupTaskMutation builder.
func (m *UsageCleanupTaskMutation) Where(ps ...predicate.UsageCleanupTask) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UsageCleanupTaskMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UsageCleanupTaskMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.UsageCleanupTask, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UsageCleanupTaskMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UsageCleanupTaskMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (UsageCleanupTask).
func (m *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) Fields() []string {
fields := make([]string, 0, 11)
if m.created_at != nil {
fields = append(fields, usagecleanuptask.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, usagecleanuptask.FieldUpdatedAt)
}
if m.status != nil {
fields = append(fields, usagecleanuptask.FieldStatus)
}
if m.filters != nil {
fields = append(fields, usagecleanuptask.FieldFilters)
}
if m.created_by != nil {
fields = append(fields, usagecleanuptask.FieldCreatedBy)
}
if m.deleted_rows != nil {
fields = append(fields, usagecleanuptask.FieldDeletedRows)
}
if m.error_message != nil {
fields = append(fields, usagecleanuptask.FieldErrorMessage)
}
if m.canceled_by != nil {
fields = append(fields, usagecleanuptask.FieldCanceledBy)
}
if m.canceled_at != nil {
fields = append(fields, usagecleanuptask.FieldCanceledAt)
}
if m.started_at != nil {
fields = append(fields, usagecleanuptask.FieldStartedAt)
}
if m.finished_at != nil {
fields = append(fields, usagecleanuptask.FieldFinishedAt)
}
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 *UsageCleanupTaskMutation) Field(name string) (ent.Value, bool) {
switch name {
case usagecleanuptask.FieldCreatedAt:
return m.CreatedAt()
case usagecleanuptask.FieldUpdatedAt:
return m.UpdatedAt()
case usagecleanuptask.FieldStatus:
return m.Status()
case usagecleanuptask.FieldFilters:
return m.Filters()
case usagecleanuptask.FieldCreatedBy:
return m.CreatedBy()
case usagecleanuptask.FieldDeletedRows:
return m.DeletedRows()
case usagecleanuptask.FieldErrorMessage:
return m.ErrorMessage()
case usagecleanuptask.FieldCanceledBy:
return m.CanceledBy()
case usagecleanuptask.FieldCanceledAt:
return m.CanceledAt()
case usagecleanuptask.FieldStartedAt:
return m.StartedAt()
case usagecleanuptask.FieldFinishedAt:
return m.FinishedAt()
}
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 *UsageCleanupTaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case usagecleanuptask.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case usagecleanuptask.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case usagecleanuptask.FieldStatus:
return m.OldStatus(ctx)
case usagecleanuptask.FieldFilters:
return m.OldFilters(ctx)
case usagecleanuptask.FieldCreatedBy:
return m.OldCreatedBy(ctx)
case usagecleanuptask.FieldDeletedRows:
return m.OldDeletedRows(ctx)
case usagecleanuptask.FieldErrorMessage:
return m.OldErrorMessage(ctx)
case usagecleanuptask.FieldCanceledBy:
return m.OldCanceledBy(ctx)
case usagecleanuptask.FieldCanceledAt:
return m.OldCanceledAt(ctx)
case usagecleanuptask.FieldStartedAt:
return m.OldStartedAt(ctx)
case usagecleanuptask.FieldFinishedAt:
return m.OldFinishedAt(ctx)
}
return nil, fmt.Errorf("unknown UsageCleanupTask 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 *UsageCleanupTaskMutation) SetField(name string, value ent.Value) error {
switch name {
case usagecleanuptask.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 usagecleanuptask.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case usagecleanuptask.FieldStatus:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStatus(v)
return nil
case usagecleanuptask.FieldFilters:
v, ok := value.(json.RawMessage)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFilters(v)
return nil
case usagecleanuptask.FieldCreatedBy:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedBy(v)
return nil
case usagecleanuptask.FieldDeletedRows:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedRows(v)
return nil
case usagecleanuptask.FieldErrorMessage:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetErrorMessage(v)
return nil
case usagecleanuptask.FieldCanceledBy:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCanceledBy(v)
return nil
case usagecleanuptask.FieldCanceledAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCanceledAt(v)
return nil
case usagecleanuptask.FieldStartedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStartedAt(v)
return nil
case usagecleanuptask.FieldFinishedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetFinishedAt(v)
return nil
}
return fmt.Errorf("unknown UsageCleanupTask field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UsageCleanupTaskMutation) AddedFields() []string {
var fields []string
if m.addcreated_by != nil {
fields = append(fields, usagecleanuptask.FieldCreatedBy)
}
if m.adddeleted_rows != nil {
fields = append(fields, usagecleanuptask.FieldDeletedRows)
}
if m.addcanceled_by != nil {
fields = append(fields, usagecleanuptask.FieldCanceledBy)
}
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 *UsageCleanupTaskMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case usagecleanuptask.FieldCreatedBy:
return m.AddedCreatedBy()
case usagecleanuptask.FieldDeletedRows:
return m.AddedDeletedRows()
case usagecleanuptask.FieldCanceledBy:
return m.AddedCanceledBy()
}
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 *UsageCleanupTaskMutation) AddField(name string, value ent.Value) error {
switch name {
case usagecleanuptask.FieldCreatedBy:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCreatedBy(v)
return nil
case usagecleanuptask.FieldDeletedRows:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddDeletedRows(v)
return nil
case usagecleanuptask.FieldCanceledBy:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddCanceledBy(v)
return nil
}
return fmt.Errorf("unknown UsageCleanupTask numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UsageCleanupTaskMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(usagecleanuptask.FieldErrorMessage) {
fields = append(fields, usagecleanuptask.FieldErrorMessage)
}
if m.FieldCleared(usagecleanuptask.FieldCanceledBy) {
fields = append(fields, usagecleanuptask.FieldCanceledBy)
}
if m.FieldCleared(usagecleanuptask.FieldCanceledAt) {
fields = append(fields, usagecleanuptask.FieldCanceledAt)
}
if m.FieldCleared(usagecleanuptask.FieldStartedAt) {
fields = append(fields, usagecleanuptask.FieldStartedAt)
}
if m.FieldCleared(usagecleanuptask.FieldFinishedAt) {
fields = append(fields, usagecleanuptask.FieldFinishedAt)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UsageCleanupTaskMutation) 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 *UsageCleanupTaskMutation) ClearField(name string) error {
switch name {
case usagecleanuptask.FieldErrorMessage:
m.ClearErrorMessage()
return nil
case usagecleanuptask.FieldCanceledBy:
m.ClearCanceledBy()
return nil
case usagecleanuptask.FieldCanceledAt:
m.ClearCanceledAt()
return nil
case usagecleanuptask.FieldStartedAt:
m.ClearStartedAt()
return nil
case usagecleanuptask.FieldFinishedAt:
m.ClearFinishedAt()
return nil
}
return fmt.Errorf("unknown UsageCleanupTask 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 *UsageCleanupTaskMutation) ResetField(name string) error {
switch name {
case usagecleanuptask.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case usagecleanuptask.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case usagecleanuptask.FieldStatus:
m.ResetStatus()
return nil
case usagecleanuptask.FieldFilters:
m.ResetFilters()
return nil
case usagecleanuptask.FieldCreatedBy:
m.ResetCreatedBy()
return nil
case usagecleanuptask.FieldDeletedRows:
m.ResetDeletedRows()
return nil
case usagecleanuptask.FieldErrorMessage:
m.ResetErrorMessage()
return nil
case usagecleanuptask.FieldCanceledBy:
m.ResetCanceledBy()
return nil
case usagecleanuptask.FieldCanceledAt:
m.ResetCanceledAt()
return nil
case usagecleanuptask.FieldStartedAt:
m.ResetStartedAt()
return nil
case usagecleanuptask.FieldFinishedAt:
m.ResetFinishedAt()
return nil
}
return fmt.Errorf("unknown UsageCleanupTask field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UsageCleanupTaskMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UsageCleanupTaskMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UsageCleanupTaskMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UsageCleanupTaskMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UsageCleanupTaskMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UsageCleanupTaskMutation) EdgeCleared(name string) bool {
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 *UsageCleanupTaskMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown UsageCleanupTask 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 *UsageCleanupTaskMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown UsageCleanupTask edge %s", name)
}
// UsageLogMutation represents an operation that mutates the UsageLog nodes in the graph.
type UsageLogMutation struct {
config
...
...
backend/ent/predicate/predicate.go
View file @
c8e2f614
...
...
@@ -33,6 +33,9 @@ type RedeemCode func(*sql.Selector)
// Setting is the predicate function for setting builders.
type
Setting
func
(
*
sql
.
Selector
)
// UsageCleanupTask is the predicate function for usagecleanuptask builders.
type
UsageCleanupTask
func
(
*
sql
.
Selector
)
// UsageLog is the predicate function for usagelog builders.
type
UsageLog
func
(
*
sql
.
Selector
)
...
...
backend/ent/runtime/runtime.go
View file @
c8e2f614
...
...
@@ -15,6 +15,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/schema"
"github.com/Wei-Shaw/sub2api/ent/setting"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
"github.com/Wei-Shaw/sub2api/ent/usagelog"
"github.com/Wei-Shaw/sub2api/ent/user"
"github.com/Wei-Shaw/sub2api/ent/userallowedgroup"
...
...
@@ -495,6 +496,43 @@ func init() {
setting
.
DefaultUpdatedAt
=
settingDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// setting.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
setting
.
UpdateDefaultUpdatedAt
=
settingDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
usagecleanuptaskMixin
:=
schema
.
UsageCleanupTask
{}
.
Mixin
()
usagecleanuptaskMixinFields0
:=
usagecleanuptaskMixin
[
0
]
.
Fields
()
_
=
usagecleanuptaskMixinFields0
usagecleanuptaskFields
:=
schema
.
UsageCleanupTask
{}
.
Fields
()
_
=
usagecleanuptaskFields
// usagecleanuptaskDescCreatedAt is the schema descriptor for created_at field.
usagecleanuptaskDescCreatedAt
:=
usagecleanuptaskMixinFields0
[
0
]
.
Descriptor
()
// usagecleanuptask.DefaultCreatedAt holds the default value on creation for the created_at field.
usagecleanuptask
.
DefaultCreatedAt
=
usagecleanuptaskDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// usagecleanuptaskDescUpdatedAt is the schema descriptor for updated_at field.
usagecleanuptaskDescUpdatedAt
:=
usagecleanuptaskMixinFields0
[
1
]
.
Descriptor
()
// usagecleanuptask.DefaultUpdatedAt holds the default value on creation for the updated_at field.
usagecleanuptask
.
DefaultUpdatedAt
=
usagecleanuptaskDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// usagecleanuptask.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
usagecleanuptask
.
UpdateDefaultUpdatedAt
=
usagecleanuptaskDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// usagecleanuptaskDescStatus is the schema descriptor for status field.
usagecleanuptaskDescStatus
:=
usagecleanuptaskFields
[
0
]
.
Descriptor
()
// usagecleanuptask.StatusValidator is a validator for the "status" field. It is called by the builders before save.
usagecleanuptask
.
StatusValidator
=
func
()
func
(
string
)
error
{
validators
:=
usagecleanuptaskDescStatus
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
status
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
status
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// usagecleanuptaskDescDeletedRows is the schema descriptor for deleted_rows field.
usagecleanuptaskDescDeletedRows
:=
usagecleanuptaskFields
[
3
]
.
Descriptor
()
// usagecleanuptask.DefaultDeletedRows holds the default value on creation for the deleted_rows field.
usagecleanuptask
.
DefaultDeletedRows
=
usagecleanuptaskDescDeletedRows
.
Default
.
(
int64
)
usagelogFields
:=
schema
.
UsageLog
{}
.
Fields
()
_
=
usagelogFields
// usagelogDescRequestID is the schema descriptor for request_id field.
...
...
backend/ent/schema/mixins/soft_delete.go
View file @
c8e2f614
...
...
@@ -5,6 +5,7 @@ package mixins
import
(
"context"
"fmt"
"reflect"
"time"
"entgo.io/ent"
...
...
@@ -12,7 +13,6 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/mixin"
dbent
"github.com/Wei-Shaw/sub2api/ent"
"github.com/Wei-Shaw/sub2api/ent/intercept"
)
...
...
@@ -113,7 +113,6 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
SetOp
(
ent
.
Op
)
SetDeletedAt
(
time
.
Time
)
WhereP
(
...
func
(
*
sql
.
Selector
))
Client
()
*
dbent
.
Client
})
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T"
,
m
)
...
...
@@ -124,7 +123,7 @@ func (d SoftDeleteMixin) Hooks() []ent.Hook {
mx
.
SetOp
(
ent
.
OpUpdate
)
// 设置删除时间为当前时间
mx
.
SetDeletedAt
(
time
.
Now
())
return
m
x
.
Client
()
.
Mutate
(
ctx
,
m
)
return
m
utateWithClient
(
ctx
,
m
,
next
)
})
},
}
...
...
@@ -137,3 +136,41 @@ func (d SoftDeleteMixin) applyPredicate(w interface{ WhereP(...func(*sql.Selecto
sql
.
FieldIsNull
(
d
.
Fields
()[
0
]
.
Descriptor
()
.
Name
),
)
}
func
mutateWithClient
(
ctx
context
.
Context
,
m
ent
.
Mutation
,
fallback
ent
.
Mutator
)
(
ent
.
Value
,
error
)
{
clientMethod
:=
reflect
.
ValueOf
(
m
)
.
MethodByName
(
"Client"
)
if
!
clientMethod
.
IsValid
()
||
clientMethod
.
Type
()
.
NumIn
()
!=
0
||
clientMethod
.
Type
()
.
NumOut
()
!=
1
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client method not found for %T"
,
m
)
}
client
:=
clientMethod
.
Call
(
nil
)[
0
]
mutateMethod
:=
client
.
MethodByName
(
"Mutate"
)
if
!
mutateMethod
.
IsValid
()
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client missing Mutate for %T"
,
m
)
}
if
mutateMethod
.
Type
()
.
NumIn
()
!=
2
||
mutateMethod
.
Type
()
.
NumOut
()
!=
2
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client signature mismatch for %T"
,
m
)
}
results
:=
mutateMethod
.
Call
([]
reflect
.
Value
{
reflect
.
ValueOf
(
ctx
),
reflect
.
ValueOf
(
m
)})
value
:=
results
[
0
]
.
Interface
()
var
err
error
if
!
results
[
1
]
.
IsNil
()
{
errValue
:=
results
[
1
]
.
Interface
()
typedErr
,
ok
:=
errValue
.
(
error
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"soft delete: unexpected error type %T for %T"
,
errValue
,
m
)
}
err
=
typedErr
}
if
err
!=
nil
{
return
nil
,
err
}
if
value
==
nil
{
return
nil
,
fmt
.
Errorf
(
"soft delete: mutation client returned nil for %T"
,
m
)
}
v
,
ok
:=
value
.
(
ent
.
Value
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"soft delete: unexpected value type %T for %T"
,
value
,
m
)
}
return
v
,
nil
}
backend/ent/schema/usage_cleanup_task.go
0 → 100644
View file @
c8e2f614
package
schema
import
(
"encoding/json"
"fmt"
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// UsageCleanupTask 定义使用记录清理任务的 schema。
type
UsageCleanupTask
struct
{
ent
.
Schema
}
func
(
UsageCleanupTask
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"usage_cleanup_tasks"
},
}
}
func
(
UsageCleanupTask
)
Mixin
()
[]
ent
.
Mixin
{
return
[]
ent
.
Mixin
{
mixins
.
TimeMixin
{},
}
}
func
(
UsageCleanupTask
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Validate
(
validateUsageCleanupStatus
),
field
.
JSON
(
"filters"
,
json
.
RawMessage
{}),
field
.
Int64
(
"created_by"
),
field
.
Int64
(
"deleted_rows"
)
.
Default
(
0
),
field
.
String
(
"error_message"
)
.
Optional
()
.
Nillable
(),
field
.
Int64
(
"canceled_by"
)
.
Optional
()
.
Nillable
(),
field
.
Time
(
"canceled_at"
)
.
Optional
()
.
Nillable
(),
field
.
Time
(
"started_at"
)
.
Optional
()
.
Nillable
(),
field
.
Time
(
"finished_at"
)
.
Optional
()
.
Nillable
(),
}
}
func
(
UsageCleanupTask
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
index
.
Fields
(
"status"
,
"created_at"
),
index
.
Fields
(
"created_at"
),
index
.
Fields
(
"canceled_at"
),
}
}
func
validateUsageCleanupStatus
(
status
string
)
error
{
switch
status
{
case
"pending"
,
"running"
,
"succeeded"
,
"failed"
,
"canceled"
:
return
nil
default
:
return
fmt
.
Errorf
(
"invalid usage cleanup status: %s"
,
status
)
}
}
backend/ent/tx.go
View file @
c8e2f614
...
...
@@ -32,6 +32,8 @@ type Tx struct {
RedeemCode
*
RedeemCodeClient
// Setting is the client for interacting with the Setting builders.
Setting
*
SettingClient
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
UsageCleanupTask
*
UsageCleanupTaskClient
// UsageLog is the client for interacting with the UsageLog builders.
UsageLog
*
UsageLogClient
// User is the client for interacting with the User builders.
...
...
@@ -184,6 +186,7 @@ func (tx *Tx) init() {
tx
.
Proxy
=
NewProxyClient
(
tx
.
config
)
tx
.
RedeemCode
=
NewRedeemCodeClient
(
tx
.
config
)
tx
.
Setting
=
NewSettingClient
(
tx
.
config
)
tx
.
UsageCleanupTask
=
NewUsageCleanupTaskClient
(
tx
.
config
)
tx
.
UsageLog
=
NewUsageLogClient
(
tx
.
config
)
tx
.
User
=
NewUserClient
(
tx
.
config
)
tx
.
UserAllowedGroup
=
NewUserAllowedGroupClient
(
tx
.
config
)
...
...
backend/ent/usagecleanuptask.go
0 → 100644
View file @
c8e2f614
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTask is the model entity for the UsageCleanupTask schema.
type
UsageCleanupTask
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt
time
.
Time
`json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt
time
.
Time
`json:"updated_at,omitempty"`
// Status holds the value of the "status" field.
Status
string
`json:"status,omitempty"`
// Filters holds the value of the "filters" field.
Filters
json
.
RawMessage
`json:"filters,omitempty"`
// CreatedBy holds the value of the "created_by" field.
CreatedBy
int64
`json:"created_by,omitempty"`
// DeletedRows holds the value of the "deleted_rows" field.
DeletedRows
int64
`json:"deleted_rows,omitempty"`
// ErrorMessage holds the value of the "error_message" field.
ErrorMessage
*
string
`json:"error_message,omitempty"`
// CanceledBy holds the value of the "canceled_by" field.
CanceledBy
*
int64
`json:"canceled_by,omitempty"`
// CanceledAt holds the value of the "canceled_at" field.
CanceledAt
*
time
.
Time
`json:"canceled_at,omitempty"`
// StartedAt holds the value of the "started_at" field.
StartedAt
*
time
.
Time
`json:"started_at,omitempty"`
// FinishedAt holds the value of the "finished_at" field.
FinishedAt
*
time
.
Time
`json:"finished_at,omitempty"`
selectValues
sql
.
SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
UsageCleanupTask
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
usagecleanuptask
.
FieldFilters
:
values
[
i
]
=
new
([]
byte
)
case
usagecleanuptask
.
FieldID
,
usagecleanuptask
.
FieldCreatedBy
,
usagecleanuptask
.
FieldDeletedRows
,
usagecleanuptask
.
FieldCanceledBy
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
usagecleanuptask
.
FieldStatus
,
usagecleanuptask
.
FieldErrorMessage
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
usagecleanuptask
.
FieldCreatedAt
,
usagecleanuptask
.
FieldUpdatedAt
,
usagecleanuptask
.
FieldCanceledAt
,
usagecleanuptask
.
FieldStartedAt
,
usagecleanuptask
.
FieldFinishedAt
:
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 UsageCleanupTask fields.
func
(
_m
*
UsageCleanupTask
)
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
usagecleanuptask
.
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
usagecleanuptask
.
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
usagecleanuptask
.
FieldUpdatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field updated_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UpdatedAt
=
value
.
Time
}
case
usagecleanuptask
.
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
usagecleanuptask
.
FieldFilters
:
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field filters"
,
values
[
i
])
}
else
if
value
!=
nil
&&
len
(
*
value
)
>
0
{
if
err
:=
json
.
Unmarshal
(
*
value
,
&
_m
.
Filters
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal field filters: %w"
,
err
)
}
}
case
usagecleanuptask
.
FieldCreatedBy
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field created_by"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CreatedBy
=
value
.
Int64
}
case
usagecleanuptask
.
FieldDeletedRows
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field deleted_rows"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
DeletedRows
=
value
.
Int64
}
case
usagecleanuptask
.
FieldErrorMessage
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field error_message"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ErrorMessage
=
new
(
string
)
*
_m
.
ErrorMessage
=
value
.
String
}
case
usagecleanuptask
.
FieldCanceledBy
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field canceled_by"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CanceledBy
=
new
(
int64
)
*
_m
.
CanceledBy
=
value
.
Int64
}
case
usagecleanuptask
.
FieldCanceledAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field canceled_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CanceledAt
=
new
(
time
.
Time
)
*
_m
.
CanceledAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldStartedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field started_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
StartedAt
=
new
(
time
.
Time
)
*
_m
.
StartedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldFinishedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field finished_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
FinishedAt
=
new
(
time
.
Time
)
*
_m
.
FinishedAt
=
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 UsageCleanupTask.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
UsageCleanupTask
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// Update returns a builder for updating this UsageCleanupTask.
// Note that you need to call UsageCleanupTask.Unwrap() before calling this method if this UsageCleanupTask
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
UsageCleanupTask
)
Update
()
*
UsageCleanupTaskUpdateOne
{
return
NewUsageCleanupTaskClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the UsageCleanupTask 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
*
UsageCleanupTask
)
Unwrap
()
*
UsageCleanupTask
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: UsageCleanupTask is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
UsageCleanupTask
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"UsageCleanupTask("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"created_at="
)
builder
.
WriteString
(
_m
.
CreatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"updated_at="
)
builder
.
WriteString
(
_m
.
UpdatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"status="
)
builder
.
WriteString
(
_m
.
Status
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"filters="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
Filters
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"created_by="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
CreatedBy
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"deleted_rows="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
DeletedRows
))
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ErrorMessage
;
v
!=
nil
{
builder
.
WriteString
(
"error_message="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
CanceledBy
;
v
!=
nil
{
builder
.
WriteString
(
"canceled_by="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
CanceledAt
;
v
!=
nil
{
builder
.
WriteString
(
"canceled_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
StartedAt
;
v
!=
nil
{
builder
.
WriteString
(
"started_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
FinishedAt
;
v
!=
nil
{
builder
.
WriteString
(
"finished_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// UsageCleanupTasks is a parsable slice of UsageCleanupTask.
type
UsageCleanupTasks
[]
*
UsageCleanupTask
backend/ent/usagecleanuptask/usagecleanuptask.go
0 → 100644
View file @
c8e2f614
// Code generated by ent, DO NOT EDIT.
package
usagecleanuptask
import
(
"time"
"entgo.io/ent/dialect/sql"
)
const
(
// Label holds the string label denoting the usagecleanuptask type in the database.
Label
=
"usage_cleanup_task"
// FieldID holds the string denoting the id field in the database.
FieldID
=
"id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt
=
"created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt
=
"updated_at"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus
=
"status"
// FieldFilters holds the string denoting the filters field in the database.
FieldFilters
=
"filters"
// FieldCreatedBy holds the string denoting the created_by field in the database.
FieldCreatedBy
=
"created_by"
// FieldDeletedRows holds the string denoting the deleted_rows field in the database.
FieldDeletedRows
=
"deleted_rows"
// FieldErrorMessage holds the string denoting the error_message field in the database.
FieldErrorMessage
=
"error_message"
// FieldCanceledBy holds the string denoting the canceled_by field in the database.
FieldCanceledBy
=
"canceled_by"
// FieldCanceledAt holds the string denoting the canceled_at field in the database.
FieldCanceledAt
=
"canceled_at"
// FieldStartedAt holds the string denoting the started_at field in the database.
FieldStartedAt
=
"started_at"
// FieldFinishedAt holds the string denoting the finished_at field in the database.
FieldFinishedAt
=
"finished_at"
// Table holds the table name of the usagecleanuptask in the database.
Table
=
"usage_cleanup_tasks"
)
// Columns holds all SQL columns for usagecleanuptask fields.
var
Columns
=
[]
string
{
FieldID
,
FieldCreatedAt
,
FieldUpdatedAt
,
FieldStatus
,
FieldFilters
,
FieldCreatedBy
,
FieldDeletedRows
,
FieldErrorMessage
,
FieldCanceledBy
,
FieldCanceledAt
,
FieldStartedAt
,
FieldFinishedAt
,
}
// 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
(
// 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
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator
func
(
string
)
error
// DefaultDeletedRows holds the default value on creation for the "deleted_rows" field.
DefaultDeletedRows
int64
)
// OrderOption defines the ordering options for the UsageCleanupTask queries.
type
OrderOption
func
(
*
sql
.
Selector
)
// ByID orders the results by the id field.
func
ByID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldID
,
opts
...
)
.
ToFunc
()
}
// ByCreatedAt orders the results by the created_at field.
func
ByCreatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUpdatedAt orders the results by the updated_at field.
func
ByUpdatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpdatedAt
,
opts
...
)
.
ToFunc
()
}
// ByStatus orders the results by the status field.
func
ByStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStatus
,
opts
...
)
.
ToFunc
()
}
// ByCreatedBy orders the results by the created_by field.
func
ByCreatedBy
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedBy
,
opts
...
)
.
ToFunc
()
}
// ByDeletedRows orders the results by the deleted_rows field.
func
ByDeletedRows
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldDeletedRows
,
opts
...
)
.
ToFunc
()
}
// ByErrorMessage orders the results by the error_message field.
func
ByErrorMessage
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldErrorMessage
,
opts
...
)
.
ToFunc
()
}
// ByCanceledBy orders the results by the canceled_by field.
func
ByCanceledBy
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCanceledBy
,
opts
...
)
.
ToFunc
()
}
// ByCanceledAt orders the results by the canceled_at field.
func
ByCanceledAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCanceledAt
,
opts
...
)
.
ToFunc
()
}
// ByStartedAt orders the results by the started_at field.
func
ByStartedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStartedAt
,
opts
...
)
.
ToFunc
()
}
// ByFinishedAt orders the results by the finished_at field.
func
ByFinishedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldFinishedAt
,
opts
...
)
.
ToFunc
()
}
backend/ent/usagecleanuptask/where.go
0 → 100644
View file @
c8e2f614
// Code generated by ent, DO NOT EDIT.
package
usagecleanuptask
import
(
"time"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func
ID
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func
CreatedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
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
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func
Status
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// CreatedBy applies equality check predicate on the "created_by" field. It's identical to CreatedByEQ.
func
CreatedBy
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedBy
,
v
))
}
// DeletedRows applies equality check predicate on the "deleted_rows" field. It's identical to DeletedRowsEQ.
func
DeletedRows
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldDeletedRows
,
v
))
}
// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ.
func
ErrorMessage
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldErrorMessage
,
v
))
}
// CanceledBy applies equality check predicate on the "canceled_by" field. It's identical to CanceledByEQ.
func
CanceledBy
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledBy
,
v
))
}
// CanceledAt applies equality check predicate on the "canceled_at" field. It's identical to CanceledAtEQ.
func
CanceledAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledAt
,
v
))
}
// StartedAt applies equality check predicate on the "started_at" field. It's identical to StartedAtEQ.
func
StartedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStartedAt
,
v
))
}
// FinishedAt applies equality check predicate on the "finished_at" field. It's identical to FinishedAtEQ.
func
FinishedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldFinishedAt
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func
CreatedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func
CreatedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func
CreatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func
CreatedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCreatedAt
,
v
))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func
CreatedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCreatedAt
,
v
))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func
CreatedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCreatedAt
,
v
))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func
CreatedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCreatedAt
,
v
))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func
UpdatedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func
UpdatedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func
UpdatedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func
UpdatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func
UpdatedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func
UpdatedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func
UpdatedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func
UpdatedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldUpdatedAt
,
v
))
}
// StatusEQ applies the EQ predicate on the "status" field.
func
StatusEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func
StatusNEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldStatus
,
v
))
}
// StatusIn applies the In predicate on the "status" field.
func
StatusIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldStatus
,
vs
...
))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func
StatusNotIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldStatus
,
vs
...
))
}
// StatusGT applies the GT predicate on the "status" field.
func
StatusGT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldStatus
,
v
))
}
// StatusGTE applies the GTE predicate on the "status" field.
func
StatusGTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldStatus
,
v
))
}
// StatusLT applies the LT predicate on the "status" field.
func
StatusLT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldStatus
,
v
))
}
// StatusLTE applies the LTE predicate on the "status" field.
func
StatusLTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldStatus
,
v
))
}
// StatusContains applies the Contains predicate on the "status" field.
func
StatusContains
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContains
(
FieldStatus
,
v
))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func
StatusHasPrefix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasPrefix
(
FieldStatus
,
v
))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func
StatusHasSuffix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasSuffix
(
FieldStatus
,
v
))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func
StatusEqualFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEqualFold
(
FieldStatus
,
v
))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func
StatusContainsFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContainsFold
(
FieldStatus
,
v
))
}
// CreatedByEQ applies the EQ predicate on the "created_by" field.
func
CreatedByEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedBy
,
v
))
}
// CreatedByNEQ applies the NEQ predicate on the "created_by" field.
func
CreatedByNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCreatedBy
,
v
))
}
// CreatedByIn applies the In predicate on the "created_by" field.
func
CreatedByIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCreatedBy
,
vs
...
))
}
// CreatedByNotIn applies the NotIn predicate on the "created_by" field.
func
CreatedByNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCreatedBy
,
vs
...
))
}
// CreatedByGT applies the GT predicate on the "created_by" field.
func
CreatedByGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCreatedBy
,
v
))
}
// CreatedByGTE applies the GTE predicate on the "created_by" field.
func
CreatedByGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCreatedBy
,
v
))
}
// CreatedByLT applies the LT predicate on the "created_by" field.
func
CreatedByLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCreatedBy
,
v
))
}
// CreatedByLTE applies the LTE predicate on the "created_by" field.
func
CreatedByLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCreatedBy
,
v
))
}
// DeletedRowsEQ applies the EQ predicate on the "deleted_rows" field.
func
DeletedRowsEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldDeletedRows
,
v
))
}
// DeletedRowsNEQ applies the NEQ predicate on the "deleted_rows" field.
func
DeletedRowsNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldDeletedRows
,
v
))
}
// DeletedRowsIn applies the In predicate on the "deleted_rows" field.
func
DeletedRowsIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldDeletedRows
,
vs
...
))
}
// DeletedRowsNotIn applies the NotIn predicate on the "deleted_rows" field.
func
DeletedRowsNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldDeletedRows
,
vs
...
))
}
// DeletedRowsGT applies the GT predicate on the "deleted_rows" field.
func
DeletedRowsGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldDeletedRows
,
v
))
}
// DeletedRowsGTE applies the GTE predicate on the "deleted_rows" field.
func
DeletedRowsGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldDeletedRows
,
v
))
}
// DeletedRowsLT applies the LT predicate on the "deleted_rows" field.
func
DeletedRowsLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldDeletedRows
,
v
))
}
// DeletedRowsLTE applies the LTE predicate on the "deleted_rows" field.
func
DeletedRowsLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldDeletedRows
,
v
))
}
// ErrorMessageEQ applies the EQ predicate on the "error_message" field.
func
ErrorMessageEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldErrorMessage
,
v
))
}
// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field.
func
ErrorMessageNEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldErrorMessage
,
v
))
}
// ErrorMessageIn applies the In predicate on the "error_message" field.
func
ErrorMessageIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldErrorMessage
,
vs
...
))
}
// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field.
func
ErrorMessageNotIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldErrorMessage
,
vs
...
))
}
// ErrorMessageGT applies the GT predicate on the "error_message" field.
func
ErrorMessageGT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldErrorMessage
,
v
))
}
// ErrorMessageGTE applies the GTE predicate on the "error_message" field.
func
ErrorMessageGTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldErrorMessage
,
v
))
}
// ErrorMessageLT applies the LT predicate on the "error_message" field.
func
ErrorMessageLT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldErrorMessage
,
v
))
}
// ErrorMessageLTE applies the LTE predicate on the "error_message" field.
func
ErrorMessageLTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldErrorMessage
,
v
))
}
// ErrorMessageContains applies the Contains predicate on the "error_message" field.
func
ErrorMessageContains
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContains
(
FieldErrorMessage
,
v
))
}
// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field.
func
ErrorMessageHasPrefix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasPrefix
(
FieldErrorMessage
,
v
))
}
// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field.
func
ErrorMessageHasSuffix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasSuffix
(
FieldErrorMessage
,
v
))
}
// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field.
func
ErrorMessageIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldErrorMessage
))
}
// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field.
func
ErrorMessageNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldErrorMessage
))
}
// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field.
func
ErrorMessageEqualFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEqualFold
(
FieldErrorMessage
,
v
))
}
// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field.
func
ErrorMessageContainsFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContainsFold
(
FieldErrorMessage
,
v
))
}
// CanceledByEQ applies the EQ predicate on the "canceled_by" field.
func
CanceledByEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledBy
,
v
))
}
// CanceledByNEQ applies the NEQ predicate on the "canceled_by" field.
func
CanceledByNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCanceledBy
,
v
))
}
// CanceledByIn applies the In predicate on the "canceled_by" field.
func
CanceledByIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCanceledBy
,
vs
...
))
}
// CanceledByNotIn applies the NotIn predicate on the "canceled_by" field.
func
CanceledByNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCanceledBy
,
vs
...
))
}
// CanceledByGT applies the GT predicate on the "canceled_by" field.
func
CanceledByGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCanceledBy
,
v
))
}
// CanceledByGTE applies the GTE predicate on the "canceled_by" field.
func
CanceledByGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCanceledBy
,
v
))
}
// CanceledByLT applies the LT predicate on the "canceled_by" field.
func
CanceledByLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCanceledBy
,
v
))
}
// CanceledByLTE applies the LTE predicate on the "canceled_by" field.
func
CanceledByLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCanceledBy
,
v
))
}
// CanceledByIsNil applies the IsNil predicate on the "canceled_by" field.
func
CanceledByIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldCanceledBy
))
}
// CanceledByNotNil applies the NotNil predicate on the "canceled_by" field.
func
CanceledByNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldCanceledBy
))
}
// CanceledAtEQ applies the EQ predicate on the "canceled_at" field.
func
CanceledAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledAt
,
v
))
}
// CanceledAtNEQ applies the NEQ predicate on the "canceled_at" field.
func
CanceledAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCanceledAt
,
v
))
}
// CanceledAtIn applies the In predicate on the "canceled_at" field.
func
CanceledAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCanceledAt
,
vs
...
))
}
// CanceledAtNotIn applies the NotIn predicate on the "canceled_at" field.
func
CanceledAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCanceledAt
,
vs
...
))
}
// CanceledAtGT applies the GT predicate on the "canceled_at" field.
func
CanceledAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCanceledAt
,
v
))
}
// CanceledAtGTE applies the GTE predicate on the "canceled_at" field.
func
CanceledAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCanceledAt
,
v
))
}
// CanceledAtLT applies the LT predicate on the "canceled_at" field.
func
CanceledAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCanceledAt
,
v
))
}
// CanceledAtLTE applies the LTE predicate on the "canceled_at" field.
func
CanceledAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCanceledAt
,
v
))
}
// CanceledAtIsNil applies the IsNil predicate on the "canceled_at" field.
func
CanceledAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldCanceledAt
))
}
// CanceledAtNotNil applies the NotNil predicate on the "canceled_at" field.
func
CanceledAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldCanceledAt
))
}
// StartedAtEQ applies the EQ predicate on the "started_at" field.
func
StartedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStartedAt
,
v
))
}
// StartedAtNEQ applies the NEQ predicate on the "started_at" field.
func
StartedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldStartedAt
,
v
))
}
// StartedAtIn applies the In predicate on the "started_at" field.
func
StartedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldStartedAt
,
vs
...
))
}
// StartedAtNotIn applies the NotIn predicate on the "started_at" field.
func
StartedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldStartedAt
,
vs
...
))
}
// StartedAtGT applies the GT predicate on the "started_at" field.
func
StartedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldStartedAt
,
v
))
}
// StartedAtGTE applies the GTE predicate on the "started_at" field.
func
StartedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldStartedAt
,
v
))
}
// StartedAtLT applies the LT predicate on the "started_at" field.
func
StartedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldStartedAt
,
v
))
}
// StartedAtLTE applies the LTE predicate on the "started_at" field.
func
StartedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldStartedAt
,
v
))
}
// StartedAtIsNil applies the IsNil predicate on the "started_at" field.
func
StartedAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldStartedAt
))
}
// StartedAtNotNil applies the NotNil predicate on the "started_at" field.
func
StartedAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldStartedAt
))
}
// FinishedAtEQ applies the EQ predicate on the "finished_at" field.
func
FinishedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldFinishedAt
,
v
))
}
// FinishedAtNEQ applies the NEQ predicate on the "finished_at" field.
func
FinishedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldFinishedAt
,
v
))
}
// FinishedAtIn applies the In predicate on the "finished_at" field.
func
FinishedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldFinishedAt
,
vs
...
))
}
// FinishedAtNotIn applies the NotIn predicate on the "finished_at" field.
func
FinishedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldFinishedAt
,
vs
...
))
}
// FinishedAtGT applies the GT predicate on the "finished_at" field.
func
FinishedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldFinishedAt
,
v
))
}
// FinishedAtGTE applies the GTE predicate on the "finished_at" field.
func
FinishedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldFinishedAt
,
v
))
}
// FinishedAtLT applies the LT predicate on the "finished_at" field.
func
FinishedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldFinishedAt
,
v
))
}
// FinishedAtLTE applies the LTE predicate on the "finished_at" field.
func
FinishedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldFinishedAt
,
v
))
}
// FinishedAtIsNil applies the IsNil predicate on the "finished_at" field.
func
FinishedAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldFinishedAt
))
}
// FinishedAtNotNil applies the NotNil predicate on the "finished_at" field.
func
FinishedAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldFinishedAt
))
}
// And groups predicates with the AND operator between them.
func
And
(
predicates
...
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
NotPredicates
(
p
))
}
backend/ent/usagecleanuptask_create.go
0 → 100644
View file @
c8e2f614
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"encoding/json"
"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/usagecleanuptask"
)
// UsageCleanupTaskCreate is the builder for creating a UsageCleanupTask entity.
type
UsageCleanupTaskCreate
struct
{
config
mutation
*
UsageCleanupTaskMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetUpdatedAt
(
v
)
return
_c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableUpdatedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetUpdatedAt
(
*
v
)
}
return
_c
}
// SetStatus sets the "status" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetStatus
(
v
string
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetStatus
(
v
)
return
_c
}
// SetFilters sets the "filters" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetFilters
(
v
)
return
_c
}
// SetCreatedBy sets the "created_by" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCreatedBy
(
v
)
return
_c
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetDeletedRows
(
v
)
return
_c
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetDeletedRows
(
*
v
)
}
return
_c
}
// SetErrorMessage sets the "error_message" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetErrorMessage
(
v
)
return
_c
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetErrorMessage
(
*
v
)
}
return
_c
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCanceledBy
(
v
)
return
_c
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCanceledBy
(
*
v
)
}
return
_c
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCanceledAt
(
v
)
return
_c
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCanceledAt
(
*
v
)
}
return
_c
}
// SetStartedAt sets the "started_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetStartedAt
(
v
)
return
_c
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetStartedAt
(
*
v
)
}
return
_c
}
// SetFinishedAt sets the "finished_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetFinishedAt
(
v
)
return
_c
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetFinishedAt
(
*
v
)
}
return
_c
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_c
*
UsageCleanupTaskCreate
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_c
.
mutation
}
// Save creates the UsageCleanupTask in the database.
func
(
_c
*
UsageCleanupTaskCreate
)
Save
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
UsageCleanupTaskCreate
)
SaveX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
UsageCleanupTaskCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreate
)
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
*
UsageCleanupTaskCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultUpdatedAt
()
_c
.
mutation
.
SetUpdatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
DeletedRows
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultDeletedRows
_c
.
mutation
.
SetDeletedRows
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
UsageCleanupTaskCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.created_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"updated_at"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.updated_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.status"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Filters
();
!
ok
{
return
&
ValidationError
{
Name
:
"filters"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.filters"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedBy
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_by"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.created_by"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
DeletedRows
();
!
ok
{
return
&
ValidationError
{
Name
:
"deleted_rows"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.deleted_rows"`
)}
}
return
nil
}
func
(
_c
*
UsageCleanupTaskCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
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
*
UsageCleanupTaskCreate
)
createSpec
()
(
*
UsageCleanupTask
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
UsageCleanupTask
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
usagecleanuptask
.
Table
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
_node
.
UpdatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
_node
.
Status
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
_node
.
Filters
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
_node
.
CreatedBy
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
_node
.
DeletedRows
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
_node
.
ErrorMessage
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
_node
.
CanceledBy
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
_node
.
CanceledAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
_node
.
StartedAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
_node
.
FinishedAt
=
&
value
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageCleanupTask.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageCleanupTaskUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
UsageCleanupTaskUpsertOne
{
_c
.
conflict
=
opts
return
&
UsageCleanupTaskUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreate
)
OnConflictColumns
(
columns
...
string
)
*
UsageCleanupTaskUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
UsageCleanupTaskUpsertOne
{
create
:
_c
,
}
}
type
(
// UsageCleanupTaskUpsertOne is the builder for "upsert"-ing
// one UsageCleanupTask node.
UsageCleanupTaskUpsertOne
struct
{
create
*
UsageCleanupTaskCreate
}
// UsageCleanupTaskUpsert is the "OnConflict" setter.
UsageCleanupTaskUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldUpdatedAt
,
v
)
return
u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldUpdatedAt
)
return
u
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldStatus
,
v
)
return
u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateStatus
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldStatus
)
return
u
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldFilters
,
v
)
return
u
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateFilters
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldFilters
)
return
u
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCreatedBy
,
v
)
return
u
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCreatedBy
)
return
u
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldCreatedBy
,
v
)
return
u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldDeletedRows
,
v
)
return
u
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldDeletedRows
)
return
u
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldDeletedRows
,
v
)
return
u
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldErrorMessage
,
v
)
return
u
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldErrorMessage
)
return
u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldErrorMessage
)
return
u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCanceledBy
,
v
)
return
u
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCanceledBy
)
return
u
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldCanceledBy
,
v
)
return
u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldCanceledBy
)
return
u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCanceledAt
,
v
)
return
u
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCanceledAt
)
return
u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldCanceledAt
)
return
u
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldStartedAt
,
v
)
return
u
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldStartedAt
)
return
u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearStartedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldStartedAt
)
return
u
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldFinishedAt
,
v
)
return
u
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldFinishedAt
)
return
u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldFinishedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateNewValues
()
*
UsageCleanupTaskUpsertOne
{
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
(
usagecleanuptask
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertOne
)
Ignore
()
*
UsageCleanupTaskUpsertOne
{
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
*
UsageCleanupTaskUpsertOne
)
DoNothing
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the UsageCleanupTaskCreate.OnConflict
// documentation for more info.
func
(
u
*
UsageCleanupTaskUpsertOne
)
Update
(
set
func
(
*
UsageCleanupTaskUpsert
))
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
UsageCleanupTaskUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateStatus
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFilters
(
v
)
})
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateFilters
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFilters
()
})
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCreatedBy
(
v
)
})
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCreatedBy
(
v
)
})
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCreatedBy
()
})
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetDeletedRows
(
v
)
})
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddDeletedRows
(
v
)
})
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateDeletedRows
()
})
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetErrorMessage
(
v
)
})
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateErrorMessage
()
})
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearErrorMessage
()
})
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledBy
(
v
)
})
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCanceledBy
(
v
)
})
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledBy
()
})
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledBy
()
})
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledAt
(
v
)
})
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledAt
()
})
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledAt
()
})
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStartedAt
(
v
)
})
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStartedAt
()
})
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearStartedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearStartedAt
()
})
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFinishedAt
(
v
)
})
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFinishedAt
()
})
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearFinishedAt
()
})
}
// Exec executes the query.
func
(
u
*
UsageCleanupTaskUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for UsageCleanupTaskCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertOne
)
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
*
UsageCleanupTaskUpsertOne
)
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
*
UsageCleanupTaskUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// UsageCleanupTaskCreateBulk is the builder for creating many UsageCleanupTask entities in bulk.
type
UsageCleanupTaskCreateBulk
struct
{
config
err
error
builders
[]
*
UsageCleanupTaskCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the UsageCleanupTask entities in the database.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
UsageCleanupTask
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
UsageCleanupTask
,
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
.
(
*
UsageCleanupTaskMutation
)
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
*
UsageCleanupTaskCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
UsageCleanupTask
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
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.UsageCleanupTask.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.UsageCleanupTaskUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
UsageCleanupTaskUpsertBulk
{
_c
.
conflict
=
opts
return
&
UsageCleanupTaskUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
UsageCleanupTaskUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
UsageCleanupTaskUpsertBulk
{
create
:
_c
,
}
}
// UsageCleanupTaskUpsertBulk is the builder for "upsert"-ing
// a bulk of UsageCleanupTask nodes.
type
UsageCleanupTaskUpsertBulk
struct
{
create
*
UsageCleanupTaskCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateNewValues
()
*
UsageCleanupTaskUpsertBulk
{
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
(
usagecleanuptask
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Ignore
()
*
UsageCleanupTaskUpsertBulk
{
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
*
UsageCleanupTaskUpsertBulk
)
DoNothing
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the UsageCleanupTaskCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Update
(
set
func
(
*
UsageCleanupTaskUpsert
))
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
UsageCleanupTaskUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateStatus
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFilters
(
v
)
})
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateFilters
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFilters
()
})
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCreatedBy
(
v
)
})
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCreatedBy
(
v
)
})
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCreatedBy
()
})
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetDeletedRows
(
v
)
})
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddDeletedRows
(
v
)
})
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateDeletedRows
()
})
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetErrorMessage
(
v
)
})
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateErrorMessage
()
})
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearErrorMessage
()
})
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledBy
(
v
)
})
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCanceledBy
(
v
)
})
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledBy
()
})
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledBy
()
})
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledAt
(
v
)
})
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledAt
()
})
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledAt
()
})
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStartedAt
(
v
)
})
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStartedAt
()
})
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearStartedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearStartedAt
()
})
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFinishedAt
(
v
)
})
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFinishedAt
()
})
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearFinishedAt
()
})
}
// Exec executes the query.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
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 UsageCleanupTaskCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for UsageCleanupTaskCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/usagecleanuptask_delete.go
0 → 100644
View file @
c8e2f614
// 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/usagecleanuptask"
)
// UsageCleanupTaskDelete is the builder for deleting a UsageCleanupTask entity.
type
UsageCleanupTaskDelete
struct
{
config
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
func
(
_d
*
UsageCleanupTaskDelete
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
UsageCleanupTaskDelete
)
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
*
UsageCleanupTaskDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
UsageCleanupTaskDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
usagecleanuptask
.
Table
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
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
}
// UsageCleanupTaskDeleteOne is the builder for deleting a single UsageCleanupTask entity.
type
UsageCleanupTaskDeleteOne
struct
{
_d
*
UsageCleanupTaskDelete
}
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/usagecleanuptask_query.go
0 → 100644
View file @
c8e2f614
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskQuery is the builder for querying UsageCleanupTask entities.
type
UsageCleanupTaskQuery
struct
{
config
ctx
*
QueryContext
order
[]
usagecleanuptask
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
UsageCleanupTask
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the UsageCleanupTaskQuery builder.
func
(
_q
*
UsageCleanupTaskQuery
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
UsageCleanupTaskQuery
)
Limit
(
limit
int
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
UsageCleanupTaskQuery
)
Offset
(
offset
int
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Offset
=
&
offset
return
_q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func
(
_q
*
UsageCleanupTaskQuery
)
Unique
(
unique
bool
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
UsageCleanupTaskQuery
)
Order
(
o
...
usagecleanuptask
.
OrderOption
)
*
UsageCleanupTaskQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// First returns the first UsageCleanupTask entity from the query.
// Returns a *NotFoundError when no UsageCleanupTask was found.
func
(
_q
*
UsageCleanupTaskQuery
)
First
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
1
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirst
))
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nil
,
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first UsageCleanupTask ID from the query.
// Returns a *NotFoundError when no UsageCleanupTask ID was found.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
1
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirstID
));
err
!=
nil
{
return
}
if
len
(
ids
)
==
0
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single UsageCleanupTask entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one UsageCleanupTask entity is found.
// Returns a *NotFoundError when no UsageCleanupTask entities are found.
func
(
_q
*
UsageCleanupTaskQuery
)
Only
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
2
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnly
))
if
err
!=
nil
{
return
nil
,
err
}
switch
len
(
nodes
)
{
case
1
:
return
nodes
[
0
],
nil
case
0
:
return
nil
,
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
usagecleanuptask
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only UsageCleanupTask ID in the query.
// Returns a *NotSingularError when more than one UsageCleanupTask ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
2
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnlyID
));
err
!=
nil
{
return
}
switch
len
(
ids
)
{
case
1
:
id
=
ids
[
0
]
case
0
:
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
err
=
&
NotSingularError
{
usagecleanuptask
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
OnlyID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// All executes the query and returns a list of UsageCleanupTasks.
func
(
_q
*
UsageCleanupTaskQuery
)
All
(
ctx
context
.
Context
)
([]
*
UsageCleanupTask
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
UsageCleanupTask
,
*
UsageCleanupTaskQuery
]()
return
withInterceptors
[[]
*
UsageCleanupTask
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
UsageCleanupTask
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of UsageCleanupTask IDs.
func
(
_q
*
UsageCleanupTaskQuery
)
IDs
(
ctx
context
.
Context
)
(
ids
[]
int64
,
err
error
)
{
if
_q
.
ctx
.
Unique
==
nil
&&
_q
.
path
!=
nil
{
_q
.
Unique
(
true
)
}
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryIDs
)
if
err
=
_q
.
Select
(
usagecleanuptask
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
IDsX
(
ctx
context
.
Context
)
[]
int64
{
ids
,
err
:=
_q
.
IDs
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
ids
}
// Count returns the count of the given query.
func
(
_q
*
UsageCleanupTaskQuery
)
Count
(
ctx
context
.
Context
)
(
int
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryCount
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
0
,
err
}
return
withInterceptors
[
int
](
ctx
,
_q
,
querierCount
[
*
UsageCleanupTaskQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
CountX
(
ctx
context
.
Context
)
int
{
count
,
err
:=
_q
.
Count
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
count
}
// Exist returns true if the query has elements in the graph.
func
(
_q
*
UsageCleanupTaskQuery
)
Exist
(
ctx
context
.
Context
)
(
bool
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryExist
)
switch
_
,
err
:=
_q
.
FirstID
(
ctx
);
{
case
IsNotFound
(
err
)
:
return
false
,
nil
case
err
!=
nil
:
return
false
,
fmt
.
Errorf
(
"ent: check existence: %w"
,
err
)
default
:
return
true
,
nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the UsageCleanupTaskQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func
(
_q
*
UsageCleanupTaskQuery
)
Clone
()
*
UsageCleanupTaskQuery
{
if
_q
==
nil
{
return
nil
}
return
&
UsageCleanupTaskQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
usagecleanuptask
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
UsageCleanupTask
{},
_q
.
predicates
...
),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.UsageCleanupTask.Query().
// GroupBy(usagecleanuptask.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
UsageCleanupTaskQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
UsageCleanupTaskGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
UsageCleanupTaskGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
usagecleanuptask
.
Label
grbuild
.
scan
=
grbuild
.
Scan
return
grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// }
//
// client.UsageCleanupTask.Query().
// Select(usagecleanuptask.FieldCreatedAt).
// Scan(ctx, &v)
func
(
_q
*
UsageCleanupTaskQuery
)
Select
(
fields
...
string
)
*
UsageCleanupTaskSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
UsageCleanupTaskSelect
{
UsageCleanupTaskQuery
:
_q
}
sbuild
.
label
=
usagecleanuptask
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a UsageCleanupTaskSelect configured with the given aggregations.
func
(
_q
*
UsageCleanupTaskQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
UsageCleanupTaskQuery
)
prepareQuery
(
ctx
context
.
Context
)
error
{
for
_
,
inter
:=
range
_q
.
inters
{
if
inter
==
nil
{
return
fmt
.
Errorf
(
"ent: uninitialized interceptor (forgotten import ent/runtime?)"
)
}
if
trv
,
ok
:=
inter
.
(
Traverser
);
ok
{
if
err
:=
trv
.
Traverse
(
ctx
,
_q
);
err
!=
nil
{
return
err
}
}
}
for
_
,
f
:=
range
_q
.
ctx
.
Fields
{
if
!
usagecleanuptask
.
ValidColumn
(
f
)
{
return
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
}
if
_q
.
path
!=
nil
{
prev
,
err
:=
_q
.
path
(
ctx
)
if
err
!=
nil
{
return
err
}
_q
.
sql
=
prev
}
return
nil
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
UsageCleanupTask
,
error
)
{
var
(
nodes
=
[]
*
UsageCleanupTask
{}
_spec
=
_q
.
querySpec
()
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
UsageCleanupTask
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
UsageCleanupTask
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
if
err
:=
sqlgraph
.
QueryNodes
(
ctx
,
_q
.
driver
,
_spec
);
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nodes
,
nil
}
return
nodes
,
nil
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
}
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
}
func
(
_q
*
UsageCleanupTaskQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
_spec
.
From
=
_q
.
sql
if
unique
:=
_q
.
ctx
.
Unique
;
unique
!=
nil
{
_spec
.
Unique
=
*
unique
}
else
if
_q
.
path
!=
nil
{
_spec
.
Unique
=
true
}
if
fields
:=
_q
.
ctx
.
Fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
usagecleanuptask
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
usagecleanuptask
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
}
if
ps
:=
_q
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
_spec
.
Limit
=
*
limit
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
_spec
.
Offset
=
*
offset
}
if
ps
:=
_q
.
order
;
len
(
ps
)
>
0
{
_spec
.
Order
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
return
_spec
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
usagecleanuptask
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
usagecleanuptask
.
Columns
}
selector
:=
builder
.
Select
(
t1
.
Columns
(
columns
...
)
...
)
.
From
(
t1
)
if
_q
.
sql
!=
nil
{
selector
=
_q
.
sql
selector
.
Select
(
selector
.
Columns
(
columns
...
)
...
)
}
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
for
_
,
p
:=
range
_q
.
order
{
p
(
selector
)
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector
.
Offset
(
*
offset
)
.
Limit
(
math
.
MaxInt32
)
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
selector
.
Limit
(
*
limit
)
}
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
UsageCleanupTaskQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
UsageCleanupTaskQuery
{
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
*
UsageCleanupTaskQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
UsageCleanupTaskQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// UsageCleanupTaskGroupBy is the group-by builder for UsageCleanupTask entities.
type
UsageCleanupTaskGroupBy
struct
{
selector
build
*
UsageCleanupTaskQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
UsageCleanupTaskGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
UsageCleanupTaskGroupBy
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_g
.
build
.
ctx
,
ent
.
OpQueryGroupBy
)
if
err
:=
_g
.
build
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
UsageCleanupTaskQuery
,
*
UsageCleanupTaskGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
UsageCleanupTaskGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
UsageCleanupTaskQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
.
Select
()
aggregation
:=
make
([]
string
,
0
,
len
(
_g
.
fns
))
for
_
,
fn
:=
range
_g
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
if
len
(
selector
.
SelectedColumns
())
==
0
{
columns
:=
make
([]
string
,
0
,
len
(
*
_g
.
flds
)
+
len
(
_g
.
fns
))
for
_
,
f
:=
range
*
_g
.
flds
{
columns
=
append
(
columns
,
selector
.
C
(
f
))
}
columns
=
append
(
columns
,
aggregation
...
)
selector
.
Select
(
columns
...
)
}
selector
.
GroupBy
(
selector
.
Columns
(
*
_g
.
flds
...
)
...
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
err
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_g
.
build
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
// UsageCleanupTaskSelect is the builder for selecting fields of UsageCleanupTask entities.
type
UsageCleanupTaskSelect
struct
{
*
UsageCleanupTaskQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
UsageCleanupTaskSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
UsageCleanupTaskSelect
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_s
.
ctx
,
ent
.
OpQuerySelect
)
if
err
:=
_s
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
UsageCleanupTaskQuery
,
*
UsageCleanupTaskSelect
](
ctx
,
_s
.
UsageCleanupTaskQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
UsageCleanupTaskSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
UsageCleanupTaskQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
aggregation
:=
make
([]
string
,
0
,
len
(
_s
.
fns
))
for
_
,
fn
:=
range
_s
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
switch
n
:=
len
(
*
_s
.
selector
.
flds
);
{
case
n
==
0
&&
len
(
aggregation
)
>
0
:
selector
.
Select
(
aggregation
...
)
case
n
!=
0
&&
len
(
aggregation
)
>
0
:
selector
.
AppendSelect
(
aggregation
...
)
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_s
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
Prev
1
2
3
4
5
…
9
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment