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
bb664d9b
Commit
bb664d9b
authored
Feb 28, 2026
by
yangjianbo
Browse files
feat(sync): full code sync from release
parent
bfc7b339
Changes
338
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/ent/group/group.go
View file @
bb664d9b
...
...
@@ -57,6 +57,8 @@ const (
FieldSoraVideoPricePerRequest
=
"sora_video_price_per_request"
// FieldSoraVideoPricePerRequestHd holds the string denoting the sora_video_price_per_request_hd field in the database.
FieldSoraVideoPricePerRequestHd
=
"sora_video_price_per_request_hd"
// FieldSoraStorageQuotaBytes holds the string denoting the sora_storage_quota_bytes field in the database.
FieldSoraStorageQuotaBytes
=
"sora_storage_quota_bytes"
// FieldClaudeCodeOnly holds the string denoting the claude_code_only field in the database.
FieldClaudeCodeOnly
=
"claude_code_only"
// FieldFallbackGroupID holds the string denoting the fallback_group_id field in the database.
...
...
@@ -169,6 +171,7 @@ var Columns = []string{
FieldSoraImagePrice540
,
FieldSoraVideoPricePerRequest
,
FieldSoraVideoPricePerRequestHd
,
FieldSoraStorageQuotaBytes
,
FieldClaudeCodeOnly
,
FieldFallbackGroupID
,
FieldFallbackGroupIDOnInvalidRequest
,
...
...
@@ -232,6 +235,8 @@ var (
SubscriptionTypeValidator
func
(
string
)
error
// DefaultDefaultValidityDays holds the default value on creation for the "default_validity_days" field.
DefaultDefaultValidityDays
int
// DefaultSoraStorageQuotaBytes holds the default value on creation for the "sora_storage_quota_bytes" field.
DefaultSoraStorageQuotaBytes
int64
// 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.
...
...
@@ -357,6 +362,11 @@ func BySoraVideoPricePerRequestHd(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldSoraVideoPricePerRequestHd
,
opts
...
)
.
ToFunc
()
}
// BySoraStorageQuotaBytes orders the results by the sora_storage_quota_bytes field.
func
BySoraStorageQuotaBytes
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldSoraStorageQuotaBytes
,
opts
...
)
.
ToFunc
()
}
// ByClaudeCodeOnly orders the results by the claude_code_only field.
func
ByClaudeCodeOnly
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldClaudeCodeOnly
,
opts
...
)
.
ToFunc
()
...
...
backend/ent/group/where.go
View file @
bb664d9b
...
...
@@ -160,6 +160,11 @@ func SoraVideoPricePerRequestHd(v float64) predicate.Group {
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldSoraVideoPricePerRequestHd
,
v
))
}
// SoraStorageQuotaBytes applies equality check predicate on the "sora_storage_quota_bytes" field. It's identical to SoraStorageQuotaBytesEQ.
func
SoraStorageQuotaBytes
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldSoraStorageQuotaBytes
,
v
))
}
// ClaudeCodeOnly applies equality check predicate on the "claude_code_only" field. It's identical to ClaudeCodeOnlyEQ.
func
ClaudeCodeOnly
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldClaudeCodeOnly
,
v
))
...
...
@@ -1245,6 +1250,46 @@ func SoraVideoPricePerRequestHdNotNil() predicate.Group {
return
predicate
.
Group
(
sql
.
FieldNotNull
(
FieldSoraVideoPricePerRequestHd
))
}
// SoraStorageQuotaBytesEQ applies the EQ predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesEQ
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldSoraStorageQuotaBytes
,
v
))
}
// SoraStorageQuotaBytesNEQ applies the NEQ predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesNEQ
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNEQ
(
FieldSoraStorageQuotaBytes
,
v
))
}
// SoraStorageQuotaBytesIn applies the In predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesIn
(
vs
...
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldIn
(
FieldSoraStorageQuotaBytes
,
vs
...
))
}
// SoraStorageQuotaBytesNotIn applies the NotIn predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesNotIn
(
vs
...
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldNotIn
(
FieldSoraStorageQuotaBytes
,
vs
...
))
}
// SoraStorageQuotaBytesGT applies the GT predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesGT
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldGT
(
FieldSoraStorageQuotaBytes
,
v
))
}
// SoraStorageQuotaBytesGTE applies the GTE predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesGTE
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldGTE
(
FieldSoraStorageQuotaBytes
,
v
))
}
// SoraStorageQuotaBytesLT applies the LT predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesLT
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldLT
(
FieldSoraStorageQuotaBytes
,
v
))
}
// SoraStorageQuotaBytesLTE applies the LTE predicate on the "sora_storage_quota_bytes" field.
func
SoraStorageQuotaBytesLTE
(
v
int64
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldLTE
(
FieldSoraStorageQuotaBytes
,
v
))
}
// ClaudeCodeOnlyEQ applies the EQ predicate on the "claude_code_only" field.
func
ClaudeCodeOnlyEQ
(
v
bool
)
predicate
.
Group
{
return
predicate
.
Group
(
sql
.
FieldEQ
(
FieldClaudeCodeOnly
,
v
))
...
...
backend/ent/group_create.go
View file @
bb664d9b
...
...
@@ -314,6 +314,20 @@ func (_c *GroupCreate) SetNillableSoraVideoPricePerRequestHd(v *float64) *GroupC
return
_c
}
// SetSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field.
func
(
_c
*
GroupCreate
)
SetSoraStorageQuotaBytes
(
v
int64
)
*
GroupCreate
{
_c
.
mutation
.
SetSoraStorageQuotaBytes
(
v
)
return
_c
}
// SetNillableSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field if the given value is not nil.
func
(
_c
*
GroupCreate
)
SetNillableSoraStorageQuotaBytes
(
v
*
int64
)
*
GroupCreate
{
if
v
!=
nil
{
_c
.
SetSoraStorageQuotaBytes
(
*
v
)
}
return
_c
}
// SetClaudeCodeOnly sets the "claude_code_only" field.
func
(
_c
*
GroupCreate
)
SetClaudeCodeOnly
(
v
bool
)
*
GroupCreate
{
_c
.
mutation
.
SetClaudeCodeOnly
(
v
)
...
...
@@ -575,6 +589,10 @@ func (_c *GroupCreate) defaults() error {
v
:=
group
.
DefaultDefaultValidityDays
_c
.
mutation
.
SetDefaultValidityDays
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
SoraStorageQuotaBytes
();
!
ok
{
v
:=
group
.
DefaultSoraStorageQuotaBytes
_c
.
mutation
.
SetSoraStorageQuotaBytes
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
ClaudeCodeOnly
();
!
ok
{
v
:=
group
.
DefaultClaudeCodeOnly
_c
.
mutation
.
SetClaudeCodeOnly
(
v
)
...
...
@@ -647,6 +665,9 @@ func (_c *GroupCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
DefaultValidityDays
();
!
ok
{
return
&
ValidationError
{
Name
:
"default_validity_days"
,
err
:
errors
.
New
(
`ent: missing required field "Group.default_validity_days"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
SoraStorageQuotaBytes
();
!
ok
{
return
&
ValidationError
{
Name
:
"sora_storage_quota_bytes"
,
err
:
errors
.
New
(
`ent: missing required field "Group.sora_storage_quota_bytes"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
ClaudeCodeOnly
();
!
ok
{
return
&
ValidationError
{
Name
:
"claude_code_only"
,
err
:
errors
.
New
(
`ent: missing required field "Group.claude_code_only"`
)}
}
...
...
@@ -773,6 +794,10 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
group
.
FieldSoraVideoPricePerRequestHd
,
field
.
TypeFloat64
,
value
)
_node
.
SoraVideoPricePerRequestHd
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
SoraStorageQuotaBytes
();
ok
{
_spec
.
SetField
(
group
.
FieldSoraStorageQuotaBytes
,
field
.
TypeInt64
,
value
)
_node
.
SoraStorageQuotaBytes
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ClaudeCodeOnly
();
ok
{
_spec
.
SetField
(
group
.
FieldClaudeCodeOnly
,
field
.
TypeBool
,
value
)
_node
.
ClaudeCodeOnly
=
value
...
...
@@ -1345,6 +1370,24 @@ func (u *GroupUpsert) ClearSoraVideoPricePerRequestHd() *GroupUpsert {
return
u
}
// SetSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field.
func
(
u
*
GroupUpsert
)
SetSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldSoraStorageQuotaBytes
,
v
)
return
u
}
// UpdateSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field to the value that was provided on create.
func
(
u
*
GroupUpsert
)
UpdateSoraStorageQuotaBytes
()
*
GroupUpsert
{
u
.
SetExcluded
(
group
.
FieldSoraStorageQuotaBytes
)
return
u
}
// AddSoraStorageQuotaBytes adds v to the "sora_storage_quota_bytes" field.
func
(
u
*
GroupUpsert
)
AddSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpsert
{
u
.
Add
(
group
.
FieldSoraStorageQuotaBytes
,
v
)
return
u
}
// SetClaudeCodeOnly sets the "claude_code_only" field.
func
(
u
*
GroupUpsert
)
SetClaudeCodeOnly
(
v
bool
)
*
GroupUpsert
{
u
.
Set
(
group
.
FieldClaudeCodeOnly
,
v
)
...
...
@@ -1970,6 +2013,27 @@ func (u *GroupUpsertOne) ClearSoraVideoPricePerRequestHd() *GroupUpsertOne {
})
}
// SetSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field.
func
(
u
*
GroupUpsertOne
)
SetSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetSoraStorageQuotaBytes
(
v
)
})
}
// AddSoraStorageQuotaBytes adds v to the "sora_storage_quota_bytes" field.
func
(
u
*
GroupUpsertOne
)
AddSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
AddSoraStorageQuotaBytes
(
v
)
})
}
// UpdateSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field to the value that was provided on create.
func
(
u
*
GroupUpsertOne
)
UpdateSoraStorageQuotaBytes
()
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateSoraStorageQuotaBytes
()
})
}
// SetClaudeCodeOnly sets the "claude_code_only" field.
func
(
u
*
GroupUpsertOne
)
SetClaudeCodeOnly
(
v
bool
)
*
GroupUpsertOne
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
...
...
@@ -2783,6 +2847,27 @@ func (u *GroupUpsertBulk) ClearSoraVideoPricePerRequestHd() *GroupUpsertBulk {
})
}
// SetSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field.
func
(
u
*
GroupUpsertBulk
)
SetSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
SetSoraStorageQuotaBytes
(
v
)
})
}
// AddSoraStorageQuotaBytes adds v to the "sora_storage_quota_bytes" field.
func
(
u
*
GroupUpsertBulk
)
AddSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
AddSoraStorageQuotaBytes
(
v
)
})
}
// UpdateSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field to the value that was provided on create.
func
(
u
*
GroupUpsertBulk
)
UpdateSoraStorageQuotaBytes
()
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
s
.
UpdateSoraStorageQuotaBytes
()
})
}
// SetClaudeCodeOnly sets the "claude_code_only" field.
func
(
u
*
GroupUpsertBulk
)
SetClaudeCodeOnly
(
v
bool
)
*
GroupUpsertBulk
{
return
u
.
Update
(
func
(
s
*
GroupUpsert
)
{
...
...
backend/ent/group_update.go
View file @
bb664d9b
...
...
@@ -463,6 +463,27 @@ func (_u *GroupUpdate) ClearSoraVideoPricePerRequestHd() *GroupUpdate {
return
_u
}
// SetSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field.
func
(
_u
*
GroupUpdate
)
SetSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpdate
{
_u
.
mutation
.
ResetSoraStorageQuotaBytes
()
_u
.
mutation
.
SetSoraStorageQuotaBytes
(
v
)
return
_u
}
// SetNillableSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field if the given value is not nil.
func
(
_u
*
GroupUpdate
)
SetNillableSoraStorageQuotaBytes
(
v
*
int64
)
*
GroupUpdate
{
if
v
!=
nil
{
_u
.
SetSoraStorageQuotaBytes
(
*
v
)
}
return
_u
}
// AddSoraStorageQuotaBytes adds value to the "sora_storage_quota_bytes" field.
func
(
_u
*
GroupUpdate
)
AddSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpdate
{
_u
.
mutation
.
AddSoraStorageQuotaBytes
(
v
)
return
_u
}
// SetClaudeCodeOnly sets the "claude_code_only" field.
func
(
_u
*
GroupUpdate
)
SetClaudeCodeOnly
(
v
bool
)
*
GroupUpdate
{
_u
.
mutation
.
SetClaudeCodeOnly
(
v
)
...
...
@@ -1036,6 +1057,12 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
_u
.
mutation
.
SoraVideoPricePerRequestHdCleared
()
{
_spec
.
ClearField
(
group
.
FieldSoraVideoPricePerRequestHd
,
field
.
TypeFloat64
)
}
if
value
,
ok
:=
_u
.
mutation
.
SoraStorageQuotaBytes
();
ok
{
_spec
.
SetField
(
group
.
FieldSoraStorageQuotaBytes
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedSoraStorageQuotaBytes
();
ok
{
_spec
.
AddField
(
group
.
FieldSoraStorageQuotaBytes
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ClaudeCodeOnly
();
ok
{
_spec
.
SetField
(
group
.
FieldClaudeCodeOnly
,
field
.
TypeBool
,
value
)
}
...
...
@@ -1825,6 +1852,27 @@ func (_u *GroupUpdateOne) ClearSoraVideoPricePerRequestHd() *GroupUpdateOne {
return
_u
}
// SetSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field.
func
(
_u
*
GroupUpdateOne
)
SetSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
ResetSoraStorageQuotaBytes
()
_u
.
mutation
.
SetSoraStorageQuotaBytes
(
v
)
return
_u
}
// SetNillableSoraStorageQuotaBytes sets the "sora_storage_quota_bytes" field if the given value is not nil.
func
(
_u
*
GroupUpdateOne
)
SetNillableSoraStorageQuotaBytes
(
v
*
int64
)
*
GroupUpdateOne
{
if
v
!=
nil
{
_u
.
SetSoraStorageQuotaBytes
(
*
v
)
}
return
_u
}
// AddSoraStorageQuotaBytes adds value to the "sora_storage_quota_bytes" field.
func
(
_u
*
GroupUpdateOne
)
AddSoraStorageQuotaBytes
(
v
int64
)
*
GroupUpdateOne
{
_u
.
mutation
.
AddSoraStorageQuotaBytes
(
v
)
return
_u
}
// SetClaudeCodeOnly sets the "claude_code_only" field.
func
(
_u
*
GroupUpdateOne
)
SetClaudeCodeOnly
(
v
bool
)
*
GroupUpdateOne
{
_u
.
mutation
.
SetClaudeCodeOnly
(
v
)
...
...
@@ -2428,6 +2476,12 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error)
if
_u
.
mutation
.
SoraVideoPricePerRequestHdCleared
()
{
_spec
.
ClearField
(
group
.
FieldSoraVideoPricePerRequestHd
,
field
.
TypeFloat64
)
}
if
value
,
ok
:=
_u
.
mutation
.
SoraStorageQuotaBytes
();
ok
{
_spec
.
SetField
(
group
.
FieldSoraStorageQuotaBytes
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedSoraStorageQuotaBytes
();
ok
{
_spec
.
AddField
(
group
.
FieldSoraStorageQuotaBytes
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ClaudeCodeOnly
();
ok
{
_spec
.
SetField
(
group
.
FieldClaudeCodeOnly
,
field
.
TypeBool
,
value
)
}
...
...
backend/ent/hook/hook.go
View file @
bb664d9b
...
...
@@ -93,6 +93,18 @@ 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 IdempotencyRecordFunc type is an adapter to allow the use of ordinary
// function as IdempotencyRecord mutator.
type
IdempotencyRecordFunc
func
(
context
.
Context
,
*
ent
.
IdempotencyRecordMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
IdempotencyRecordFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
IdempotencyRecordMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.IdempotencyRecordMutation"
,
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
)
...
...
backend/ent/idempotencyrecord.go
0 → 100644
View file @
bb664d9b
// 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/idempotencyrecord"
)
// IdempotencyRecord is the model entity for the IdempotencyRecord schema.
type
IdempotencyRecord
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt
time
.
Time
`json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt
time
.
Time
`json:"updated_at,omitempty"`
// Scope holds the value of the "scope" field.
Scope
string
`json:"scope,omitempty"`
// IdempotencyKeyHash holds the value of the "idempotency_key_hash" field.
IdempotencyKeyHash
string
`json:"idempotency_key_hash,omitempty"`
// RequestFingerprint holds the value of the "request_fingerprint" field.
RequestFingerprint
string
`json:"request_fingerprint,omitempty"`
// Status holds the value of the "status" field.
Status
string
`json:"status,omitempty"`
// ResponseStatus holds the value of the "response_status" field.
ResponseStatus
*
int
`json:"response_status,omitempty"`
// ResponseBody holds the value of the "response_body" field.
ResponseBody
*
string
`json:"response_body,omitempty"`
// ErrorReason holds the value of the "error_reason" field.
ErrorReason
*
string
`json:"error_reason,omitempty"`
// LockedUntil holds the value of the "locked_until" field.
LockedUntil
*
time
.
Time
`json:"locked_until,omitempty"`
// ExpiresAt holds the value of the "expires_at" field.
ExpiresAt
time
.
Time
`json:"expires_at,omitempty"`
selectValues
sql
.
SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
IdempotencyRecord
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
idempotencyrecord
.
FieldID
,
idempotencyrecord
.
FieldResponseStatus
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
idempotencyrecord
.
FieldScope
,
idempotencyrecord
.
FieldIdempotencyKeyHash
,
idempotencyrecord
.
FieldRequestFingerprint
,
idempotencyrecord
.
FieldStatus
,
idempotencyrecord
.
FieldResponseBody
,
idempotencyrecord
.
FieldErrorReason
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
idempotencyrecord
.
FieldCreatedAt
,
idempotencyrecord
.
FieldUpdatedAt
,
idempotencyrecord
.
FieldLockedUntil
,
idempotencyrecord
.
FieldExpiresAt
:
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 IdempotencyRecord fields.
func
(
_m
*
IdempotencyRecord
)
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
idempotencyrecord
.
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
idempotencyrecord
.
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
idempotencyrecord
.
FieldUpdatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field updated_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UpdatedAt
=
value
.
Time
}
case
idempotencyrecord
.
FieldScope
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field scope"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Scope
=
value
.
String
}
case
idempotencyrecord
.
FieldIdempotencyKeyHash
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field idempotency_key_hash"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
IdempotencyKeyHash
=
value
.
String
}
case
idempotencyrecord
.
FieldRequestFingerprint
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field request_fingerprint"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
RequestFingerprint
=
value
.
String
}
case
idempotencyrecord
.
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
idempotencyrecord
.
FieldResponseStatus
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field response_status"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ResponseStatus
=
new
(
int
)
*
_m
.
ResponseStatus
=
int
(
value
.
Int64
)
}
case
idempotencyrecord
.
FieldResponseBody
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field response_body"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ResponseBody
=
new
(
string
)
*
_m
.
ResponseBody
=
value
.
String
}
case
idempotencyrecord
.
FieldErrorReason
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field error_reason"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ErrorReason
=
new
(
string
)
*
_m
.
ErrorReason
=
value
.
String
}
case
idempotencyrecord
.
FieldLockedUntil
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field locked_until"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
LockedUntil
=
new
(
time
.
Time
)
*
_m
.
LockedUntil
=
value
.
Time
}
case
idempotencyrecord
.
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
=
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 IdempotencyRecord.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
IdempotencyRecord
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// Update returns a builder for updating this IdempotencyRecord.
// Note that you need to call IdempotencyRecord.Unwrap() before calling this method if this IdempotencyRecord
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
IdempotencyRecord
)
Update
()
*
IdempotencyRecordUpdateOne
{
return
NewIdempotencyRecordClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the IdempotencyRecord 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
*
IdempotencyRecord
)
Unwrap
()
*
IdempotencyRecord
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: IdempotencyRecord is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
IdempotencyRecord
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"IdempotencyRecord("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"created_at="
)
builder
.
WriteString
(
_m
.
CreatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"updated_at="
)
builder
.
WriteString
(
_m
.
UpdatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"scope="
)
builder
.
WriteString
(
_m
.
Scope
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"idempotency_key_hash="
)
builder
.
WriteString
(
_m
.
IdempotencyKeyHash
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"request_fingerprint="
)
builder
.
WriteString
(
_m
.
RequestFingerprint
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"status="
)
builder
.
WriteString
(
_m
.
Status
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ResponseStatus
;
v
!=
nil
{
builder
.
WriteString
(
"response_status="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ResponseBody
;
v
!=
nil
{
builder
.
WriteString
(
"response_body="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ErrorReason
;
v
!=
nil
{
builder
.
WriteString
(
"error_reason="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
LockedUntil
;
v
!=
nil
{
builder
.
WriteString
(
"locked_until="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"expires_at="
)
builder
.
WriteString
(
_m
.
ExpiresAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// IdempotencyRecords is a parsable slice of IdempotencyRecord.
type
IdempotencyRecords
[]
*
IdempotencyRecord
backend/ent/idempotencyrecord/idempotencyrecord.go
0 → 100644
View file @
bb664d9b
// Code generated by ent, DO NOT EDIT.
package
idempotencyrecord
import
(
"time"
"entgo.io/ent/dialect/sql"
)
const
(
// Label holds the string label denoting the idempotencyrecord type in the database.
Label
=
"idempotency_record"
// FieldID holds the string denoting the id field in the database.
FieldID
=
"id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt
=
"created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt
=
"updated_at"
// FieldScope holds the string denoting the scope field in the database.
FieldScope
=
"scope"
// FieldIdempotencyKeyHash holds the string denoting the idempotency_key_hash field in the database.
FieldIdempotencyKeyHash
=
"idempotency_key_hash"
// FieldRequestFingerprint holds the string denoting the request_fingerprint field in the database.
FieldRequestFingerprint
=
"request_fingerprint"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus
=
"status"
// FieldResponseStatus holds the string denoting the response_status field in the database.
FieldResponseStatus
=
"response_status"
// FieldResponseBody holds the string denoting the response_body field in the database.
FieldResponseBody
=
"response_body"
// FieldErrorReason holds the string denoting the error_reason field in the database.
FieldErrorReason
=
"error_reason"
// FieldLockedUntil holds the string denoting the locked_until field in the database.
FieldLockedUntil
=
"locked_until"
// FieldExpiresAt holds the string denoting the expires_at field in the database.
FieldExpiresAt
=
"expires_at"
// Table holds the table name of the idempotencyrecord in the database.
Table
=
"idempotency_records"
)
// Columns holds all SQL columns for idempotencyrecord fields.
var
Columns
=
[]
string
{
FieldID
,
FieldCreatedAt
,
FieldUpdatedAt
,
FieldScope
,
FieldIdempotencyKeyHash
,
FieldRequestFingerprint
,
FieldStatus
,
FieldResponseStatus
,
FieldResponseBody
,
FieldErrorReason
,
FieldLockedUntil
,
FieldExpiresAt
,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func
ValidColumn
(
column
string
)
bool
{
for
i
:=
range
Columns
{
if
column
==
Columns
[
i
]
{
return
true
}
}
return
false
}
var
(
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt
func
()
time
.
Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt
func
()
time
.
Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt
func
()
time
.
Time
// ScopeValidator is a validator for the "scope" field. It is called by the builders before save.
ScopeValidator
func
(
string
)
error
// IdempotencyKeyHashValidator is a validator for the "idempotency_key_hash" field. It is called by the builders before save.
IdempotencyKeyHashValidator
func
(
string
)
error
// RequestFingerprintValidator is a validator for the "request_fingerprint" field. It is called by the builders before save.
RequestFingerprintValidator
func
(
string
)
error
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator
func
(
string
)
error
// ErrorReasonValidator is a validator for the "error_reason" field. It is called by the builders before save.
ErrorReasonValidator
func
(
string
)
error
)
// OrderOption defines the ordering options for the IdempotencyRecord queries.
type
OrderOption
func
(
*
sql
.
Selector
)
// ByID orders the results by the id field.
func
ByID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldID
,
opts
...
)
.
ToFunc
()
}
// ByCreatedAt orders the results by the created_at field.
func
ByCreatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUpdatedAt orders the results by the updated_at field.
func
ByUpdatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpdatedAt
,
opts
...
)
.
ToFunc
()
}
// ByScope orders the results by the scope field.
func
ByScope
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldScope
,
opts
...
)
.
ToFunc
()
}
// ByIdempotencyKeyHash orders the results by the idempotency_key_hash field.
func
ByIdempotencyKeyHash
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldIdempotencyKeyHash
,
opts
...
)
.
ToFunc
()
}
// ByRequestFingerprint orders the results by the request_fingerprint field.
func
ByRequestFingerprint
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldRequestFingerprint
,
opts
...
)
.
ToFunc
()
}
// ByStatus orders the results by the status field.
func
ByStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStatus
,
opts
...
)
.
ToFunc
()
}
// ByResponseStatus orders the results by the response_status field.
func
ByResponseStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldResponseStatus
,
opts
...
)
.
ToFunc
()
}
// ByResponseBody orders the results by the response_body field.
func
ByResponseBody
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldResponseBody
,
opts
...
)
.
ToFunc
()
}
// ByErrorReason orders the results by the error_reason field.
func
ByErrorReason
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldErrorReason
,
opts
...
)
.
ToFunc
()
}
// ByLockedUntil orders the results by the locked_until field.
func
ByLockedUntil
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldLockedUntil
,
opts
...
)
.
ToFunc
()
}
// ByExpiresAt orders the results by the expires_at field.
func
ByExpiresAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldExpiresAt
,
opts
...
)
.
ToFunc
()
}
backend/ent/idempotencyrecord/where.go
0 → 100644
View file @
bb664d9b
This diff is collapsed.
Click to expand it.
backend/ent/idempotencyrecord_create.go
0 → 100644
View file @
bb664d9b
This diff is collapsed.
Click to expand it.
backend/ent/idempotencyrecord_delete.go
0 → 100644
View file @
bb664d9b
// 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/idempotencyrecord"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// IdempotencyRecordDelete is the builder for deleting a IdempotencyRecord entity.
type
IdempotencyRecordDelete
struct
{
config
hooks
[]
Hook
mutation
*
IdempotencyRecordMutation
}
// Where appends a list predicates to the IdempotencyRecordDelete builder.
func
(
_d
*
IdempotencyRecordDelete
)
Where
(
ps
...
predicate
.
IdempotencyRecord
)
*
IdempotencyRecordDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
IdempotencyRecordDelete
)
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
*
IdempotencyRecordDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
IdempotencyRecordDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
idempotencyrecord
.
Table
,
sqlgraph
.
NewFieldSpec
(
idempotencyrecord
.
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
}
// IdempotencyRecordDeleteOne is the builder for deleting a single IdempotencyRecord entity.
type
IdempotencyRecordDeleteOne
struct
{
_d
*
IdempotencyRecordDelete
}
// Where appends a list predicates to the IdempotencyRecordDelete builder.
func
(
_d
*
IdempotencyRecordDeleteOne
)
Where
(
ps
...
predicate
.
IdempotencyRecord
)
*
IdempotencyRecordDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
IdempotencyRecordDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
idempotencyrecord
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
IdempotencyRecordDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/idempotencyrecord_query.go
0 → 100644
View file @
bb664d9b
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// IdempotencyRecordQuery is the builder for querying IdempotencyRecord entities.
type
IdempotencyRecordQuery
struct
{
config
ctx
*
QueryContext
order
[]
idempotencyrecord
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
IdempotencyRecord
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the IdempotencyRecordQuery builder.
func
(
_q
*
IdempotencyRecordQuery
)
Where
(
ps
...
predicate
.
IdempotencyRecord
)
*
IdempotencyRecordQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
IdempotencyRecordQuery
)
Limit
(
limit
int
)
*
IdempotencyRecordQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
IdempotencyRecordQuery
)
Offset
(
offset
int
)
*
IdempotencyRecordQuery
{
_q
.
ctx
.
Offset
=
&
offset
return
_q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func
(
_q
*
IdempotencyRecordQuery
)
Unique
(
unique
bool
)
*
IdempotencyRecordQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
IdempotencyRecordQuery
)
Order
(
o
...
idempotencyrecord
.
OrderOption
)
*
IdempotencyRecordQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// First returns the first IdempotencyRecord entity from the query.
// Returns a *NotFoundError when no IdempotencyRecord was found.
func
(
_q
*
IdempotencyRecordQuery
)
First
(
ctx
context
.
Context
)
(
*
IdempotencyRecord
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
1
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirst
))
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nil
,
&
NotFoundError
{
idempotencyrecord
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
FirstX
(
ctx
context
.
Context
)
*
IdempotencyRecord
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first IdempotencyRecord ID from the query.
// Returns a *NotFoundError when no IdempotencyRecord ID was found.
func
(
_q
*
IdempotencyRecordQuery
)
FirstID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
1
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirstID
));
err
!=
nil
{
return
}
if
len
(
ids
)
==
0
{
err
=
&
NotFoundError
{
idempotencyrecord
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single IdempotencyRecord entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one IdempotencyRecord entity is found.
// Returns a *NotFoundError when no IdempotencyRecord entities are found.
func
(
_q
*
IdempotencyRecordQuery
)
Only
(
ctx
context
.
Context
)
(
*
IdempotencyRecord
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
2
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnly
))
if
err
!=
nil
{
return
nil
,
err
}
switch
len
(
nodes
)
{
case
1
:
return
nodes
[
0
],
nil
case
0
:
return
nil
,
&
NotFoundError
{
idempotencyrecord
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
idempotencyrecord
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
OnlyX
(
ctx
context
.
Context
)
*
IdempotencyRecord
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only IdempotencyRecord ID in the query.
// Returns a *NotSingularError when more than one IdempotencyRecord ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
IdempotencyRecordQuery
)
OnlyID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
2
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnlyID
));
err
!=
nil
{
return
}
switch
len
(
ids
)
{
case
1
:
id
=
ids
[
0
]
case
0
:
err
=
&
NotFoundError
{
idempotencyrecord
.
Label
}
default
:
err
=
&
NotSingularError
{
idempotencyrecord
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
OnlyIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
OnlyID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// All executes the query and returns a list of IdempotencyRecords.
func
(
_q
*
IdempotencyRecordQuery
)
All
(
ctx
context
.
Context
)
([]
*
IdempotencyRecord
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
IdempotencyRecord
,
*
IdempotencyRecordQuery
]()
return
withInterceptors
[[]
*
IdempotencyRecord
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
IdempotencyRecord
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of IdempotencyRecord IDs.
func
(
_q
*
IdempotencyRecordQuery
)
IDs
(
ctx
context
.
Context
)
(
ids
[]
int64
,
err
error
)
{
if
_q
.
ctx
.
Unique
==
nil
&&
_q
.
path
!=
nil
{
_q
.
Unique
(
true
)
}
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryIDs
)
if
err
=
_q
.
Select
(
idempotencyrecord
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
IDsX
(
ctx
context
.
Context
)
[]
int64
{
ids
,
err
:=
_q
.
IDs
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
ids
}
// Count returns the count of the given query.
func
(
_q
*
IdempotencyRecordQuery
)
Count
(
ctx
context
.
Context
)
(
int
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryCount
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
0
,
err
}
return
withInterceptors
[
int
](
ctx
,
_q
,
querierCount
[
*
IdempotencyRecordQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
CountX
(
ctx
context
.
Context
)
int
{
count
,
err
:=
_q
.
Count
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
count
}
// Exist returns true if the query has elements in the graph.
func
(
_q
*
IdempotencyRecordQuery
)
Exist
(
ctx
context
.
Context
)
(
bool
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryExist
)
switch
_
,
err
:=
_q
.
FirstID
(
ctx
);
{
case
IsNotFound
(
err
)
:
return
false
,
nil
case
err
!=
nil
:
return
false
,
fmt
.
Errorf
(
"ent: check existence: %w"
,
err
)
default
:
return
true
,
nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func
(
_q
*
IdempotencyRecordQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the IdempotencyRecordQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func
(
_q
*
IdempotencyRecordQuery
)
Clone
()
*
IdempotencyRecordQuery
{
if
_q
==
nil
{
return
nil
}
return
&
IdempotencyRecordQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
idempotencyrecord
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
IdempotencyRecord
{},
_q
.
predicates
...
),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.IdempotencyRecord.Query().
// GroupBy(idempotencyrecord.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
IdempotencyRecordQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
IdempotencyRecordGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
IdempotencyRecordGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
idempotencyrecord
.
Label
grbuild
.
scan
=
grbuild
.
Scan
return
grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// }
//
// client.IdempotencyRecord.Query().
// Select(idempotencyrecord.FieldCreatedAt).
// Scan(ctx, &v)
func
(
_q
*
IdempotencyRecordQuery
)
Select
(
fields
...
string
)
*
IdempotencyRecordSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
IdempotencyRecordSelect
{
IdempotencyRecordQuery
:
_q
}
sbuild
.
label
=
idempotencyrecord
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a IdempotencyRecordSelect configured with the given aggregations.
func
(
_q
*
IdempotencyRecordQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
IdempotencyRecordSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
IdempotencyRecordQuery
)
prepareQuery
(
ctx
context
.
Context
)
error
{
for
_
,
inter
:=
range
_q
.
inters
{
if
inter
==
nil
{
return
fmt
.
Errorf
(
"ent: uninitialized interceptor (forgotten import ent/runtime?)"
)
}
if
trv
,
ok
:=
inter
.
(
Traverser
);
ok
{
if
err
:=
trv
.
Traverse
(
ctx
,
_q
);
err
!=
nil
{
return
err
}
}
}
for
_
,
f
:=
range
_q
.
ctx
.
Fields
{
if
!
idempotencyrecord
.
ValidColumn
(
f
)
{
return
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
}
if
_q
.
path
!=
nil
{
prev
,
err
:=
_q
.
path
(
ctx
)
if
err
!=
nil
{
return
err
}
_q
.
sql
=
prev
}
return
nil
}
func
(
_q
*
IdempotencyRecordQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
IdempotencyRecord
,
error
)
{
var
(
nodes
=
[]
*
IdempotencyRecord
{}
_spec
=
_q
.
querySpec
()
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
IdempotencyRecord
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
IdempotencyRecord
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
if
err
:=
sqlgraph
.
QueryNodes
(
ctx
,
_q
.
driver
,
_spec
);
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nodes
,
nil
}
return
nodes
,
nil
}
func
(
_q
*
IdempotencyRecordQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
}
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
}
func
(
_q
*
IdempotencyRecordQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
idempotencyrecord
.
Table
,
idempotencyrecord
.
Columns
,
sqlgraph
.
NewFieldSpec
(
idempotencyrecord
.
FieldID
,
field
.
TypeInt64
))
_spec
.
From
=
_q
.
sql
if
unique
:=
_q
.
ctx
.
Unique
;
unique
!=
nil
{
_spec
.
Unique
=
*
unique
}
else
if
_q
.
path
!=
nil
{
_spec
.
Unique
=
true
}
if
fields
:=
_q
.
ctx
.
Fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
idempotencyrecord
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
idempotencyrecord
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
}
if
ps
:=
_q
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
_spec
.
Limit
=
*
limit
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
_spec
.
Offset
=
*
offset
}
if
ps
:=
_q
.
order
;
len
(
ps
)
>
0
{
_spec
.
Order
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
return
_spec
}
func
(
_q
*
IdempotencyRecordQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
idempotencyrecord
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
idempotencyrecord
.
Columns
}
selector
:=
builder
.
Select
(
t1
.
Columns
(
columns
...
)
...
)
.
From
(
t1
)
if
_q
.
sql
!=
nil
{
selector
=
_q
.
sql
selector
.
Select
(
selector
.
Columns
(
columns
...
)
...
)
}
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
for
_
,
p
:=
range
_q
.
order
{
p
(
selector
)
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector
.
Offset
(
*
offset
)
.
Limit
(
math
.
MaxInt32
)
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
selector
.
Limit
(
*
limit
)
}
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
IdempotencyRecordQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
IdempotencyRecordQuery
{
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
*
IdempotencyRecordQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
IdempotencyRecordQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// IdempotencyRecordGroupBy is the group-by builder for IdempotencyRecord entities.
type
IdempotencyRecordGroupBy
struct
{
selector
build
*
IdempotencyRecordQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
IdempotencyRecordGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
IdempotencyRecordGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
IdempotencyRecordGroupBy
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_g
.
build
.
ctx
,
ent
.
OpQueryGroupBy
)
if
err
:=
_g
.
build
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
IdempotencyRecordQuery
,
*
IdempotencyRecordGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
IdempotencyRecordGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
IdempotencyRecordQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
.
Select
()
aggregation
:=
make
([]
string
,
0
,
len
(
_g
.
fns
))
for
_
,
fn
:=
range
_g
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
if
len
(
selector
.
SelectedColumns
())
==
0
{
columns
:=
make
([]
string
,
0
,
len
(
*
_g
.
flds
)
+
len
(
_g
.
fns
))
for
_
,
f
:=
range
*
_g
.
flds
{
columns
=
append
(
columns
,
selector
.
C
(
f
))
}
columns
=
append
(
columns
,
aggregation
...
)
selector
.
Select
(
columns
...
)
}
selector
.
GroupBy
(
selector
.
Columns
(
*
_g
.
flds
...
)
...
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
err
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_g
.
build
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
// IdempotencyRecordSelect is the builder for selecting fields of IdempotencyRecord entities.
type
IdempotencyRecordSelect
struct
{
*
IdempotencyRecordQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
IdempotencyRecordSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
IdempotencyRecordSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
IdempotencyRecordSelect
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_s
.
ctx
,
ent
.
OpQuerySelect
)
if
err
:=
_s
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
IdempotencyRecordQuery
,
*
IdempotencyRecordSelect
](
ctx
,
_s
.
IdempotencyRecordQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
IdempotencyRecordSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
IdempotencyRecordQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
aggregation
:=
make
([]
string
,
0
,
len
(
_s
.
fns
))
for
_
,
fn
:=
range
_s
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
switch
n
:=
len
(
*
_s
.
selector
.
flds
);
{
case
n
==
0
&&
len
(
aggregation
)
>
0
:
selector
.
Select
(
aggregation
...
)
case
n
!=
0
&&
len
(
aggregation
)
>
0
:
selector
.
AppendSelect
(
aggregation
...
)
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_s
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
backend/ent/idempotencyrecord_update.go
0 → 100644
View file @
bb664d9b
This diff is collapsed.
Click to expand it.
backend/ent/intercept/intercept.go
View file @
bb664d9b
...
...
@@ -15,6 +15,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
...
...
@@ -276,6 +277,33 @@ func (f TraverseGroup) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.GroupQuery"
,
q
)
}
// The IdempotencyRecordFunc type is an adapter to allow the use of ordinary function as a Querier.
type
IdempotencyRecordFunc
func
(
context
.
Context
,
*
ent
.
IdempotencyRecordQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
IdempotencyRecordFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
IdempotencyRecordQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.IdempotencyRecordQuery"
,
q
)
}
// The TraverseIdempotencyRecord type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseIdempotencyRecord
func
(
context
.
Context
,
*
ent
.
IdempotencyRecordQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseIdempotencyRecord
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseIdempotencyRecord
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
IdempotencyRecordQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.IdempotencyRecordQuery"
,
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
)
...
...
@@ -644,6 +672,8 @@ func NewQuery(q ent.Query) (Query, error) {
return
&
query
[
*
ent
.
ErrorPassthroughRuleQuery
,
predicate
.
ErrorPassthroughRule
,
errorpassthroughrule
.
OrderOption
]{
typ
:
ent
.
TypeErrorPassthroughRule
,
tq
:
q
},
nil
case
*
ent
.
GroupQuery
:
return
&
query
[
*
ent
.
GroupQuery
,
predicate
.
Group
,
group
.
OrderOption
]{
typ
:
ent
.
TypeGroup
,
tq
:
q
},
nil
case
*
ent
.
IdempotencyRecordQuery
:
return
&
query
[
*
ent
.
IdempotencyRecordQuery
,
predicate
.
IdempotencyRecord
,
idempotencyrecord
.
OrderOption
]{
typ
:
ent
.
TypeIdempotencyRecord
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeQuery
:
return
&
query
[
*
ent
.
PromoCodeQuery
,
predicate
.
PromoCode
,
promocode
.
OrderOption
]{
typ
:
ent
.
TypePromoCode
,
tq
:
q
},
nil
case
*
ent
.
PromoCodeUsageQuery
:
...
...
backend/ent/migrate/schema.go
View file @
bb664d9b
...
...
@@ -108,6 +108,8 @@ var (
{
Name
:
"rate_limited_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"rate_limit_reset_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"overload_until"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"temp_unschedulable_until"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"temp_unschedulable_reason"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"session_window_start"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"session_window_end"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"session_window_status"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
Size
:
20
},
...
...
@@ -121,7 +123,7 @@ var (
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"accounts_proxies_proxy"
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
5
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
7
]},
RefColumns
:
[]
*
schema
.
Column
{
ProxiesColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
...
...
@@ -145,7 +147,7 @@ var (
{
Name
:
"account_proxy_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
5
]},
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
2
7
]},
},
{
Name
:
"account_priority"
,
...
...
@@ -177,6 +179,16 @@ var (
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
21
]},
},
{
Name
:
"account_platform_priority"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
6
],
AccountsColumns
[
11
]},
},
{
Name
:
"account_priority_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
AccountsColumns
[
11
],
AccountsColumns
[
13
]},
},
{
Name
:
"account_deleted_at"
,
Unique
:
false
,
...
...
@@ -376,6 +388,7 @@ var (
{
Name
:
"sora_image_price_540"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"sora_video_price_per_request"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"sora_video_price_per_request_hd"
,
Type
:
field
.
TypeFloat64
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"decimal(20,8)"
}},
{
Name
:
"sora_storage_quota_bytes"
,
Type
:
field
.
TypeInt64
,
Default
:
0
},
{
Name
:
"claude_code_only"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"fallback_group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"fallback_group_id_on_invalid_request"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
...
...
@@ -419,7 +432,45 @@ var (
{
Name
:
"group_sort_order"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
GroupsColumns
[
29
]},
Columns
:
[]
*
schema
.
Column
{
GroupsColumns
[
30
]},
},
},
}
// IdempotencyRecordsColumns holds the columns for the "idempotency_records" table.
IdempotencyRecordsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"updated_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"scope"
,
Type
:
field
.
TypeString
,
Size
:
128
},
{
Name
:
"idempotency_key_hash"
,
Type
:
field
.
TypeString
,
Size
:
64
},
{
Name
:
"request_fingerprint"
,
Type
:
field
.
TypeString
,
Size
:
64
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
32
},
{
Name
:
"response_status"
,
Type
:
field
.
TypeInt
,
Nullable
:
true
},
{
Name
:
"response_body"
,
Type
:
field
.
TypeString
,
Nullable
:
true
},
{
Name
:
"error_reason"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
Size
:
128
},
{
Name
:
"locked_until"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"expires_at"
,
Type
:
field
.
TypeTime
},
}
// IdempotencyRecordsTable holds the schema information for the "idempotency_records" table.
IdempotencyRecordsTable
=
&
schema
.
Table
{
Name
:
"idempotency_records"
,
Columns
:
IdempotencyRecordsColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
IdempotencyRecordsColumns
[
0
]},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"idempotencyrecord_scope_idempotency_key_hash"
,
Unique
:
true
,
Columns
:
[]
*
schema
.
Column
{
IdempotencyRecordsColumns
[
3
],
IdempotencyRecordsColumns
[
4
]},
},
{
Name
:
"idempotencyrecord_expires_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
IdempotencyRecordsColumns
[
11
]},
},
{
Name
:
"idempotencyrecord_status_locked_until"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
IdempotencyRecordsColumns
[
6
],
IdempotencyRecordsColumns
[
10
]},
},
},
}
...
...
@@ -771,6 +822,11 @@ var (
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
28
],
UsageLogsColumns
[
27
]},
},
{
Name
:
"usagelog_group_id_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
30
],
UsageLogsColumns
[
27
]},
},
},
}
// UsersColumns holds the columns for the "users" table.
...
...
@@ -790,6 +846,8 @@ var (
{
Name
:
"totp_secret_encrypted"
,
Type
:
field
.
TypeString
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"text"
}},
{
Name
:
"totp_enabled"
,
Type
:
field
.
TypeBool
,
Default
:
false
},
{
Name
:
"totp_enabled_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
},
{
Name
:
"sora_storage_quota_bytes"
,
Type
:
field
.
TypeInt64
,
Default
:
0
},
{
Name
:
"sora_storage_used_bytes"
,
Type
:
field
.
TypeInt64
,
Default
:
0
},
}
// UsersTable holds the schema information for the "users" table.
UsersTable
=
&
schema
.
Table
{
...
...
@@ -995,6 +1053,11 @@ var (
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserSubscriptionsColumns
[
5
]},
},
{
Name
:
"usersubscription_user_id_status_expires_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UserSubscriptionsColumns
[
16
],
UserSubscriptionsColumns
[
6
],
UserSubscriptionsColumns
[
5
]},
},
{
Name
:
"usersubscription_assigned_by"
,
Unique
:
false
,
...
...
@@ -1021,6 +1084,7 @@ var (
AnnouncementReadsTable
,
ErrorPassthroughRulesTable
,
GroupsTable
,
IdempotencyRecordsTable
,
PromoCodesTable
,
PromoCodeUsagesTable
,
ProxiesTable
,
...
...
@@ -1066,6 +1130,9 @@ func init() {
GroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"groups"
,
}
IdempotencyRecordsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"idempotency_records"
,
}
PromoCodesTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"promo_codes"
,
}
...
...
backend/ent/mutation.go
View file @
bb664d9b
This diff is collapsed.
Click to expand it.
backend/ent/predicate/predicate.go
View file @
bb664d9b
...
...
@@ -27,6 +27,9 @@ type ErrorPassthroughRule func(*sql.Selector)
// Group is the predicate function for group builders.
type
Group
func
(
*
sql
.
Selector
)
// IdempotencyRecord is the predicate function for idempotencyrecord builders.
type
IdempotencyRecord
func
(
*
sql
.
Selector
)
// PromoCode is the predicate function for promocode builders.
type
PromoCode
func
(
*
sql
.
Selector
)
...
...
backend/ent/runtime/runtime.go
View file @
bb664d9b
...
...
@@ -12,6 +12,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/idempotencyrecord"
"github.com/Wei-Shaw/sub2api/ent/promocode"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
"github.com/Wei-Shaw/sub2api/ent/proxy"
...
...
@@ -209,7 +210,7 @@ func init() {
// account.DefaultSchedulable holds the default value on creation for the schedulable field.
account
.
DefaultSchedulable
=
accountDescSchedulable
.
Default
.
(
bool
)
// accountDescSessionWindowStatus is the schema descriptor for session_window_status field.
accountDescSessionWindowStatus
:=
accountFields
[
2
1
]
.
Descriptor
()
accountDescSessionWindowStatus
:=
accountFields
[
2
3
]
.
Descriptor
()
// account.SessionWindowStatusValidator is a validator for the "session_window_status" field. It is called by the builders before save.
account
.
SessionWindowStatusValidator
=
accountDescSessionWindowStatus
.
Validators
[
0
]
.
(
func
(
string
)
error
)
accountgroupFields
:=
schema
.
AccountGroup
{}
.
Fields
()
...
...
@@ -398,26 +399,65 @@ func init() {
groupDescDefaultValidityDays
:=
groupFields
[
10
]
.
Descriptor
()
// group.DefaultDefaultValidityDays holds the default value on creation for the default_validity_days field.
group
.
DefaultDefaultValidityDays
=
groupDescDefaultValidityDays
.
Default
.
(
int
)
// groupDescSoraStorageQuotaBytes is the schema descriptor for sora_storage_quota_bytes field.
groupDescSoraStorageQuotaBytes
:=
groupFields
[
18
]
.
Descriptor
()
// group.DefaultSoraStorageQuotaBytes holds the default value on creation for the sora_storage_quota_bytes field.
group
.
DefaultSoraStorageQuotaBytes
=
groupDescSoraStorageQuotaBytes
.
Default
.
(
int64
)
// groupDescClaudeCodeOnly is the schema descriptor for claude_code_only field.
groupDescClaudeCodeOnly
:=
groupFields
[
1
8
]
.
Descriptor
()
groupDescClaudeCodeOnly
:=
groupFields
[
1
9
]
.
Descriptor
()
// group.DefaultClaudeCodeOnly holds the default value on creation for the claude_code_only field.
group
.
DefaultClaudeCodeOnly
=
groupDescClaudeCodeOnly
.
Default
.
(
bool
)
// groupDescModelRoutingEnabled is the schema descriptor for model_routing_enabled field.
groupDescModelRoutingEnabled
:=
groupFields
[
2
2
]
.
Descriptor
()
groupDescModelRoutingEnabled
:=
groupFields
[
2
3
]
.
Descriptor
()
// group.DefaultModelRoutingEnabled holds the default value on creation for the model_routing_enabled field.
group
.
DefaultModelRoutingEnabled
=
groupDescModelRoutingEnabled
.
Default
.
(
bool
)
// groupDescMcpXMLInject is the schema descriptor for mcp_xml_inject field.
groupDescMcpXMLInject
:=
groupFields
[
2
3
]
.
Descriptor
()
groupDescMcpXMLInject
:=
groupFields
[
2
4
]
.
Descriptor
()
// group.DefaultMcpXMLInject holds the default value on creation for the mcp_xml_inject field.
group
.
DefaultMcpXMLInject
=
groupDescMcpXMLInject
.
Default
.
(
bool
)
// groupDescSupportedModelScopes is the schema descriptor for supported_model_scopes field.
groupDescSupportedModelScopes
:=
groupFields
[
2
4
]
.
Descriptor
()
groupDescSupportedModelScopes
:=
groupFields
[
2
5
]
.
Descriptor
()
// group.DefaultSupportedModelScopes holds the default value on creation for the supported_model_scopes field.
group
.
DefaultSupportedModelScopes
=
groupDescSupportedModelScopes
.
Default
.
([]
string
)
// groupDescSortOrder is the schema descriptor for sort_order field.
groupDescSortOrder
:=
groupFields
[
2
5
]
.
Descriptor
()
groupDescSortOrder
:=
groupFields
[
2
6
]
.
Descriptor
()
// group.DefaultSortOrder holds the default value on creation for the sort_order field.
group
.
DefaultSortOrder
=
groupDescSortOrder
.
Default
.
(
int
)
idempotencyrecordMixin
:=
schema
.
IdempotencyRecord
{}
.
Mixin
()
idempotencyrecordMixinFields0
:=
idempotencyrecordMixin
[
0
]
.
Fields
()
_
=
idempotencyrecordMixinFields0
idempotencyrecordFields
:=
schema
.
IdempotencyRecord
{}
.
Fields
()
_
=
idempotencyrecordFields
// idempotencyrecordDescCreatedAt is the schema descriptor for created_at field.
idempotencyrecordDescCreatedAt
:=
idempotencyrecordMixinFields0
[
0
]
.
Descriptor
()
// idempotencyrecord.DefaultCreatedAt holds the default value on creation for the created_at field.
idempotencyrecord
.
DefaultCreatedAt
=
idempotencyrecordDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// idempotencyrecordDescUpdatedAt is the schema descriptor for updated_at field.
idempotencyrecordDescUpdatedAt
:=
idempotencyrecordMixinFields0
[
1
]
.
Descriptor
()
// idempotencyrecord.DefaultUpdatedAt holds the default value on creation for the updated_at field.
idempotencyrecord
.
DefaultUpdatedAt
=
idempotencyrecordDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// idempotencyrecord.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
idempotencyrecord
.
UpdateDefaultUpdatedAt
=
idempotencyrecordDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// idempotencyrecordDescScope is the schema descriptor for scope field.
idempotencyrecordDescScope
:=
idempotencyrecordFields
[
0
]
.
Descriptor
()
// idempotencyrecord.ScopeValidator is a validator for the "scope" field. It is called by the builders before save.
idempotencyrecord
.
ScopeValidator
=
idempotencyrecordDescScope
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// idempotencyrecordDescIdempotencyKeyHash is the schema descriptor for idempotency_key_hash field.
idempotencyrecordDescIdempotencyKeyHash
:=
idempotencyrecordFields
[
1
]
.
Descriptor
()
// idempotencyrecord.IdempotencyKeyHashValidator is a validator for the "idempotency_key_hash" field. It is called by the builders before save.
idempotencyrecord
.
IdempotencyKeyHashValidator
=
idempotencyrecordDescIdempotencyKeyHash
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// idempotencyrecordDescRequestFingerprint is the schema descriptor for request_fingerprint field.
idempotencyrecordDescRequestFingerprint
:=
idempotencyrecordFields
[
2
]
.
Descriptor
()
// idempotencyrecord.RequestFingerprintValidator is a validator for the "request_fingerprint" field. It is called by the builders before save.
idempotencyrecord
.
RequestFingerprintValidator
=
idempotencyrecordDescRequestFingerprint
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// idempotencyrecordDescStatus is the schema descriptor for status field.
idempotencyrecordDescStatus
:=
idempotencyrecordFields
[
3
]
.
Descriptor
()
// idempotencyrecord.StatusValidator is a validator for the "status" field. It is called by the builders before save.
idempotencyrecord
.
StatusValidator
=
idempotencyrecordDescStatus
.
Validators
[
0
]
.
(
func
(
string
)
error
)
// idempotencyrecordDescErrorReason is the schema descriptor for error_reason field.
idempotencyrecordDescErrorReason
:=
idempotencyrecordFields
[
6
]
.
Descriptor
()
// idempotencyrecord.ErrorReasonValidator is a validator for the "error_reason" field. It is called by the builders before save.
idempotencyrecord
.
ErrorReasonValidator
=
idempotencyrecordDescErrorReason
.
Validators
[
0
]
.
(
func
(
string
)
error
)
promocodeFields
:=
schema
.
PromoCode
{}
.
Fields
()
_
=
promocodeFields
// promocodeDescCode is the schema descriptor for code field.
...
...
@@ -918,6 +958,14 @@ func init() {
userDescTotpEnabled
:=
userFields
[
9
]
.
Descriptor
()
// user.DefaultTotpEnabled holds the default value on creation for the totp_enabled field.
user
.
DefaultTotpEnabled
=
userDescTotpEnabled
.
Default
.
(
bool
)
// userDescSoraStorageQuotaBytes is the schema descriptor for sora_storage_quota_bytes field.
userDescSoraStorageQuotaBytes
:=
userFields
[
11
]
.
Descriptor
()
// user.DefaultSoraStorageQuotaBytes holds the default value on creation for the sora_storage_quota_bytes field.
user
.
DefaultSoraStorageQuotaBytes
=
userDescSoraStorageQuotaBytes
.
Default
.
(
int64
)
// userDescSoraStorageUsedBytes is the schema descriptor for sora_storage_used_bytes field.
userDescSoraStorageUsedBytes
:=
userFields
[
12
]
.
Descriptor
()
// user.DefaultSoraStorageUsedBytes holds the default value on creation for the sora_storage_used_bytes field.
user
.
DefaultSoraStorageUsedBytes
=
userDescSoraStorageUsedBytes
.
Default
.
(
int64
)
userallowedgroupFields
:=
schema
.
UserAllowedGroup
{}
.
Fields
()
_
=
userallowedgroupFields
// userallowedgroupDescCreatedAt is the schema descriptor for created_at field.
...
...
backend/ent/schema/account.go
View file @
bb664d9b
This diff is collapsed.
Click to expand it.
backend/ent/schema/group.go
View file @
bb664d9b
...
...
@@ -105,6 +105,10 @@ func (Group) Fields() []ent.Field {
Nillable
()
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"decimal(20,8)"
}),
// Sora 存储配额
field
.
Int64
(
"sora_storage_quota_bytes"
)
.
Default
(
0
),
// Claude Code 客户端限制 (added by migration 029)
field
.
Bool
(
"claude_code_only"
)
.
Default
(
false
)
.
...
...
backend/ent/schema/usage_log.go
View file @
bb664d9b
...
...
@@ -179,5 +179,7 @@ func (UsageLog) Indexes() []ent.Index {
// 复合索引用于时间范围查询
index
.
Fields
(
"user_id"
,
"created_at"
),
index
.
Fields
(
"api_key_id"
,
"created_at"
),
// 分组维度时间范围查询(线上由 SQL 迁移创建 group_id IS NOT NULL 的部分索引)
index
.
Fields
(
"group_id"
,
"created_at"
),
}
}
Prev
1
2
3
4
5
6
…
17
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