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
b9b4db3d
Commit
b9b4db3d
authored
Jan 17, 2026
by
song
Browse files
Merge upstream/main
parents
5a6f60a9
dae0d532
Changes
230
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
230 of 230+
files are displayed.
Plain diff
Email patch
backend/ent/apikey_update.go
View file @
b9b4db3d
...
...
@@ -10,6 +10,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
...
...
@@ -133,6 +134,42 @@ func (_u *APIKeyUpdate) SetNillableStatus(v *string) *APIKeyUpdate {
return
_u
}
// SetIPWhitelist sets the "ip_whitelist" field.
func
(
_u
*
APIKeyUpdate
)
SetIPWhitelist
(
v
[]
string
)
*
APIKeyUpdate
{
_u
.
mutation
.
SetIPWhitelist
(
v
)
return
_u
}
// AppendIPWhitelist appends value to the "ip_whitelist" field.
func
(
_u
*
APIKeyUpdate
)
AppendIPWhitelist
(
v
[]
string
)
*
APIKeyUpdate
{
_u
.
mutation
.
AppendIPWhitelist
(
v
)
return
_u
}
// ClearIPWhitelist clears the value of the "ip_whitelist" field.
func
(
_u
*
APIKeyUpdate
)
ClearIPWhitelist
()
*
APIKeyUpdate
{
_u
.
mutation
.
ClearIPWhitelist
()
return
_u
}
// SetIPBlacklist sets the "ip_blacklist" field.
func
(
_u
*
APIKeyUpdate
)
SetIPBlacklist
(
v
[]
string
)
*
APIKeyUpdate
{
_u
.
mutation
.
SetIPBlacklist
(
v
)
return
_u
}
// AppendIPBlacklist appends value to the "ip_blacklist" field.
func
(
_u
*
APIKeyUpdate
)
AppendIPBlacklist
(
v
[]
string
)
*
APIKeyUpdate
{
_u
.
mutation
.
AppendIPBlacklist
(
v
)
return
_u
}
// ClearIPBlacklist clears the value of the "ip_blacklist" field.
func
(
_u
*
APIKeyUpdate
)
ClearIPBlacklist
()
*
APIKeyUpdate
{
_u
.
mutation
.
ClearIPBlacklist
()
return
_u
}
// SetUser sets the "user" edge to the User entity.
func
(
_u
*
APIKeyUpdate
)
SetUser
(
v
*
User
)
*
APIKeyUpdate
{
return
_u
.
SetUserID
(
v
.
ID
)
...
...
@@ -291,6 +328,28 @@ func (_u *APIKeyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
apikey
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
IPWhitelist
();
ok
{
_spec
.
SetField
(
apikey
.
FieldIPWhitelist
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedIPWhitelist
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
apikey
.
FieldIPWhitelist
,
value
)
})
}
if
_u
.
mutation
.
IPWhitelistCleared
()
{
_spec
.
ClearField
(
apikey
.
FieldIPWhitelist
,
field
.
TypeJSON
)
}
if
value
,
ok
:=
_u
.
mutation
.
IPBlacklist
();
ok
{
_spec
.
SetField
(
apikey
.
FieldIPBlacklist
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedIPBlacklist
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
apikey
.
FieldIPBlacklist
,
value
)
})
}
if
_u
.
mutation
.
IPBlacklistCleared
()
{
_spec
.
ClearField
(
apikey
.
FieldIPBlacklist
,
field
.
TypeJSON
)
}
if
_u
.
mutation
.
UserCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
...
...
@@ -516,6 +575,42 @@ func (_u *APIKeyUpdateOne) SetNillableStatus(v *string) *APIKeyUpdateOne {
return
_u
}
// SetIPWhitelist sets the "ip_whitelist" field.
func
(
_u
*
APIKeyUpdateOne
)
SetIPWhitelist
(
v
[]
string
)
*
APIKeyUpdateOne
{
_u
.
mutation
.
SetIPWhitelist
(
v
)
return
_u
}
// AppendIPWhitelist appends value to the "ip_whitelist" field.
func
(
_u
*
APIKeyUpdateOne
)
AppendIPWhitelist
(
v
[]
string
)
*
APIKeyUpdateOne
{
_u
.
mutation
.
AppendIPWhitelist
(
v
)
return
_u
}
// ClearIPWhitelist clears the value of the "ip_whitelist" field.
func
(
_u
*
APIKeyUpdateOne
)
ClearIPWhitelist
()
*
APIKeyUpdateOne
{
_u
.
mutation
.
ClearIPWhitelist
()
return
_u
}
// SetIPBlacklist sets the "ip_blacklist" field.
func
(
_u
*
APIKeyUpdateOne
)
SetIPBlacklist
(
v
[]
string
)
*
APIKeyUpdateOne
{
_u
.
mutation
.
SetIPBlacklist
(
v
)
return
_u
}
// AppendIPBlacklist appends value to the "ip_blacklist" field.
func
(
_u
*
APIKeyUpdateOne
)
AppendIPBlacklist
(
v
[]
string
)
*
APIKeyUpdateOne
{
_u
.
mutation
.
AppendIPBlacklist
(
v
)
return
_u
}
// ClearIPBlacklist clears the value of the "ip_blacklist" field.
func
(
_u
*
APIKeyUpdateOne
)
ClearIPBlacklist
()
*
APIKeyUpdateOne
{
_u
.
mutation
.
ClearIPBlacklist
()
return
_u
}
// SetUser sets the "user" edge to the User entity.
func
(
_u
*
APIKeyUpdateOne
)
SetUser
(
v
*
User
)
*
APIKeyUpdateOne
{
return
_u
.
SetUserID
(
v
.
ID
)
...
...
@@ -704,6 +799,28 @@ func (_u *APIKeyUpdateOne) sqlSave(ctx context.Context) (_node *APIKey, err erro
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
apikey
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
IPWhitelist
();
ok
{
_spec
.
SetField
(
apikey
.
FieldIPWhitelist
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedIPWhitelist
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
apikey
.
FieldIPWhitelist
,
value
)
})
}
if
_u
.
mutation
.
IPWhitelistCleared
()
{
_spec
.
ClearField
(
apikey
.
FieldIPWhitelist
,
field
.
TypeJSON
)
}
if
value
,
ok
:=
_u
.
mutation
.
IPBlacklist
();
ok
{
_spec
.
SetField
(
apikey
.
FieldIPBlacklist
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedIPBlacklist
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
apikey
.
FieldIPBlacklist
,
value
)
})
}
if
_u
.
mutation
.
IPBlacklistCleared
()
{
_spec
.
ClearField
(
apikey
.
FieldIPBlacklist
,
field
.
TypeJSON
)
}
if
_u
.
mutation
.
UserCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2O
,
...
...
backend/ent/client.go
View file @
b9b4db3d
...
...
@@ -19,6 +19,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
...
@@ -45,6 +47,10 @@ type Client struct {
AccountGroup
*
AccountGroupClient
// Group is the client for interacting with the Group builders.
Group
*
GroupClient
// PromoCode is the client for interacting with the PromoCode builders.
PromoCode
*
PromoCodeClient
// PromoCodeUsage is the client for interacting with the PromoCodeUsage builders.
PromoCodeUsage
*
PromoCodeUsageClient
// Proxy is the client for interacting with the Proxy builders.
Proxy
*
ProxyClient
// RedeemCode is the client for interacting with the RedeemCode builders.
...
...
@@ -78,6 +84,8 @@ func (c *Client) init() {
c
.
Account
=
NewAccountClient
(
c
.
config
)
c
.
AccountGroup
=
NewAccountGroupClient
(
c
.
config
)
c
.
Group
=
NewGroupClient
(
c
.
config
)
c
.
PromoCode
=
NewPromoCodeClient
(
c
.
config
)
c
.
PromoCodeUsage
=
NewPromoCodeUsageClient
(
c
.
config
)
c
.
Proxy
=
NewProxyClient
(
c
.
config
)
c
.
RedeemCode
=
NewRedeemCodeClient
(
c
.
config
)
c
.
Setting
=
NewSettingClient
(
c
.
config
)
...
...
@@ -183,6 +191,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
Account
:
NewAccountClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
PromoCode
:
NewPromoCodeClient
(
cfg
),
PromoCodeUsage
:
NewPromoCodeUsageClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
...
...
@@ -215,6 +225,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
Account
:
NewAccountClient
(
cfg
),
AccountGroup
:
NewAccountGroupClient
(
cfg
),
Group
:
NewGroupClient
(
cfg
),
PromoCode
:
NewPromoCodeClient
(
cfg
),
PromoCodeUsage
:
NewPromoCodeUsageClient
(
cfg
),
Proxy
:
NewProxyClient
(
cfg
),
RedeemCode
:
NewRedeemCodeClient
(
cfg
),
Setting
:
NewSettingClient
(
cfg
),
...
...
@@ -253,9 +265,9 @@ func (c *Client) Close() error {
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func
(
c
*
Client
)
Use
(
hooks
...
Hook
)
{
for
_
,
n
:=
range
[]
interface
{
Use
(
...
Hook
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
xy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
moCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
n
.
Use
(
hooks
...
)
}
...
...
@@ -265,9 +277,9 @@ func (c *Client) Use(hooks ...Hook) {
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func
(
c
*
Client
)
Intercept
(
interceptors
...
Interceptor
)
{
for
_
,
n
:=
range
[]
interface
{
Intercept
(
...
Interceptor
)
}{
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
xy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
c
.
APIKey
,
c
.
Account
,
c
.
AccountGroup
,
c
.
Group
,
c
.
Pro
moCode
,
c
.
PromoCodeUsage
,
c
.
Proxy
,
c
.
RedeemCode
,
c
.
Setting
,
c
.
UsageLog
,
c
.
User
,
c
.
UserAllowedGroup
,
c
.
UserAttributeDefinition
,
c
.
UserAttributeValue
,
c
.
UserSubscription
,
}
{
n
.
Intercept
(
interceptors
...
)
}
...
...
@@ -284,6 +296,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return
c
.
AccountGroup
.
mutate
(
ctx
,
m
)
case
*
GroupMutation
:
return
c
.
Group
.
mutate
(
ctx
,
m
)
case
*
PromoCodeMutation
:
return
c
.
PromoCode
.
mutate
(
ctx
,
m
)
case
*
PromoCodeUsageMutation
:
return
c
.
PromoCodeUsage
.
mutate
(
ctx
,
m
)
case
*
ProxyMutation
:
return
c
.
Proxy
.
mutate
(
ctx
,
m
)
case
*
RedeemCodeMutation
:
...
...
@@ -1068,6 +1084,320 @@ func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, erro
}
}
// PromoCodeClient is a client for the PromoCode schema.
type
PromoCodeClient
struct
{
config
}
// NewPromoCodeClient returns a client for the PromoCode from the given config.
func
NewPromoCodeClient
(
c
config
)
*
PromoCodeClient
{
return
&
PromoCodeClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `promocode.Hooks(f(g(h())))`.
func
(
c
*
PromoCodeClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
PromoCode
=
append
(
c
.
hooks
.
PromoCode
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `promocode.Intercept(f(g(h())))`.
func
(
c
*
PromoCodeClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
PromoCode
=
append
(
c
.
inters
.
PromoCode
,
interceptors
...
)
}
// Create returns a builder for creating a PromoCode entity.
func
(
c
*
PromoCodeClient
)
Create
()
*
PromoCodeCreate
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpCreate
)
return
&
PromoCodeCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of PromoCode entities.
func
(
c
*
PromoCodeClient
)
CreateBulk
(
builders
...*
PromoCodeCreate
)
*
PromoCodeCreateBulk
{
return
&
PromoCodeCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func
(
c
*
PromoCodeClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
PromoCodeCreate
,
int
))
*
PromoCodeCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
PromoCodeCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to PromoCodeClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
PromoCodeCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
PromoCodeCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for PromoCode.
func
(
c
*
PromoCodeClient
)
Update
()
*
PromoCodeUpdate
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpUpdate
)
return
&
PromoCodeUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
PromoCodeClient
)
UpdateOne
(
_m
*
PromoCode
)
*
PromoCodeUpdateOne
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCode
(
_m
))
return
&
PromoCodeUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
PromoCodeClient
)
UpdateOneID
(
id
int64
)
*
PromoCodeUpdateOne
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCodeID
(
id
))
return
&
PromoCodeUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for PromoCode.
func
(
c
*
PromoCodeClient
)
Delete
()
*
PromoCodeDelete
{
mutation
:=
newPromoCodeMutation
(
c
.
config
,
OpDelete
)
return
&
PromoCodeDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
PromoCodeClient
)
DeleteOne
(
_m
*
PromoCode
)
*
PromoCodeDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
PromoCodeClient
)
DeleteOneID
(
id
int64
)
*
PromoCodeDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
promocode
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
PromoCodeDeleteOne
{
builder
}
}
// Query returns a query builder for PromoCode.
func
(
c
*
PromoCodeClient
)
Query
()
*
PromoCodeQuery
{
return
&
PromoCodeQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypePromoCode
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a PromoCode entity by its id.
func
(
c
*
PromoCodeClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
PromoCode
,
error
)
{
return
c
.
Query
()
.
Where
(
promocode
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
PromoCodeClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
PromoCode
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// QueryUsageRecords queries the usage_records edge of a PromoCode.
func
(
c
*
PromoCodeClient
)
QueryUsageRecords
(
_m
*
PromoCode
)
*
PromoCodeUsageQuery
{
query
:=
(
&
PromoCodeUsageClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
promocode
.
Table
,
promocode
.
FieldID
,
id
),
sqlgraph
.
To
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
promocode
.
UsageRecordsTable
,
promocode
.
UsageRecordsColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// Hooks returns the client hooks.
func
(
c
*
PromoCodeClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
PromoCode
}
// Interceptors returns the client interceptors.
func
(
c
*
PromoCodeClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
PromoCode
}
func
(
c
*
PromoCodeClient
)
mutate
(
ctx
context
.
Context
,
m
*
PromoCodeMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
PromoCodeCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
PromoCodeUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
PromoCodeUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
PromoCodeDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown PromoCode mutation op: %q"
,
m
.
Op
())
}
}
// PromoCodeUsageClient is a client for the PromoCodeUsage schema.
type
PromoCodeUsageClient
struct
{
config
}
// NewPromoCodeUsageClient returns a client for the PromoCodeUsage from the given config.
func
NewPromoCodeUsageClient
(
c
config
)
*
PromoCodeUsageClient
{
return
&
PromoCodeUsageClient
{
config
:
c
}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `promocodeusage.Hooks(f(g(h())))`.
func
(
c
*
PromoCodeUsageClient
)
Use
(
hooks
...
Hook
)
{
c
.
hooks
.
PromoCodeUsage
=
append
(
c
.
hooks
.
PromoCodeUsage
,
hooks
...
)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `promocodeusage.Intercept(f(g(h())))`.
func
(
c
*
PromoCodeUsageClient
)
Intercept
(
interceptors
...
Interceptor
)
{
c
.
inters
.
PromoCodeUsage
=
append
(
c
.
inters
.
PromoCodeUsage
,
interceptors
...
)
}
// Create returns a builder for creating a PromoCodeUsage entity.
func
(
c
*
PromoCodeUsageClient
)
Create
()
*
PromoCodeUsageCreate
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpCreate
)
return
&
PromoCodeUsageCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// CreateBulk returns a builder for creating a bulk of PromoCodeUsage entities.
func
(
c
*
PromoCodeUsageClient
)
CreateBulk
(
builders
...*
PromoCodeUsageCreate
)
*
PromoCodeUsageCreateBulk
{
return
&
PromoCodeUsageCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func
(
c
*
PromoCodeUsageClient
)
MapCreateBulk
(
slice
any
,
setFunc
func
(
*
PromoCodeUsageCreate
,
int
))
*
PromoCodeUsageCreateBulk
{
rv
:=
reflect
.
ValueOf
(
slice
)
if
rv
.
Kind
()
!=
reflect
.
Slice
{
return
&
PromoCodeUsageCreateBulk
{
err
:
fmt
.
Errorf
(
"calling to PromoCodeUsageClient.MapCreateBulk with wrong type %T, need slice"
,
slice
)}
}
builders
:=
make
([]
*
PromoCodeUsageCreate
,
rv
.
Len
())
for
i
:=
0
;
i
<
rv
.
Len
();
i
++
{
builders
[
i
]
=
c
.
Create
()
setFunc
(
builders
[
i
],
i
)
}
return
&
PromoCodeUsageCreateBulk
{
config
:
c
.
config
,
builders
:
builders
}
}
// Update returns an update builder for PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
Update
()
*
PromoCodeUsageUpdate
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpUpdate
)
return
&
PromoCodeUsageUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOne returns an update builder for the given entity.
func
(
c
*
PromoCodeUsageClient
)
UpdateOne
(
_m
*
PromoCodeUsage
)
*
PromoCodeUsageUpdateOne
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCodeUsage
(
_m
))
return
&
PromoCodeUsageUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// UpdateOneID returns an update builder for the given id.
func
(
c
*
PromoCodeUsageClient
)
UpdateOneID
(
id
int64
)
*
PromoCodeUsageUpdateOne
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpUpdateOne
,
withPromoCodeUsageID
(
id
))
return
&
PromoCodeUsageUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// Delete returns a delete builder for PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
Delete
()
*
PromoCodeUsageDelete
{
mutation
:=
newPromoCodeUsageMutation
(
c
.
config
,
OpDelete
)
return
&
PromoCodeUsageDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
mutation
}
}
// DeleteOne returns a builder for deleting the given entity.
func
(
c
*
PromoCodeUsageClient
)
DeleteOne
(
_m
*
PromoCodeUsage
)
*
PromoCodeUsageDeleteOne
{
return
c
.
DeleteOneID
(
_m
.
ID
)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func
(
c
*
PromoCodeUsageClient
)
DeleteOneID
(
id
int64
)
*
PromoCodeUsageDeleteOne
{
builder
:=
c
.
Delete
()
.
Where
(
promocodeusage
.
ID
(
id
))
builder
.
mutation
.
id
=
&
id
builder
.
mutation
.
op
=
OpDeleteOne
return
&
PromoCodeUsageDeleteOne
{
builder
}
}
// Query returns a query builder for PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
Query
()
*
PromoCodeUsageQuery
{
return
&
PromoCodeUsageQuery
{
config
:
c
.
config
,
ctx
:
&
QueryContext
{
Type
:
TypePromoCodeUsage
},
inters
:
c
.
Interceptors
(),
}
}
// Get returns a PromoCodeUsage entity by its id.
func
(
c
*
PromoCodeUsageClient
)
Get
(
ctx
context
.
Context
,
id
int64
)
(
*
PromoCodeUsage
,
error
)
{
return
c
.
Query
()
.
Where
(
promocodeusage
.
ID
(
id
))
.
Only
(
ctx
)
}
// GetX is like Get, but panics if an error occurs.
func
(
c
*
PromoCodeUsageClient
)
GetX
(
ctx
context
.
Context
,
id
int64
)
*
PromoCodeUsage
{
obj
,
err
:=
c
.
Get
(
ctx
,
id
)
if
err
!=
nil
{
panic
(
err
)
}
return
obj
}
// QueryPromoCode queries the promo_code edge of a PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
QueryPromoCode
(
_m
*
PromoCodeUsage
)
*
PromoCodeQuery
{
query
:=
(
&
PromoCodeClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
,
id
),
sqlgraph
.
To
(
promocode
.
Table
,
promocode
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
promocodeusage
.
PromoCodeTable
,
promocodeusage
.
PromoCodeColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// QueryUser queries the user edge of a PromoCodeUsage.
func
(
c
*
PromoCodeUsageClient
)
QueryUser
(
_m
*
PromoCodeUsage
)
*
UserQuery
{
query
:=
(
&
UserClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
,
id
),
sqlgraph
.
To
(
user
.
Table
,
user
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
M2O
,
true
,
promocodeusage
.
UserTable
,
promocodeusage
.
UserColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// Hooks returns the client hooks.
func
(
c
*
PromoCodeUsageClient
)
Hooks
()
[]
Hook
{
return
c
.
hooks
.
PromoCodeUsage
}
// Interceptors returns the client interceptors.
func
(
c
*
PromoCodeUsageClient
)
Interceptors
()
[]
Interceptor
{
return
c
.
inters
.
PromoCodeUsage
}
func
(
c
*
PromoCodeUsageClient
)
mutate
(
ctx
context
.
Context
,
m
*
PromoCodeUsageMutation
)
(
Value
,
error
)
{
switch
m
.
Op
()
{
case
OpCreate
:
return
(
&
PromoCodeUsageCreate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdate
:
return
(
&
PromoCodeUsageUpdate
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpUpdateOne
:
return
(
&
PromoCodeUsageUpdateOne
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Save
(
ctx
)
case
OpDelete
,
OpDeleteOne
:
return
(
&
PromoCodeUsageDelete
{
config
:
c
.
config
,
hooks
:
c
.
Hooks
(),
mutation
:
m
})
.
Exec
(
ctx
)
default
:
return
nil
,
fmt
.
Errorf
(
"ent: unknown PromoCodeUsage mutation op: %q"
,
m
.
Op
())
}
}
// ProxyClient is a client for the Proxy schema.
type
ProxyClient
struct
{
config
...
...
@@ -1950,6 +2280,22 @@ func (c *UserClient) QueryAttributeValues(_m *User) *UserAttributeValueQuery {
return
query
}
// QueryPromoCodeUsages queries the promo_code_usages edge of a User.
func
(
c
*
UserClient
)
QueryPromoCodeUsages
(
_m
*
User
)
*
PromoCodeUsageQuery
{
query
:=
(
&
PromoCodeUsageClient
{
config
:
c
.
config
})
.
Query
()
query
.
path
=
func
(
context
.
Context
)
(
fromV
*
sql
.
Selector
,
_
error
)
{
id
:=
_m
.
ID
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
user
.
Table
,
user
.
FieldID
,
id
),
sqlgraph
.
To
(
promocodeusage
.
Table
,
promocodeusage
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
user
.
PromoCodeUsagesTable
,
user
.
PromoCodeUsagesColumn
),
)
fromV
=
sqlgraph
.
Neighbors
(
_m
.
driver
.
Dialect
(),
step
)
return
fromV
,
nil
}
return
query
}
// QueryUserAllowedGroups queries the user_allowed_groups edge of a User.
func
(
c
*
UserClient
)
QueryUserAllowedGroups
(
_m
*
User
)
*
UserAllowedGroupQuery
{
query
:=
(
&
UserAllowedGroupClient
{
config
:
c
.
config
})
.
Query
()
...
...
@@ -2627,14 +2973,14 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
// hooks and interceptors per client, for fast access.
type
(
hooks
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
xy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
moCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Hook
}
inters
struct
{
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
xy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
APIKey
,
Account
,
AccountGroup
,
Group
,
Pro
moCode
,
PromoCodeUsage
,
Proxy
,
RedeemCode
,
Setting
,
UsageLog
,
User
,
UserAllowedGroup
,
UserAttributeDefinition
,
UserAttributeValue
,
UserSubscription
[]
ent
.
Interceptor
}
)
...
...
backend/ent/ent.go
View file @
b9b4db3d
...
...
@@ -16,6 +16,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/accountgroup"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
...
@@ -89,6 +91,8 @@ func checkColumn(t, c string) error {
account
.
Table
:
account
.
ValidColumn
,
accountgroup
.
Table
:
accountgroup
.
ValidColumn
,
group
.
Table
:
group
.
ValidColumn
,
promocode
.
Table
:
promocode
.
ValidColumn
,
promocodeusage
.
Table
:
promocodeusage
.
ValidColumn
,
proxy
.
Table
:
proxy
.
ValidColumn
,
redeemcode
.
Table
:
redeemcode
.
ValidColumn
,
setting
.
Table
:
setting
.
ValidColumn
,
...
...
backend/ent/generate.go
View file @
b9b4db3d
...
...
@@ -2,4 +2,5 @@
package
ent
// 启用 sql/execquery 以生成 ExecContext/QueryContext 的透传接口,便于事务内执行原生 SQL。
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert,intercept,sql/execquery --idtype int64 ./schema
// 启用 sql/lock 以支持 FOR UPDATE 行锁。
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/upsert,intercept,sql/execquery,sql/lock --idtype int64 ./schema
backend/ent/group.go
View file @
b9b4db3d
...
...
@@ -3,6 +3,7 @@
package
ent
import
(
"encoding/json"
"fmt"
"strings"
"time"
...
...
@@ -55,6 +56,10 @@ type Group struct {
ClaudeCodeOnly
bool
`json:"claude_code_only,omitempty"`
// 非 Claude Code 请求降级使用的分组 ID
FallbackGroupID
*
int64
`json:"fallback_group_id,omitempty"`
// 模型路由配置:模型模式 -> 优先账号ID列表
ModelRouting
map
[
string
][]
int64
`json:"model_routing,omitempty"`
// 是否启用模型路由配置
ModelRoutingEnabled
bool
`json:"model_routing_enabled,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the GroupQuery when eager-loading is set.
Edges
GroupEdges
`json:"edges"`
...
...
@@ -161,7 +166,9 @@ func (*Group) scanValues(columns []string) ([]any, error) {
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
group
.
FieldIsExclusive
,
group
.
FieldClaudeCodeOnly
:
case
group
.
FieldModelRouting
:
values
[
i
]
=
new
([]
byte
)
case
group
.
FieldIsExclusive
,
group
.
FieldClaudeCodeOnly
,
group
.
FieldModelRoutingEnabled
:
values
[
i
]
=
new
(
sql
.
NullBool
)
case
group
.
FieldRateMultiplier
,
group
.
FieldDailyLimitUsd
,
group
.
FieldWeeklyLimitUsd
,
group
.
FieldMonthlyLimitUsd
,
group
.
FieldImagePrice1k
,
group
.
FieldImagePrice2k
,
group
.
FieldImagePrice4k
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
...
...
@@ -315,6 +322,20 @@ func (_m *Group) assignValues(columns []string, values []any) error {
_m
.
FallbackGroupID
=
new
(
int64
)
*
_m
.
FallbackGroupID
=
value
.
Int64
}
case
group
.
FieldModelRouting
:
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field model_routing"
,
values
[
i
])
}
else
if
value
!=
nil
&&
len
(
*
value
)
>
0
{
if
err
:=
json
.
Unmarshal
(
*
value
,
&
_m
.
ModelRouting
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal field model_routing: %w"
,
err
)
}
}
case
group
.
FieldModelRoutingEnabled
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullBool
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field model_routing_enabled"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ModelRoutingEnabled
=
value
.
Bool
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
...
...
@@ -465,6 +486,12 @@ func (_m *Group) String() string {
builder
.
WriteString
(
"fallback_group_id="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"model_routing="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
ModelRouting
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"model_routing_enabled="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
ModelRoutingEnabled
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
...
...
backend/ent/group/group.go
View file @
b9b4db3d
...
...
@@ -53,6 +53,10 @@ const (
FieldClaudeCodeOnly
=
"claude_code_only"
// FieldFallbackGroupID holds the string denoting the fallback_group_id field in the database.
FieldFallbackGroupID
=
"fallback_group_id"
// FieldModelRouting holds the string denoting the model_routing field in the database.
FieldModelRouting
=
"model_routing"
// FieldModelRoutingEnabled holds the string denoting the model_routing_enabled field in the database.
FieldModelRoutingEnabled
=
"model_routing_enabled"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys
=
"api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...
...
@@ -147,6 +151,8 @@ var Columns = []string{
FieldImagePrice4k
,
FieldClaudeCodeOnly
,
FieldFallbackGroupID
,
FieldModelRouting
,
FieldModelRoutingEnabled
,
}
var
(
...
...
@@ -204,6 +210,8 @@ var (
DefaultDefaultValidityDays
int
// DefaultClaudeCodeOnly holds the default value on creation for the "claude_code_only" field.
DefaultClaudeCodeOnly
bool
// DefaultModelRoutingEnabled holds the default value on creation for the "model_routing_enabled" field.
DefaultModelRoutingEnabled
bool
)
// OrderOption defines the ordering options for the Group queries.
...
...
@@ -309,6 +317,11 @@ func ByFallbackGroupID(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldFallbackGroupID
,
opts
...
)
.
ToFunc
()
}
// ByModelRoutingEnabled orders the results by the model_routing_enabled field.
func
ByModelRoutingEnabled
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldModelRoutingEnabled
,
opts
...
)
.
ToFunc
()
}
// ByAPIKeysCount orders the results by api_keys count.
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/group/where.go
View file @
b9b4db3d
...
...
@@ -150,6 +150,11 @@ func FallbackGroupID(v int64) predicate.Group {
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldFallbackGroupID
,
v
))
}
// ModelRoutingEnabled applies equality check predicate on the "model_routing_enabled" field. It's identical to ModelRoutingEnabledEQ.
func
ModelRoutingEnabled
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldModelRoutingEnabled
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
...
...
@@ -1065,6 +1070,26 @@ func FallbackGroupIDNotNil() predicate.Group {
return
predicate
.
Group
(
sql
.
FieldNotNull
(
FieldFallbackGroupID
))
}
// ModelRoutingIsNil applies the IsNil predicate on the "model_routing" field.
func
ModelRoutingIsNil
()
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldIsNull
(
FieldModelRouting
))
}
// ModelRoutingNotNil applies the NotNil predicate on the "model_routing" field.
func
ModelRoutingNotNil
()
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNotNull
(
FieldModelRouting
))
}
// ModelRoutingEnabledEQ applies the EQ predicate on the "model_routing_enabled" field.
func
ModelRoutingEnabledEQ
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldModelRoutingEnabled
,
v
))
}
// ModelRoutingEnabledNEQ applies the NEQ predicate on the "model_routing_enabled" field.
func
ModelRoutingEnabledNEQ
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldModelRoutingEnabled
,
v
))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func
HasAPIKeys
()
predicate
.
Group
{
return
predicate
.
Group
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/group_create.go
View file @
b9b4db3d
...
...
@@ -286,6 +286,26 @@ func (_c *GroupCreate) SetNillableFallbackGroupID(v *int64) *GroupCreate {
return
_c
}
// SetModelRouting sets the "model_routing" field.
func
(
_c
*
GroupCreate
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupCreate
{
_c
.
mutation
.
SetModelRouting
(
v
)
return
_c
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func
(
_c
*
GroupCreate
)
SetModelRoutingEnabled
(
v
bool
)
*
GroupCreate
{
_c
.
mutation
.
SetModelRoutingEnabled
(
v
)
return
_c
}
// SetNillableModelRoutingEnabled sets the "model_routing_enabled" field if the given value is not nil.
func
(
_c
*
GroupCreate
)
SetNillableModelRoutingEnabled
(
v
*
bool
)
*
GroupCreate
{
if
v
!=
nil
{
_c
.
SetModelRoutingEnabled
(
*
v
)
}
return
_c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_c
*
GroupCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupCreate
{
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -455,6 +475,10 @@ func (_c *GroupCreate) defaults() error {
v
:=
group
.
DefaultClaudeCodeOnly
_c
.
mutation
.
SetClaudeCodeOnly
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
ModelRoutingEnabled
();
!
ok
{
v
:=
group
.
DefaultModelRoutingEnabled
_c
.
mutation
.
SetModelRoutingEnabled
(
v
)
}
return
nil
}
...
...
@@ -510,6 +534,9 @@ func (_c *GroupCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
ClaudeCodeOnly
();
!
ok
{
return
&
ValidationError
{
Name
:
"claude_code_only"
,
err
:
errors
.
New
(
`ent: missing required field "Group.claude_code_only"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
ModelRoutingEnabled
();
!
ok
{
return
&
ValidationError
{
Name
:
"model_routing_enabled"
,
err
:
errors
.
New
(
`ent: missing required field "Group.model_routing_enabled"`
)}
}
return
nil
}
...
...
@@ -613,6 +640,14 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
,
value
)
_node
.
FallbackGroupID
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
ModelRouting
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
_node
.
ModelRouting
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ModelRoutingEnabled
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
_node
.
ModelRoutingEnabled
=
value
}
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1093,6 +1128,36 @@ func (u *GroupUpsert) ClearFallbackGroupID() *GroupUpsert {
return
u
}
// SetModelRouting sets the "model_routing" field.
func
(
u
*
GroupUpsert
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldModelRouting
,
v
)
return
u
}
// UpdateModelRouting sets the "model_routing" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateModelRouting
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldModelRouting
)
return
u
}
// ClearModelRouting clears the value of the "model_routing" field.
func
(
u
*
GroupUpsert
)
ClearModelRouting
()
*
GroupUpsert
{
u
.
SetNull
(
group
.
FieldModelRouting
)
return
u
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func
(
u
*
GroupUpsert
)
SetModelRoutingEnabled
(
v
bool
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldModelRoutingEnabled
,
v
)
return
u
}
// UpdateModelRoutingEnabled sets the "model_routing_enabled" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateModelRoutingEnabled
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldModelRoutingEnabled
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
...
...
@@ -1516,6 +1581,41 @@ func (u *GroupUpsertOne) ClearFallbackGroupID() *GroupUpsertOne {
})
}
// SetModelRouting sets the "model_routing" field.
func
(
u
*
GroupUpsertOne
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetModelRouting
(
v
)
})
}
// UpdateModelRouting sets the "model_routing" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateModelRouting
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateModelRouting
()
})
}
// ClearModelRouting clears the value of the "model_routing" field.
func
(
u
*
GroupUpsertOne
)
ClearModelRouting
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
ClearModelRouting
()
})
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func
(
u
*
GroupUpsertOne
)
SetModelRoutingEnabled
(
v
bool
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetModelRoutingEnabled
(
v
)
})
}
// UpdateModelRoutingEnabled sets the "model_routing_enabled" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateModelRoutingEnabled
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateModelRoutingEnabled
()
})
}
// Exec executes the query.
func
(
u
*
GroupUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
...
...
@@ -2105,6 +2205,41 @@ func (u *GroupUpsertBulk) ClearFallbackGroupID() *GroupUpsertBulk {
})
}
// SetModelRouting sets the "model_routing" field.
func
(
u
*
GroupUpsertBulk
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetModelRouting
(
v
)
})
}
// UpdateModelRouting sets the "model_routing" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateModelRouting
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateModelRouting
()
})
}
// ClearModelRouting clears the value of the "model_routing" field.
func
(
u
*
GroupUpsertBulk
)
ClearModelRouting
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
ClearModelRouting
()
})
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func
(
u
*
GroupUpsertBulk
)
SetModelRoutingEnabled
(
v
bool
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetModelRoutingEnabled
(
v
)
})
}
// UpdateModelRoutingEnabled sets the "model_routing_enabled" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateModelRoutingEnabled
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateModelRoutingEnabled
()
})
}
// Exec executes the query.
func
(
u
*
GroupUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
...
...
backend/ent/group_query.go
View file @
b9b4db3d
...
...
@@ -9,6 +9,7 @@ import (
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
...
...
@@ -39,6 +40,7 @@ type GroupQuery struct {
withAllowedUsers
*
UserQuery
withAccountGroups
*
AccountGroupQuery
withUserAllowedGroups
*
UserAllowedGroupQuery
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
...
...
@@ -643,6 +645,9 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group,
node
.
Edges
.
loadedTypes
=
loadedTypes
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
...
...
@@ -1025,6 +1030,9 @@ func (_q *GroupQuery) loadUserAllowedGroups(ctx context.Context, query *UserAllo
func
(
_q
*
GroupQuery
)
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
...
...
@@ -1087,6 +1095,9 @@ func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
...
...
@@ -1104,6 +1115,32 @@ func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
GroupQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
GroupQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
GroupQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
GroupQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// GroupGroupBy is the group-by builder for Group entities.
type
GroupGroupBy
struct
{
selector
...
...
backend/ent/group_update.go
View file @
b9b4db3d
...
...
@@ -395,6 +395,32 @@ func (_u *GroupUpdate) ClearFallbackGroupID() *GroupUpdate {
return
_u
}
// SetModelRouting sets the "model_routing" field.
func
(
_u
*
GroupUpdate
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpdate
{
_u
.
mutation
.
SetModelRouting
(
v
)
return
_u
}
// ClearModelRouting clears the value of the "model_routing" field.
func
(
_u
*
GroupUpdate
)
ClearModelRouting
()
*
GroupUpdate
{
_u
.
mutation
.
ClearModelRouting
()
return
_u
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func
(
_u
*
GroupUpdate
)
SetModelRoutingEnabled
(
v
bool
)
*
GroupUpdate
{
_u
.
mutation
.
SetModelRoutingEnabled
(
v
)
return
_u
}
// SetNillableModelRoutingEnabled sets the "model_routing_enabled" field if the given value is not nil.
func
(
_u
*
GroupUpdate
)
SetNillableModelRoutingEnabled
(
v
*
bool
)
*
GroupUpdate
{
if
v
!=
nil
{
_u
.
SetModelRoutingEnabled
(
*
v
)
}
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
GroupUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdate
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -803,6 +829,15 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
_u
.
mutation
.
FallbackGroupIDCleared
()
{
_spec
.
ClearField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
ModelRouting
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
}
if
_u
.
mutation
.
ModelRoutingCleared
()
{
_spec
.
ClearField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
)
}
if
value
,
ok
:=
_u
.
mutation
.
ModelRoutingEnabled
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1478,6 +1513,32 @@ func (_u *GroupUpdateOne) ClearFallbackGroupID() *GroupUpdateOne {
return
_u
}
// SetModelRouting sets the "model_routing" field.
func
(
_u
*
GroupUpdateOne
)
SetModelRouting
(
v
map
[
string
][]
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
SetModelRouting
(
v
)
return
_u
}
// ClearModelRouting clears the value of the "model_routing" field.
func
(
_u
*
GroupUpdateOne
)
ClearModelRouting
()
*
GroupUpdateOne
{
_u
.
mutation
.
ClearModelRouting
()
return
_u
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func
(
_u
*
GroupUpdateOne
)
SetModelRoutingEnabled
(
v
bool
)
*
GroupUpdateOne
{
_u
.
mutation
.
SetModelRoutingEnabled
(
v
)
return
_u
}
// SetNillableModelRoutingEnabled sets the "model_routing_enabled" field if the given value is not nil.
func
(
_u
*
GroupUpdateOne
)
SetNillableModelRoutingEnabled
(
v
*
bool
)
*
GroupUpdateOne
{
if
v
!=
nil
{
_u
.
SetModelRoutingEnabled
(
*
v
)
}
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
GroupUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -1916,6 +1977,15 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if
_u
.
mutation
.
FallbackGroupIDCleared
()
{
_spec
.
ClearField
(
group
.
FieldFallbackGroupID
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
ModelRouting
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
,
value
)
}
if
_u
.
mutation
.
ModelRoutingCleared
()
{
_spec
.
ClearField
(
group
.
FieldModelRouting
,
field
.
TypeJSON
)
}
if
value
,
ok
:=
_u
.
mutation
.
ModelRoutingEnabled
();
ok
{
_spec
.
SetField
(
group
.
FieldModelRoutingEnabled
,
field
.
TypeBool
,
value
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
backend/ent/hook/hook.go
View file @
b9b4db3d
...
...
@@ -57,6 +57,30 @@ func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.GroupMutation"
,
m
)
}
// The PromoCodeFunc type is an adapter to allow the use of ordinary
// function as PromoCode mutator.
type
PromoCodeFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
PromoCodeFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
PromoCodeMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.PromoCodeMutation"
,
m
)
}
// The PromoCodeUsageFunc type is an adapter to allow the use of ordinary
// function as PromoCodeUsage mutator.
type
PromoCodeUsageFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeUsageMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
PromoCodeUsageFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
PromoCodeUsageMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.PromoCodeUsageMutation"
,
m
)
}
// The ProxyFunc type is an adapter to allow the use of ordinary
// function as Proxy mutator.
type
ProxyFunc
func
(
context
.
Context
,
*
ent
.
ProxyMutation
)
(
ent
.
Value
,
error
)
...
...
backend/ent/intercept/intercept.go
View file @
b9b4db3d
...
...
@@ -13,6 +13,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
...
@@ -188,6 +190,60 @@ func (f TraverseGroup) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.GroupQuery"
,
q
)
}
// The PromoCodeFunc type is an adapter to allow the use of ordinary function as a Querier.
type
PromoCodeFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
PromoCodeFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeQuery"
,
q
)
}
// The TraversePromoCode type is an adapter to allow the use of ordinary function as Traverser.
type
TraversePromoCode
func
(
context
.
Context
,
*
ent
.
PromoCodeQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraversePromoCode
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraversePromoCode
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeQuery"
,
q
)
}
// The PromoCodeUsageFunc type is an adapter to allow the use of ordinary function as a Querier.
type
PromoCodeUsageFunc
func
(
context
.
Context
,
*
ent
.
PromoCodeUsageQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
PromoCodeUsageFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeUsageQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeUsageQuery"
,
q
)
}
// The TraversePromoCodeUsage type is an adapter to allow the use of ordinary function as Traverser.
type
TraversePromoCodeUsage
func
(
context
.
Context
,
*
ent
.
PromoCodeUsageQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraversePromoCodeUsage
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraversePromoCodeUsage
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
PromoCodeUsageQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.PromoCodeUsageQuery"
,
q
)
}
// The ProxyFunc type is an adapter to allow the use of ordinary function as a Querier.
type
ProxyFunc
func
(
context
.
Context
,
*
ent
.
ProxyQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -442,6 +498,10 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
AccountGroupQuery
,
predicate
.
AccountGroup
,
accountgroup
.
OrderOption
]{
typ
:
ent
.
TypeAccountGroup
,
tq
:
q
},
nil
case
*
ent
.
GroupQuery
:
return
&
query
[
*
ent
.
GroupQuery
,
predicate
.
Group
,
group
.
OrderOption
]{
typ
:
ent
.
TypeGroup
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeQuery
:
return
&
query
[
*
ent
.
PromoCodeQuery
,
predicate
.
PromoCode
,
promocode
.
OrderOption
]{
typ
:
ent
.
TypePromoCode
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeUsageQuery
:
return
&
query
[
*
ent
.
PromoCodeUsageQuery
,
predicate
.
PromoCodeUsage
,
promocodeusage
.
OrderOption
]{
typ
:
ent
.
TypePromoCodeUsage
,
tq
:
q
},
nil
case
*
ent
.
ProxyQuery
:
return
&
query
[
*
ent
.
ProxyQuery
,
predicate
.
Proxy
,
proxy
.
OrderOption
]{
typ
:
ent
.
TypeProxy
,
tq
:
q
},
nil
case
*
ent
.
RedeemCodeQuery
:
...
...
backend/ent/migrate/schema.go
View file @
b9b4db3d
...
...
@@ -18,6 +18,8 @@ var (
{
Name
:
"key"
,
Type
:
field
.
TypeString
,
Unique
:
true
,
Size
:
128
},
{
Name
:
"name"
,
Type
:
field
.
TypeString
,
Size
:
100
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"ip_whitelist"
,
Type
:
field
.
TypeJSON
,
Nullable
:
true
},
{
Name
:
"ip_blacklist"
,
Type
:
field
.
TypeJSON
,
Nullable
:
true
},
{
Name
:
"group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
}
...
...
@@ -29,13 +31,13 @@ var (
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"api_keys_groups_api_keys"
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
7
]},
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
9
]},
RefColumns
:
[]
*
schema
.
Column
{
GroupsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
{
Symbol
:
"api_keys_users_api_keys"
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
8
]},
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
10
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
...
...
@@ -44,12 +46,12 @@ var (
{
Name
:
"apikey_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
8
]},
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
10
]},
},
{
Name
:
"apikey_group_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
7
]},
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
9
]},
},
{
Name
:
"apikey_status"
,
...
...
@@ -77,6 +79,7 @@ var (
{
Name
:
"extra"
,
Type
:
field
.
TypeJSON
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"concurrency"
,
Type
:
field
.
TypeInt
,
Default
:
3
},
{
Name
:
"priority"
,
Type
:
field
.
TypeInt
,
Default
:
50
},
{
Name
:
"rate_multiplier"
,
Type
:
field
.
TypeFloat64
,
Default
:
1
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(10,4)"
}},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"error_message"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"last_used_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
...
...
@@ -99,7 +102,7 @@ var (
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"accounts_proxies_proxy"
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
4
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
5
]},
RefColumns
:
[]
*
schema
.
Column
{
ProxiesColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
...
...
@@ -118,12 +121,12 @@ var (
{
Name
:
"account_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
2
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
3
]},
},
{
Name
:
"account_proxy_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
4
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
5
]},
},
{
Name
:
"account_priority"
,
...
...
@@ -133,27 +136,27 @@ var (
{
Name
:
"account_last_used_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
4
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
5
]},
},
{
Name
:
"account_schedulable"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
7
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
8
]},
},
{
Name
:
"account_rate_limited_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
8
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
1
9
]},
},
{
Name
:
"account_rate_limit_reset_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
19
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
20
]},
},
{
Name
:
"account_overload_until"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
0
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
1
]},
},
{
Name
:
"account_deleted_at"
,
...
...
@@ -223,6 +226,8 @@ var (
{
Name
:
"image_price_4k"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"claude_code_only"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"fallback_group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"model_routing"
,
Type
:
field
.
TypeJSON
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"jsonb"
}},
{
Name
:
"model_routing_enabled"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
}
// GroupsTable holds the schema information for the "groups" table.
GroupsTable
=
&
schema
.
Table
{
...
...
@@ -257,6 +262,82 @@ var (
},
},
}
// PromoCodesColumns holds the columns for the "promo_codes" table.
PromoCodesColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"code"
,
Type
:
field
.
TypeString
,
Unique
:
true
,
Size
:
32
},
{
Name
:
"bonus_amount"
,
Type
:
field
.
TypeFloat64
,
Default
:
0
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"max_uses"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"used_count"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"expires_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"notes"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"updated_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
}
// PromoCodesTable holds the schema information for the "promo_codes" table.
PromoCodesTable
=
&
schema
.
Table
{
Name
:
"promo_codes"
,
Columns
:
PromoCodesColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"promocode_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
5
]},
},
{
Name
:
"promocode_expires_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
6
]},
},
},
}
// PromoCodeUsagesColumns holds the columns for the "promo_code_usages" table.
PromoCodeUsagesColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"bonus_amount"
,
Type
:
field
.
TypeFloat64
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"used_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"promo_code_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
}
// PromoCodeUsagesTable holds the schema information for the "promo_code_usages" table.
PromoCodeUsagesTable
=
&
schema
.
Table
{
Name
:
"promo_code_usages"
,
Columns
:
PromoCodeUsagesColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"promo_code_usages_promo_codes_usage_records"
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
3
]},
RefColumns
:
[]
*
schema
.
Column
{
PromoCodesColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"promo_code_usages_users_promo_code_usages"
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
4
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"promocodeusage_promo_code_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
3
]},
},
{
Name
:
"promocodeusage_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
4
]},
},
{
Name
:
"promocodeusage_promo_code_id_user_id"
,
Unique
:
true
,
Columns
:
[]
*
schema
.
Column
{
PromoCodeUsagesColumns
[
3
],
PromoCodeUsagesColumns
[
4
]},
},
},
}
// ProxiesColumns holds the columns for the "proxies" table.
ProxiesColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -371,11 +452,13 @@ var (
{
Name
:
"total_cost"
,
Type
:
field
.
TypeFloat64
,
Default
:
0
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,10)"
}},
{
Name
:
"actual_cost"
,
Type
:
field
.
TypeFloat64
,
Default
:
0
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,10)"
}},
{
Name
:
"rate_multiplier"
,
Type
:
field
.
TypeFloat64
,
Default
:
1
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(10,4)"
}},
{
Name
:
"account_rate_multiplier"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(10,4)"
}},
{
Name
:
"billing_type"
,
Type
:
field
.
TypeInt8
,
Default
:
0
},
{
Name
:
"stream"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"duration_ms"
,
Type
:
field
.
TypeInt
,
Nullable
:
true
},
{
Name
:
"first_token_ms"
,
Type
:
field
.
TypeInt
,
Nullable
:
true
},
{
Name
:
"user_agent"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
Size
:
512
},
{
Name
:
"ip_address"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
Size
:
45
},
{
Name
:
"image_count"
,
Type
:
field
.
TypeInt
,
Default
:
0
},
{
Name
:
"image_size"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
Size
:
10
},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
...
...
@@ -393,31 +476,31 @@ var (
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"usage_logs_api_keys_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
4
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
6
]},
RefColumns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"usage_logs_accounts_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
5
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
7
]},
RefColumns
:
[]
*
schema
.
Column
{
AccountsColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"usage_logs_groups_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
6
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
8
]},
RefColumns
:
[]
*
schema
.
Column
{
GroupsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
{
Symbol
:
"usage_logs_users_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
7
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
9
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"usage_logs_user_subscriptions_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
28
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
30
]},
RefColumns
:
[]
*
schema
.
Column
{
UserSubscriptionsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
...
...
@@ -426,32 +509,32 @@ var (
{
Name
:
"usagelog_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
7
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
9
]},
},
{
Name
:
"usagelog_api_key_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
4
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
6
]},
},
{
Name
:
"usagelog_account_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
5
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
7
]},
},
{
Name
:
"usagelog_group_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
6
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
8
]},
},
{
Name
:
"usagelog_subscription_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
28
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
30
]},
},
{
Name
:
"usagelog_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
3
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
5
]},
},
{
Name
:
"usagelog_model"
,
...
...
@@ -466,12 +549,12 @@ var (
{
Name
:
"usagelog_user_id_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
7
],
UsageLogsColumns
[
2
3
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
9
],
UsageLogsColumns
[
2
5
]},
},
{
Name
:
"usagelog_api_key_id_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
4
],
UsageLogsColumns
[
2
3
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
6
],
UsageLogsColumns
[
2
5
]},
},
},
}
...
...
@@ -717,6 +800,8 @@ var (
AccountsTable
,
AccountGroupsTable
,
GroupsTable
,
PromoCodesTable
,
PromoCodeUsagesTable
,
ProxiesTable
,
RedeemCodesTable
,
SettingsTable
,
...
...
@@ -747,6 +832,14 @@ func init() {
GroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"groups"
,
}
PromoCodesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"promo_codes"
,
}
PromoCodeUsagesTable
.
ForeignKeys
[
0
]
.
RefTable
=
PromoCodesTable
PromoCodeUsagesTable
.
ForeignKeys
[
1
]
.
RefTable
=
UsersTable
PromoCodeUsagesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"promo_code_usages"
,
}
ProxiesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"proxies"
,
}
...
...
backend/ent/mutation.go
View file @
b9b4db3d
...
...
@@ -16,6 +16,8 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
"github.com/Wei-Shaw/sub2api/ent/setting"
...
...
@@ -40,6 +42,8 @@ const (
TypeAccount = "Account"
TypeAccountGroup = "AccountGroup"
TypeGroup = "Group"
TypePromoCode = "PromoCode"
TypePromoCodeUsage = "PromoCodeUsage"
TypeProxy = "Proxy"
TypeRedeemCode = "RedeemCode"
TypeSetting = "Setting"
...
...
@@ -54,26 +58,30 @@ const (
// APIKeyMutation represents an operation that mutates the APIKey nodes in the graph.
type APIKeyMutation struct {
config
op Op
typ string
id *int64
created_at *time.Time
updated_at *time.Time
deleted_at *time.Time
key *string
name *string
status *string
clearedFields map[string]struct{}
user *int64
cleareduser bool
group *int64
clearedgroup bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
done bool
oldValue func(context.Context) (*APIKey, error)
predicates []predicate.APIKey
op Op
typ string
id *int64
created_at *time.Time
updated_at *time.Time
deleted_at *time.Time
key *string
name *string
status *string
ip_whitelist *[]string
appendip_whitelist []string
ip_blacklist *[]string
appendip_blacklist []string
clearedFields map[string]struct{}
user *int64
cleareduser bool
group *int64
clearedgroup bool
usage_logs map[int64]struct{}
removedusage_logs map[int64]struct{}
clearedusage_logs bool
done bool
oldValue func(context.Context) (*APIKey, error)
predicates []predicate.APIKey
}
var _ ent.Mutation = (*APIKeyMutation)(nil)
...
...
@@ -488,6 +496,136 @@ func (m *APIKeyMutation) ResetStatus() {
m.status = nil
}
// SetIPWhitelist sets the "ip_whitelist" field.
func (m *APIKeyMutation) SetIPWhitelist(s []string) {
m.ip_whitelist = &s
m.appendip_whitelist = nil
}
// IPWhitelist returns the value of the "ip_whitelist" field in the mutation.
func (m *APIKeyMutation) IPWhitelist() (r []string, exists bool) {
v := m.ip_whitelist
if v == nil {
return
}
return *v, true
}
// OldIPWhitelist returns the old "ip_whitelist" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldIPWhitelist(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIPWhitelist is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIPWhitelist requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIPWhitelist: %w", err)
}
return oldValue.IPWhitelist, nil
}
// AppendIPWhitelist adds s to the "ip_whitelist" field.
func (m *APIKeyMutation) AppendIPWhitelist(s []string) {
m.appendip_whitelist = append(m.appendip_whitelist, s...)
}
// AppendedIPWhitelist returns the list of values that were appended to the "ip_whitelist" field in this mutation.
func (m *APIKeyMutation) AppendedIPWhitelist() ([]string, bool) {
if len(m.appendip_whitelist) == 0 {
return nil, false
}
return m.appendip_whitelist, true
}
// ClearIPWhitelist clears the value of the "ip_whitelist" field.
func (m *APIKeyMutation) ClearIPWhitelist() {
m.ip_whitelist = nil
m.appendip_whitelist = nil
m.clearedFields[apikey.FieldIPWhitelist] = struct{}{}
}
// IPWhitelistCleared returns if the "ip_whitelist" field was cleared in this mutation.
func (m *APIKeyMutation) IPWhitelistCleared() bool {
_, ok := m.clearedFields[apikey.FieldIPWhitelist]
return ok
}
// ResetIPWhitelist resets all changes to the "ip_whitelist" field.
func (m *APIKeyMutation) ResetIPWhitelist() {
m.ip_whitelist = nil
m.appendip_whitelist = nil
delete(m.clearedFields, apikey.FieldIPWhitelist)
}
// SetIPBlacklist sets the "ip_blacklist" field.
func (m *APIKeyMutation) SetIPBlacklist(s []string) {
m.ip_blacklist = &s
m.appendip_blacklist = nil
}
// IPBlacklist returns the value of the "ip_blacklist" field in the mutation.
func (m *APIKeyMutation) IPBlacklist() (r []string, exists bool) {
v := m.ip_blacklist
if v == nil {
return
}
return *v, true
}
// OldIPBlacklist returns the old "ip_blacklist" field's value of the APIKey entity.
// If the APIKey object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *APIKeyMutation) OldIPBlacklist(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIPBlacklist is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIPBlacklist requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIPBlacklist: %w", err)
}
return oldValue.IPBlacklist, nil
}
// AppendIPBlacklist adds s to the "ip_blacklist" field.
func (m *APIKeyMutation) AppendIPBlacklist(s []string) {
m.appendip_blacklist = append(m.appendip_blacklist, s...)
}
// AppendedIPBlacklist returns the list of values that were appended to the "ip_blacklist" field in this mutation.
func (m *APIKeyMutation) AppendedIPBlacklist() ([]string, bool) {
if len(m.appendip_blacklist) == 0 {
return nil, false
}
return m.appendip_blacklist, true
}
// ClearIPBlacklist clears the value of the "ip_blacklist" field.
func (m *APIKeyMutation) ClearIPBlacklist() {
m.ip_blacklist = nil
m.appendip_blacklist = nil
m.clearedFields[apikey.FieldIPBlacklist] = struct{}{}
}
// IPBlacklistCleared returns if the "ip_blacklist" field was cleared in this mutation.
func (m *APIKeyMutation) IPBlacklistCleared() bool {
_, ok := m.clearedFields[apikey.FieldIPBlacklist]
return ok
}
// ResetIPBlacklist resets all changes to the "ip_blacklist" field.
func (m *APIKeyMutation) ResetIPBlacklist() {
m.ip_blacklist = nil
m.appendip_blacklist = nil
delete(m.clearedFields, apikey.FieldIPBlacklist)
}
// ClearUser clears the "user" edge to the User entity.
func (m *APIKeyMutation) ClearUser() {
m.cleareduser = true
...
...
@@ -630,7 +768,7 @@ func (m *APIKeyMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *APIKeyMutation) Fields() []string {
fields := make([]string, 0,
8
)
fields := make([]string, 0,
10
)
if m.created_at != nil {
fields = append(fields, apikey.FieldCreatedAt)
}
...
...
@@ -655,6 +793,12 @@ func (m *APIKeyMutation) Fields() []string {
if m.status != nil {
fields = append(fields, apikey.FieldStatus)
}
if m.ip_whitelist != nil {
fields = append(fields, apikey.FieldIPWhitelist)
}
if m.ip_blacklist != nil {
fields = append(fields, apikey.FieldIPBlacklist)
}
return fields
}
...
...
@@ -679,6 +823,10 @@ func (m *APIKeyMutation) Field(name string) (ent.Value, bool) {
return m.GroupID()
case apikey.FieldStatus:
return m.Status()
case apikey.FieldIPWhitelist:
return m.IPWhitelist()
case apikey.FieldIPBlacklist:
return m.IPBlacklist()
}
return nil, false
}
...
...
@@ -704,6 +852,10 @@ func (m *APIKeyMutation) OldField(ctx context.Context, name string) (ent.Value,
return m.OldGroupID(ctx)
case apikey.FieldStatus:
return m.OldStatus(ctx)
case apikey.FieldIPWhitelist:
return m.OldIPWhitelist(ctx)
case apikey.FieldIPBlacklist:
return m.OldIPBlacklist(ctx)
}
return nil, fmt.Errorf("unknown APIKey field %s", name)
}
...
...
@@ -769,6 +921,20 @@ func (m *APIKeyMutation) SetField(name string, value ent.Value) error {
}
m.SetStatus(v)
return nil
case apikey.FieldIPWhitelist:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIPWhitelist(v)
return nil
case apikey.FieldIPBlacklist:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIPBlacklist(v)
return nil
}
return fmt.Errorf("unknown APIKey field %s", name)
}
...
...
@@ -808,6 +974,12 @@ func (m *APIKeyMutation) ClearedFields() []string {
if m.FieldCleared(apikey.FieldGroupID) {
fields = append(fields, apikey.FieldGroupID)
}
if m.FieldCleared(apikey.FieldIPWhitelist) {
fields = append(fields, apikey.FieldIPWhitelist)
}
if m.FieldCleared(apikey.FieldIPBlacklist) {
fields = append(fields, apikey.FieldIPBlacklist)
}
return fields
}
...
...
@@ -828,6 +1000,12 @@ func (m *APIKeyMutation) ClearField(name string) error {
case apikey.FieldGroupID:
m.ClearGroupID()
return nil
case apikey.FieldIPWhitelist:
m.ClearIPWhitelist()
return nil
case apikey.FieldIPBlacklist:
m.ClearIPBlacklist()
return nil
}
return fmt.Errorf("unknown APIKey nullable field %s", name)
}
...
...
@@ -860,6 +1038,12 @@ func (m *APIKeyMutation) ResetField(name string) error {
case apikey.FieldStatus:
m.ResetStatus()
return nil
case apikey.FieldIPWhitelist:
m.ResetIPWhitelist()
return nil
case apikey.FieldIPBlacklist:
m.ResetIPBlacklist()
return nil
}
return fmt.Errorf("unknown APIKey field %s", name)
}
...
...
@@ -1003,6 +1187,8 @@ type AccountMutation struct {
addconcurrency *int
priority *int
addpriority *int
rate_multiplier *float64
addrate_multiplier *float64
status *string
error_message *string
last_used_at *time.Time
...
...
@@ -1638,6 +1824,62 @@ func (m *AccountMutation) ResetPriority() {
m.addpriority = nil
}
// SetRateMultiplier sets the "rate_multiplier" field.
func (m *AccountMutation) SetRateMultiplier(f float64) {
m.rate_multiplier = &f
m.addrate_multiplier = nil
}
// RateMultiplier returns the value of the "rate_multiplier" field in the mutation.
func (m *AccountMutation) RateMultiplier() (r float64, exists bool) {
v := m.rate_multiplier
if v == nil {
return
}
return *v, true
}
// OldRateMultiplier returns the old "rate_multiplier" field's value of the Account entity.
// If the Account 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 *AccountMutation) OldRateMultiplier(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldRateMultiplier is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldRateMultiplier requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldRateMultiplier: %w", err)
}
return oldValue.RateMultiplier, nil
}
// AddRateMultiplier adds f to the "rate_multiplier" field.
func (m *AccountMutation) AddRateMultiplier(f float64) {
if m.addrate_multiplier != nil {
*m.addrate_multiplier += f
} else {
m.addrate_multiplier = &f
}
}
// AddedRateMultiplier returns the value that was added to the "rate_multiplier" field in this mutation.
func (m *AccountMutation) AddedRateMultiplier() (r float64, exists bool) {
v := m.addrate_multiplier
if v == nil {
return
}
return *v, true
}
// ResetRateMultiplier resets all changes to the "rate_multiplier" field.
func (m *AccountMutation) ResetRateMultiplier() {
m.rate_multiplier = nil
m.addrate_multiplier = nil
}
// SetStatus sets the "status" field.
func (m *AccountMutation) SetStatus(s string) {
m.status = &s
...
...
@@ -2356,7 +2598,7 @@ func (m *AccountMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *AccountMutation) Fields() []string {
fields := make([]string, 0, 2
4
)
fields := make([]string, 0, 2
5
)
if m.created_at != nil {
fields = append(fields, account.FieldCreatedAt)
}
...
...
@@ -2393,6 +2635,9 @@ func (m *AccountMutation) Fields() []string {
if m.priority != nil {
fields = append(fields, account.FieldPriority)
}
if m.rate_multiplier != nil {
fields = append(fields, account.FieldRateMultiplier)
}
if m.status != nil {
fields = append(fields, account.FieldStatus)
}
...
...
@@ -2461,6 +2706,8 @@ func (m *AccountMutation) Field(name string) (ent.Value, bool) {
return m.Concurrency()
case account.FieldPriority:
return m.Priority()
case account.FieldRateMultiplier:
return m.RateMultiplier()
case account.FieldStatus:
return m.Status()
case account.FieldErrorMessage:
...
...
@@ -2518,6 +2765,8 @@ func (m *AccountMutation) OldField(ctx context.Context, name string) (ent.Value,
return m.OldConcurrency(ctx)
case account.FieldPriority:
return m.OldPriority(ctx)
case account.FieldRateMultiplier:
return m.OldRateMultiplier(ctx)
case account.FieldStatus:
return m.OldStatus(ctx)
case account.FieldErrorMessage:
...
...
@@ -2635,6 +2884,13 @@ func (m *AccountMutation) SetField(name string, value ent.Value) error {
}
m.SetPriority(v)
return nil
case account.FieldRateMultiplier:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetRateMultiplier(v)
return nil
case account.FieldStatus:
v, ok := value.(string)
if !ok {
...
...
@@ -2733,6 +2989,9 @@ func (m *AccountMutation) AddedFields() []string {
if m.addpriority != nil {
fields = append(fields, account.FieldPriority)
}
if m.addrate_multiplier != nil {
fields = append(fields, account.FieldRateMultiplier)
}
return fields
}
...
...
@@ -2745,6 +3004,8 @@ func (m *AccountMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedConcurrency()
case account.FieldPriority:
return m.AddedPriority()
case account.FieldRateMultiplier:
return m.AddedRateMultiplier()
}
return nil, false
}
...
...
@@ -2768,6 +3029,13 @@ func (m *AccountMutation) AddField(name string, value ent.Value) error {
}
m.AddPriority(v)
return nil
case account.FieldRateMultiplier:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddRateMultiplier(v)
return nil
}
return fmt.Errorf("unknown Account numeric field %s", name)
}
...
...
@@ -2906,6 +3174,9 @@ func (m *AccountMutation) ResetField(name string) error {
case account.FieldPriority:
m.ResetPriority()
return nil
case account.FieldRateMultiplier:
m.ResetRateMultiplier()
return nil
case account.FieldStatus:
m.ResetStatus()
return nil
...
...
@@ -3593,6 +3864,8 @@ type GroupMutation struct {
claude_code_only *bool
fallback_group_id *int64
addfallback_group_id *int64
model_routing *map[string][]int64
model_routing_enabled *bool
clearedFields map[string]struct{}
api_keys map[int64]struct{}
removedapi_keys map[int64]struct{}
...
...
@@ -4703,6 +4976,91 @@ func (m *GroupMutation) ResetFallbackGroupID() {
delete(m.clearedFields, group.FieldFallbackGroupID)
}
// SetModelRouting sets the "model_routing" field.
func (m *GroupMutation) SetModelRouting(value map[string][]int64) {
m.model_routing = &value
}
// ModelRouting returns the value of the "model_routing" field in the mutation.
func (m *GroupMutation) ModelRouting() (r map[string][]int64, exists bool) {
v := m.model_routing
if v == nil {
return
}
return *v, true
}
// OldModelRouting returns the old "model_routing" field's value of the Group entity.
// If the Group 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 *GroupMutation) OldModelRouting(ctx context.Context) (v map[string][]int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModelRouting is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModelRouting requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModelRouting: %w", err)
}
return oldValue.ModelRouting, nil
}
// ClearModelRouting clears the value of the "model_routing" field.
func (m *GroupMutation) ClearModelRouting() {
m.model_routing = nil
m.clearedFields[group.FieldModelRouting] = struct{}{}
}
// ModelRoutingCleared returns if the "model_routing" field was cleared in this mutation.
func (m *GroupMutation) ModelRoutingCleared() bool {
_, ok := m.clearedFields[group.FieldModelRouting]
return ok
}
// ResetModelRouting resets all changes to the "model_routing" field.
func (m *GroupMutation) ResetModelRouting() {
m.model_routing = nil
delete(m.clearedFields, group.FieldModelRouting)
}
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
func (m *GroupMutation) SetModelRoutingEnabled(b bool) {
m.model_routing_enabled = &b
}
// ModelRoutingEnabled returns the value of the "model_routing_enabled" field in the mutation.
func (m *GroupMutation) ModelRoutingEnabled() (r bool, exists bool) {
v := m.model_routing_enabled
if v == nil {
return
}
return *v, true
}
// OldModelRoutingEnabled returns the old "model_routing_enabled" field's value of the Group entity.
// If the Group 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 *GroupMutation) OldModelRoutingEnabled(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModelRoutingEnabled is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModelRoutingEnabled requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModelRoutingEnabled: %w", err)
}
return oldValue.ModelRoutingEnabled, nil
}
// ResetModelRoutingEnabled resets all changes to the "model_routing_enabled" field.
func (m *GroupMutation) ResetModelRoutingEnabled() {
m.model_routing_enabled = nil
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
if m.api_keys == nil {
...
...
@@ -5061,7 +5419,7 @@ func (m *GroupMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *GroupMutation) Fields() []string {
fields := make([]string, 0, 1
9
)
fields := make([]string, 0,
2
1)
if m.created_at != nil {
fields = append(fields, group.FieldCreatedAt)
}
...
...
@@ -5119,6 +5477,12 @@ func (m *GroupMutation) Fields() []string {
if m.fallback_group_id != nil {
fields = append(fields, group.FieldFallbackGroupID)
}
if m.model_routing != nil {
fields = append(fields, group.FieldModelRouting)
}
if m.model_routing_enabled != nil {
fields = append(fields, group.FieldModelRoutingEnabled)
}
return fields
}
...
...
@@ -5165,6 +5529,10 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
return m.ClaudeCodeOnly()
case group.FieldFallbackGroupID:
return m.FallbackGroupID()
case group.FieldModelRouting:
return m.ModelRouting()
case group.FieldModelRoutingEnabled:
return m.ModelRoutingEnabled()
}
return nil, false
}
...
...
@@ -5212,6 +5580,10 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
return m.OldClaudeCodeOnly(ctx)
case group.FieldFallbackGroupID:
return m.OldFallbackGroupID(ctx)
case group.FieldModelRouting:
return m.OldModelRouting(ctx)
case group.FieldModelRoutingEnabled:
return m.OldModelRoutingEnabled(ctx)
}
return nil, fmt.Errorf("unknown Group field %s", name)
}
...
...
@@ -5354,6 +5726,20 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
}
m.SetFallbackGroupID(v)
return nil
case group.FieldModelRouting:
v, ok := value.(map[string][]int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModelRouting(v)
return nil
case group.FieldModelRoutingEnabled:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModelRoutingEnabled(v)
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
...
...
@@ -5522,6 +5908,9 @@ func (m *GroupMutation) ClearedFields() []string {
if m.FieldCleared(group.FieldFallbackGroupID) {
fields = append(fields, group.FieldFallbackGroupID)
}
if m.FieldCleared(group.FieldModelRouting) {
fields = append(fields, group.FieldModelRouting)
}
return fields
}
...
...
@@ -5563,6 +5952,9 @@ func (m *GroupMutation) ClearField(name string) error {
case group.FieldFallbackGroupID:
m.ClearFallbackGroupID()
return nil
case group.FieldModelRouting:
m.ClearModelRouting()
return nil
}
return fmt.Errorf("unknown Group nullable field %s", name)
}
...
...
@@ -5628,6 +6020,12 @@ func (m *GroupMutation) ResetField(name string) error {
case group.FieldFallbackGroupID:
m.ResetFallbackGroupID()
return nil
case group.FieldModelRouting:
m.ResetModelRouting()
return nil
case group.FieldModelRoutingEnabled:
m.ResetModelRoutingEnabled()
return nil
}
return fmt.Errorf("unknown Group field %s", name)
}
...
...
@@ -5697,153 +6095,1771 @@ func (m *GroupMutation) AddedIDs(name string) []ent.Value {
}
return ids
}
return nil
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GroupMutation) RemovedEdges() []string {
edges := make([]string, 0, 6)
if m.removedapi_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
if m.removedredeem_codes != nil {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.removedsubscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.removedusage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.removedaccounts != nil {
edges = append(edges, group.EdgeAccounts)
}
if m.removedallowed_users != nil {
edges = append(edges, group.EdgeAllowedUsers)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GroupMutation) RemovedIDs(name string) []ent.Value {
switch name {
case group.EdgeAPIKeys:
ids := make([]ent.Value, 0, len(m.removedapi_keys))
for id := range m.removedapi_keys {
ids = append(ids, id)
}
return ids
case group.EdgeRedeemCodes:
ids := make([]ent.Value, 0, len(m.removedredeem_codes))
for id := range m.removedredeem_codes {
ids = append(ids, id)
}
return ids
case group.EdgeSubscriptions:
ids := make([]ent.Value, 0, len(m.removedsubscriptions))
for id := range m.removedsubscriptions {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
ids = append(ids, id)
}
return ids
case group.EdgeAllowedUsers:
ids := make([]ent.Value, 0, len(m.removedallowed_users))
for id := range m.removedallowed_users {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
edges := make([]string, 0, 6)
if m.clearedapi_keys {
edges = append(edges, group.EdgeAPIKeys)
}
if m.clearedredeem_codes {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.clearedsubscriptions {
edges = append(edges, group.EdgeSubscriptions)
}
if m.clearedusage_logs {
edges = append(edges, group.EdgeUsageLogs)
}
if m.clearedaccounts {
edges = append(edges, group.EdgeAccounts)
}
if m.clearedallowed_users {
edges = append(edges, group.EdgeAllowedUsers)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GroupMutation) EdgeCleared(name string) bool {
switch name {
case group.EdgeAPIKeys:
return m.clearedapi_keys
case group.EdgeRedeemCodes:
return m.clearedredeem_codes
case group.EdgeSubscriptions:
return m.clearedsubscriptions
case group.EdgeUsageLogs:
return m.clearedusage_logs
case group.EdgeAccounts:
return m.clearedaccounts
case group.EdgeAllowedUsers:
return m.clearedallowed_users
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *GroupMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown Group unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *GroupMutation) ResetEdge(name string) error {
switch name {
case group.EdgeAPIKeys:
m.ResetAPIKeys()
return nil
case group.EdgeRedeemCodes:
m.ResetRedeemCodes()
return nil
case group.EdgeSubscriptions:
m.ResetSubscriptions()
return nil
case group.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
case group.EdgeAccounts:
m.ResetAccounts()
return nil
case group.EdgeAllowedUsers:
m.ResetAllowedUsers()
return nil
}
return fmt.Errorf("unknown Group edge %s", name)
}
// PromoCodeMutation represents an operation that mutates the PromoCode nodes in the graph.
type PromoCodeMutation struct {
config
op Op
typ string
id *int64
code *string
bonus_amount *float64
addbonus_amount *float64
max_uses *int
addmax_uses *int
used_count *int
addused_count *int
status *string
expires_at *time.Time
notes *string
created_at *time.Time
updated_at *time.Time
clearedFields map[string]struct{}
usage_records map[int64]struct{}
removedusage_records map[int64]struct{}
clearedusage_records bool
done bool
oldValue func(context.Context) (*PromoCode, error)
predicates []predicate.PromoCode
}
var _ ent.Mutation = (*PromoCodeMutation)(nil)
// promocodeOption allows management of the mutation configuration using functional options.
type promocodeOption func(*PromoCodeMutation)
// newPromoCodeMutation creates new mutation for the PromoCode entity.
func newPromoCodeMutation(c config, op Op, opts ...promocodeOption) *PromoCodeMutation {
m := &PromoCodeMutation{
config: c,
op: op,
typ: TypePromoCode,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withPromoCodeID sets the ID field of the mutation.
func withPromoCodeID(id int64) promocodeOption {
return func(m *PromoCodeMutation) {
var (
err error
once sync.Once
value *PromoCode
)
m.oldValue = func(ctx context.Context) (*PromoCode, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().PromoCode.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withPromoCode sets the old PromoCode of the mutation.
func withPromoCode(node *PromoCode) promocodeOption {
return func(m *PromoCodeMutation) {
m.oldValue = func(context.Context) (*PromoCode, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PromoCodeMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PromoCodeMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PromoCodeMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PromoCodeMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().PromoCode.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCode sets the "code" field.
func (m *PromoCodeMutation) SetCode(s string) {
m.code = &s
}
// Code returns the value of the "code" field in the mutation.
func (m *PromoCodeMutation) Code() (r string, exists bool) {
v := m.code
if v == nil {
return
}
return *v, true
}
// OldCode returns the old "code" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldCode(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCode is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCode requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCode: %w", err)
}
return oldValue.Code, nil
}
// ResetCode resets all changes to the "code" field.
func (m *PromoCodeMutation) ResetCode() {
m.code = nil
}
// SetBonusAmount sets the "bonus_amount" field.
func (m *PromoCodeMutation) SetBonusAmount(f float64) {
m.bonus_amount = &f
m.addbonus_amount = nil
}
// BonusAmount returns the value of the "bonus_amount" field in the mutation.
func (m *PromoCodeMutation) BonusAmount() (r float64, exists bool) {
v := m.bonus_amount
if v == nil {
return
}
return *v, true
}
// OldBonusAmount returns the old "bonus_amount" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldBonusAmount(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBonusAmount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBonusAmount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBonusAmount: %w", err)
}
return oldValue.BonusAmount, nil
}
// AddBonusAmount adds f to the "bonus_amount" field.
func (m *PromoCodeMutation) AddBonusAmount(f float64) {
if m.addbonus_amount != nil {
*m.addbonus_amount += f
} else {
m.addbonus_amount = &f
}
}
// AddedBonusAmount returns the value that was added to the "bonus_amount" field in this mutation.
func (m *PromoCodeMutation) AddedBonusAmount() (r float64, exists bool) {
v := m.addbonus_amount
if v == nil {
return
}
return *v, true
}
// ResetBonusAmount resets all changes to the "bonus_amount" field.
func (m *PromoCodeMutation) ResetBonusAmount() {
m.bonus_amount = nil
m.addbonus_amount = nil
}
// SetMaxUses sets the "max_uses" field.
func (m *PromoCodeMutation) SetMaxUses(i int) {
m.max_uses = &i
m.addmax_uses = nil
}
// MaxUses returns the value of the "max_uses" field in the mutation.
func (m *PromoCodeMutation) MaxUses() (r int, exists bool) {
v := m.max_uses
if v == nil {
return
}
return *v, true
}
// OldMaxUses returns the old "max_uses" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldMaxUses(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMaxUses is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMaxUses requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMaxUses: %w", err)
}
return oldValue.MaxUses, nil
}
// AddMaxUses adds i to the "max_uses" field.
func (m *PromoCodeMutation) AddMaxUses(i int) {
if m.addmax_uses != nil {
*m.addmax_uses += i
} else {
m.addmax_uses = &i
}
}
// AddedMaxUses returns the value that was added to the "max_uses" field in this mutation.
func (m *PromoCodeMutation) AddedMaxUses() (r int, exists bool) {
v := m.addmax_uses
if v == nil {
return
}
return *v, true
}
// ResetMaxUses resets all changes to the "max_uses" field.
func (m *PromoCodeMutation) ResetMaxUses() {
m.max_uses = nil
m.addmax_uses = nil
}
// SetUsedCount sets the "used_count" field.
func (m *PromoCodeMutation) SetUsedCount(i int) {
m.used_count = &i
m.addused_count = nil
}
// UsedCount returns the value of the "used_count" field in the mutation.
func (m *PromoCodeMutation) UsedCount() (r int, exists bool) {
v := m.used_count
if v == nil {
return
}
return *v, true
}
// OldUsedCount returns the old "used_count" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldUsedCount(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsedCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsedCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsedCount: %w", err)
}
return oldValue.UsedCount, nil
}
// AddUsedCount adds i to the "used_count" field.
func (m *PromoCodeMutation) AddUsedCount(i int) {
if m.addused_count != nil {
*m.addused_count += i
} else {
m.addused_count = &i
}
}
// AddedUsedCount returns the value that was added to the "used_count" field in this mutation.
func (m *PromoCodeMutation) AddedUsedCount() (r int, exists bool) {
v := m.addused_count
if v == nil {
return
}
return *v, true
}
// ResetUsedCount resets all changes to the "used_count" field.
func (m *PromoCodeMutation) ResetUsedCount() {
m.used_count = nil
m.addused_count = nil
}
// SetStatus sets the "status" field.
func (m *PromoCodeMutation) SetStatus(s string) {
m.status = &s
}
// Status returns the value of the "status" field in the mutation.
func (m *PromoCodeMutation) Status() (r string, exists bool) {
v := m.status
if v == nil {
return
}
return *v, true
}
// OldStatus returns the old "status" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldStatus(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldStatus requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
}
return oldValue.Status, nil
}
// ResetStatus resets all changes to the "status" field.
func (m *PromoCodeMutation) ResetStatus() {
m.status = nil
}
// SetExpiresAt sets the "expires_at" field.
func (m *PromoCodeMutation) SetExpiresAt(t time.Time) {
m.expires_at = &t
}
// ExpiresAt returns the value of the "expires_at" field in the mutation.
func (m *PromoCodeMutation) ExpiresAt() (r time.Time, exists bool) {
v := m.expires_at
if v == nil {
return
}
return *v, true
}
// OldExpiresAt returns the old "expires_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldExpiresAt(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldExpiresAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldExpiresAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldExpiresAt: %w", err)
}
return oldValue.ExpiresAt, nil
}
// ClearExpiresAt clears the value of the "expires_at" field.
func (m *PromoCodeMutation) ClearExpiresAt() {
m.expires_at = nil
m.clearedFields[promocode.FieldExpiresAt] = struct{}{}
}
// ExpiresAtCleared returns if the "expires_at" field was cleared in this mutation.
func (m *PromoCodeMutation) ExpiresAtCleared() bool {
_, ok := m.clearedFields[promocode.FieldExpiresAt]
return ok
}
// ResetExpiresAt resets all changes to the "expires_at" field.
func (m *PromoCodeMutation) ResetExpiresAt() {
m.expires_at = nil
delete(m.clearedFields, promocode.FieldExpiresAt)
}
// SetNotes sets the "notes" field.
func (m *PromoCodeMutation) SetNotes(s string) {
m.notes = &s
}
// Notes returns the value of the "notes" field in the mutation.
func (m *PromoCodeMutation) Notes() (r string, exists bool) {
v := m.notes
if v == nil {
return
}
return *v, true
}
// OldNotes returns the old "notes" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldNotes(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldNotes is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldNotes requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldNotes: %w", err)
}
return oldValue.Notes, nil
}
// ClearNotes clears the value of the "notes" field.
func (m *PromoCodeMutation) ClearNotes() {
m.notes = nil
m.clearedFields[promocode.FieldNotes] = struct{}{}
}
// NotesCleared returns if the "notes" field was cleared in this mutation.
func (m *PromoCodeMutation) NotesCleared() bool {
_, ok := m.clearedFields[promocode.FieldNotes]
return ok
}
// ResetNotes resets all changes to the "notes" field.
func (m *PromoCodeMutation) ResetNotes() {
m.notes = nil
delete(m.clearedFields, promocode.FieldNotes)
}
// SetCreatedAt sets the "created_at" field.
func (m *PromoCodeMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PromoCodeMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *PromoCodeMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *PromoCodeMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PromoCodeMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the PromoCode entity.
// If the PromoCode object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *PromoCodeMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by ids.
func (m *PromoCodeMutation) AddUsageRecordIDs(ids ...int64) {
if m.usage_records == nil {
m.usage_records = make(map[int64]struct{})
}
for i := range ids {
m.usage_records[ids[i]] = struct{}{}
}
}
// ClearUsageRecords clears the "usage_records" edge to the PromoCodeUsage entity.
func (m *PromoCodeMutation) ClearUsageRecords() {
m.clearedusage_records = true
}
// UsageRecordsCleared reports if the "usage_records" edge to the PromoCodeUsage entity was cleared.
func (m *PromoCodeMutation) UsageRecordsCleared() bool {
return m.clearedusage_records
}
// RemoveUsageRecordIDs removes the "usage_records" edge to the PromoCodeUsage entity by IDs.
func (m *PromoCodeMutation) RemoveUsageRecordIDs(ids ...int64) {
if m.removedusage_records == nil {
m.removedusage_records = make(map[int64]struct{})
}
for i := range ids {
delete(m.usage_records, ids[i])
m.removedusage_records[ids[i]] = struct{}{}
}
}
// RemovedUsageRecords returns the removed IDs of the "usage_records" edge to the PromoCodeUsage entity.
func (m *PromoCodeMutation) RemovedUsageRecordsIDs() (ids []int64) {
for id := range m.removedusage_records {
ids = append(ids, id)
}
return
}
// UsageRecordsIDs returns the "usage_records" edge IDs in the mutation.
func (m *PromoCodeMutation) UsageRecordsIDs() (ids []int64) {
for id := range m.usage_records {
ids = append(ids, id)
}
return
}
// ResetUsageRecords resets all changes to the "usage_records" edge.
func (m *PromoCodeMutation) ResetUsageRecords() {
m.usage_records = nil
m.clearedusage_records = false
m.removedusage_records = nil
}
// Where appends a list predicates to the PromoCodeMutation builder.
func (m *PromoCodeMutation) Where(ps ...predicate.PromoCode) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the PromoCodeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PromoCodeMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.PromoCode, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *PromoCodeMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *PromoCodeMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (PromoCode).
func (m *PromoCodeMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PromoCodeMutation) Fields() []string {
fields := make([]string, 0, 9)
if m.code != nil {
fields = append(fields, promocode.FieldCode)
}
if m.bonus_amount != nil {
fields = append(fields, promocode.FieldBonusAmount)
}
if m.max_uses != nil {
fields = append(fields, promocode.FieldMaxUses)
}
if m.used_count != nil {
fields = append(fields, promocode.FieldUsedCount)
}
if m.status != nil {
fields = append(fields, promocode.FieldStatus)
}
if m.expires_at != nil {
fields = append(fields, promocode.FieldExpiresAt)
}
if m.notes != nil {
fields = append(fields, promocode.FieldNotes)
}
if m.created_at != nil {
fields = append(fields, promocode.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, promocode.FieldUpdatedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PromoCodeMutation) Field(name string) (ent.Value, bool) {
switch name {
case promocode.FieldCode:
return m.Code()
case promocode.FieldBonusAmount:
return m.BonusAmount()
case promocode.FieldMaxUses:
return m.MaxUses()
case promocode.FieldUsedCount:
return m.UsedCount()
case promocode.FieldStatus:
return m.Status()
case promocode.FieldExpiresAt:
return m.ExpiresAt()
case promocode.FieldNotes:
return m.Notes()
case promocode.FieldCreatedAt:
return m.CreatedAt()
case promocode.FieldUpdatedAt:
return m.UpdatedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PromoCodeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case promocode.FieldCode:
return m.OldCode(ctx)
case promocode.FieldBonusAmount:
return m.OldBonusAmount(ctx)
case promocode.FieldMaxUses:
return m.OldMaxUses(ctx)
case promocode.FieldUsedCount:
return m.OldUsedCount(ctx)
case promocode.FieldStatus:
return m.OldStatus(ctx)
case promocode.FieldExpiresAt:
return m.OldExpiresAt(ctx)
case promocode.FieldNotes:
return m.OldNotes(ctx)
case promocode.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case promocode.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
}
return nil, fmt.Errorf("unknown PromoCode field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeMutation) SetField(name string, value ent.Value) error {
switch name {
case promocode.FieldCode:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCode(v)
return nil
case promocode.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBonusAmount(v)
return nil
case promocode.FieldMaxUses:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMaxUses(v)
return nil
case promocode.FieldUsedCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsedCount(v)
return nil
case promocode.FieldStatus:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetStatus(v)
return nil
case promocode.FieldExpiresAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetExpiresAt(v)
return nil
case promocode.FieldNotes:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetNotes(v)
return nil
case promocode.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case promocode.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
}
return fmt.Errorf("unknown PromoCode field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PromoCodeMutation) AddedFields() []string {
var fields []string
if m.addbonus_amount != nil {
fields = append(fields, promocode.FieldBonusAmount)
}
if m.addmax_uses != nil {
fields = append(fields, promocode.FieldMaxUses)
}
if m.addused_count != nil {
fields = append(fields, promocode.FieldUsedCount)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PromoCodeMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case promocode.FieldBonusAmount:
return m.AddedBonusAmount()
case promocode.FieldMaxUses:
return m.AddedMaxUses()
case promocode.FieldUsedCount:
return m.AddedUsedCount()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeMutation) AddField(name string, value ent.Value) error {
switch name {
case promocode.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddBonusAmount(v)
return nil
case promocode.FieldMaxUses:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMaxUses(v)
return nil
case promocode.FieldUsedCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUsedCount(v)
return nil
}
return fmt.Errorf("unknown PromoCode numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PromoCodeMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(promocode.FieldExpiresAt) {
fields = append(fields, promocode.FieldExpiresAt)
}
if m.FieldCleared(promocode.FieldNotes) {
fields = append(fields, promocode.FieldNotes)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PromoCodeMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PromoCodeMutation) ClearField(name string) error {
switch name {
case promocode.FieldExpiresAt:
m.ClearExpiresAt()
return nil
case promocode.FieldNotes:
m.ClearNotes()
return nil
}
return fmt.Errorf("unknown PromoCode nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PromoCodeMutation) ResetField(name string) error {
switch name {
case promocode.FieldCode:
m.ResetCode()
return nil
case promocode.FieldBonusAmount:
m.ResetBonusAmount()
return nil
case promocode.FieldMaxUses:
m.ResetMaxUses()
return nil
case promocode.FieldUsedCount:
m.ResetUsedCount()
return nil
case promocode.FieldStatus:
m.ResetStatus()
return nil
case promocode.FieldExpiresAt:
m.ResetExpiresAt()
return nil
case promocode.FieldNotes:
m.ResetNotes()
return nil
case promocode.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case promocode.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
}
return fmt.Errorf("unknown PromoCode field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PromoCodeMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.usage_records != nil {
edges = append(edges, promocode.EdgeUsageRecords)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PromoCodeMutation) AddedIDs(name string) []ent.Value {
switch name {
case promocode.EdgeUsageRecords:
ids := make([]ent.Value, 0, len(m.usage_records))
for id := range m.usage_records {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PromoCodeMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
if m.removedusage_records != nil {
edges = append(edges, promocode.EdgeUsageRecords)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PromoCodeMutation) RemovedIDs(name string) []ent.Value {
switch name {
case promocode.EdgeUsageRecords:
ids := make([]ent.Value, 0, len(m.removedusage_records))
for id := range m.removedusage_records {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PromoCodeMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.clearedusage_records {
edges = append(edges, promocode.EdgeUsageRecords)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PromoCodeMutation) EdgeCleared(name string) bool {
switch name {
case promocode.EdgeUsageRecords:
return m.clearedusage_records
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *PromoCodeMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown PromoCode unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *PromoCodeMutation) ResetEdge(name string) error {
switch name {
case promocode.EdgeUsageRecords:
m.ResetUsageRecords()
return nil
}
return fmt.Errorf("unknown PromoCode edge %s", name)
}
// PromoCodeUsageMutation represents an operation that mutates the PromoCodeUsage nodes in the graph.
type PromoCodeUsageMutation struct {
config
op Op
typ string
id *int64
bonus_amount *float64
addbonus_amount *float64
used_at *time.Time
clearedFields map[string]struct{}
promo_code *int64
clearedpromo_code bool
user *int64
cleareduser bool
done bool
oldValue func(context.Context) (*PromoCodeUsage, error)
predicates []predicate.PromoCodeUsage
}
var _ ent.Mutation = (*PromoCodeUsageMutation)(nil)
// promocodeusageOption allows management of the mutation configuration using functional options.
type promocodeusageOption func(*PromoCodeUsageMutation)
// newPromoCodeUsageMutation creates new mutation for the PromoCodeUsage entity.
func newPromoCodeUsageMutation(c config, op Op, opts ...promocodeusageOption) *PromoCodeUsageMutation {
m := &PromoCodeUsageMutation{
config: c,
op: op,
typ: TypePromoCodeUsage,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withPromoCodeUsageID sets the ID field of the mutation.
func withPromoCodeUsageID(id int64) promocodeusageOption {
return func(m *PromoCodeUsageMutation) {
var (
err error
once sync.Once
value *PromoCodeUsage
)
m.oldValue = func(ctx context.Context) (*PromoCodeUsage, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().PromoCodeUsage.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withPromoCodeUsage sets the old PromoCodeUsage of the mutation.
func withPromoCodeUsage(node *PromoCodeUsage) promocodeusageOption {
return func(m *PromoCodeUsageMutation) {
m.oldValue = func(context.Context) (*PromoCodeUsage, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PromoCodeUsageMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PromoCodeUsageMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PromoCodeUsageMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PromoCodeUsageMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().PromoCodeUsage.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetPromoCodeID sets the "promo_code_id" field.
func (m *PromoCodeUsageMutation) SetPromoCodeID(i int64) {
m.promo_code = &i
}
// PromoCodeID returns the value of the "promo_code_id" field in the mutation.
func (m *PromoCodeUsageMutation) PromoCodeID() (r int64, exists bool) {
v := m.promo_code
if v == nil {
return
}
return *v, true
}
// OldPromoCodeID returns the old "promo_code_id" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldPromoCodeID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPromoCodeID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPromoCodeID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPromoCodeID: %w", err)
}
return oldValue.PromoCodeID, nil
}
// ResetPromoCodeID resets all changes to the "promo_code_id" field.
func (m *PromoCodeUsageMutation) ResetPromoCodeID() {
m.promo_code = nil
}
// SetUserID sets the "user_id" field.
func (m *PromoCodeUsageMutation) SetUserID(i int64) {
m.user = &i
}
// UserID returns the value of the "user_id" field in the mutation.
func (m *PromoCodeUsageMutation) UserID() (r int64, exists bool) {
v := m.user
if v == nil {
return
}
return *v, true
}
// OldUserID returns the old "user_id" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldUserID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUserID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
}
return oldValue.UserID, nil
}
// ResetUserID resets all changes to the "user_id" field.
func (m *PromoCodeUsageMutation) ResetUserID() {
m.user = nil
}
// SetBonusAmount sets the "bonus_amount" field.
func (m *PromoCodeUsageMutation) SetBonusAmount(f float64) {
m.bonus_amount = &f
m.addbonus_amount = nil
}
// BonusAmount returns the value of the "bonus_amount" field in the mutation.
func (m *PromoCodeUsageMutation) BonusAmount() (r float64, exists bool) {
v := m.bonus_amount
if v == nil {
return
}
return *v, true
}
// OldBonusAmount returns the old "bonus_amount" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldBonusAmount(ctx context.Context) (v float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBonusAmount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBonusAmount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBonusAmount: %w", err)
}
return oldValue.BonusAmount, nil
}
// AddBonusAmount adds f to the "bonus_amount" field.
func (m *PromoCodeUsageMutation) AddBonusAmount(f float64) {
if m.addbonus_amount != nil {
*m.addbonus_amount += f
} else {
m.addbonus_amount = &f
}
}
// AddedBonusAmount returns the value that was added to the "bonus_amount" field in this mutation.
func (m *PromoCodeUsageMutation) AddedBonusAmount() (r float64, exists bool) {
v := m.addbonus_amount
if v == nil {
return
}
return *v, true
}
// ResetBonusAmount resets all changes to the "bonus_amount" field.
func (m *PromoCodeUsageMutation) ResetBonusAmount() {
m.bonus_amount = nil
m.addbonus_amount = nil
}
// SetUsedAt sets the "used_at" field.
func (m *PromoCodeUsageMutation) SetUsedAt(t time.Time) {
m.used_at = &t
}
// UsedAt returns the value of the "used_at" field in the mutation.
func (m *PromoCodeUsageMutation) UsedAt() (r time.Time, exists bool) {
v := m.used_at
if v == nil {
return
}
return *v, true
}
// OldUsedAt returns the old "used_at" field's value of the PromoCodeUsage entity.
// If the PromoCodeUsage object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PromoCodeUsageMutation) OldUsedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsedAt: %w", err)
}
return oldValue.UsedAt, nil
}
// ResetUsedAt resets all changes to the "used_at" field.
func (m *PromoCodeUsageMutation) ResetUsedAt() {
m.used_at = nil
}
// ClearPromoCode clears the "promo_code" edge to the PromoCode entity.
func (m *PromoCodeUsageMutation) ClearPromoCode() {
m.clearedpromo_code = true
m.clearedFields[promocodeusage.FieldPromoCodeID] = struct{}{}
}
// PromoCodeCleared reports if the "promo_code" edge to the PromoCode entity was cleared.
func (m *PromoCodeUsageMutation) PromoCodeCleared() bool {
return m.clearedpromo_code
}
// PromoCodeIDs returns the "promo_code" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// PromoCodeID instead. It exists only for internal usage by the builders.
func (m *PromoCodeUsageMutation) PromoCodeIDs() (ids []int64) {
if id := m.promo_code; id != nil {
ids = append(ids, *id)
}
return
}
// ResetPromoCode resets all changes to the "promo_code" edge.
func (m *PromoCodeUsageMutation) ResetPromoCode() {
m.promo_code = nil
m.clearedpromo_code = false
}
// ClearUser clears the "user" edge to the User entity.
func (m *PromoCodeUsageMutation) ClearUser() {
m.cleareduser = true
m.clearedFields[promocodeusage.FieldUserID] = struct{}{}
}
// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *PromoCodeUsageMutation) UserCleared() bool {
return m.cleareduser
}
// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *PromoCodeUsageMutation) UserIDs() (ids []int64) {
if id := m.user; id != nil {
ids = append(ids, *id)
}
return
}
// ResetUser resets all changes to the "user" edge.
func (m *PromoCodeUsageMutation) ResetUser() {
m.user = nil
m.cleareduser = false
}
// Where appends a list predicates to the PromoCodeUsageMutation builder.
func (m *PromoCodeUsageMutation) Where(ps ...predicate.PromoCodeUsage) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the PromoCodeUsageMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PromoCodeUsageMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.PromoCodeUsage, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *PromoCodeUsageMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *PromoCodeUsageMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (PromoCodeUsage).
func (m *PromoCodeUsageMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PromoCodeUsageMutation) Fields() []string {
fields := make([]string, 0, 4)
if m.promo_code != nil {
fields = append(fields, promocodeusage.FieldPromoCodeID)
}
if m.user != nil {
fields = append(fields, promocodeusage.FieldUserID)
}
if m.bonus_amount != nil {
fields = append(fields, promocodeusage.FieldBonusAmount)
}
if m.used_at != nil {
fields = append(fields, promocodeusage.FieldUsedAt)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PromoCodeUsageMutation) Field(name string) (ent.Value, bool) {
switch name {
case promocodeusage.FieldPromoCodeID:
return m.PromoCodeID()
case promocodeusage.FieldUserID:
return m.UserID()
case promocodeusage.FieldBonusAmount:
return m.BonusAmount()
case promocodeusage.FieldUsedAt:
return m.UsedAt()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PromoCodeUsageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case promocodeusage.FieldPromoCodeID:
return m.OldPromoCodeID(ctx)
case promocodeusage.FieldUserID:
return m.OldUserID(ctx)
case promocodeusage.FieldBonusAmount:
return m.OldBonusAmount(ctx)
case promocodeusage.FieldUsedAt:
return m.OldUsedAt(ctx)
}
return nil, fmt.Errorf("unknown PromoCodeUsage field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeUsageMutation) SetField(name string, value ent.Value) error {
switch name {
case promocodeusage.FieldPromoCodeID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPromoCodeID(v)
return nil
case promocodeusage.FieldUserID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUserID(v)
return nil
case promocodeusage.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBonusAmount(v)
return nil
case promocodeusage.FieldUsedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsedAt(v)
return nil
}
return fmt.Errorf("unknown PromoCodeUsage field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PromoCodeUsageMutation) AddedFields() []string {
var fields []string
if m.addbonus_amount != nil {
fields = append(fields, promocodeusage.FieldBonusAmount)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PromoCodeUsageMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case promocodeusage.FieldBonusAmount:
return m.AddedBonusAmount()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PromoCodeUsageMutation) AddField(name string, value ent.Value) error {
switch name {
case promocodeusage.FieldBonusAmount:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddBonusAmount(v)
return nil
}
return fmt.Errorf("unknown PromoCodeUsage numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PromoCodeUsageMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PromoCodeUsageMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PromoCodeUsageMutation) ClearField(name string) error {
return fmt.Errorf("unknown PromoCodeUsage nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PromoCodeUsageMutation) ResetField(name string) error {
switch name {
case promocodeusage.FieldPromoCodeID:
m.ResetPromoCodeID()
return nil
case promocodeusage.FieldUserID:
m.ResetUserID()
return nil
case promocodeusage.FieldBonusAmount:
m.ResetBonusAmount()
return nil
case promocodeusage.FieldUsedAt:
m.ResetUsedAt()
return nil
}
return fmt.Errorf("unknown PromoCodeUsage field %s", name)
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GroupMutation) RemovedEdges() []string {
edges := make([]string, 0, 6)
if m.removedapi_keys != nil {
edges = append(edges, group.EdgeAPIKeys)
}
if m.removedredeem_codes != nil {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.removedsubscriptions != nil {
edges = append(edges, group.EdgeSubscriptions)
}
if m.removedusage_logs != nil {
edges = append(edges, group.EdgeUsageLogs)
}
if m.removedaccounts != nil {
edges = append(edges, group.EdgeAccounts)
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PromoCodeUsageMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.promo_code != nil {
edges = append(edges, promocodeusage.EdgePromoCode)
}
if m.
removedallowed_
user
s
!= nil {
edges = append(edges,
g
ro
up.EdgeAllowed
User
s
)
if m.user != nil {
edges = append(edges,
p
ro
mocodeusage.Edge
User)
}
return edges
}
//
Remov
edIDs returns all IDs (to other nodes) that were
remov
ed for the
edge with
//
the given
name in this mutation.
func (m *
G
ro
up
Mutation)
Remov
edIDs(name string) []ent.Value {
//
Add
edIDs returns all IDs (to other nodes) that were
add
ed for the
given edge
// name in this mutation.
func (m *
P
ro
moCodeUsage
Mutation)
Add
edIDs(name string) []ent.Value {
switch name {
case group.EdgeAPIKeys:
ids := make([]ent.Value, 0, len(m.removedapi_keys))
for id := range m.removedapi_keys {
ids = append(ids, id)
}
return ids
case group.EdgeRedeemCodes:
ids := make([]ent.Value, 0, len(m.removedredeem_codes))
for id := range m.removedredeem_codes {
ids = append(ids, id)
}
return ids
case group.EdgeSubscriptions:
ids := make([]ent.Value, 0, len(m.removedsubscriptions))
for id := range m.removedsubscriptions {
ids = append(ids, id)
}
return ids
case group.EdgeUsageLogs:
ids := make([]ent.Value, 0, len(m.removedusage_logs))
for id := range m.removedusage_logs {
ids = append(ids, id)
}
return ids
case group.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
ids = append(ids, id)
case promocodeusage.EdgePromoCode:
if id := m.promo_code; id != nil {
return []ent.Value{*id}
}
return ids
case group.EdgeAllowedUsers:
ids := make([]ent.Value, 0, len(m.removedallowed_users))
for id := range m.removedallowed_users {
ids = append(ids, id)
case promocodeusage.EdgeUser:
if id := m.user; id != nil {
return []ent.Value{*id}
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PromoCodeUsageMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PromoCodeUsageMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GroupMutation) ClearedEdges() []string {
edges := make([]string, 0, 6)
if m.clearedapi_keys {
edges = append(edges, group.EdgeAPIKeys)
}
if m.clearedredeem_codes {
edges = append(edges, group.EdgeRedeemCodes)
}
if m.clearedsubscriptions {
edges = append(edges, group.EdgeSubscriptions)
}
if m.clearedusage_logs {
edges = append(edges, group.EdgeUsageLogs)
}
if m.clearedaccounts {
edges = append(edges, group.EdgeAccounts)
func (m *PromoCodeUsageMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.clearedpromo_code {
edges = append(edges, promocodeusage.EdgePromoCode)
}
if m.cleared
allowed_
user
s
{
edges = append(edges,
g
ro
up.EdgeAllowed
User
s
)
if m.cleareduser {
edges = append(edges,
p
ro
mocodeusage.Edge
User)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *
G
ro
up
Mutation) EdgeCleared(name string) bool {
func (m *
P
ro
moCodeUsage
Mutation) EdgeCleared(name string) bool {
switch name {
case group.EdgeAPIKeys:
return m.clearedapi_keys
case group.EdgeRedeemCodes:
return m.clearedredeem_codes
case group.EdgeSubscriptions:
return m.clearedsubscriptions
case group.EdgeUsageLogs:
return m.clearedusage_logs
case group.EdgeAccounts:
return m.clearedaccounts
case group.EdgeAllowedUsers:
return m.clearedallowed_users
case promocodeusage.EdgePromoCode:
return m.clearedpromo_code
case promocodeusage.EdgeUser:
return m.cleareduser
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *
G
ro
up
Mutation) ClearEdge(name string) error {
func (m *
P
ro
moCodeUsage
Mutation) ClearEdge(name string) error {
switch name {
case promocodeusage.EdgePromoCode:
m.ClearPromoCode()
return nil
case promocodeusage.EdgeUser:
m.ClearUser()
return nil
}
return fmt.Errorf("unknown
G
ro
up
unique edge %s", name)
return fmt.Errorf("unknown
P
ro
moCodeUsage
unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *
G
ro
up
Mutation) ResetEdge(name string) error {
func (m *
P
ro
moCodeUsage
Mutation) ResetEdge(name string) error {
switch name {
case group.EdgeAPIKeys:
m.ResetAPIKeys()
return nil
case group.EdgeRedeemCodes:
m.ResetRedeemCodes()
return nil
case group.EdgeSubscriptions:
m.ResetSubscriptions()
return nil
case group.EdgeUsageLogs:
m.ResetUsageLogs()
return nil
case group.EdgeAccounts:
m.ResetAccounts()
case promocodeusage.EdgePromoCode:
m.ResetPromoCode()
return nil
case
g
ro
up.EdgeAllowed
User
s
:
m.Reset
Allowed
User
s
()
case
p
ro
mocodeusage.Edge
User:
m.ResetUser()
return nil
}
return fmt.Errorf("unknown
G
ro
up
edge %s", name)
return fmt.Errorf("unknown
P
ro
moCodeUsage
edge %s", name)
}
// ProxyMutation represents an operation that mutates the Proxy nodes in the graph.
...
...
@@ -8388,6 +10404,8 @@ type UsageLogMutation struct {
addactual_cost *float64
rate_multiplier *float64
addrate_multiplier *float64
account_rate_multiplier *float64
addaccount_rate_multiplier *float64
billing_type *int8
addbilling_type *int8
stream *bool
...
...
@@ -8396,6 +10414,7 @@ type UsageLogMutation struct {
first_token_ms *int
addfirst_token_ms *int
user_agent *string
ip_address *string
image_count *int
addimage_count *int
image_size *string
...
...
@@ -9520,6 +11539,76 @@ func (m *UsageLogMutation) ResetRateMultiplier() {
m.addrate_multiplier = nil
}
// SetAccountRateMultiplier sets the "account_rate_multiplier" field.
func (m *UsageLogMutation) SetAccountRateMultiplier(f float64) {
m.account_rate_multiplier = &f
m.addaccount_rate_multiplier = nil
}
// AccountRateMultiplier returns the value of the "account_rate_multiplier" field in the mutation.
func (m *UsageLogMutation) AccountRateMultiplier() (r float64, exists bool) {
v := m.account_rate_multiplier
if v == nil {
return
}
return *v, true
}
// OldAccountRateMultiplier returns the old "account_rate_multiplier" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldAccountRateMultiplier(ctx context.Context) (v *float64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAccountRateMultiplier is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAccountRateMultiplier requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAccountRateMultiplier: %w", err)
}
return oldValue.AccountRateMultiplier, nil
}
// AddAccountRateMultiplier adds f to the "account_rate_multiplier" field.
func (m *UsageLogMutation) AddAccountRateMultiplier(f float64) {
if m.addaccount_rate_multiplier != nil {
*m.addaccount_rate_multiplier += f
} else {
m.addaccount_rate_multiplier = &f
}
}
// AddedAccountRateMultiplier returns the value that was added to the "account_rate_multiplier" field in this mutation.
func (m *UsageLogMutation) AddedAccountRateMultiplier() (r float64, exists bool) {
v := m.addaccount_rate_multiplier
if v == nil {
return
}
return *v, true
}
// ClearAccountRateMultiplier clears the value of the "account_rate_multiplier" field.
func (m *UsageLogMutation) ClearAccountRateMultiplier() {
m.account_rate_multiplier = nil
m.addaccount_rate_multiplier = nil
m.clearedFields[usagelog.FieldAccountRateMultiplier] = struct{}{}
}
// AccountRateMultiplierCleared returns if the "account_rate_multiplier" field was cleared in this mutation.
func (m *UsageLogMutation) AccountRateMultiplierCleared() bool {
_, ok := m.clearedFields[usagelog.FieldAccountRateMultiplier]
return ok
}
// ResetAccountRateMultiplier resets all changes to the "account_rate_multiplier" field.
func (m *UsageLogMutation) ResetAccountRateMultiplier() {
m.account_rate_multiplier = nil
m.addaccount_rate_multiplier = nil
delete(m.clearedFields, usagelog.FieldAccountRateMultiplier)
}
// SetBillingType sets the "billing_type" field.
func (m *UsageLogMutation) SetBillingType(i int8) {
m.billing_type = &i
...
...
@@ -9801,6 +11890,55 @@ func (m *UsageLogMutation) ResetUserAgent() {
delete(m.clearedFields, usagelog.FieldUserAgent)
}
// SetIPAddress sets the "ip_address" field.
func (m *UsageLogMutation) SetIPAddress(s string) {
m.ip_address = &s
}
// IPAddress returns the value of the "ip_address" field in the mutation.
func (m *UsageLogMutation) IPAddress() (r string, exists bool) {
v := m.ip_address
if v == nil {
return
}
return *v, true
}
// OldIPAddress returns the old "ip_address" field's value of the UsageLog entity.
// If the UsageLog object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UsageLogMutation) OldIPAddress(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIPAddress is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIPAddress requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIPAddress: %w", err)
}
return oldValue.IPAddress, nil
}
// ClearIPAddress clears the value of the "ip_address" field.
func (m *UsageLogMutation) ClearIPAddress() {
m.ip_address = nil
m.clearedFields[usagelog.FieldIPAddress] = struct{}{}
}
// IPAddressCleared returns if the "ip_address" field was cleared in this mutation.
func (m *UsageLogMutation) IPAddressCleared() bool {
_, ok := m.clearedFields[usagelog.FieldIPAddress]
return ok
}
// ResetIPAddress resets all changes to the "ip_address" field.
func (m *UsageLogMutation) ResetIPAddress() {
m.ip_address = nil
delete(m.clearedFields, usagelog.FieldIPAddress)
}
// SetImageCount sets the "image_count" field.
func (m *UsageLogMutation) SetImageCount(i int) {
m.image_count = &i
...
...
@@ -10111,7 +12249,7 @@ func (m *UsageLogMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UsageLogMutation) Fields() []string {
fields := make([]string, 0,
28
)
fields := make([]string, 0,
30
)
if m.user != nil {
fields = append(fields, usagelog.FieldUserID)
}
...
...
@@ -10172,6 +12310,9 @@ func (m *UsageLogMutation) Fields() []string {
if m.rate_multiplier != nil {
fields = append(fields, usagelog.FieldRateMultiplier)
}
if m.account_rate_multiplier != nil {
fields = append(fields, usagelog.FieldAccountRateMultiplier)
}
if m.billing_type != nil {
fields = append(fields, usagelog.FieldBillingType)
}
...
...
@@ -10187,6 +12328,9 @@ func (m *UsageLogMutation) Fields() []string {
if m.user_agent != nil {
fields = append(fields, usagelog.FieldUserAgent)
}
if m.ip_address != nil {
fields = append(fields, usagelog.FieldIPAddress)
}
if m.image_count != nil {
fields = append(fields, usagelog.FieldImageCount)
}
...
...
@@ -10244,6 +12388,8 @@ func (m *UsageLogMutation) Field(name string) (ent.Value, bool) {
return m.ActualCost()
case usagelog.FieldRateMultiplier:
return m.RateMultiplier()
case usagelog.FieldAccountRateMultiplier:
return m.AccountRateMultiplier()
case usagelog.FieldBillingType:
return m.BillingType()
case usagelog.FieldStream:
...
...
@@ -10254,6 +12400,8 @@ func (m *UsageLogMutation) Field(name string) (ent.Value, bool) {
return m.FirstTokenMs()
case usagelog.FieldUserAgent:
return m.UserAgent()
case usagelog.FieldIPAddress:
return m.IPAddress()
case usagelog.FieldImageCount:
return m.ImageCount()
case usagelog.FieldImageSize:
...
...
@@ -10309,6 +12457,8 @@ func (m *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value
return m.OldActualCost(ctx)
case usagelog.FieldRateMultiplier:
return m.OldRateMultiplier(ctx)
case usagelog.FieldAccountRateMultiplier:
return m.OldAccountRateMultiplier(ctx)
case usagelog.FieldBillingType:
return m.OldBillingType(ctx)
case usagelog.FieldStream:
...
...
@@ -10319,6 +12469,8 @@ func (m *UsageLogMutation) OldField(ctx context.Context, name string) (ent.Value
return m.OldFirstTokenMs(ctx)
case usagelog.FieldUserAgent:
return m.OldUserAgent(ctx)
case usagelog.FieldIPAddress:
return m.OldIPAddress(ctx)
case usagelog.FieldImageCount:
return m.OldImageCount(ctx)
case usagelog.FieldImageSize:
...
...
@@ -10474,6 +12626,13 @@ func (m *UsageLogMutation) SetField(name string, value ent.Value) error {
}
m.SetRateMultiplier(v)
return nil
case usagelog.FieldAccountRateMultiplier:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAccountRateMultiplier(v)
return nil
case usagelog.FieldBillingType:
v, ok := value.(int8)
if !ok {
...
...
@@ -10509,6 +12668,13 @@ func (m *UsageLogMutation) SetField(name string, value ent.Value) error {
}
m.SetUserAgent(v)
return nil
case usagelog.FieldIPAddress:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIPAddress(v)
return nil
case usagelog.FieldImageCount:
v, ok := value.(int)
if !ok {
...
...
@@ -10577,6 +12743,9 @@ func (m *UsageLogMutation) AddedFields() []string {
if m.addrate_multiplier != nil {
fields = append(fields, usagelog.FieldRateMultiplier)
}
if m.addaccount_rate_multiplier != nil {
fields = append(fields, usagelog.FieldAccountRateMultiplier)
}
if m.addbilling_type != nil {
fields = append(fields, usagelog.FieldBillingType)
}
...
...
@@ -10623,6 +12792,8 @@ func (m *UsageLogMutation) AddedField(name string) (ent.Value, bool) {
return m.AddedActualCost()
case usagelog.FieldRateMultiplier:
return m.AddedRateMultiplier()
case usagelog.FieldAccountRateMultiplier:
return m.AddedAccountRateMultiplier()
case usagelog.FieldBillingType:
return m.AddedBillingType()
case usagelog.FieldDurationMs:
...
...
@@ -10731,6 +12902,13 @@ func (m *UsageLogMutation) AddField(name string, value ent.Value) error {
}
m.AddRateMultiplier(v)
return nil
case usagelog.FieldAccountRateMultiplier:
v, ok := value.(float64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddAccountRateMultiplier(v)
return nil
case usagelog.FieldBillingType:
v, ok := value.(int8)
if !ok {
...
...
@@ -10773,6 +12951,9 @@ func (m *UsageLogMutation) ClearedFields() []string {
if m.FieldCleared(usagelog.FieldSubscriptionID) {
fields = append(fields, usagelog.FieldSubscriptionID)
}
if m.FieldCleared(usagelog.FieldAccountRateMultiplier) {
fields = append(fields, usagelog.FieldAccountRateMultiplier)
}
if m.FieldCleared(usagelog.FieldDurationMs) {
fields = append(fields, usagelog.FieldDurationMs)
}
...
...
@@ -10782,6 +12963,9 @@ func (m *UsageLogMutation) ClearedFields() []string {
if m.FieldCleared(usagelog.FieldUserAgent) {
fields = append(fields, usagelog.FieldUserAgent)
}
if m.FieldCleared(usagelog.FieldIPAddress) {
fields = append(fields, usagelog.FieldIPAddress)
}
if m.FieldCleared(usagelog.FieldImageSize) {
fields = append(fields, usagelog.FieldImageSize)
}
...
...
@@ -10805,6 +12989,9 @@ func (m *UsageLogMutation) ClearField(name string) error {
case usagelog.FieldSubscriptionID:
m.ClearSubscriptionID()
return nil
case usagelog.FieldAccountRateMultiplier:
m.ClearAccountRateMultiplier()
return nil
case usagelog.FieldDurationMs:
m.ClearDurationMs()
return nil
...
...
@@ -10814,6 +13001,9 @@ func (m *UsageLogMutation) ClearField(name string) error {
case usagelog.FieldUserAgent:
m.ClearUserAgent()
return nil
case usagelog.FieldIPAddress:
m.ClearIPAddress()
return nil
case usagelog.FieldImageSize:
m.ClearImageSize()
return nil
...
...
@@ -10885,6 +13075,9 @@ func (m *UsageLogMutation) ResetField(name string) error {
case usagelog.FieldRateMultiplier:
m.ResetRateMultiplier()
return nil
case usagelog.FieldAccountRateMultiplier:
m.ResetAccountRateMultiplier()
return nil
case usagelog.FieldBillingType:
m.ResetBillingType()
return nil
...
...
@@ -10900,6 +13093,9 @@ func (m *UsageLogMutation) ResetField(name string) error {
case usagelog.FieldUserAgent:
m.ResetUserAgent()
return nil
case usagelog.FieldIPAddress:
m.ResetIPAddress()
return nil
case usagelog.FieldImageCount:
m.ResetImageCount()
return nil
...
...
@@ -11100,6 +13296,9 @@ type UserMutation struct {
attribute_values map[int64]struct{}
removedattribute_values map[int64]struct{}
clearedattribute_values bool
promo_code_usages map[int64]struct{}
removedpromo_code_usages map[int64]struct{}
clearedpromo_code_usages bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
...
...
@@ -12030,6 +14229,60 @@ func (m *UserMutation) ResetAttributeValues() {
m.removedattribute_values = nil
}
// AddPromoCodeUsageIDs adds the "promo_code_usages" edge to the PromoCodeUsage entity by ids.
func (m *UserMutation) AddPromoCodeUsageIDs(ids ...int64) {
if m.promo_code_usages == nil {
m.promo_code_usages = make(map[int64]struct{})
}
for i := range ids {
m.promo_code_usages[ids[i]] = struct{}{}
}
}
// ClearPromoCodeUsages clears the "promo_code_usages" edge to the PromoCodeUsage entity.
func (m *UserMutation) ClearPromoCodeUsages() {
m.clearedpromo_code_usages = true
}
// PromoCodeUsagesCleared reports if the "promo_code_usages" edge to the PromoCodeUsage entity was cleared.
func (m *UserMutation) PromoCodeUsagesCleared() bool {
return m.clearedpromo_code_usages
}
// RemovePromoCodeUsageIDs removes the "promo_code_usages" edge to the PromoCodeUsage entity by IDs.
func (m *UserMutation) RemovePromoCodeUsageIDs(ids ...int64) {
if m.removedpromo_code_usages == nil {
m.removedpromo_code_usages = make(map[int64]struct{})
}
for i := range ids {
delete(m.promo_code_usages, ids[i])
m.removedpromo_code_usages[ids[i]] = struct{}{}
}
}
// RemovedPromoCodeUsages returns the removed IDs of the "promo_code_usages" edge to the PromoCodeUsage entity.
func (m *UserMutation) RemovedPromoCodeUsagesIDs() (ids []int64) {
for id := range m.removedpromo_code_usages {
ids = append(ids, id)
}
return
}
// PromoCodeUsagesIDs returns the "promo_code_usages" edge IDs in the mutation.
func (m *UserMutation) PromoCodeUsagesIDs() (ids []int64) {
for id := range m.promo_code_usages {
ids = append(ids, id)
}
return
}
// ResetPromoCodeUsages resets all changes to the "promo_code_usages" edge.
func (m *UserMutation) ResetPromoCodeUsages() {
m.promo_code_usages = nil
m.clearedpromo_code_usages = false
m.removedpromo_code_usages = nil
}
// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
m.predicates = append(m.predicates, ps...)
...
...
@@ -12369,7 +14622,7 @@ func (m *UserMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.api_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
}
...
...
@@ -12391,6 +14644,9 @@ func (m *UserMutation) AddedEdges() []string {
if m.attribute_values != nil {
edges = append(edges, user.EdgeAttributeValues)
}
if m.promo_code_usages != nil {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
}
...
...
@@ -12440,13 +14696,19 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case user.EdgePromoCodeUsages:
ids := make([]ent.Value, 0, len(m.promo_code_usages))
for id := range m.promo_code_usages {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.removedapi_keys != nil {
edges = append(edges, user.EdgeAPIKeys)
}
...
...
@@ -12468,6 +14730,9 @@ func (m *UserMutation) RemovedEdges() []string {
if m.removedattribute_values != nil {
edges = append(edges, user.EdgeAttributeValues)
}
if m.removedpromo_code_usages != nil {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
}
...
...
@@ -12517,13 +14782,19 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
case user.EdgePromoCodeUsages:
ids := make([]ent.Value, 0, len(m.removedpromo_code_usages))
for id := range m.removedpromo_code_usages {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
edges := make([]string, 0,
7
)
edges := make([]string, 0,
8
)
if m.clearedapi_keys {
edges = append(edges, user.EdgeAPIKeys)
}
...
...
@@ -12545,6 +14816,9 @@ func (m *UserMutation) ClearedEdges() []string {
if m.clearedattribute_values {
edges = append(edges, user.EdgeAttributeValues)
}
if m.clearedpromo_code_usages {
edges = append(edges, user.EdgePromoCodeUsages)
}
return edges
}
...
...
@@ -12566,6 +14840,8 @@ func (m *UserMutation) EdgeCleared(name string) bool {
return m.clearedusage_logs
case user.EdgeAttributeValues:
return m.clearedattribute_values
case user.EdgePromoCodeUsages:
return m.clearedpromo_code_usages
}
return false
}
...
...
@@ -12603,6 +14879,9 @@ func (m *UserMutation) ResetEdge(name string) error {
case user.EdgeAttributeValues:
m.ResetAttributeValues()
return nil
case user.EdgePromoCodeUsages:
m.ResetPromoCodeUsages()
return nil
}
return fmt.Errorf("unknown User edge %s", name)
}
...
...
backend/ent/predicate/predicate.go
View file @
b9b4db3d
...
...
@@ -18,6 +18,12 @@ type AccountGroup func(*sql.Selector)
// Group is the predicate function for group builders.
type
Group
func
(
*
sql
.
Selector
)
// PromoCode is the predicate function for promocode builders.
type
PromoCode
func
(
*
sql
.
Selector
)
// PromoCodeUsage is the predicate function for promocodeusage builders.
type
PromoCodeUsage
func
(
*
sql
.
Selector
)
// Proxy is the predicate function for proxy builders.
type
Proxy
func
(
*
sql
.
Selector
)
...
...
backend/ent/promocode.go
0 → 100644
View file @
b9b4db3d
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/promocode"
)
// PromoCode is the model entity for the PromoCode schema.
type
PromoCode
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// 优惠码
Code
string
`json:"code,omitempty"`
// 赠送余额金额
BonusAmount
float64
`json:"bonus_amount,omitempty"`
// 最大使用次数,0表示无限制
MaxUses
int
`json:"max_uses,omitempty"`
// 已使用次数
UsedCount
int
`json:"used_count,omitempty"`
// 状态: active, disabled
Status
string
`json:"status,omitempty"`
// 过期时间,null表示永不过期
ExpiresAt
*
time
.
Time
`json:"expires_at,omitempty"`
// 备注
Notes
*
string
`json:"notes,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt
time
.
Time
`json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt
time
.
Time
`json:"updated_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PromoCodeQuery when eager-loading is set.
Edges
PromoCodeEdges
`json:"edges"`
selectValues
sql
.
SelectValues
}
// PromoCodeEdges holds the relations/edges for other nodes in the graph.
type
PromoCodeEdges
struct
{
// UsageRecords holds the value of the usage_records edge.
UsageRecords
[]
*
PromoCodeUsage
`json:"usage_records,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes
[
1
]
bool
}
// UsageRecordsOrErr returns the UsageRecords value or an error if the edge
// was not loaded in eager-loading.
func
(
e
PromoCodeEdges
)
UsageRecordsOrErr
()
([]
*
PromoCodeUsage
,
error
)
{
if
e
.
loadedTypes
[
0
]
{
return
e
.
UsageRecords
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"usage_records"
}
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
PromoCode
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
promocode
.
FieldBonusAmount
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
promocode
.
FieldID
,
promocode
.
FieldMaxUses
,
promocode
.
FieldUsedCount
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
promocode
.
FieldCode
,
promocode
.
FieldStatus
,
promocode
.
FieldNotes
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
promocode
.
FieldExpiresAt
,
promocode
.
FieldCreatedAt
,
promocode
.
FieldUpdatedAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
default
:
values
[
i
]
=
new
(
sql
.
UnknownType
)
}
}
return
values
,
nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the PromoCode fields.
func
(
_m
*
PromoCode
)
assignValues
(
columns
[]
string
,
values
[]
any
)
error
{
if
m
,
n
:=
len
(
values
),
len
(
columns
);
m
<
n
{
return
fmt
.
Errorf
(
"mismatch number of scan values: %d != %d"
,
m
,
n
)
}
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
promocode
.
FieldID
:
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
)
if
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field id"
,
value
)
}
_m
.
ID
=
int64
(
value
.
Int64
)
case
promocode
.
FieldCode
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field code"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Code
=
value
.
String
}
case
promocode
.
FieldBonusAmount
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullFloat64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field bonus_amount"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
BonusAmount
=
value
.
Float64
}
case
promocode
.
FieldMaxUses
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field max_uses"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
MaxUses
=
int
(
value
.
Int64
)
}
case
promocode
.
FieldUsedCount
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field used_count"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UsedCount
=
int
(
value
.
Int64
)
}
case
promocode
.
FieldStatus
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field status"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Status
=
value
.
String
}
case
promocode
.
FieldExpiresAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field expires_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ExpiresAt
=
new
(
time
.
Time
)
*
_m
.
ExpiresAt
=
value
.
Time
}
case
promocode
.
FieldNotes
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field notes"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Notes
=
new
(
string
)
*
_m
.
Notes
=
value
.
String
}
case
promocode
.
FieldCreatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field created_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CreatedAt
=
value
.
Time
}
case
promocode
.
FieldUpdatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field updated_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UpdatedAt
=
value
.
Time
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
}
return
nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the PromoCode.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
PromoCode
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// QueryUsageRecords queries the "usage_records" edge of the PromoCode entity.
func
(
_m
*
PromoCode
)
QueryUsageRecords
()
*
PromoCodeUsageQuery
{
return
NewPromoCodeClient
(
_m
.
config
)
.
QueryUsageRecords
(
_m
)
}
// Update returns a builder for updating this PromoCode.
// Note that you need to call PromoCode.Unwrap() before calling this method if this PromoCode
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
PromoCode
)
Update
()
*
PromoCodeUpdateOne
{
return
NewPromoCodeClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the PromoCode entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func
(
_m
*
PromoCode
)
Unwrap
()
*
PromoCode
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: PromoCode is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
PromoCode
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"PromoCode("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"code="
)
builder
.
WriteString
(
_m
.
Code
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"bonus_amount="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
BonusAmount
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"max_uses="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
MaxUses
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"used_count="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
UsedCount
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"status="
)
builder
.
WriteString
(
_m
.
Status
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ExpiresAt
;
v
!=
nil
{
builder
.
WriteString
(
"expires_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
Notes
;
v
!=
nil
{
builder
.
WriteString
(
"notes="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"created_at="
)
builder
.
WriteString
(
_m
.
CreatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"updated_at="
)
builder
.
WriteString
(
_m
.
UpdatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// PromoCodes is a parsable slice of PromoCode.
type
PromoCodes
[]
*
PromoCode
backend/ent/promocode/promocode.go
0 → 100644
View file @
b9b4db3d
// Code generated by ent, DO NOT EDIT.
package
promocode
import
(
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const
(
// Label holds the string label denoting the promocode type in the database.
Label
=
"promo_code"
// FieldID holds the string denoting the id field in the database.
FieldID
=
"id"
// FieldCode holds the string denoting the code field in the database.
FieldCode
=
"code"
// FieldBonusAmount holds the string denoting the bonus_amount field in the database.
FieldBonusAmount
=
"bonus_amount"
// FieldMaxUses holds the string denoting the max_uses field in the database.
FieldMaxUses
=
"max_uses"
// FieldUsedCount holds the string denoting the used_count field in the database.
FieldUsedCount
=
"used_count"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus
=
"status"
// FieldExpiresAt holds the string denoting the expires_at field in the database.
FieldExpiresAt
=
"expires_at"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes
=
"notes"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt
=
"created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt
=
"updated_at"
// EdgeUsageRecords holds the string denoting the usage_records edge name in mutations.
EdgeUsageRecords
=
"usage_records"
// Table holds the table name of the promocode in the database.
Table
=
"promo_codes"
// UsageRecordsTable is the table that holds the usage_records relation/edge.
UsageRecordsTable
=
"promo_code_usages"
// UsageRecordsInverseTable is the table name for the PromoCodeUsage entity.
// It exists in this package in order to avoid circular dependency with the "promocodeusage" package.
UsageRecordsInverseTable
=
"promo_code_usages"
// UsageRecordsColumn is the table column denoting the usage_records relation/edge.
UsageRecordsColumn
=
"promo_code_id"
)
// Columns holds all SQL columns for promocode fields.
var
Columns
=
[]
string
{
FieldID
,
FieldCode
,
FieldBonusAmount
,
FieldMaxUses
,
FieldUsedCount
,
FieldStatus
,
FieldExpiresAt
,
FieldNotes
,
FieldCreatedAt
,
FieldUpdatedAt
,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func
ValidColumn
(
column
string
)
bool
{
for
i
:=
range
Columns
{
if
column
==
Columns
[
i
]
{
return
true
}
}
return
false
}
var
(
// CodeValidator is a validator for the "code" field. It is called by the builders before save.
CodeValidator
func
(
string
)
error
// DefaultBonusAmount holds the default value on creation for the "bonus_amount" field.
DefaultBonusAmount
float64
// DefaultMaxUses holds the default value on creation for the "max_uses" field.
DefaultMaxUses
int
// DefaultUsedCount holds the default value on creation for the "used_count" field.
DefaultUsedCount
int
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus
string
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator
func
(
string
)
error
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt
func
()
time
.
Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt
func
()
time
.
Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt
func
()
time
.
Time
)
// OrderOption defines the ordering options for the PromoCode queries.
type
OrderOption
func
(
*
sql
.
Selector
)
// ByID orders the results by the id field.
func
ByID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldID
,
opts
...
)
.
ToFunc
()
}
// ByCode orders the results by the code field.
func
ByCode
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCode
,
opts
...
)
.
ToFunc
()
}
// ByBonusAmount orders the results by the bonus_amount field.
func
ByBonusAmount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldBonusAmount
,
opts
...
)
.
ToFunc
()
}
// ByMaxUses orders the results by the max_uses field.
func
ByMaxUses
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldMaxUses
,
opts
...
)
.
ToFunc
()
}
// ByUsedCount orders the results by the used_count field.
func
ByUsedCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUsedCount
,
opts
...
)
.
ToFunc
()
}
// ByStatus orders the results by the status field.
func
ByStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStatus
,
opts
...
)
.
ToFunc
()
}
// ByExpiresAt orders the results by the expires_at field.
func
ByExpiresAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldExpiresAt
,
opts
...
)
.
ToFunc
()
}
// ByNotes orders the results by the notes field.
func
ByNotes
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldNotes
,
opts
...
)
.
ToFunc
()
}
// ByCreatedAt orders the results by the created_at field.
func
ByCreatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUpdatedAt orders the results by the updated_at field.
func
ByUpdatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpdatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUsageRecordsCount orders the results by usage_records count.
func
ByUsageRecordsCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborsCount
(
s
,
newUsageRecordsStep
(),
opts
...
)
}
}
// ByUsageRecords orders the results by usage_records terms.
func
ByUsageRecords
(
term
sql
.
OrderTerm
,
terms
...
sql
.
OrderTerm
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborTerms
(
s
,
newUsageRecordsStep
(),
append
([]
sql
.
OrderTerm
{
term
},
terms
...
)
...
)
}
}
func
newUsageRecordsStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
UsageRecordsInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
UsageRecordsTable
,
UsageRecordsColumn
),
)
}
backend/ent/promocode/where.go
0 → 100644
View file @
b9b4db3d
// Code generated by ent, DO NOT EDIT.
package
promocode
import
(
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func
ID
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// Code applies equality check predicate on the "code" field. It's identical to CodeEQ.
func
Code
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCode
,
v
))
}
// BonusAmount applies equality check predicate on the "bonus_amount" field. It's identical to BonusAmountEQ.
func
BonusAmount
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldBonusAmount
,
v
))
}
// MaxUses applies equality check predicate on the "max_uses" field. It's identical to MaxUsesEQ.
func
MaxUses
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldMaxUses
,
v
))
}
// UsedCount applies equality check predicate on the "used_count" field. It's identical to UsedCountEQ.
func
UsedCount
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUsedCount
,
v
))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func
Status
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
func
ExpiresAt
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldExpiresAt
,
v
))
}
// Notes applies equality check predicate on the "notes" field. It's identical to NotesEQ.
func
Notes
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func
CreatedAt
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func
UpdatedAt
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// CodeEQ applies the EQ predicate on the "code" field.
func
CodeEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCode
,
v
))
}
// CodeNEQ applies the NEQ predicate on the "code" field.
func
CodeNEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldCode
,
v
))
}
// CodeIn applies the In predicate on the "code" field.
func
CodeIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldCode
,
vs
...
))
}
// CodeNotIn applies the NotIn predicate on the "code" field.
func
CodeNotIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldCode
,
vs
...
))
}
// CodeGT applies the GT predicate on the "code" field.
func
CodeGT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldCode
,
v
))
}
// CodeGTE applies the GTE predicate on the "code" field.
func
CodeGTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldCode
,
v
))
}
// CodeLT applies the LT predicate on the "code" field.
func
CodeLT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldCode
,
v
))
}
// CodeLTE applies the LTE predicate on the "code" field.
func
CodeLTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldCode
,
v
))
}
// CodeContains applies the Contains predicate on the "code" field.
func
CodeContains
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContains
(
FieldCode
,
v
))
}
// CodeHasPrefix applies the HasPrefix predicate on the "code" field.
func
CodeHasPrefix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasPrefix
(
FieldCode
,
v
))
}
// CodeHasSuffix applies the HasSuffix predicate on the "code" field.
func
CodeHasSuffix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasSuffix
(
FieldCode
,
v
))
}
// CodeEqualFold applies the EqualFold predicate on the "code" field.
func
CodeEqualFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEqualFold
(
FieldCode
,
v
))
}
// CodeContainsFold applies the ContainsFold predicate on the "code" field.
func
CodeContainsFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContainsFold
(
FieldCode
,
v
))
}
// BonusAmountEQ applies the EQ predicate on the "bonus_amount" field.
func
BonusAmountEQ
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldBonusAmount
,
v
))
}
// BonusAmountNEQ applies the NEQ predicate on the "bonus_amount" field.
func
BonusAmountNEQ
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldBonusAmount
,
v
))
}
// BonusAmountIn applies the In predicate on the "bonus_amount" field.
func
BonusAmountIn
(
vs
...
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldBonusAmount
,
vs
...
))
}
// BonusAmountNotIn applies the NotIn predicate on the "bonus_amount" field.
func
BonusAmountNotIn
(
vs
...
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldBonusAmount
,
vs
...
))
}
// BonusAmountGT applies the GT predicate on the "bonus_amount" field.
func
BonusAmountGT
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldBonusAmount
,
v
))
}
// BonusAmountGTE applies the GTE predicate on the "bonus_amount" field.
func
BonusAmountGTE
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldBonusAmount
,
v
))
}
// BonusAmountLT applies the LT predicate on the "bonus_amount" field.
func
BonusAmountLT
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldBonusAmount
,
v
))
}
// BonusAmountLTE applies the LTE predicate on the "bonus_amount" field.
func
BonusAmountLTE
(
v
float64
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldBonusAmount
,
v
))
}
// MaxUsesEQ applies the EQ predicate on the "max_uses" field.
func
MaxUsesEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldMaxUses
,
v
))
}
// MaxUsesNEQ applies the NEQ predicate on the "max_uses" field.
func
MaxUsesNEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldMaxUses
,
v
))
}
// MaxUsesIn applies the In predicate on the "max_uses" field.
func
MaxUsesIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldMaxUses
,
vs
...
))
}
// MaxUsesNotIn applies the NotIn predicate on the "max_uses" field.
func
MaxUsesNotIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldMaxUses
,
vs
...
))
}
// MaxUsesGT applies the GT predicate on the "max_uses" field.
func
MaxUsesGT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldMaxUses
,
v
))
}
// MaxUsesGTE applies the GTE predicate on the "max_uses" field.
func
MaxUsesGTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldMaxUses
,
v
))
}
// MaxUsesLT applies the LT predicate on the "max_uses" field.
func
MaxUsesLT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldMaxUses
,
v
))
}
// MaxUsesLTE applies the LTE predicate on the "max_uses" field.
func
MaxUsesLTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldMaxUses
,
v
))
}
// UsedCountEQ applies the EQ predicate on the "used_count" field.
func
UsedCountEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUsedCount
,
v
))
}
// UsedCountNEQ applies the NEQ predicate on the "used_count" field.
func
UsedCountNEQ
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldUsedCount
,
v
))
}
// UsedCountIn applies the In predicate on the "used_count" field.
func
UsedCountIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldUsedCount
,
vs
...
))
}
// UsedCountNotIn applies the NotIn predicate on the "used_count" field.
func
UsedCountNotIn
(
vs
...
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldUsedCount
,
vs
...
))
}
// UsedCountGT applies the GT predicate on the "used_count" field.
func
UsedCountGT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldUsedCount
,
v
))
}
// UsedCountGTE applies the GTE predicate on the "used_count" field.
func
UsedCountGTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldUsedCount
,
v
))
}
// UsedCountLT applies the LT predicate on the "used_count" field.
func
UsedCountLT
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldUsedCount
,
v
))
}
// UsedCountLTE applies the LTE predicate on the "used_count" field.
func
UsedCountLTE
(
v
int
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldUsedCount
,
v
))
}
// StatusEQ applies the EQ predicate on the "status" field.
func
StatusEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func
StatusNEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldStatus
,
v
))
}
// StatusIn applies the In predicate on the "status" field.
func
StatusIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldStatus
,
vs
...
))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func
StatusNotIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldStatus
,
vs
...
))
}
// StatusGT applies the GT predicate on the "status" field.
func
StatusGT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldStatus
,
v
))
}
// StatusGTE applies the GTE predicate on the "status" field.
func
StatusGTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldStatus
,
v
))
}
// StatusLT applies the LT predicate on the "status" field.
func
StatusLT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldStatus
,
v
))
}
// StatusLTE applies the LTE predicate on the "status" field.
func
StatusLTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldStatus
,
v
))
}
// StatusContains applies the Contains predicate on the "status" field.
func
StatusContains
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContains
(
FieldStatus
,
v
))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func
StatusHasPrefix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasPrefix
(
FieldStatus
,
v
))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func
StatusHasSuffix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasSuffix
(
FieldStatus
,
v
))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func
StatusEqualFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEqualFold
(
FieldStatus
,
v
))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func
StatusContainsFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContainsFold
(
FieldStatus
,
v
))
}
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
func
ExpiresAtEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldExpiresAt
,
v
))
}
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
func
ExpiresAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldExpiresAt
,
v
))
}
// ExpiresAtIn applies the In predicate on the "expires_at" field.
func
ExpiresAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldExpiresAt
,
vs
...
))
}
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
func
ExpiresAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldExpiresAt
,
vs
...
))
}
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
func
ExpiresAtGT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldExpiresAt
,
v
))
}
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
func
ExpiresAtGTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldExpiresAt
,
v
))
}
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
func
ExpiresAtLT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldExpiresAt
,
v
))
}
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
func
ExpiresAtLTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldExpiresAt
,
v
))
}
// ExpiresAtIsNil applies the IsNil predicate on the "expires_at" field.
func
ExpiresAtIsNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIsNull
(
FieldExpiresAt
))
}
// ExpiresAtNotNil applies the NotNil predicate on the "expires_at" field.
func
ExpiresAtNotNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotNull
(
FieldExpiresAt
))
}
// NotesEQ applies the EQ predicate on the "notes" field.
func
NotesEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
}
// NotesNEQ applies the NEQ predicate on the "notes" field.
func
NotesNEQ
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldNotes
,
v
))
}
// NotesIn applies the In predicate on the "notes" field.
func
NotesIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldNotes
,
vs
...
))
}
// NotesNotIn applies the NotIn predicate on the "notes" field.
func
NotesNotIn
(
vs
...
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldNotes
,
vs
...
))
}
// NotesGT applies the GT predicate on the "notes" field.
func
NotesGT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldNotes
,
v
))
}
// NotesGTE applies the GTE predicate on the "notes" field.
func
NotesGTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldNotes
,
v
))
}
// NotesLT applies the LT predicate on the "notes" field.
func
NotesLT
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldNotes
,
v
))
}
// NotesLTE applies the LTE predicate on the "notes" field.
func
NotesLTE
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldNotes
,
v
))
}
// NotesContains applies the Contains predicate on the "notes" field.
func
NotesContains
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContains
(
FieldNotes
,
v
))
}
// NotesHasPrefix applies the HasPrefix predicate on the "notes" field.
func
NotesHasPrefix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasPrefix
(
FieldNotes
,
v
))
}
// NotesHasSuffix applies the HasSuffix predicate on the "notes" field.
func
NotesHasSuffix
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldHasSuffix
(
FieldNotes
,
v
))
}
// NotesIsNil applies the IsNil predicate on the "notes" field.
func
NotesIsNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIsNull
(
FieldNotes
))
}
// NotesNotNil applies the NotNil predicate on the "notes" field.
func
NotesNotNil
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotNull
(
FieldNotes
))
}
// NotesEqualFold applies the EqualFold predicate on the "notes" field.
func
NotesEqualFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEqualFold
(
FieldNotes
,
v
))
}
// NotesContainsFold applies the ContainsFold predicate on the "notes" field.
func
NotesContainsFold
(
v
string
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldContainsFold
(
FieldNotes
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func
CreatedAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func
CreatedAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func
CreatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func
CreatedAtGT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldCreatedAt
,
v
))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func
CreatedAtGTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldCreatedAt
,
v
))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func
CreatedAtLT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldCreatedAt
,
v
))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func
CreatedAtLTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldCreatedAt
,
v
))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func
UpdatedAtEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func
UpdatedAtNEQ
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func
UpdatedAtIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func
UpdatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldNotIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func
UpdatedAtGT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func
UpdatedAtGTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldGTE
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func
UpdatedAtLT
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func
UpdatedAtLTE
(
v
time
.
Time
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
FieldLTE
(
FieldUpdatedAt
,
v
))
}
// HasUsageRecords applies the HasEdge predicate on the "usage_records" edge.
func
HasUsageRecords
()
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
func
(
s
*
sql
.
Selector
)
{
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
UsageRecordsTable
,
UsageRecordsColumn
),
)
sqlgraph
.
HasNeighbors
(
s
,
step
)
})
}
// HasUsageRecordsWith applies the HasEdge predicate on the "usage_records" edge with a given conditions (other predicates).
func
HasUsageRecordsWith
(
preds
...
predicate
.
PromoCodeUsage
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newUsageRecordsStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
for
_
,
p
:=
range
preds
{
p
(
s
)
}
})
})
}
// And groups predicates with the AND operator between them.
func
And
(
predicates
...
predicate
.
PromoCode
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
PromoCode
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
PromoCode
)
predicate
.
PromoCode
{
return
predicate
.
PromoCode
(
sql
.
NotPredicates
(
p
))
}
backend/ent/promocode_create.go
0 → 100644
View file @
b9b4db3d
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
)
// PromoCodeCreate is the builder for creating a PromoCode entity.
type
PromoCodeCreate
struct
{
config
mutation
*
PromoCodeMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetCode sets the "code" field.
func
(
_c
*
PromoCodeCreate
)
SetCode
(
v
string
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetCode
(
v
)
return
_c
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
_c
*
PromoCodeCreate
)
SetBonusAmount
(
v
float64
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetBonusAmount
(
v
)
return
_c
}
// SetNillableBonusAmount sets the "bonus_amount" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableBonusAmount
(
v
*
float64
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetBonusAmount
(
*
v
)
}
return
_c
}
// SetMaxUses sets the "max_uses" field.
func
(
_c
*
PromoCodeCreate
)
SetMaxUses
(
v
int
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetMaxUses
(
v
)
return
_c
}
// SetNillableMaxUses sets the "max_uses" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableMaxUses
(
v
*
int
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetMaxUses
(
*
v
)
}
return
_c
}
// SetUsedCount sets the "used_count" field.
func
(
_c
*
PromoCodeCreate
)
SetUsedCount
(
v
int
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetUsedCount
(
v
)
return
_c
}
// SetNillableUsedCount sets the "used_count" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableUsedCount
(
v
*
int
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetUsedCount
(
*
v
)
}
return
_c
}
// SetStatus sets the "status" field.
func
(
_c
*
PromoCodeCreate
)
SetStatus
(
v
string
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetStatus
(
v
)
return
_c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableStatus
(
v
*
string
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetStatus
(
*
v
)
}
return
_c
}
// SetExpiresAt sets the "expires_at" field.
func
(
_c
*
PromoCodeCreate
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetExpiresAt
(
v
)
return
_c
}
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableExpiresAt
(
v
*
time
.
Time
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetExpiresAt
(
*
v
)
}
return
_c
}
// SetNotes sets the "notes" field.
func
(
_c
*
PromoCodeCreate
)
SetNotes
(
v
string
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetNotes
(
v
)
return
_c
}
// SetNillableNotes sets the "notes" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableNotes
(
v
*
string
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetNotes
(
*
v
)
}
return
_c
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
PromoCodeCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_c
*
PromoCodeCreate
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeCreate
{
_c
.
mutation
.
SetUpdatedAt
(
v
)
return
_c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func
(
_c
*
PromoCodeCreate
)
SetNillableUpdatedAt
(
v
*
time
.
Time
)
*
PromoCodeCreate
{
if
v
!=
nil
{
_c
.
SetUpdatedAt
(
*
v
)
}
return
_c
}
// AddUsageRecordIDs adds the "usage_records" edge to the PromoCodeUsage entity by IDs.
func
(
_c
*
PromoCodeCreate
)
AddUsageRecordIDs
(
ids
...
int64
)
*
PromoCodeCreate
{
_c
.
mutation
.
AddUsageRecordIDs
(
ids
...
)
return
_c
}
// AddUsageRecords adds the "usage_records" edges to the PromoCodeUsage entity.
func
(
_c
*
PromoCodeCreate
)
AddUsageRecords
(
v
...*
PromoCodeUsage
)
*
PromoCodeCreate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_c
.
AddUsageRecordIDs
(
ids
...
)
}
// Mutation returns the PromoCodeMutation object of the builder.
func
(
_c
*
PromoCodeCreate
)
Mutation
()
*
PromoCodeMutation
{
return
_c
.
mutation
}
// Save creates the PromoCode in the database.
func
(
_c
*
PromoCodeCreate
)
Save
(
ctx
context
.
Context
)
(
*
PromoCode
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
PromoCodeCreate
)
SaveX
(
ctx
context
.
Context
)
*
PromoCode
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
PromoCodeCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
PromoCodeCreate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_c
*
PromoCodeCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
BonusAmount
();
!
ok
{
v
:=
promocode
.
DefaultBonusAmount
_c
.
mutation
.
SetBonusAmount
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
MaxUses
();
!
ok
{
v
:=
promocode
.
DefaultMaxUses
_c
.
mutation
.
SetMaxUses
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UsedCount
();
!
ok
{
v
:=
promocode
.
DefaultUsedCount
_c
.
mutation
.
SetUsedCount
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
v
:=
promocode
.
DefaultStatus
_c
.
mutation
.
SetStatus
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
promocode
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
promocode
.
DefaultUpdatedAt
()
_c
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
PromoCodeCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
Code
();
!
ok
{
return
&
ValidationError
{
Name
:
"code"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.code"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Code
();
ok
{
if
err
:=
promocode
.
CodeValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"code"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.code": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
BonusAmount
();
!
ok
{
return
&
ValidationError
{
Name
:
"bonus_amount"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.bonus_amount"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
MaxUses
();
!
ok
{
return
&
ValidationError
{
Name
:
"max_uses"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.max_uses"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UsedCount
();
!
ok
{
return
&
ValidationError
{
Name
:
"used_count"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.used_count"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.status"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
if
err
:=
promocode
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "PromoCode.status": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.created_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"updated_at"
,
err
:
errors
.
New
(
`ent: missing required field "PromoCode.updated_at"`
)}
}
return
nil
}
func
(
_c
*
PromoCodeCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
PromoCode
,
error
)
{
if
err
:=
_c
.
check
();
err
!=
nil
{
return
nil
,
err
}
_node
,
_spec
:=
_c
.
createSpec
()
if
err
:=
sqlgraph
.
CreateNode
(
ctx
,
_c
.
driver
,
_spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
id
:=
_spec
.
ID
.
Value
.
(
int64
)
_node
.
ID
=
int64
(
id
)
_c
.
mutation
.
id
=
&
_node
.
ID
_c
.
mutation
.
done
=
true
return
_node
,
nil
}
func
(
_c
*
PromoCodeCreate
)
createSpec
()
(
*
PromoCode
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
PromoCode
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
promocode
.
Table
,
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
Code
();
ok
{
_spec
.
SetField
(
promocode
.
FieldCode
,
field
.
TypeString
,
value
)
_node
.
Code
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
BonusAmount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldBonusAmount
,
field
.
TypeFloat64
,
value
)
_node
.
BonusAmount
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
MaxUses
();
ok
{
_spec
.
SetField
(
promocode
.
FieldMaxUses
,
field
.
TypeInt
,
value
)
_node
.
MaxUses
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UsedCount
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUsedCount
,
field
.
TypeInt
,
value
)
_node
.
UsedCount
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
promocode
.
FieldStatus
,
field
.
TypeString
,
value
)
_node
.
Status
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ExpiresAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldExpiresAt
,
field
.
TypeTime
,
value
)
_node
.
ExpiresAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
promocode
.
FieldNotes
,
field
.
TypeString
,
value
)
_node
.
Notes
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
promocode
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
_node
.
UpdatedAt
=
value
}
if
nodes
:=
_c
.
mutation
.
UsageRecordsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
promocode
.
UsageRecordsTable
,
Columns
:
[]
string
{
promocode
.
UsageRecordsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
promocodeusage
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.PromoCode.Create().
// SetCode(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.PromoCodeUpsert) {
// SetCode(v+v).
// }).
// Exec(ctx)
func
(
_c
*
PromoCodeCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
PromoCodeUpsertOne
{
_c
.
conflict
=
opts
return
&
PromoCodeUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
PromoCodeCreate
)
OnConflictColumns
(
columns
...
string
)
*
PromoCodeUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
PromoCodeUpsertOne
{
create
:
_c
,
}
}
type
(
// PromoCodeUpsertOne is the builder for "upsert"-ing
// one PromoCode node.
PromoCodeUpsertOne
struct
{
create
*
PromoCodeCreate
}
// PromoCodeUpsert is the "OnConflict" setter.
PromoCodeUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetCode sets the "code" field.
func
(
u
*
PromoCodeUpsert
)
SetCode
(
v
string
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldCode
,
v
)
return
u
}
// UpdateCode sets the "code" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateCode
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldCode
)
return
u
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUpsert
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldBonusAmount
,
v
)
return
u
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateBonusAmount
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldBonusAmount
)
return
u
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUpsert
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpsert
{
u
.
Add
(
promocode
.
FieldBonusAmount
,
v
)
return
u
}
// SetMaxUses sets the "max_uses" field.
func
(
u
*
PromoCodeUpsert
)
SetMaxUses
(
v
int
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldMaxUses
,
v
)
return
u
}
// UpdateMaxUses sets the "max_uses" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateMaxUses
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldMaxUses
)
return
u
}
// AddMaxUses adds v to the "max_uses" field.
func
(
u
*
PromoCodeUpsert
)
AddMaxUses
(
v
int
)
*
PromoCodeUpsert
{
u
.
Add
(
promocode
.
FieldMaxUses
,
v
)
return
u
}
// SetUsedCount sets the "used_count" field.
func
(
u
*
PromoCodeUpsert
)
SetUsedCount
(
v
int
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldUsedCount
,
v
)
return
u
}
// UpdateUsedCount sets the "used_count" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateUsedCount
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldUsedCount
)
return
u
}
// AddUsedCount adds v to the "used_count" field.
func
(
u
*
PromoCodeUpsert
)
AddUsedCount
(
v
int
)
*
PromoCodeUpsert
{
u
.
Add
(
promocode
.
FieldUsedCount
,
v
)
return
u
}
// SetStatus sets the "status" field.
func
(
u
*
PromoCodeUpsert
)
SetStatus
(
v
string
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldStatus
,
v
)
return
u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateStatus
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldStatus
)
return
u
}
// SetExpiresAt sets the "expires_at" field.
func
(
u
*
PromoCodeUpsert
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldExpiresAt
,
v
)
return
u
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateExpiresAt
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldExpiresAt
)
return
u
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
u
*
PromoCodeUpsert
)
ClearExpiresAt
()
*
PromoCodeUpsert
{
u
.
SetNull
(
promocode
.
FieldExpiresAt
)
return
u
}
// SetNotes sets the "notes" field.
func
(
u
*
PromoCodeUpsert
)
SetNotes
(
v
string
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldNotes
,
v
)
return
u
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateNotes
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldNotes
)
return
u
}
// ClearNotes clears the value of the "notes" field.
func
(
u
*
PromoCodeUpsert
)
ClearNotes
()
*
PromoCodeUpsert
{
u
.
SetNull
(
promocode
.
FieldNotes
)
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
PromoCodeUpsert
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpsert
{
u
.
Set
(
promocode
.
FieldUpdatedAt
,
v
)
return
u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsert
)
UpdateUpdatedAt
()
*
PromoCodeUpsert
{
u
.
SetExcluded
(
promocode
.
FieldUpdatedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertOne
)
UpdateNewValues
()
*
PromoCodeUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
if
_
,
exists
:=
u
.
create
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
promocode
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertOne
)
Ignore
()
*
PromoCodeUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
PromoCodeUpsertOne
)
DoNothing
()
*
PromoCodeUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the PromoCodeCreate.OnConflict
// documentation for more info.
func
(
u
*
PromoCodeUpsertOne
)
Update
(
set
func
(
*
PromoCodeUpsert
))
*
PromoCodeUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
PromoCodeUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetCode sets the "code" field.
func
(
u
*
PromoCodeUpsertOne
)
SetCode
(
v
string
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetCode
(
v
)
})
}
// UpdateCode sets the "code" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateCode
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateCode
()
})
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertOne
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetBonusAmount
(
v
)
})
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertOne
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddBonusAmount
(
v
)
})
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateBonusAmount
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateBonusAmount
()
})
}
// SetMaxUses sets the "max_uses" field.
func
(
u
*
PromoCodeUpsertOne
)
SetMaxUses
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetMaxUses
(
v
)
})
}
// AddMaxUses adds v to the "max_uses" field.
func
(
u
*
PromoCodeUpsertOne
)
AddMaxUses
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddMaxUses
(
v
)
})
}
// UpdateMaxUses sets the "max_uses" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateMaxUses
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateMaxUses
()
})
}
// SetUsedCount sets the "used_count" field.
func
(
u
*
PromoCodeUpsertOne
)
SetUsedCount
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUsedCount
(
v
)
})
}
// AddUsedCount adds v to the "used_count" field.
func
(
u
*
PromoCodeUpsertOne
)
AddUsedCount
(
v
int
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddUsedCount
(
v
)
})
}
// UpdateUsedCount sets the "used_count" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateUsedCount
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUsedCount
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
PromoCodeUpsertOne
)
SetStatus
(
v
string
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateStatus
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetExpiresAt sets the "expires_at" field.
func
(
u
*
PromoCodeUpsertOne
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetExpiresAt
(
v
)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateExpiresAt
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateExpiresAt
()
})
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
u
*
PromoCodeUpsertOne
)
ClearExpiresAt
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearExpiresAt
()
})
}
// SetNotes sets the "notes" field.
func
(
u
*
PromoCodeUpsertOne
)
SetNotes
(
v
string
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetNotes
(
v
)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateNotes
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateNotes
()
})
}
// ClearNotes clears the value of the "notes" field.
func
(
u
*
PromoCodeUpsertOne
)
ClearNotes
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearNotes
()
})
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
PromoCodeUpsertOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertOne
)
UpdateUpdatedAt
()
*
PromoCodeUpsertOne
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// Exec executes the query.
func
(
u
*
PromoCodeUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for PromoCodeCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
PromoCodeUpsertOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func
(
u
*
PromoCodeUpsertOne
)
ID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
node
,
err
:=
u
.
create
.
Save
(
ctx
)
if
err
!=
nil
{
return
id
,
err
}
return
node
.
ID
,
nil
}
// IDX is like ID, but panics if an error occurs.
func
(
u
*
PromoCodeUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// PromoCodeCreateBulk is the builder for creating many PromoCode entities in bulk.
type
PromoCodeCreateBulk
struct
{
config
err
error
builders
[]
*
PromoCodeCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the PromoCode entities in the database.
func
(
_c
*
PromoCodeCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
PromoCode
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
PromoCode
,
len
(
_c
.
builders
))
mutators
:=
make
([]
Mutator
,
len
(
_c
.
builders
))
for
i
:=
range
_c
.
builders
{
func
(
i
int
,
root
context
.
Context
)
{
builder
:=
_c
.
builders
[
i
]
builder
.
defaults
()
var
mut
Mutator
=
MutateFunc
(
func
(
ctx
context
.
Context
,
m
Mutation
)
(
Value
,
error
)
{
mutation
,
ok
:=
m
.
(
*
PromoCodeMutation
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T"
,
m
)
}
if
err
:=
builder
.
check
();
err
!=
nil
{
return
nil
,
err
}
builder
.
mutation
=
mutation
var
err
error
nodes
[
i
],
specs
[
i
]
=
builder
.
createSpec
()
if
i
<
len
(
mutators
)
-
1
{
_
,
err
=
mutators
[
i
+
1
]
.
Mutate
(
root
,
_c
.
builders
[
i
+
1
]
.
mutation
)
}
else
{
spec
:=
&
sqlgraph
.
BatchCreateSpec
{
Nodes
:
specs
}
spec
.
OnConflict
=
_c
.
conflict
// Invoke the actual operation on the latest mutation in the chain.
if
err
=
sqlgraph
.
BatchCreate
(
ctx
,
_c
.
driver
,
spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
}
}
if
err
!=
nil
{
return
nil
,
err
}
mutation
.
id
=
&
nodes
[
i
]
.
ID
if
specs
[
i
]
.
ID
.
Value
!=
nil
{
id
:=
specs
[
i
]
.
ID
.
Value
.
(
int64
)
nodes
[
i
]
.
ID
=
int64
(
id
)
}
mutation
.
done
=
true
return
nodes
[
i
],
nil
})
for
i
:=
len
(
builder
.
hooks
)
-
1
;
i
>=
0
;
i
--
{
mut
=
builder
.
hooks
[
i
](
mut
)
}
mutators
[
i
]
=
mut
}(
i
,
ctx
)
}
if
len
(
mutators
)
>
0
{
if
_
,
err
:=
mutators
[
0
]
.
Mutate
(
ctx
,
_c
.
builders
[
0
]
.
mutation
);
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
// SaveX is like Save, but panics if an error occurs.
func
(
_c
*
PromoCodeCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
PromoCode
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
PromoCodeCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
PromoCodeCreateBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.PromoCode.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.PromoCodeUpsert) {
// SetCode(v+v).
// }).
// Exec(ctx)
func
(
_c
*
PromoCodeCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
PromoCodeUpsertBulk
{
_c
.
conflict
=
opts
return
&
PromoCodeUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
PromoCodeCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
PromoCodeUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
PromoCodeUpsertBulk
{
create
:
_c
,
}
}
// PromoCodeUpsertBulk is the builder for "upsert"-ing
// a bulk of PromoCode nodes.
type
PromoCodeUpsertBulk
struct
{
create
*
PromoCodeCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertBulk
)
UpdateNewValues
()
*
PromoCodeUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
for
_
,
b
:=
range
u
.
create
.
builders
{
if
_
,
exists
:=
b
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
promocode
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.PromoCode.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
PromoCodeUpsertBulk
)
Ignore
()
*
PromoCodeUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
PromoCodeUpsertBulk
)
DoNothing
()
*
PromoCodeUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the PromoCodeCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
PromoCodeUpsertBulk
)
Update
(
set
func
(
*
PromoCodeUpsert
))
*
PromoCodeUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
PromoCodeUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetCode sets the "code" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetCode
(
v
string
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetCode
(
v
)
})
}
// UpdateCode sets the "code" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateCode
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateCode
()
})
}
// SetBonusAmount sets the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetBonusAmount
(
v
float64
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetBonusAmount
(
v
)
})
}
// AddBonusAmount adds v to the "bonus_amount" field.
func
(
u
*
PromoCodeUpsertBulk
)
AddBonusAmount
(
v
float64
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddBonusAmount
(
v
)
})
}
// UpdateBonusAmount sets the "bonus_amount" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateBonusAmount
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateBonusAmount
()
})
}
// SetMaxUses sets the "max_uses" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetMaxUses
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetMaxUses
(
v
)
})
}
// AddMaxUses adds v to the "max_uses" field.
func
(
u
*
PromoCodeUpsertBulk
)
AddMaxUses
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddMaxUses
(
v
)
})
}
// UpdateMaxUses sets the "max_uses" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateMaxUses
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateMaxUses
()
})
}
// SetUsedCount sets the "used_count" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetUsedCount
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUsedCount
(
v
)
})
}
// AddUsedCount adds v to the "used_count" field.
func
(
u
*
PromoCodeUpsertBulk
)
AddUsedCount
(
v
int
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
AddUsedCount
(
v
)
})
}
// UpdateUsedCount sets the "used_count" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateUsedCount
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUsedCount
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetStatus
(
v
string
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateStatus
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetExpiresAt sets the "expires_at" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetExpiresAt
(
v
time
.
Time
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetExpiresAt
(
v
)
})
}
// UpdateExpiresAt sets the "expires_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateExpiresAt
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateExpiresAt
()
})
}
// ClearExpiresAt clears the value of the "expires_at" field.
func
(
u
*
PromoCodeUpsertBulk
)
ClearExpiresAt
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearExpiresAt
()
})
}
// SetNotes sets the "notes" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetNotes
(
v
string
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetNotes
(
v
)
})
}
// UpdateNotes sets the "notes" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateNotes
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateNotes
()
})
}
// ClearNotes clears the value of the "notes" field.
func
(
u
*
PromoCodeUpsertBulk
)
ClearNotes
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
ClearNotes
()
})
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
PromoCodeUpsertBulk
)
SetUpdatedAt
(
v
time
.
Time
)
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
PromoCodeUpsertBulk
)
UpdateUpdatedAt
()
*
PromoCodeUpsertBulk
{
return
u
.
Update
(
func
(
s
*
PromoCodeUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// Exec executes the query.
func
(
u
*
PromoCodeUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
return
u
.
create
.
err
}
for
i
,
b
:=
range
u
.
create
.
builders
{
if
len
(
b
.
conflict
)
!=
0
{
return
fmt
.
Errorf
(
"ent: OnConflict was set for builder %d. Set it on the PromoCodeCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for PromoCodeCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
PromoCodeUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/promocode_delete.go
0 → 100644
View file @
b9b4db3d
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/promocode"
)
// PromoCodeDelete is the builder for deleting a PromoCode entity.
type
PromoCodeDelete
struct
{
config
hooks
[]
Hook
mutation
*
PromoCodeMutation
}
// Where appends a list predicates to the PromoCodeDelete builder.
func
(
_d
*
PromoCodeDelete
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
PromoCodeDelete
)
Exec
(
ctx
context
.
Context
)
(
int
,
error
)
{
return
withHooks
(
ctx
,
_d
.
sqlExec
,
_d
.
mutation
,
_d
.
hooks
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
PromoCodeDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
PromoCodeDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
promocode
.
Table
,
sqlgraph
.
NewFieldSpec
(
promocode
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_d
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
affected
,
err
:=
sqlgraph
.
DeleteNodes
(
ctx
,
_d
.
driver
,
_spec
)
if
err
!=
nil
&&
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
_d
.
mutation
.
done
=
true
return
affected
,
err
}
// PromoCodeDeleteOne is the builder for deleting a single PromoCode entity.
type
PromoCodeDeleteOne
struct
{
_d
*
PromoCodeDelete
}
// Where appends a list predicates to the PromoCodeDelete builder.
func
(
_d
*
PromoCodeDeleteOne
)
Where
(
ps
...
predicate
.
PromoCode
)
*
PromoCodeDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
PromoCodeDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
promocode
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
PromoCodeDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
Prev
1
2
3
4
5
6
…
12
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