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
0170d19f
"vscode:/vscode.git/clone" did not exist on "3851628a43936134ada6fe84029b84a20fe73ce7"
Commit
0170d19f
authored
Feb 02, 2026
by
song
Browse files
merge upstream main
parent
7ade9baa
Changes
319
Hide whitespace changes
Inline
Side-by-side
backend/ent/schema/usage_cleanup_task.go
0 → 100644
View file @
0170d19f
package
schema
import
(
"encoding/json"
"fmt"
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// UsageCleanupTask 定义使用记录清理任务的 schema。
type
UsageCleanupTask
struct
{
ent
.
Schema
}
func
(
UsageCleanupTask
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"usage_cleanup_tasks"
},
}
}
func
(
UsageCleanupTask
)
Mixin
()
[]
ent
.
Mixin
{
return
[]
ent
.
Mixin
{
mixins
.
TimeMixin
{},
}
}
func
(
UsageCleanupTask
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Validate
(
validateUsageCleanupStatus
),
field
.
JSON
(
"filters"
,
json
.
RawMessage
{}),
field
.
Int64
(
"created_by"
),
field
.
Int64
(
"deleted_rows"
)
.
Default
(
0
),
field
.
String
(
"error_message"
)
.
Optional
()
.
Nillable
(),
field
.
Int64
(
"canceled_by"
)
.
Optional
()
.
Nillable
(),
field
.
Time
(
"canceled_at"
)
.
Optional
()
.
Nillable
(),
field
.
Time
(
"started_at"
)
.
Optional
()
.
Nillable
(),
field
.
Time
(
"finished_at"
)
.
Optional
()
.
Nillable
(),
}
}
func
(
UsageCleanupTask
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
index
.
Fields
(
"status"
,
"created_at"
),
index
.
Fields
(
"created_at"
),
index
.
Fields
(
"canceled_at"
),
}
}
func
validateUsageCleanupStatus
(
status
string
)
error
{
switch
status
{
case
"pending"
,
"running"
,
"succeeded"
,
"failed"
,
"canceled"
:
return
nil
default
:
return
fmt
.
Errorf
(
"invalid usage cleanup status: %s"
,
status
)
}
}
backend/ent/schema/user.go
View file @
0170d19f
...
...
@@ -2,7 +2,7 @@ package schema
import
(
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect"
...
...
@@ -43,7 +43,7 @@ func (User) Fields() []ent.Field {
NotEmpty
(),
field
.
String
(
"role"
)
.
MaxLen
(
20
)
.
Default
(
service
.
RoleUser
),
Default
(
domain
.
RoleUser
),
field
.
Float
(
"balance"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"decimal(20,8)"
})
.
Default
(
0
),
...
...
@@ -51,7 +51,7 @@ func (User) Fields() []ent.Field {
Default
(
5
),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
StatusActive
),
Default
(
domain
.
StatusActive
),
// Optional profile fields (added later; default '' in DB migration)
field
.
String
(
"username"
)
.
...
...
@@ -61,6 +61,17 @@ func (User) Fields() []ent.Field {
field
.
String
(
"notes"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"text"
})
.
Default
(
""
),
// TOTP 双因素认证字段
field
.
String
(
"totp_secret_encrypted"
)
.
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"text"
})
.
Optional
()
.
Nillable
(),
field
.
Bool
(
"totp_enabled"
)
.
Default
(
false
),
field
.
Time
(
"totp_enabled_at"
)
.
Optional
()
.
Nillable
(),
}
}
...
...
@@ -70,6 +81,7 @@ func (User) Edges() []ent.Edge {
edge
.
To
(
"redeem_codes"
,
RedeemCode
.
Type
),
edge
.
To
(
"subscriptions"
,
UserSubscription
.
Type
),
edge
.
To
(
"assigned_subscriptions"
,
UserSubscription
.
Type
),
edge
.
To
(
"announcement_reads"
,
AnnouncementRead
.
Type
),
edge
.
To
(
"allowed_groups"
,
Group
.
Type
)
.
Through
(
"user_allowed_groups"
,
UserAllowedGroup
.
Type
),
edge
.
To
(
"usage_logs"
,
UsageLog
.
Type
),
...
...
backend/ent/schema/user_subscription.go
View file @
0170d19f
...
...
@@ -4,7 +4,7 @@ import (
"time"
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
"github.com/Wei-Shaw/sub2api/internal/
service
"
"github.com/Wei-Shaw/sub2api/internal/
domain
"
"entgo.io/ent"
"entgo.io/ent/dialect"
...
...
@@ -44,7 +44,7 @@ func (UserSubscription) Fields() []ent.Field {
SchemaType
(
map
[
string
]
string
{
dialect
.
Postgres
:
"timestamptz"
}),
field
.
String
(
"status"
)
.
MaxLen
(
20
)
.
Default
(
service
.
SubscriptionStatusActive
),
Default
(
domain
.
SubscriptionStatusActive
),
field
.
Time
(
"daily_window_start"
)
.
Optional
()
.
...
...
backend/ent/tx.go
View file @
0170d19f
...
...
@@ -20,6 +20,10 @@ type Tx struct {
Account
*
AccountClient
// AccountGroup is the client for interacting with the AccountGroup builders.
AccountGroup
*
AccountGroupClient
// Announcement is the client for interacting with the Announcement builders.
Announcement
*
AnnouncementClient
// AnnouncementRead is the client for interacting with the AnnouncementRead builders.
AnnouncementRead
*
AnnouncementReadClient
// Group is the client for interacting with the Group builders.
Group
*
GroupClient
// PromoCode is the client for interacting with the PromoCode builders.
...
...
@@ -32,6 +36,8 @@ type Tx struct {
RedeemCode
*
RedeemCodeClient
// Setting is the client for interacting with the Setting builders.
Setting
*
SettingClient
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
UsageCleanupTask
*
UsageCleanupTaskClient
// UsageLog is the client for interacting with the UsageLog builders.
UsageLog
*
UsageLogClient
// User is the client for interacting with the User builders.
...
...
@@ -178,12 +184,15 @@ func (tx *Tx) init() {
tx
.
APIKey
=
NewAPIKeyClient
(
tx
.
config
)
tx
.
Account
=
NewAccountClient
(
tx
.
config
)
tx
.
AccountGroup
=
NewAccountGroupClient
(
tx
.
config
)
tx
.
Announcement
=
NewAnnouncementClient
(
tx
.
config
)
tx
.
AnnouncementRead
=
NewAnnouncementReadClient
(
tx
.
config
)
tx
.
Group
=
NewGroupClient
(
tx
.
config
)
tx
.
PromoCode
=
NewPromoCodeClient
(
tx
.
config
)
tx
.
PromoCodeUsage
=
NewPromoCodeUsageClient
(
tx
.
config
)
tx
.
Proxy
=
NewProxyClient
(
tx
.
config
)
tx
.
RedeemCode
=
NewRedeemCodeClient
(
tx
.
config
)
tx
.
Setting
=
NewSettingClient
(
tx
.
config
)
tx
.
UsageCleanupTask
=
NewUsageCleanupTaskClient
(
tx
.
config
)
tx
.
UsageLog
=
NewUsageLogClient
(
tx
.
config
)
tx
.
User
=
NewUserClient
(
tx
.
config
)
tx
.
UserAllowedGroup
=
NewUserAllowedGroupClient
(
tx
.
config
)
...
...
backend/ent/usagecleanuptask.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTask is the model entity for the UsageCleanupTask schema.
type
UsageCleanupTask
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt
time
.
Time
`json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt
time
.
Time
`json:"updated_at,omitempty"`
// Status holds the value of the "status" field.
Status
string
`json:"status,omitempty"`
// Filters holds the value of the "filters" field.
Filters
json
.
RawMessage
`json:"filters,omitempty"`
// CreatedBy holds the value of the "created_by" field.
CreatedBy
int64
`json:"created_by,omitempty"`
// DeletedRows holds the value of the "deleted_rows" field.
DeletedRows
int64
`json:"deleted_rows,omitempty"`
// ErrorMessage holds the value of the "error_message" field.
ErrorMessage
*
string
`json:"error_message,omitempty"`
// CanceledBy holds the value of the "canceled_by" field.
CanceledBy
*
int64
`json:"canceled_by,omitempty"`
// CanceledAt holds the value of the "canceled_at" field.
CanceledAt
*
time
.
Time
`json:"canceled_at,omitempty"`
// StartedAt holds the value of the "started_at" field.
StartedAt
*
time
.
Time
`json:"started_at,omitempty"`
// FinishedAt holds the value of the "finished_at" field.
FinishedAt
*
time
.
Time
`json:"finished_at,omitempty"`
selectValues
sql
.
SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
UsageCleanupTask
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
usagecleanuptask
.
FieldFilters
:
values
[
i
]
=
new
([]
byte
)
case
usagecleanuptask
.
FieldID
,
usagecleanuptask
.
FieldCreatedBy
,
usagecleanuptask
.
FieldDeletedRows
,
usagecleanuptask
.
FieldCanceledBy
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
usagecleanuptask
.
FieldStatus
,
usagecleanuptask
.
FieldErrorMessage
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
usagecleanuptask
.
FieldCreatedAt
,
usagecleanuptask
.
FieldUpdatedAt
,
usagecleanuptask
.
FieldCanceledAt
,
usagecleanuptask
.
FieldStartedAt
,
usagecleanuptask
.
FieldFinishedAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
default
:
values
[
i
]
=
new
(
sql
.
UnknownType
)
}
}
return
values
,
nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the UsageCleanupTask fields.
func
(
_m
*
UsageCleanupTask
)
assignValues
(
columns
[]
string
,
values
[]
any
)
error
{
if
m
,
n
:=
len
(
values
),
len
(
columns
);
m
<
n
{
return
fmt
.
Errorf
(
"mismatch number of scan values: %d != %d"
,
m
,
n
)
}
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
usagecleanuptask
.
FieldID
:
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
)
if
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field id"
,
value
)
}
_m
.
ID
=
int64
(
value
.
Int64
)
case
usagecleanuptask
.
FieldCreatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field created_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CreatedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldUpdatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field updated_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UpdatedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldStatus
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field status"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Status
=
value
.
String
}
case
usagecleanuptask
.
FieldFilters
:
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field filters"
,
values
[
i
])
}
else
if
value
!=
nil
&&
len
(
*
value
)
>
0
{
if
err
:=
json
.
Unmarshal
(
*
value
,
&
_m
.
Filters
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal field filters: %w"
,
err
)
}
}
case
usagecleanuptask
.
FieldCreatedBy
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field created_by"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CreatedBy
=
value
.
Int64
}
case
usagecleanuptask
.
FieldDeletedRows
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field deleted_rows"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
DeletedRows
=
value
.
Int64
}
case
usagecleanuptask
.
FieldErrorMessage
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field error_message"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ErrorMessage
=
new
(
string
)
*
_m
.
ErrorMessage
=
value
.
String
}
case
usagecleanuptask
.
FieldCanceledBy
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field canceled_by"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CanceledBy
=
new
(
int64
)
*
_m
.
CanceledBy
=
value
.
Int64
}
case
usagecleanuptask
.
FieldCanceledAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field canceled_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CanceledAt
=
new
(
time
.
Time
)
*
_m
.
CanceledAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldStartedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field started_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
StartedAt
=
new
(
time
.
Time
)
*
_m
.
StartedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldFinishedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field finished_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
FinishedAt
=
new
(
time
.
Time
)
*
_m
.
FinishedAt
=
value
.
Time
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
}
return
nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the UsageCleanupTask.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
UsageCleanupTask
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// Update returns a builder for updating this UsageCleanupTask.
// Note that you need to call UsageCleanupTask.Unwrap() before calling this method if this UsageCleanupTask
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
UsageCleanupTask
)
Update
()
*
UsageCleanupTaskUpdateOne
{
return
NewUsageCleanupTaskClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the UsageCleanupTask entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func
(
_m
*
UsageCleanupTask
)
Unwrap
()
*
UsageCleanupTask
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: UsageCleanupTask is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
UsageCleanupTask
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"UsageCleanupTask("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"created_at="
)
builder
.
WriteString
(
_m
.
CreatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"updated_at="
)
builder
.
WriteString
(
_m
.
UpdatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"status="
)
builder
.
WriteString
(
_m
.
Status
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"filters="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
Filters
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"created_by="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
CreatedBy
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"deleted_rows="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
DeletedRows
))
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ErrorMessage
;
v
!=
nil
{
builder
.
WriteString
(
"error_message="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
CanceledBy
;
v
!=
nil
{
builder
.
WriteString
(
"canceled_by="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
CanceledAt
;
v
!=
nil
{
builder
.
WriteString
(
"canceled_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
StartedAt
;
v
!=
nil
{
builder
.
WriteString
(
"started_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
FinishedAt
;
v
!=
nil
{
builder
.
WriteString
(
"finished_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// UsageCleanupTasks is a parsable slice of UsageCleanupTask.
type
UsageCleanupTasks
[]
*
UsageCleanupTask
backend/ent/usagecleanuptask/usagecleanuptask.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
usagecleanuptask
import
(
"time"
"entgo.io/ent/dialect/sql"
)
const
(
// Label holds the string label denoting the usagecleanuptask type in the database.
Label
=
"usage_cleanup_task"
// FieldID holds the string denoting the id field in the database.
FieldID
=
"id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt
=
"created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt
=
"updated_at"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus
=
"status"
// FieldFilters holds the string denoting the filters field in the database.
FieldFilters
=
"filters"
// FieldCreatedBy holds the string denoting the created_by field in the database.
FieldCreatedBy
=
"created_by"
// FieldDeletedRows holds the string denoting the deleted_rows field in the database.
FieldDeletedRows
=
"deleted_rows"
// FieldErrorMessage holds the string denoting the error_message field in the database.
FieldErrorMessage
=
"error_message"
// FieldCanceledBy holds the string denoting the canceled_by field in the database.
FieldCanceledBy
=
"canceled_by"
// FieldCanceledAt holds the string denoting the canceled_at field in the database.
FieldCanceledAt
=
"canceled_at"
// FieldStartedAt holds the string denoting the started_at field in the database.
FieldStartedAt
=
"started_at"
// FieldFinishedAt holds the string denoting the finished_at field in the database.
FieldFinishedAt
=
"finished_at"
// Table holds the table name of the usagecleanuptask in the database.
Table
=
"usage_cleanup_tasks"
)
// Columns holds all SQL columns for usagecleanuptask fields.
var
Columns
=
[]
string
{
FieldID
,
FieldCreatedAt
,
FieldUpdatedAt
,
FieldStatus
,
FieldFilters
,
FieldCreatedBy
,
FieldDeletedRows
,
FieldErrorMessage
,
FieldCanceledBy
,
FieldCanceledAt
,
FieldStartedAt
,
FieldFinishedAt
,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func
ValidColumn
(
column
string
)
bool
{
for
i
:=
range
Columns
{
if
column
==
Columns
[
i
]
{
return
true
}
}
return
false
}
var
(
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt
func
()
time
.
Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt
func
()
time
.
Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt
func
()
time
.
Time
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator
func
(
string
)
error
// DefaultDeletedRows holds the default value on creation for the "deleted_rows" field.
DefaultDeletedRows
int64
)
// OrderOption defines the ordering options for the UsageCleanupTask queries.
type
OrderOption
func
(
*
sql
.
Selector
)
// ByID orders the results by the id field.
func
ByID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldID
,
opts
...
)
.
ToFunc
()
}
// ByCreatedAt orders the results by the created_at field.
func
ByCreatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUpdatedAt orders the results by the updated_at field.
func
ByUpdatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpdatedAt
,
opts
...
)
.
ToFunc
()
}
// ByStatus orders the results by the status field.
func
ByStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStatus
,
opts
...
)
.
ToFunc
()
}
// ByCreatedBy orders the results by the created_by field.
func
ByCreatedBy
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedBy
,
opts
...
)
.
ToFunc
()
}
// ByDeletedRows orders the results by the deleted_rows field.
func
ByDeletedRows
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldDeletedRows
,
opts
...
)
.
ToFunc
()
}
// ByErrorMessage orders the results by the error_message field.
func
ByErrorMessage
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldErrorMessage
,
opts
...
)
.
ToFunc
()
}
// ByCanceledBy orders the results by the canceled_by field.
func
ByCanceledBy
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCanceledBy
,
opts
...
)
.
ToFunc
()
}
// ByCanceledAt orders the results by the canceled_at field.
func
ByCanceledAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCanceledAt
,
opts
...
)
.
ToFunc
()
}
// ByStartedAt orders the results by the started_at field.
func
ByStartedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStartedAt
,
opts
...
)
.
ToFunc
()
}
// ByFinishedAt orders the results by the finished_at field.
func
ByFinishedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldFinishedAt
,
opts
...
)
.
ToFunc
()
}
backend/ent/usagecleanuptask/where.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
usagecleanuptask
import
(
"time"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func
ID
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func
CreatedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func
UpdatedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func
Status
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// CreatedBy applies equality check predicate on the "created_by" field. It's identical to CreatedByEQ.
func
CreatedBy
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedBy
,
v
))
}
// DeletedRows applies equality check predicate on the "deleted_rows" field. It's identical to DeletedRowsEQ.
func
DeletedRows
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldDeletedRows
,
v
))
}
// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ.
func
ErrorMessage
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldErrorMessage
,
v
))
}
// CanceledBy applies equality check predicate on the "canceled_by" field. It's identical to CanceledByEQ.
func
CanceledBy
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledBy
,
v
))
}
// CanceledAt applies equality check predicate on the "canceled_at" field. It's identical to CanceledAtEQ.
func
CanceledAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledAt
,
v
))
}
// StartedAt applies equality check predicate on the "started_at" field. It's identical to StartedAtEQ.
func
StartedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStartedAt
,
v
))
}
// FinishedAt applies equality check predicate on the "finished_at" field. It's identical to FinishedAtEQ.
func
FinishedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldFinishedAt
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func
CreatedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func
CreatedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func
CreatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func
CreatedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCreatedAt
,
v
))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func
CreatedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCreatedAt
,
v
))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func
CreatedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCreatedAt
,
v
))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func
CreatedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCreatedAt
,
v
))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func
UpdatedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func
UpdatedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func
UpdatedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func
UpdatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func
UpdatedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func
UpdatedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func
UpdatedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func
UpdatedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldUpdatedAt
,
v
))
}
// StatusEQ applies the EQ predicate on the "status" field.
func
StatusEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func
StatusNEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldStatus
,
v
))
}
// StatusIn applies the In predicate on the "status" field.
func
StatusIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldStatus
,
vs
...
))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func
StatusNotIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldStatus
,
vs
...
))
}
// StatusGT applies the GT predicate on the "status" field.
func
StatusGT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldStatus
,
v
))
}
// StatusGTE applies the GTE predicate on the "status" field.
func
StatusGTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldStatus
,
v
))
}
// StatusLT applies the LT predicate on the "status" field.
func
StatusLT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldStatus
,
v
))
}
// StatusLTE applies the LTE predicate on the "status" field.
func
StatusLTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldStatus
,
v
))
}
// StatusContains applies the Contains predicate on the "status" field.
func
StatusContains
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContains
(
FieldStatus
,
v
))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func
StatusHasPrefix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasPrefix
(
FieldStatus
,
v
))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func
StatusHasSuffix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasSuffix
(
FieldStatus
,
v
))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func
StatusEqualFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEqualFold
(
FieldStatus
,
v
))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func
StatusContainsFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContainsFold
(
FieldStatus
,
v
))
}
// CreatedByEQ applies the EQ predicate on the "created_by" field.
func
CreatedByEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedBy
,
v
))
}
// CreatedByNEQ applies the NEQ predicate on the "created_by" field.
func
CreatedByNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCreatedBy
,
v
))
}
// CreatedByIn applies the In predicate on the "created_by" field.
func
CreatedByIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCreatedBy
,
vs
...
))
}
// CreatedByNotIn applies the NotIn predicate on the "created_by" field.
func
CreatedByNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCreatedBy
,
vs
...
))
}
// CreatedByGT applies the GT predicate on the "created_by" field.
func
CreatedByGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCreatedBy
,
v
))
}
// CreatedByGTE applies the GTE predicate on the "created_by" field.
func
CreatedByGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCreatedBy
,
v
))
}
// CreatedByLT applies the LT predicate on the "created_by" field.
func
CreatedByLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCreatedBy
,
v
))
}
// CreatedByLTE applies the LTE predicate on the "created_by" field.
func
CreatedByLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCreatedBy
,
v
))
}
// DeletedRowsEQ applies the EQ predicate on the "deleted_rows" field.
func
DeletedRowsEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldDeletedRows
,
v
))
}
// DeletedRowsNEQ applies the NEQ predicate on the "deleted_rows" field.
func
DeletedRowsNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldDeletedRows
,
v
))
}
// DeletedRowsIn applies the In predicate on the "deleted_rows" field.
func
DeletedRowsIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldDeletedRows
,
vs
...
))
}
// DeletedRowsNotIn applies the NotIn predicate on the "deleted_rows" field.
func
DeletedRowsNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldDeletedRows
,
vs
...
))
}
// DeletedRowsGT applies the GT predicate on the "deleted_rows" field.
func
DeletedRowsGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldDeletedRows
,
v
))
}
// DeletedRowsGTE applies the GTE predicate on the "deleted_rows" field.
func
DeletedRowsGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldDeletedRows
,
v
))
}
// DeletedRowsLT applies the LT predicate on the "deleted_rows" field.
func
DeletedRowsLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldDeletedRows
,
v
))
}
// DeletedRowsLTE applies the LTE predicate on the "deleted_rows" field.
func
DeletedRowsLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldDeletedRows
,
v
))
}
// ErrorMessageEQ applies the EQ predicate on the "error_message" field.
func
ErrorMessageEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldErrorMessage
,
v
))
}
// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field.
func
ErrorMessageNEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldErrorMessage
,
v
))
}
// ErrorMessageIn applies the In predicate on the "error_message" field.
func
ErrorMessageIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldErrorMessage
,
vs
...
))
}
// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field.
func
ErrorMessageNotIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldErrorMessage
,
vs
...
))
}
// ErrorMessageGT applies the GT predicate on the "error_message" field.
func
ErrorMessageGT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldErrorMessage
,
v
))
}
// ErrorMessageGTE applies the GTE predicate on the "error_message" field.
func
ErrorMessageGTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldErrorMessage
,
v
))
}
// ErrorMessageLT applies the LT predicate on the "error_message" field.
func
ErrorMessageLT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldErrorMessage
,
v
))
}
// ErrorMessageLTE applies the LTE predicate on the "error_message" field.
func
ErrorMessageLTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldErrorMessage
,
v
))
}
// ErrorMessageContains applies the Contains predicate on the "error_message" field.
func
ErrorMessageContains
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContains
(
FieldErrorMessage
,
v
))
}
// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field.
func
ErrorMessageHasPrefix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasPrefix
(
FieldErrorMessage
,
v
))
}
// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field.
func
ErrorMessageHasSuffix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasSuffix
(
FieldErrorMessage
,
v
))
}
// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field.
func
ErrorMessageIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldErrorMessage
))
}
// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field.
func
ErrorMessageNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldErrorMessage
))
}
// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field.
func
ErrorMessageEqualFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEqualFold
(
FieldErrorMessage
,
v
))
}
// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field.
func
ErrorMessageContainsFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContainsFold
(
FieldErrorMessage
,
v
))
}
// CanceledByEQ applies the EQ predicate on the "canceled_by" field.
func
CanceledByEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledBy
,
v
))
}
// CanceledByNEQ applies the NEQ predicate on the "canceled_by" field.
func
CanceledByNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCanceledBy
,
v
))
}
// CanceledByIn applies the In predicate on the "canceled_by" field.
func
CanceledByIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCanceledBy
,
vs
...
))
}
// CanceledByNotIn applies the NotIn predicate on the "canceled_by" field.
func
CanceledByNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCanceledBy
,
vs
...
))
}
// CanceledByGT applies the GT predicate on the "canceled_by" field.
func
CanceledByGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCanceledBy
,
v
))
}
// CanceledByGTE applies the GTE predicate on the "canceled_by" field.
func
CanceledByGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCanceledBy
,
v
))
}
// CanceledByLT applies the LT predicate on the "canceled_by" field.
func
CanceledByLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCanceledBy
,
v
))
}
// CanceledByLTE applies the LTE predicate on the "canceled_by" field.
func
CanceledByLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCanceledBy
,
v
))
}
// CanceledByIsNil applies the IsNil predicate on the "canceled_by" field.
func
CanceledByIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldCanceledBy
))
}
// CanceledByNotNil applies the NotNil predicate on the "canceled_by" field.
func
CanceledByNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldCanceledBy
))
}
// CanceledAtEQ applies the EQ predicate on the "canceled_at" field.
func
CanceledAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledAt
,
v
))
}
// CanceledAtNEQ applies the NEQ predicate on the "canceled_at" field.
func
CanceledAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCanceledAt
,
v
))
}
// CanceledAtIn applies the In predicate on the "canceled_at" field.
func
CanceledAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCanceledAt
,
vs
...
))
}
// CanceledAtNotIn applies the NotIn predicate on the "canceled_at" field.
func
CanceledAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCanceledAt
,
vs
...
))
}
// CanceledAtGT applies the GT predicate on the "canceled_at" field.
func
CanceledAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCanceledAt
,
v
))
}
// CanceledAtGTE applies the GTE predicate on the "canceled_at" field.
func
CanceledAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCanceledAt
,
v
))
}
// CanceledAtLT applies the LT predicate on the "canceled_at" field.
func
CanceledAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCanceledAt
,
v
))
}
// CanceledAtLTE applies the LTE predicate on the "canceled_at" field.
func
CanceledAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCanceledAt
,
v
))
}
// CanceledAtIsNil applies the IsNil predicate on the "canceled_at" field.
func
CanceledAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldCanceledAt
))
}
// CanceledAtNotNil applies the NotNil predicate on the "canceled_at" field.
func
CanceledAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldCanceledAt
))
}
// StartedAtEQ applies the EQ predicate on the "started_at" field.
func
StartedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStartedAt
,
v
))
}
// StartedAtNEQ applies the NEQ predicate on the "started_at" field.
func
StartedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldStartedAt
,
v
))
}
// StartedAtIn applies the In predicate on the "started_at" field.
func
StartedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldStartedAt
,
vs
...
))
}
// StartedAtNotIn applies the NotIn predicate on the "started_at" field.
func
StartedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldStartedAt
,
vs
...
))
}
// StartedAtGT applies the GT predicate on the "started_at" field.
func
StartedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldStartedAt
,
v
))
}
// StartedAtGTE applies the GTE predicate on the "started_at" field.
func
StartedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldStartedAt
,
v
))
}
// StartedAtLT applies the LT predicate on the "started_at" field.
func
StartedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldStartedAt
,
v
))
}
// StartedAtLTE applies the LTE predicate on the "started_at" field.
func
StartedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldStartedAt
,
v
))
}
// StartedAtIsNil applies the IsNil predicate on the "started_at" field.
func
StartedAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldStartedAt
))
}
// StartedAtNotNil applies the NotNil predicate on the "started_at" field.
func
StartedAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldStartedAt
))
}
// FinishedAtEQ applies the EQ predicate on the "finished_at" field.
func
FinishedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldFinishedAt
,
v
))
}
// FinishedAtNEQ applies the NEQ predicate on the "finished_at" field.
func
FinishedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldFinishedAt
,
v
))
}
// FinishedAtIn applies the In predicate on the "finished_at" field.
func
FinishedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldFinishedAt
,
vs
...
))
}
// FinishedAtNotIn applies the NotIn predicate on the "finished_at" field.
func
FinishedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldFinishedAt
,
vs
...
))
}
// FinishedAtGT applies the GT predicate on the "finished_at" field.
func
FinishedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldFinishedAt
,
v
))
}
// FinishedAtGTE applies the GTE predicate on the "finished_at" field.
func
FinishedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldFinishedAt
,
v
))
}
// FinishedAtLT applies the LT predicate on the "finished_at" field.
func
FinishedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldFinishedAt
,
v
))
}
// FinishedAtLTE applies the LTE predicate on the "finished_at" field.
func
FinishedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldFinishedAt
,
v
))
}
// FinishedAtIsNil applies the IsNil predicate on the "finished_at" field.
func
FinishedAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldFinishedAt
))
}
// FinishedAtNotNil applies the NotNil predicate on the "finished_at" field.
func
FinishedAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldFinishedAt
))
}
// And groups predicates with the AND operator between them.
func
And
(
predicates
...
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
NotPredicates
(
p
))
}
backend/ent/usagecleanuptask_create.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"encoding/json"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskCreate is the builder for creating a UsageCleanupTask entity.
type
UsageCleanupTaskCreate
struct
{
config
mutation
*
UsageCleanupTaskMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetUpdatedAt
(
v
)
return
_c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableUpdatedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetUpdatedAt
(
*
v
)
}
return
_c
}
// SetStatus sets the "status" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetStatus
(
v
string
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetStatus
(
v
)
return
_c
}
// SetFilters sets the "filters" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetFilters
(
v
)
return
_c
}
// SetCreatedBy sets the "created_by" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCreatedBy
(
v
)
return
_c
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetDeletedRows
(
v
)
return
_c
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetDeletedRows
(
*
v
)
}
return
_c
}
// SetErrorMessage sets the "error_message" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetErrorMessage
(
v
)
return
_c
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetErrorMessage
(
*
v
)
}
return
_c
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCanceledBy
(
v
)
return
_c
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCanceledBy
(
*
v
)
}
return
_c
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCanceledAt
(
v
)
return
_c
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCanceledAt
(
*
v
)
}
return
_c
}
// SetStartedAt sets the "started_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetStartedAt
(
v
)
return
_c
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetStartedAt
(
*
v
)
}
return
_c
}
// SetFinishedAt sets the "finished_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetFinishedAt
(
v
)
return
_c
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetFinishedAt
(
*
v
)
}
return
_c
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_c
*
UsageCleanupTaskCreate
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_c
.
mutation
}
// Save creates the UsageCleanupTask in the database.
func
(
_c
*
UsageCleanupTaskCreate
)
Save
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
UsageCleanupTaskCreate
)
SaveX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
UsageCleanupTaskCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_c
*
UsageCleanupTaskCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultUpdatedAt
()
_c
.
mutation
.
SetUpdatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
DeletedRows
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultDeletedRows
_c
.
mutation
.
SetDeletedRows
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
UsageCleanupTaskCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.created_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"updated_at"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.updated_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.status"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Filters
();
!
ok
{
return
&
ValidationError
{
Name
:
"filters"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.filters"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedBy
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_by"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.created_by"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
DeletedRows
();
!
ok
{
return
&
ValidationError
{
Name
:
"deleted_rows"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.deleted_rows"`
)}
}
return
nil
}
func
(
_c
*
UsageCleanupTaskCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
if
err
:=
_c
.
check
();
err
!=
nil
{
return
nil
,
err
}
_node
,
_spec
:=
_c
.
createSpec
()
if
err
:=
sqlgraph
.
CreateNode
(
ctx
,
_c
.
driver
,
_spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
id
:=
_spec
.
ID
.
Value
.
(
int64
)
_node
.
ID
=
int64
(
id
)
_c
.
mutation
.
id
=
&
_node
.
ID
_c
.
mutation
.
done
=
true
return
_node
,
nil
}
func
(
_c
*
UsageCleanupTaskCreate
)
createSpec
()
(
*
UsageCleanupTask
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
UsageCleanupTask
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
usagecleanuptask
.
Table
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
_node
.
UpdatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
_node
.
Status
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
_node
.
Filters
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
_node
.
CreatedBy
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
_node
.
DeletedRows
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
_node
.
ErrorMessage
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
_node
.
CanceledBy
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
_node
.
CanceledAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
_node
.
StartedAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
_node
.
FinishedAt
=
&
value
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageCleanupTask.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageCleanupTaskUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
UsageCleanupTaskUpsertOne
{
_c
.
conflict
=
opts
return
&
UsageCleanupTaskUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreate
)
OnConflictColumns
(
columns
...
string
)
*
UsageCleanupTaskUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
UsageCleanupTaskUpsertOne
{
create
:
_c
,
}
}
type
(
// UsageCleanupTaskUpsertOne is the builder for "upsert"-ing
// one UsageCleanupTask node.
UsageCleanupTaskUpsertOne
struct
{
create
*
UsageCleanupTaskCreate
}
// UsageCleanupTaskUpsert is the "OnConflict" setter.
UsageCleanupTaskUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldUpdatedAt
,
v
)
return
u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldUpdatedAt
)
return
u
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldStatus
,
v
)
return
u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateStatus
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldStatus
)
return
u
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldFilters
,
v
)
return
u
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateFilters
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldFilters
)
return
u
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCreatedBy
,
v
)
return
u
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCreatedBy
)
return
u
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldCreatedBy
,
v
)
return
u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldDeletedRows
,
v
)
return
u
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldDeletedRows
)
return
u
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldDeletedRows
,
v
)
return
u
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldErrorMessage
,
v
)
return
u
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldErrorMessage
)
return
u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldErrorMessage
)
return
u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCanceledBy
,
v
)
return
u
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCanceledBy
)
return
u
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldCanceledBy
,
v
)
return
u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldCanceledBy
)
return
u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCanceledAt
,
v
)
return
u
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCanceledAt
)
return
u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldCanceledAt
)
return
u
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldStartedAt
,
v
)
return
u
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldStartedAt
)
return
u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearStartedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldStartedAt
)
return
u
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldFinishedAt
,
v
)
return
u
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldFinishedAt
)
return
u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldFinishedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateNewValues
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
if
_
,
exists
:=
u
.
create
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
usagecleanuptask
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertOne
)
Ignore
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
UsageCleanupTaskUpsertOne
)
DoNothing
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the UsageCleanupTaskCreate.OnConflict
// documentation for more info.
func
(
u
*
UsageCleanupTaskUpsertOne
)
Update
(
set
func
(
*
UsageCleanupTaskUpsert
))
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
UsageCleanupTaskUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateStatus
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFilters
(
v
)
})
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateFilters
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFilters
()
})
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCreatedBy
(
v
)
})
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCreatedBy
(
v
)
})
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCreatedBy
()
})
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetDeletedRows
(
v
)
})
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddDeletedRows
(
v
)
})
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateDeletedRows
()
})
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetErrorMessage
(
v
)
})
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateErrorMessage
()
})
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearErrorMessage
()
})
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledBy
(
v
)
})
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCanceledBy
(
v
)
})
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledBy
()
})
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledBy
()
})
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledAt
(
v
)
})
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledAt
()
})
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledAt
()
})
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStartedAt
(
v
)
})
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStartedAt
()
})
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearStartedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearStartedAt
()
})
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFinishedAt
(
v
)
})
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFinishedAt
()
})
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearFinishedAt
()
})
}
// Exec executes the query.
func
(
u
*
UsageCleanupTaskUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for UsageCleanupTaskCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
node
,
err
:=
u
.
create
.
Save
(
ctx
)
if
err
!=
nil
{
return
id
,
err
}
return
node
.
ID
,
nil
}
// IDX is like ID, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// UsageCleanupTaskCreateBulk is the builder for creating many UsageCleanupTask entities in bulk.
type
UsageCleanupTaskCreateBulk
struct
{
config
err
error
builders
[]
*
UsageCleanupTaskCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the UsageCleanupTask entities in the database.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
UsageCleanupTask
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
UsageCleanupTask
,
len
(
_c
.
builders
))
mutators
:=
make
([]
Mutator
,
len
(
_c
.
builders
))
for
i
:=
range
_c
.
builders
{
func
(
i
int
,
root
context
.
Context
)
{
builder
:=
_c
.
builders
[
i
]
builder
.
defaults
()
var
mut
Mutator
=
MutateFunc
(
func
(
ctx
context
.
Context
,
m
Mutation
)
(
Value
,
error
)
{
mutation
,
ok
:=
m
.
(
*
UsageCleanupTaskMutation
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T"
,
m
)
}
if
err
:=
builder
.
check
();
err
!=
nil
{
return
nil
,
err
}
builder
.
mutation
=
mutation
var
err
error
nodes
[
i
],
specs
[
i
]
=
builder
.
createSpec
()
if
i
<
len
(
mutators
)
-
1
{
_
,
err
=
mutators
[
i
+
1
]
.
Mutate
(
root
,
_c
.
builders
[
i
+
1
]
.
mutation
)
}
else
{
spec
:=
&
sqlgraph
.
BatchCreateSpec
{
Nodes
:
specs
}
spec
.
OnConflict
=
_c
.
conflict
// Invoke the actual operation on the latest mutation in the chain.
if
err
=
sqlgraph
.
BatchCreate
(
ctx
,
_c
.
driver
,
spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
}
}
if
err
!=
nil
{
return
nil
,
err
}
mutation
.
id
=
&
nodes
[
i
]
.
ID
if
specs
[
i
]
.
ID
.
Value
!=
nil
{
id
:=
specs
[
i
]
.
ID
.
Value
.
(
int64
)
nodes
[
i
]
.
ID
=
int64
(
id
)
}
mutation
.
done
=
true
return
nodes
[
i
],
nil
})
for
i
:=
len
(
builder
.
hooks
)
-
1
;
i
>=
0
;
i
--
{
mut
=
builder
.
hooks
[
i
](
mut
)
}
mutators
[
i
]
=
mut
}(
i
,
ctx
)
}
if
len
(
mutators
)
>
0
{
if
_
,
err
:=
mutators
[
0
]
.
Mutate
(
ctx
,
_c
.
builders
[
0
]
.
mutation
);
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
// SaveX is like Save, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
UsageCleanupTask
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageCleanupTask.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageCleanupTaskUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
UsageCleanupTaskUpsertBulk
{
_c
.
conflict
=
opts
return
&
UsageCleanupTaskUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
UsageCleanupTaskUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
UsageCleanupTaskUpsertBulk
{
create
:
_c
,
}
}
// UsageCleanupTaskUpsertBulk is the builder for "upsert"-ing
// a bulk of UsageCleanupTask nodes.
type
UsageCleanupTaskUpsertBulk
struct
{
create
*
UsageCleanupTaskCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateNewValues
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
for
_
,
b
:=
range
u
.
create
.
builders
{
if
_
,
exists
:=
b
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
usagecleanuptask
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Ignore
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
DoNothing
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the UsageCleanupTaskCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Update
(
set
func
(
*
UsageCleanupTaskUpsert
))
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
UsageCleanupTaskUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateStatus
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFilters
(
v
)
})
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateFilters
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFilters
()
})
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCreatedBy
(
v
)
})
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCreatedBy
(
v
)
})
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCreatedBy
()
})
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetDeletedRows
(
v
)
})
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddDeletedRows
(
v
)
})
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateDeletedRows
()
})
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetErrorMessage
(
v
)
})
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateErrorMessage
()
})
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearErrorMessage
()
})
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledBy
(
v
)
})
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCanceledBy
(
v
)
})
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledBy
()
})
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledBy
()
})
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledAt
(
v
)
})
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledAt
()
})
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledAt
()
})
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStartedAt
(
v
)
})
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStartedAt
()
})
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearStartedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearStartedAt
()
})
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFinishedAt
(
v
)
})
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFinishedAt
()
})
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearFinishedAt
()
})
}
// Exec executes the query.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
return
u
.
create
.
err
}
for
i
,
b
:=
range
u
.
create
.
builders
{
if
len
(
b
.
conflict
)
!=
0
{
return
fmt
.
Errorf
(
"ent: OnConflict was set for builder %d. Set it on the UsageCleanupTaskCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for UsageCleanupTaskCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/usagecleanuptask_delete.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskDelete is the builder for deleting a UsageCleanupTask entity.
type
UsageCleanupTaskDelete
struct
{
config
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
func
(
_d
*
UsageCleanupTaskDelete
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
UsageCleanupTaskDelete
)
Exec
(
ctx
context
.
Context
)
(
int
,
error
)
{
return
withHooks
(
ctx
,
_d
.
sqlExec
,
_d
.
mutation
,
_d
.
hooks
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
UsageCleanupTaskDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
UsageCleanupTaskDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
usagecleanuptask
.
Table
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_d
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
affected
,
err
:=
sqlgraph
.
DeleteNodes
(
ctx
,
_d
.
driver
,
_spec
)
if
err
!=
nil
&&
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
_d
.
mutation
.
done
=
true
return
affected
,
err
}
// UsageCleanupTaskDeleteOne is the builder for deleting a single UsageCleanupTask entity.
type
UsageCleanupTaskDeleteOne
struct
{
_d
*
UsageCleanupTaskDelete
}
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/usagecleanuptask_query.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskQuery is the builder for querying UsageCleanupTask entities.
type
UsageCleanupTaskQuery
struct
{
config
ctx
*
QueryContext
order
[]
usagecleanuptask
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
UsageCleanupTask
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the UsageCleanupTaskQuery builder.
func
(
_q
*
UsageCleanupTaskQuery
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
UsageCleanupTaskQuery
)
Limit
(
limit
int
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
UsageCleanupTaskQuery
)
Offset
(
offset
int
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Offset
=
&
offset
return
_q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func
(
_q
*
UsageCleanupTaskQuery
)
Unique
(
unique
bool
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
UsageCleanupTaskQuery
)
Order
(
o
...
usagecleanuptask
.
OrderOption
)
*
UsageCleanupTaskQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// First returns the first UsageCleanupTask entity from the query.
// Returns a *NotFoundError when no UsageCleanupTask was found.
func
(
_q
*
UsageCleanupTaskQuery
)
First
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
1
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirst
))
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nil
,
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first UsageCleanupTask ID from the query.
// Returns a *NotFoundError when no UsageCleanupTask ID was found.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
1
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirstID
));
err
!=
nil
{
return
}
if
len
(
ids
)
==
0
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single UsageCleanupTask entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one UsageCleanupTask entity is found.
// Returns a *NotFoundError when no UsageCleanupTask entities are found.
func
(
_q
*
UsageCleanupTaskQuery
)
Only
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
2
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnly
))
if
err
!=
nil
{
return
nil
,
err
}
switch
len
(
nodes
)
{
case
1
:
return
nodes
[
0
],
nil
case
0
:
return
nil
,
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
usagecleanuptask
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only UsageCleanupTask ID in the query.
// Returns a *NotSingularError when more than one UsageCleanupTask ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
2
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnlyID
));
err
!=
nil
{
return
}
switch
len
(
ids
)
{
case
1
:
id
=
ids
[
0
]
case
0
:
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
err
=
&
NotSingularError
{
usagecleanuptask
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
OnlyID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// All executes the query and returns a list of UsageCleanupTasks.
func
(
_q
*
UsageCleanupTaskQuery
)
All
(
ctx
context
.
Context
)
([]
*
UsageCleanupTask
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
UsageCleanupTask
,
*
UsageCleanupTaskQuery
]()
return
withInterceptors
[[]
*
UsageCleanupTask
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
UsageCleanupTask
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of UsageCleanupTask IDs.
func
(
_q
*
UsageCleanupTaskQuery
)
IDs
(
ctx
context
.
Context
)
(
ids
[]
int64
,
err
error
)
{
if
_q
.
ctx
.
Unique
==
nil
&&
_q
.
path
!=
nil
{
_q
.
Unique
(
true
)
}
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryIDs
)
if
err
=
_q
.
Select
(
usagecleanuptask
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
IDsX
(
ctx
context
.
Context
)
[]
int64
{
ids
,
err
:=
_q
.
IDs
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
ids
}
// Count returns the count of the given query.
func
(
_q
*
UsageCleanupTaskQuery
)
Count
(
ctx
context
.
Context
)
(
int
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryCount
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
0
,
err
}
return
withInterceptors
[
int
](
ctx
,
_q
,
querierCount
[
*
UsageCleanupTaskQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
CountX
(
ctx
context
.
Context
)
int
{
count
,
err
:=
_q
.
Count
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
count
}
// Exist returns true if the query has elements in the graph.
func
(
_q
*
UsageCleanupTaskQuery
)
Exist
(
ctx
context
.
Context
)
(
bool
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryExist
)
switch
_
,
err
:=
_q
.
FirstID
(
ctx
);
{
case
IsNotFound
(
err
)
:
return
false
,
nil
case
err
!=
nil
:
return
false
,
fmt
.
Errorf
(
"ent: check existence: %w"
,
err
)
default
:
return
true
,
nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the UsageCleanupTaskQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func
(
_q
*
UsageCleanupTaskQuery
)
Clone
()
*
UsageCleanupTaskQuery
{
if
_q
==
nil
{
return
nil
}
return
&
UsageCleanupTaskQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
usagecleanuptask
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
UsageCleanupTask
{},
_q
.
predicates
...
),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.UsageCleanupTask.Query().
// GroupBy(usagecleanuptask.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
UsageCleanupTaskQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
UsageCleanupTaskGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
UsageCleanupTaskGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
usagecleanuptask
.
Label
grbuild
.
scan
=
grbuild
.
Scan
return
grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// }
//
// client.UsageCleanupTask.Query().
// Select(usagecleanuptask.FieldCreatedAt).
// Scan(ctx, &v)
func
(
_q
*
UsageCleanupTaskQuery
)
Select
(
fields
...
string
)
*
UsageCleanupTaskSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
UsageCleanupTaskSelect
{
UsageCleanupTaskQuery
:
_q
}
sbuild
.
label
=
usagecleanuptask
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a UsageCleanupTaskSelect configured with the given aggregations.
func
(
_q
*
UsageCleanupTaskQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
UsageCleanupTaskQuery
)
prepareQuery
(
ctx
context
.
Context
)
error
{
for
_
,
inter
:=
range
_q
.
inters
{
if
inter
==
nil
{
return
fmt
.
Errorf
(
"ent: uninitialized interceptor (forgotten import ent/runtime?)"
)
}
if
trv
,
ok
:=
inter
.
(
Traverser
);
ok
{
if
err
:=
trv
.
Traverse
(
ctx
,
_q
);
err
!=
nil
{
return
err
}
}
}
for
_
,
f
:=
range
_q
.
ctx
.
Fields
{
if
!
usagecleanuptask
.
ValidColumn
(
f
)
{
return
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
}
if
_q
.
path
!=
nil
{
prev
,
err
:=
_q
.
path
(
ctx
)
if
err
!=
nil
{
return
err
}
_q
.
sql
=
prev
}
return
nil
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
UsageCleanupTask
,
error
)
{
var
(
nodes
=
[]
*
UsageCleanupTask
{}
_spec
=
_q
.
querySpec
()
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
UsageCleanupTask
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
UsageCleanupTask
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
if
err
:=
sqlgraph
.
QueryNodes
(
ctx
,
_q
.
driver
,
_spec
);
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nodes
,
nil
}
return
nodes
,
nil
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
}
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
}
func
(
_q
*
UsageCleanupTaskQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
_spec
.
From
=
_q
.
sql
if
unique
:=
_q
.
ctx
.
Unique
;
unique
!=
nil
{
_spec
.
Unique
=
*
unique
}
else
if
_q
.
path
!=
nil
{
_spec
.
Unique
=
true
}
if
fields
:=
_q
.
ctx
.
Fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
usagecleanuptask
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
usagecleanuptask
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
}
if
ps
:=
_q
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
_spec
.
Limit
=
*
limit
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
_spec
.
Offset
=
*
offset
}
if
ps
:=
_q
.
order
;
len
(
ps
)
>
0
{
_spec
.
Order
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
return
_spec
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
usagecleanuptask
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
usagecleanuptask
.
Columns
}
selector
:=
builder
.
Select
(
t1
.
Columns
(
columns
...
)
...
)
.
From
(
t1
)
if
_q
.
sql
!=
nil
{
selector
=
_q
.
sql
selector
.
Select
(
selector
.
Columns
(
columns
...
)
...
)
}
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
for
_
,
p
:=
range
_q
.
order
{
p
(
selector
)
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector
.
Offset
(
*
offset
)
.
Limit
(
math
.
MaxInt32
)
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
selector
.
Limit
(
*
limit
)
}
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
UsageCleanupTaskQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
UsageCleanupTaskQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
UsageCleanupTaskQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
UsageCleanupTaskQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// UsageCleanupTaskGroupBy is the group-by builder for UsageCleanupTask entities.
type
UsageCleanupTaskGroupBy
struct
{
selector
build
*
UsageCleanupTaskQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
UsageCleanupTaskGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
UsageCleanupTaskGroupBy
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_g
.
build
.
ctx
,
ent
.
OpQueryGroupBy
)
if
err
:=
_g
.
build
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
UsageCleanupTaskQuery
,
*
UsageCleanupTaskGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
UsageCleanupTaskGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
UsageCleanupTaskQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
.
Select
()
aggregation
:=
make
([]
string
,
0
,
len
(
_g
.
fns
))
for
_
,
fn
:=
range
_g
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
if
len
(
selector
.
SelectedColumns
())
==
0
{
columns
:=
make
([]
string
,
0
,
len
(
*
_g
.
flds
)
+
len
(
_g
.
fns
))
for
_
,
f
:=
range
*
_g
.
flds
{
columns
=
append
(
columns
,
selector
.
C
(
f
))
}
columns
=
append
(
columns
,
aggregation
...
)
selector
.
Select
(
columns
...
)
}
selector
.
GroupBy
(
selector
.
Columns
(
*
_g
.
flds
...
)
...
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
err
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_g
.
build
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
// UsageCleanupTaskSelect is the builder for selecting fields of UsageCleanupTask entities.
type
UsageCleanupTaskSelect
struct
{
*
UsageCleanupTaskQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
UsageCleanupTaskSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
UsageCleanupTaskSelect
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_s
.
ctx
,
ent
.
OpQuerySelect
)
if
err
:=
_s
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
UsageCleanupTaskQuery
,
*
UsageCleanupTaskSelect
](
ctx
,
_s
.
UsageCleanupTaskQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
UsageCleanupTaskSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
UsageCleanupTaskQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
aggregation
:=
make
([]
string
,
0
,
len
(
_s
.
fns
))
for
_
,
fn
:=
range
_s
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
switch
n
:=
len
(
*
_s
.
selector
.
flds
);
{
case
n
==
0
&&
len
(
aggregation
)
>
0
:
selector
.
Select
(
aggregation
...
)
case
n
!=
0
&&
len
(
aggregation
)
>
0
:
selector
.
AppendSelect
(
aggregation
...
)
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_s
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
backend/ent/usagecleanuptask_update.go
0 → 100644
View file @
0170d19f
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"encoding/json"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskUpdate is the builder for updating UsageCleanupTask entities.
type
UsageCleanupTaskUpdate
struct
{
config
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
func
(
_u
*
UsageCleanupTaskUpdate
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// SetStatus sets the "status" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetStatus
(
v
)
return
_u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableStatus
(
v
*
string
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetStatus
(
*
v
)
}
return
_u
}
// SetFilters sets the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetFilters
(
v
)
return
_u
}
// AppendFilters appends value to the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AppendFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AppendFilters
(
v
)
return
_u
}
// SetCreatedBy sets the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ResetCreatedBy
()
_u
.
mutation
.
SetCreatedBy
(
v
)
return
_u
}
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableCreatedBy
(
v
*
int64
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetCreatedBy
(
*
v
)
}
return
_u
}
// AddCreatedBy adds value to the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AddCreatedBy
(
v
)
return
_u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ResetDeletedRows
()
_u
.
mutation
.
SetDeletedRows
(
v
)
return
_u
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetDeletedRows
(
*
v
)
}
return
_u
}
// AddDeletedRows adds value to the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AddDeletedRows
(
v
)
return
_u
}
// SetErrorMessage sets the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetErrorMessage
(
v
)
return
_u
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetErrorMessage
(
*
v
)
}
return
_u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearErrorMessage
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearErrorMessage
()
return
_u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ResetCanceledBy
()
_u
.
mutation
.
SetCanceledBy
(
v
)
return
_u
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetCanceledBy
(
*
v
)
}
return
_u
}
// AddCanceledBy adds value to the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AddCanceledBy
(
v
)
return
_u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearCanceledBy
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearCanceledBy
()
return
_u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetCanceledAt
(
v
)
return
_u
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetCanceledAt
(
*
v
)
}
return
_u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearCanceledAt
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearCanceledAt
()
return
_u
}
// SetStartedAt sets the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetStartedAt
(
v
)
return
_u
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetStartedAt
(
*
v
)
}
return
_u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearStartedAt
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearStartedAt
()
return
_u
}
// SetFinishedAt sets the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetFinishedAt
(
v
)
return
_u
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetFinishedAt
(
*
v
)
}
return
_u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearFinishedAt
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearFinishedAt
()
return
_u
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_u
*
UsageCleanupTaskUpdate
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_u
.
mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
UsageCleanupTaskUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdate
)
SaveX
(
ctx
context
.
Context
)
int
{
affected
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
affected
}
// Exec executes the query.
func
(
_u
*
UsageCleanupTaskUpdate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_u
*
UsageCleanupTaskUpdate
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
UsageCleanupTaskUpdate
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
UsageCleanupTaskUpdate
)
sqlSave
(
ctx
context
.
Context
)
(
_node
int
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_u
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedFilters
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
usagecleanuptask
.
FieldFilters
,
value
)
})
}
if
value
,
ok
:=
_u
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCreatedBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedDeletedRows
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
ErrorMessageCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCanceledBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
_u
.
mutation
.
CanceledByCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
CanceledAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
StartedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
FinishedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
)
}
if
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
0
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
// UsageCleanupTaskUpdateOne is the builder for updating a single UsageCleanupTask entity.
type
UsageCleanupTaskUpdateOne
struct
{
config
fields
[]
string
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// SetStatus sets the "status" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetStatus
(
v
)
return
_u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableStatus
(
v
*
string
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetStatus
(
*
v
)
}
return
_u
}
// SetFilters sets the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetFilters
(
v
)
return
_u
}
// AppendFilters appends value to the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AppendFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AppendFilters
(
v
)
return
_u
}
// SetCreatedBy sets the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ResetCreatedBy
()
_u
.
mutation
.
SetCreatedBy
(
v
)
return
_u
}
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableCreatedBy
(
v
*
int64
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetCreatedBy
(
*
v
)
}
return
_u
}
// AddCreatedBy adds value to the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AddCreatedBy
(
v
)
return
_u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ResetDeletedRows
()
_u
.
mutation
.
SetDeletedRows
(
v
)
return
_u
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetDeletedRows
(
*
v
)
}
return
_u
}
// AddDeletedRows adds value to the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AddDeletedRows
(
v
)
return
_u
}
// SetErrorMessage sets the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetErrorMessage
(
v
)
return
_u
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetErrorMessage
(
*
v
)
}
return
_u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearErrorMessage
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearErrorMessage
()
return
_u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ResetCanceledBy
()
_u
.
mutation
.
SetCanceledBy
(
v
)
return
_u
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetCanceledBy
(
*
v
)
}
return
_u
}
// AddCanceledBy adds value to the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AddCanceledBy
(
v
)
return
_u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearCanceledBy
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearCanceledBy
()
return
_u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetCanceledAt
(
v
)
return
_u
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetCanceledAt
(
*
v
)
}
return
_u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearCanceledAt
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearCanceledAt
()
return
_u
}
// SetStartedAt sets the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetStartedAt
(
v
)
return
_u
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetStartedAt
(
*
v
)
}
return
_u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearStartedAt
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearStartedAt
()
return
_u
}
// SetFinishedAt sets the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetFinishedAt
(
v
)
return
_u
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetFinishedAt
(
*
v
)
}
return
_u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearFinishedAt
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearFinishedAt
()
return
_u
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_u
.
mutation
}
// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Select
(
field
string
,
fields
...
string
)
*
UsageCleanupTaskUpdateOne
{
_u
.
fields
=
append
([]
string
{
field
},
fields
...
)
return
_u
}
// Save executes the query and returns the updated UsageCleanupTask entity.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Save
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SaveX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// Exec executes the query on the entity.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
UsageCleanupTaskUpdateOne
)
sqlSave
(
ctx
context
.
Context
)
(
_node
*
UsageCleanupTask
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
id
,
ok
:=
_u
.
mutation
.
ID
()
if
!
ok
{
return
nil
,
&
ValidationError
{
Name
:
"id"
,
err
:
errors
.
New
(
`ent: missing "UsageCleanupTask.id" for update`
)}
}
_spec
.
Node
.
ID
.
Value
=
id
if
fields
:=
_u
.
fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
usagecleanuptask
.
FieldID
)
for
_
,
f
:=
range
fields
{
if
!
usagecleanuptask
.
ValidColumn
(
f
)
{
return
nil
,
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
if
f
!=
usagecleanuptask
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
f
)
}
}
}
if
ps
:=
_u
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedFilters
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
usagecleanuptask
.
FieldFilters
,
value
)
})
}
if
value
,
ok
:=
_u
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCreatedBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedDeletedRows
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
ErrorMessageCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCanceledBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
_u
.
mutation
.
CanceledByCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
CanceledAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
StartedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
FinishedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
)
}
_node
=
&
UsageCleanupTask
{
config
:
_u
.
config
}
_spec
.
Assign
=
_node
.
assignValues
_spec
.
ScanValues
=
_node
.
scanValues
if
err
=
sqlgraph
.
UpdateNode
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
backend/ent/user.go
View file @
0170d19f
...
...
@@ -39,6 +39,12 @@ type User struct {
Username
string
`json:"username,omitempty"`
// Notes holds the value of the "notes" field.
Notes
string
`json:"notes,omitempty"`
// TotpSecretEncrypted holds the value of the "totp_secret_encrypted" field.
TotpSecretEncrypted
*
string
`json:"totp_secret_encrypted,omitempty"`
// TotpEnabled holds the value of the "totp_enabled" field.
TotpEnabled
bool
`json:"totp_enabled,omitempty"`
// TotpEnabledAt holds the value of the "totp_enabled_at" field.
TotpEnabledAt
*
time
.
Time
`json:"totp_enabled_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UserQuery when eager-loading is set.
Edges
UserEdges
`json:"edges"`
...
...
@@ -55,6 +61,8 @@ type UserEdges struct {
Subscriptions
[]
*
UserSubscription
`json:"subscriptions,omitempty"`
// AssignedSubscriptions holds the value of the assigned_subscriptions edge.
AssignedSubscriptions
[]
*
UserSubscription
`json:"assigned_subscriptions,omitempty"`
// AnnouncementReads holds the value of the announcement_reads edge.
AnnouncementReads
[]
*
AnnouncementRead
`json:"announcement_reads,omitempty"`
// AllowedGroups holds the value of the allowed_groups edge.
AllowedGroups
[]
*
Group
`json:"allowed_groups,omitempty"`
// UsageLogs holds the value of the usage_logs edge.
...
...
@@ -67,7 +75,7 @@ type UserEdges struct {
UserAllowedGroups
[]
*
UserAllowedGroup
`json:"user_allowed_groups,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes
[
9
]
bool
loadedTypes
[
10
]
bool
}
// APIKeysOrErr returns the APIKeys value or an error if the edge
...
...
@@ -106,10 +114,19 @@ func (e UserEdges) AssignedSubscriptionsOrErr() ([]*UserSubscription, error) {
return
nil
,
&
NotLoadedError
{
edge
:
"assigned_subscriptions"
}
}
// AnnouncementReadsOrErr returns the AnnouncementReads value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
AnnouncementReadsOrErr
()
([]
*
AnnouncementRead
,
error
)
{
if
e
.
loadedTypes
[
4
]
{
return
e
.
AnnouncementReads
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"announcement_reads"
}
}
// AllowedGroupsOrErr returns the AllowedGroups value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
AllowedGroupsOrErr
()
([]
*
Group
,
error
)
{
if
e
.
loadedTypes
[
4
]
{
if
e
.
loadedTypes
[
5
]
{
return
e
.
AllowedGroups
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"allowed_groups"
}
...
...
@@ -118,7 +135,7 @@ func (e UserEdges) AllowedGroupsOrErr() ([]*Group, error) {
// UsageLogsOrErr returns the UsageLogs value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
UsageLogsOrErr
()
([]
*
UsageLog
,
error
)
{
if
e
.
loadedTypes
[
5
]
{
if
e
.
loadedTypes
[
6
]
{
return
e
.
UsageLogs
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"usage_logs"
}
...
...
@@ -127,7 +144,7 @@ func (e UserEdges) UsageLogsOrErr() ([]*UsageLog, error) {
// AttributeValuesOrErr returns the AttributeValues value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
AttributeValuesOrErr
()
([]
*
UserAttributeValue
,
error
)
{
if
e
.
loadedTypes
[
6
]
{
if
e
.
loadedTypes
[
7
]
{
return
e
.
AttributeValues
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"attribute_values"
}
...
...
@@ -136,7 +153,7 @@ func (e UserEdges) AttributeValuesOrErr() ([]*UserAttributeValue, error) {
// PromoCodeUsagesOrErr returns the PromoCodeUsages value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
PromoCodeUsagesOrErr
()
([]
*
PromoCodeUsage
,
error
)
{
if
e
.
loadedTypes
[
7
]
{
if
e
.
loadedTypes
[
8
]
{
return
e
.
PromoCodeUsages
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"promo_code_usages"
}
...
...
@@ -145,7 +162,7 @@ func (e UserEdges) PromoCodeUsagesOrErr() ([]*PromoCodeUsage, error) {
// UserAllowedGroupsOrErr returns the UserAllowedGroups value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
UserAllowedGroupsOrErr
()
([]
*
UserAllowedGroup
,
error
)
{
if
e
.
loadedTypes
[
8
]
{
if
e
.
loadedTypes
[
9
]
{
return
e
.
UserAllowedGroups
,
nil
}
return
nil
,
&
NotLoadedError
{
edge
:
"user_allowed_groups"
}
...
...
@@ -156,13 +173,15 @@ func (*User) scanValues(columns []string) ([]any, error) {
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
user
.
FieldTotpEnabled
:
values
[
i
]
=
new
(
sql
.
NullBool
)
case
user
.
FieldBalance
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
user
.
FieldID
,
user
.
FieldConcurrency
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldNotes
:
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldNotes
,
user
.
FieldTotpSecretEncrypted
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
user
.
FieldCreatedAt
,
user
.
FieldUpdatedAt
,
user
.
FieldDeletedAt
:
case
user
.
FieldCreatedAt
,
user
.
FieldUpdatedAt
,
user
.
FieldDeletedAt
,
user
.
FieldTotpEnabledAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
default
:
values
[
i
]
=
new
(
sql
.
UnknownType
)
...
...
@@ -252,6 +271,26 @@ func (_m *User) assignValues(columns []string, values []any) error {
}
else
if
value
.
Valid
{
_m
.
Notes
=
value
.
String
}
case
user
.
FieldTotpSecretEncrypted
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field totp_secret_encrypted"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
TotpSecretEncrypted
=
new
(
string
)
*
_m
.
TotpSecretEncrypted
=
value
.
String
}
case
user
.
FieldTotpEnabled
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullBool
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field totp_enabled"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
TotpEnabled
=
value
.
Bool
}
case
user
.
FieldTotpEnabledAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field totp_enabled_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
TotpEnabledAt
=
new
(
time
.
Time
)
*
_m
.
TotpEnabledAt
=
value
.
Time
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
...
...
@@ -285,6 +324,11 @@ func (_m *User) QueryAssignedSubscriptions() *UserSubscriptionQuery {
return
NewUserClient
(
_m
.
config
)
.
QueryAssignedSubscriptions
(
_m
)
}
// QueryAnnouncementReads queries the "announcement_reads" edge of the User entity.
func
(
_m
*
User
)
QueryAnnouncementReads
()
*
AnnouncementReadQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryAnnouncementReads
(
_m
)
}
// QueryAllowedGroups queries the "allowed_groups" edge of the User entity.
func
(
_m
*
User
)
QueryAllowedGroups
()
*
GroupQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryAllowedGroups
(
_m
)
...
...
@@ -367,6 +411,19 @@ func (_m *User) String() string {
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"notes="
)
builder
.
WriteString
(
_m
.
Notes
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
TotpSecretEncrypted
;
v
!=
nil
{
builder
.
WriteString
(
"totp_secret_encrypted="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"totp_enabled="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
TotpEnabled
))
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
TotpEnabledAt
;
v
!=
nil
{
builder
.
WriteString
(
"totp_enabled_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
...
...
backend/ent/user/user.go
View file @
0170d19f
...
...
@@ -37,6 +37,12 @@ const (
FieldUsername
=
"username"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes
=
"notes"
// FieldTotpSecretEncrypted holds the string denoting the totp_secret_encrypted field in the database.
FieldTotpSecretEncrypted
=
"totp_secret_encrypted"
// FieldTotpEnabled holds the string denoting the totp_enabled field in the database.
FieldTotpEnabled
=
"totp_enabled"
// FieldTotpEnabledAt holds the string denoting the totp_enabled_at field in the database.
FieldTotpEnabledAt
=
"totp_enabled_at"
// 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.
...
...
@@ -45,6 +51,8 @@ const (
EdgeSubscriptions
=
"subscriptions"
// EdgeAssignedSubscriptions holds the string denoting the assigned_subscriptions edge name in mutations.
EdgeAssignedSubscriptions
=
"assigned_subscriptions"
// EdgeAnnouncementReads holds the string denoting the announcement_reads edge name in mutations.
EdgeAnnouncementReads
=
"announcement_reads"
// EdgeAllowedGroups holds the string denoting the allowed_groups edge name in mutations.
EdgeAllowedGroups
=
"allowed_groups"
// EdgeUsageLogs holds the string denoting the usage_logs edge name in mutations.
...
...
@@ -85,6 +93,13 @@ const (
AssignedSubscriptionsInverseTable
=
"user_subscriptions"
// AssignedSubscriptionsColumn is the table column denoting the assigned_subscriptions relation/edge.
AssignedSubscriptionsColumn
=
"assigned_by"
// AnnouncementReadsTable is the table that holds the announcement_reads relation/edge.
AnnouncementReadsTable
=
"announcement_reads"
// AnnouncementReadsInverseTable is the table name for the AnnouncementRead entity.
// It exists in this package in order to avoid circular dependency with the "announcementread" package.
AnnouncementReadsInverseTable
=
"announcement_reads"
// AnnouncementReadsColumn is the table column denoting the announcement_reads relation/edge.
AnnouncementReadsColumn
=
"user_id"
// AllowedGroupsTable is the table that holds the allowed_groups relation/edge. The primary key declared below.
AllowedGroupsTable
=
"user_allowed_groups"
// AllowedGroupsInverseTable is the table name for the Group entity.
...
...
@@ -134,6 +149,9 @@ var Columns = []string{
FieldStatus
,
FieldUsername
,
FieldNotes
,
FieldTotpSecretEncrypted
,
FieldTotpEnabled
,
FieldTotpEnabledAt
,
}
var
(
...
...
@@ -188,6 +206,8 @@ var (
UsernameValidator
func
(
string
)
error
// DefaultNotes holds the default value on creation for the "notes" field.
DefaultNotes
string
// DefaultTotpEnabled holds the default value on creation for the "totp_enabled" field.
DefaultTotpEnabled
bool
)
// OrderOption defines the ordering options for the User queries.
...
...
@@ -253,6 +273,21 @@ func ByNotes(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldNotes
,
opts
...
)
.
ToFunc
()
}
// ByTotpSecretEncrypted orders the results by the totp_secret_encrypted field.
func
ByTotpSecretEncrypted
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldTotpSecretEncrypted
,
opts
...
)
.
ToFunc
()
}
// ByTotpEnabled orders the results by the totp_enabled field.
func
ByTotpEnabled
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldTotpEnabled
,
opts
...
)
.
ToFunc
()
}
// ByTotpEnabledAt orders the results by the totp_enabled_at field.
func
ByTotpEnabledAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldTotpEnabledAt
,
opts
...
)
.
ToFunc
()
}
// ByAPIKeysCount orders the results by api_keys count.
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
@@ -309,6 +344,20 @@ func ByAssignedSubscriptions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOp
}
}
// ByAnnouncementReadsCount orders the results by announcement_reads count.
func
ByAnnouncementReadsCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborsCount
(
s
,
newAnnouncementReadsStep
(),
opts
...
)
}
}
// ByAnnouncementReads orders the results by announcement_reads terms.
func
ByAnnouncementReads
(
term
sql
.
OrderTerm
,
terms
...
sql
.
OrderTerm
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
sqlgraph
.
OrderByNeighborTerms
(
s
,
newAnnouncementReadsStep
(),
append
([]
sql
.
OrderTerm
{
term
},
terms
...
)
...
)
}
}
// ByAllowedGroupsCount orders the results by allowed_groups count.
func
ByAllowedGroupsCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
@@ -406,6 +455,13 @@ func newAssignedSubscriptionsStep() *sqlgraph.Step {
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
AssignedSubscriptionsTable
,
AssignedSubscriptionsColumn
),
)
}
func
newAnnouncementReadsStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
To
(
AnnouncementReadsInverseTable
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
AnnouncementReadsTable
,
AnnouncementReadsColumn
),
)
}
func
newAllowedGroupsStep
()
*
sqlgraph
.
Step
{
return
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
...
...
backend/ent/user/where.go
View file @
0170d19f
...
...
@@ -110,6 +110,21 @@ func Notes(v string) predicate.User {
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
}
// TotpSecretEncrypted applies equality check predicate on the "totp_secret_encrypted" field. It's identical to TotpSecretEncryptedEQ.
func
TotpSecretEncrypted
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpEnabled applies equality check predicate on the "totp_enabled" field. It's identical to TotpEnabledEQ.
func
TotpEnabled
(
v
bool
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabled
,
v
))
}
// TotpEnabledAt applies equality check predicate on the "totp_enabled_at" field. It's identical to TotpEnabledAtEQ.
func
TotpEnabledAt
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabledAt
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
...
...
@@ -710,6 +725,141 @@ func NotesContainsFold(v string) predicate.User {
return
predicate
.
User
(
sql
.
FieldContainsFold
(
FieldNotes
,
v
))
}
// TotpSecretEncryptedEQ applies the EQ predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedNEQ applies the NEQ predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedNEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedIn applies the In predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedIn
(
vs
...
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIn
(
FieldTotpSecretEncrypted
,
vs
...
))
}
// TotpSecretEncryptedNotIn applies the NotIn predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedNotIn
(
vs
...
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotIn
(
FieldTotpSecretEncrypted
,
vs
...
))
}
// TotpSecretEncryptedGT applies the GT predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedGT
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGT
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedGTE applies the GTE predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedGTE
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGTE
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedLT applies the LT predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedLT
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLT
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedLTE applies the LTE predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedLTE
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedContains applies the Contains predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedContains
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldContains
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedHasPrefix applies the HasPrefix predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedHasPrefix
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldHasPrefix
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedHasSuffix applies the HasSuffix predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedHasSuffix
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldHasSuffix
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedIsNil applies the IsNil predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedIsNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIsNull
(
FieldTotpSecretEncrypted
))
}
// TotpSecretEncryptedNotNil applies the NotNil predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedNotNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotNull
(
FieldTotpSecretEncrypted
))
}
// TotpSecretEncryptedEqualFold applies the EqualFold predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedEqualFold
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEqualFold
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedContainsFold applies the ContainsFold predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedContainsFold
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldContainsFold
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpEnabledEQ applies the EQ predicate on the "totp_enabled" field.
func
TotpEnabledEQ
(
v
bool
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabled
,
v
))
}
// TotpEnabledNEQ applies the NEQ predicate on the "totp_enabled" field.
func
TotpEnabledNEQ
(
v
bool
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldTotpEnabled
,
v
))
}
// TotpEnabledAtEQ applies the EQ predicate on the "totp_enabled_at" field.
func
TotpEnabledAtEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtNEQ applies the NEQ predicate on the "totp_enabled_at" field.
func
TotpEnabledAtNEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtIn applies the In predicate on the "totp_enabled_at" field.
func
TotpEnabledAtIn
(
vs
...
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIn
(
FieldTotpEnabledAt
,
vs
...
))
}
// TotpEnabledAtNotIn applies the NotIn predicate on the "totp_enabled_at" field.
func
TotpEnabledAtNotIn
(
vs
...
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotIn
(
FieldTotpEnabledAt
,
vs
...
))
}
// TotpEnabledAtGT applies the GT predicate on the "totp_enabled_at" field.
func
TotpEnabledAtGT
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGT
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtGTE applies the GTE predicate on the "totp_enabled_at" field.
func
TotpEnabledAtGTE
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGTE
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtLT applies the LT predicate on the "totp_enabled_at" field.
func
TotpEnabledAtLT
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLT
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtLTE applies the LTE predicate on the "totp_enabled_at" field.
func
TotpEnabledAtLTE
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtIsNil applies the IsNil predicate on the "totp_enabled_at" field.
func
TotpEnabledAtIsNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIsNull
(
FieldTotpEnabledAt
))
}
// TotpEnabledAtNotNil applies the NotNil predicate on the "totp_enabled_at" field.
func
TotpEnabledAtNotNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotNull
(
FieldTotpEnabledAt
))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func
HasAPIKeys
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
...
...
@@ -802,6 +952,29 @@ func HasAssignedSubscriptionsWith(preds ...predicate.UserSubscription) predicate
})
}
// HasAnnouncementReads applies the HasEdge predicate on the "announcement_reads" edge.
func
HasAnnouncementReads
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
Table
,
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
AnnouncementReadsTable
,
AnnouncementReadsColumn
),
)
sqlgraph
.
HasNeighbors
(
s
,
step
)
})
}
// HasAnnouncementReadsWith applies the HasEdge predicate on the "announcement_reads" edge with a given conditions (other predicates).
func
HasAnnouncementReadsWith
(
preds
...
predicate
.
AnnouncementRead
)
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newAnnouncementReadsStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
for
_
,
p
:=
range
preds
{
p
(
s
)
}
})
})
}
// HasAllowedGroups applies the HasEdge predicate on the "allowed_groups" edge.
func
HasAllowedGroups
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user_create.go
View file @
0170d19f
...
...
@@ -11,6 +11,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
...
...
@@ -167,6 +168,48 @@ func (_c *UserCreate) SetNillableNotes(v *string) *UserCreate {
return
_c
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
_c
*
UserCreate
)
SetTotpSecretEncrypted
(
v
string
)
*
UserCreate
{
_c
.
mutation
.
SetTotpSecretEncrypted
(
v
)
return
_c
}
// SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableTotpSecretEncrypted
(
v
*
string
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetTotpSecretEncrypted
(
*
v
)
}
return
_c
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
_c
*
UserCreate
)
SetTotpEnabled
(
v
bool
)
*
UserCreate
{
_c
.
mutation
.
SetTotpEnabled
(
v
)
return
_c
}
// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableTotpEnabled
(
v
*
bool
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetTotpEnabled
(
*
v
)
}
return
_c
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
_c
*
UserCreate
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserCreate
{
_c
.
mutation
.
SetTotpEnabledAt
(
v
)
return
_c
}
// SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableTotpEnabledAt
(
v
*
time
.
Time
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetTotpEnabledAt
(
*
v
)
}
return
_c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_c
*
UserCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -227,6 +270,21 @@ func (_c *UserCreate) AddAssignedSubscriptions(v ...*UserSubscription) *UserCrea
return
_c
.
AddAssignedSubscriptionIDs
(
ids
...
)
}
// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
func
(
_c
*
UserCreate
)
AddAnnouncementReadIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddAnnouncementReadIDs
(
ids
...
)
return
_c
}
// AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
func
(
_c
*
UserCreate
)
AddAnnouncementReads
(
v
...*
AnnouncementRead
)
*
UserCreate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_c
.
AddAnnouncementReadIDs
(
ids
...
)
}
// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
func
(
_c
*
UserCreate
)
AddAllowedGroupIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddAllowedGroupIDs
(
ids
...
)
...
...
@@ -362,6 +420,10 @@ func (_c *UserCreate) defaults() error {
v
:=
user
.
DefaultNotes
_c
.
mutation
.
SetNotes
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
TotpEnabled
();
!
ok
{
v
:=
user
.
DefaultTotpEnabled
_c
.
mutation
.
SetTotpEnabled
(
v
)
}
return
nil
}
...
...
@@ -422,6 +484,9 @@ func (_c *UserCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
Notes
();
!
ok
{
return
&
ValidationError
{
Name
:
"notes"
,
err
:
errors
.
New
(
`ent: missing required field "User.notes"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
TotpEnabled
();
!
ok
{
return
&
ValidationError
{
Name
:
"totp_enabled"
,
err
:
errors
.
New
(
`ent: missing required field "User.totp_enabled"`
)}
}
return
nil
}
...
...
@@ -493,6 +558,18 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
_node
.
Notes
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
TotpSecretEncrypted
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
,
value
)
_node
.
TotpSecretEncrypted
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
TotpEnabled
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabled
,
field
.
TypeBool
,
value
)
_node
.
TotpEnabled
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
TotpEnabledAt
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
,
value
)
_node
.
TotpEnabledAt
=
&
value
}
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -557,6 +634,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
if
nodes
:=
_c
.
mutation
.
AnnouncementReadsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
=
append
(
_spec
.
Edges
,
edge
)
}
if
nodes
:=
_c
.
mutation
.
AllowedGroupsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2M
,
...
...
@@ -815,6 +908,54 @@ func (u *UserUpsert) UpdateNotes() *UserUpsert {
return
u
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
u
*
UserUpsert
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldTotpSecretEncrypted
,
v
)
return
u
}
// UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateTotpSecretEncrypted
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldTotpSecretEncrypted
)
return
u
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
u
*
UserUpsert
)
ClearTotpSecretEncrypted
()
*
UserUpsert
{
u
.
SetNull
(
user
.
FieldTotpSecretEncrypted
)
return
u
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
u
*
UserUpsert
)
SetTotpEnabled
(
v
bool
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldTotpEnabled
,
v
)
return
u
}
// UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateTotpEnabled
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldTotpEnabled
)
return
u
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
u
*
UserUpsert
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldTotpEnabledAt
,
v
)
return
u
}
// UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateTotpEnabledAt
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldTotpEnabledAt
)
return
u
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
u
*
UserUpsert
)
ClearTotpEnabledAt
()
*
UserUpsert
{
u
.
SetNull
(
user
.
FieldTotpEnabledAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
...
...
@@ -1021,6 +1162,62 @@ func (u *UserUpsertOne) UpdateNotes() *UserUpsertOne {
})
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertOne
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpSecretEncrypted
(
v
)
})
}
// UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateTotpSecretEncrypted
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpSecretEncrypted
()
})
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertOne
)
ClearTotpSecretEncrypted
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpSecretEncrypted
()
})
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
u
*
UserUpsertOne
)
SetTotpEnabled
(
v
bool
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabled
(
v
)
})
}
// UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateTotpEnabled
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabled
()
})
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
u
*
UserUpsertOne
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabledAt
(
v
)
})
}
// UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateTotpEnabledAt
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabledAt
()
})
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
u
*
UserUpsertOne
)
ClearTotpEnabledAt
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpEnabledAt
()
})
}
// Exec executes the query.
func
(
u
*
UserUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
...
...
@@ -1393,6 +1590,62 @@ func (u *UserUpsertBulk) UpdateNotes() *UserUpsertBulk {
})
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertBulk
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpSecretEncrypted
(
v
)
})
}
// UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateTotpSecretEncrypted
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpSecretEncrypted
()
})
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertBulk
)
ClearTotpSecretEncrypted
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpSecretEncrypted
()
})
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
u
*
UserUpsertBulk
)
SetTotpEnabled
(
v
bool
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabled
(
v
)
})
}
// UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateTotpEnabled
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabled
()
})
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
u
*
UserUpsertBulk
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabledAt
(
v
)
})
}
// UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateTotpEnabledAt
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabledAt
()
})
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
u
*
UserUpsertBulk
)
ClearTotpEnabledAt
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpEnabledAt
()
})
}
// Exec executes the query.
func
(
u
*
UserUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
...
...
backend/ent/user_query.go
View file @
0170d19f
...
...
@@ -13,6 +13,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
...
...
@@ -36,6 +37,7 @@ type UserQuery struct {
withRedeemCodes
*
RedeemCodeQuery
withSubscriptions
*
UserSubscriptionQuery
withAssignedSubscriptions
*
UserSubscriptionQuery
withAnnouncementReads
*
AnnouncementReadQuery
withAllowedGroups
*
GroupQuery
withUsageLogs
*
UsageLogQuery
withAttributeValues
*
UserAttributeValueQuery
...
...
@@ -166,6 +168,28 @@ func (_q *UserQuery) QueryAssignedSubscriptions() *UserSubscriptionQuery {
return
query
}
// QueryAnnouncementReads chains the current query on the "announcement_reads" edge.
func
(
_q
*
UserQuery
)
QueryAnnouncementReads
()
*
AnnouncementReadQuery
{
query
:=
(
&
AnnouncementReadClient
{
config
:
_q
.
config
})
.
Query
()
query
.
path
=
func
(
ctx
context
.
Context
)
(
fromU
*
sql
.
Selector
,
err
error
)
{
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
selector
:=
_q
.
sqlQuery
(
ctx
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
nil
,
err
}
step
:=
sqlgraph
.
NewStep
(
sqlgraph
.
From
(
user
.
Table
,
user
.
FieldID
,
selector
),
sqlgraph
.
To
(
announcementread
.
Table
,
announcementread
.
FieldID
),
sqlgraph
.
Edge
(
sqlgraph
.
O2M
,
false
,
user
.
AnnouncementReadsTable
,
user
.
AnnouncementReadsColumn
),
)
fromU
=
sqlgraph
.
SetNeighbors
(
_q
.
driver
.
Dialect
(),
step
)
return
fromU
,
nil
}
return
query
}
// QueryAllowedGroups chains the current query on the "allowed_groups" edge.
func
(
_q
*
UserQuery
)
QueryAllowedGroups
()
*
GroupQuery
{
query
:=
(
&
GroupClient
{
config
:
_q
.
config
})
.
Query
()
...
...
@@ -472,6 +496,7 @@ func (_q *UserQuery) Clone() *UserQuery {
withRedeemCodes
:
_q
.
withRedeemCodes
.
Clone
(),
withSubscriptions
:
_q
.
withSubscriptions
.
Clone
(),
withAssignedSubscriptions
:
_q
.
withAssignedSubscriptions
.
Clone
(),
withAnnouncementReads
:
_q
.
withAnnouncementReads
.
Clone
(),
withAllowedGroups
:
_q
.
withAllowedGroups
.
Clone
(),
withUsageLogs
:
_q
.
withUsageLogs
.
Clone
(),
withAttributeValues
:
_q
.
withAttributeValues
.
Clone
(),
...
...
@@ -527,6 +552,17 @@ func (_q *UserQuery) WithAssignedSubscriptions(opts ...func(*UserSubscriptionQue
return
_q
}
// WithAnnouncementReads tells the query-builder to eager-load the nodes that are connected to
// the "announcement_reads" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UserQuery
)
WithAnnouncementReads
(
opts
...
func
(
*
AnnouncementReadQuery
))
*
UserQuery
{
query
:=
(
&
AnnouncementReadClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
_q
.
withAnnouncementReads
=
query
return
_q
}
// WithAllowedGroups tells the query-builder to eager-load the nodes that are connected to
// the "allowed_groups" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UserQuery
)
WithAllowedGroups
(
opts
...
func
(
*
GroupQuery
))
*
UserQuery
{
...
...
@@ -660,11 +696,12 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
var
(
nodes
=
[]
*
User
{}
_spec
=
_q
.
querySpec
()
loadedTypes
=
[
9
]
bool
{
loadedTypes
=
[
10
]
bool
{
_q
.
withAPIKeys
!=
nil
,
_q
.
withRedeemCodes
!=
nil
,
_q
.
withSubscriptions
!=
nil
,
_q
.
withAssignedSubscriptions
!=
nil
,
_q
.
withAnnouncementReads
!=
nil
,
_q
.
withAllowedGroups
!=
nil
,
_q
.
withUsageLogs
!=
nil
,
_q
.
withAttributeValues
!=
nil
,
...
...
@@ -723,6 +760,13 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
return
nil
,
err
}
}
if
query
:=
_q
.
withAnnouncementReads
;
query
!=
nil
{
if
err
:=
_q
.
loadAnnouncementReads
(
ctx
,
query
,
nodes
,
func
(
n
*
User
)
{
n
.
Edges
.
AnnouncementReads
=
[]
*
AnnouncementRead
{}
},
func
(
n
*
User
,
e
*
AnnouncementRead
)
{
n
.
Edges
.
AnnouncementReads
=
append
(
n
.
Edges
.
AnnouncementReads
,
e
)
});
err
!=
nil
{
return
nil
,
err
}
}
if
query
:=
_q
.
withAllowedGroups
;
query
!=
nil
{
if
err
:=
_q
.
loadAllowedGroups
(
ctx
,
query
,
nodes
,
func
(
n
*
User
)
{
n
.
Edges
.
AllowedGroups
=
[]
*
Group
{}
},
...
...
@@ -887,6 +931,36 @@ func (_q *UserQuery) loadAssignedSubscriptions(ctx context.Context, query *UserS
}
return
nil
}
func
(
_q
*
UserQuery
)
loadAnnouncementReads
(
ctx
context
.
Context
,
query
*
AnnouncementReadQuery
,
nodes
[]
*
User
,
init
func
(
*
User
),
assign
func
(
*
User
,
*
AnnouncementRead
))
error
{
fks
:=
make
([]
driver
.
Value
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
]
*
User
)
for
i
:=
range
nodes
{
fks
=
append
(
fks
,
nodes
[
i
]
.
ID
)
nodeids
[
nodes
[
i
]
.
ID
]
=
nodes
[
i
]
if
init
!=
nil
{
init
(
nodes
[
i
])
}
}
if
len
(
query
.
ctx
.
Fields
)
>
0
{
query
.
ctx
.
AppendFieldOnce
(
announcementread
.
FieldUserID
)
}
query
.
Where
(
predicate
.
AnnouncementRead
(
func
(
s
*
sql
.
Selector
)
{
s
.
Where
(
sql
.
InValues
(
s
.
C
(
user
.
AnnouncementReadsColumn
),
fks
...
))
}))
neighbors
,
err
:=
query
.
All
(
ctx
)
if
err
!=
nil
{
return
err
}
for
_
,
n
:=
range
neighbors
{
fk
:=
n
.
UserID
node
,
ok
:=
nodeids
[
fk
]
if
!
ok
{
return
fmt
.
Errorf
(
`unexpected referenced foreign-key "user_id" returned %v for node %v`
,
fk
,
n
.
ID
)
}
assign
(
node
,
n
)
}
return
nil
}
func
(
_q
*
UserQuery
)
loadAllowedGroups
(
ctx
context
.
Context
,
query
*
GroupQuery
,
nodes
[]
*
User
,
init
func
(
*
User
),
assign
func
(
*
User
,
*
Group
))
error
{
edgeIDs
:=
make
([]
driver
.
Value
,
len
(
nodes
))
byID
:=
make
(
map
[
int64
]
*
User
)
...
...
backend/ent/user_update.go
View file @
0170d19f
...
...
@@ -11,6 +11,7 @@ import (
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/announcementread"
"github.com/Wei-Shaw/sub2api/ent/apikey"
"github.com/Wei-Shaw/sub2api/ent/group"
"github.com/Wei-Shaw/sub2api/ent/predicate"
...
...
@@ -187,6 +188,60 @@ func (_u *UserUpdate) SetNillableNotes(v *string) *UserUpdate {
return
_u
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdate
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpdate
{
_u
.
mutation
.
SetTotpSecretEncrypted
(
v
)
return
_u
}
// SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableTotpSecretEncrypted
(
v
*
string
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetTotpSecretEncrypted
(
*
v
)
}
return
_u
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdate
)
ClearTotpSecretEncrypted
()
*
UserUpdate
{
_u
.
mutation
.
ClearTotpSecretEncrypted
()
return
_u
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
_u
*
UserUpdate
)
SetTotpEnabled
(
v
bool
)
*
UserUpdate
{
_u
.
mutation
.
SetTotpEnabled
(
v
)
return
_u
}
// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableTotpEnabled
(
v
*
bool
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetTotpEnabled
(
*
v
)
}
return
_u
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
_u
*
UserUpdate
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpdate
{
_u
.
mutation
.
SetTotpEnabledAt
(
v
)
return
_u
}
// SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableTotpEnabledAt
(
v
*
time
.
Time
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetTotpEnabledAt
(
*
v
)
}
return
_u
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
_u
*
UserUpdate
)
ClearTotpEnabledAt
()
*
UserUpdate
{
_u
.
mutation
.
ClearTotpEnabledAt
()
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
UserUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -247,6 +302,21 @@ func (_u *UserUpdate) AddAssignedSubscriptions(v ...*UserSubscription) *UserUpda
return
_u
.
AddAssignedSubscriptionIDs
(
ids
...
)
}
// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
func
(
_u
*
UserUpdate
)
AddAnnouncementReadIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddAnnouncementReadIDs
(
ids
...
)
return
_u
}
// AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
func
(
_u
*
UserUpdate
)
AddAnnouncementReads
(
v
...*
AnnouncementRead
)
*
UserUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddAnnouncementReadIDs
(
ids
...
)
}
// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
func
(
_u
*
UserUpdate
)
AddAllowedGroupIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddAllowedGroupIDs
(
ids
...
)
...
...
@@ -396,6 +466,27 @@ func (_u *UserUpdate) RemoveAssignedSubscriptions(v ...*UserSubscription) *UserU
return
_u
.
RemoveAssignedSubscriptionIDs
(
ids
...
)
}
// ClearAnnouncementReads clears all "announcement_reads" edges to the AnnouncementRead entity.
func
(
_u
*
UserUpdate
)
ClearAnnouncementReads
()
*
UserUpdate
{
_u
.
mutation
.
ClearAnnouncementReads
()
return
_u
}
// RemoveAnnouncementReadIDs removes the "announcement_reads" edge to AnnouncementRead entities by IDs.
func
(
_u
*
UserUpdate
)
RemoveAnnouncementReadIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
RemoveAnnouncementReadIDs
(
ids
...
)
return
_u
}
// RemoveAnnouncementReads removes "announcement_reads" edges to AnnouncementRead entities.
func
(
_u
*
UserUpdate
)
RemoveAnnouncementReads
(
v
...*
AnnouncementRead
)
*
UserUpdate
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemoveAnnouncementReadIDs
(
ids
...
)
}
// ClearAllowedGroups clears all "allowed_groups" edges to the Group entity.
func
(
_u
*
UserUpdate
)
ClearAllowedGroups
()
*
UserUpdate
{
_u
.
mutation
.
ClearAllowedGroups
()
...
...
@@ -603,6 +694,21 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpSecretEncrypted
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
TotpSecretEncryptedCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabled
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabled
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabledAt
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
TotpEnabledAtCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -783,6 +889,51 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
AnnouncementReadsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedAnnouncementReadsIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
AnnouncementReadsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
AnnouncementReadsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
AllowedGroupsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2M
,
...
...
@@ -1147,6 +1298,60 @@ func (_u *UserUpdateOne) SetNillableNotes(v *string) *UserUpdateOne {
return
_u
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdateOne
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpdateOne
{
_u
.
mutation
.
SetTotpSecretEncrypted
(
v
)
return
_u
}
// SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableTotpSecretEncrypted
(
v
*
string
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetTotpSecretEncrypted
(
*
v
)
}
return
_u
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdateOne
)
ClearTotpSecretEncrypted
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearTotpSecretEncrypted
()
return
_u
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
_u
*
UserUpdateOne
)
SetTotpEnabled
(
v
bool
)
*
UserUpdateOne
{
_u
.
mutation
.
SetTotpEnabled
(
v
)
return
_u
}
// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableTotpEnabled
(
v
*
bool
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetTotpEnabled
(
*
v
)
}
return
_u
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
_u
*
UserUpdateOne
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpdateOne
{
_u
.
mutation
.
SetTotpEnabledAt
(
v
)
return
_u
}
// SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableTotpEnabledAt
(
v
*
time
.
Time
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetTotpEnabledAt
(
*
v
)
}
return
_u
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
_u
*
UserUpdateOne
)
ClearTotpEnabledAt
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearTotpEnabledAt
()
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -1207,6 +1412,21 @@ func (_u *UserUpdateOne) AddAssignedSubscriptions(v ...*UserSubscription) *UserU
return
_u
.
AddAssignedSubscriptionIDs
(
ids
...
)
}
// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddAnnouncementReadIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddAnnouncementReadIDs
(
ids
...
)
return
_u
}
// AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
func
(
_u
*
UserUpdateOne
)
AddAnnouncementReads
(
v
...*
AnnouncementRead
)
*
UserUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
AddAnnouncementReadIDs
(
ids
...
)
}
// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddAllowedGroupIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddAllowedGroupIDs
(
ids
...
)
...
...
@@ -1356,6 +1576,27 @@ func (_u *UserUpdateOne) RemoveAssignedSubscriptions(v ...*UserSubscription) *Us
return
_u
.
RemoveAssignedSubscriptionIDs
(
ids
...
)
}
// ClearAnnouncementReads clears all "announcement_reads" edges to the AnnouncementRead entity.
func
(
_u
*
UserUpdateOne
)
ClearAnnouncementReads
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearAnnouncementReads
()
return
_u
}
// RemoveAnnouncementReadIDs removes the "announcement_reads" edge to AnnouncementRead entities by IDs.
func
(
_u
*
UserUpdateOne
)
RemoveAnnouncementReadIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
RemoveAnnouncementReadIDs
(
ids
...
)
return
_u
}
// RemoveAnnouncementReads removes "announcement_reads" edges to AnnouncementRead entities.
func
(
_u
*
UserUpdateOne
)
RemoveAnnouncementReads
(
v
...*
AnnouncementRead
)
*
UserUpdateOne
{
ids
:=
make
([]
int64
,
len
(
v
))
for
i
:=
range
v
{
ids
[
i
]
=
v
[
i
]
.
ID
}
return
_u
.
RemoveAnnouncementReadIDs
(
ids
...
)
}
// ClearAllowedGroups clears all "allowed_groups" edges to the Group entity.
func
(
_u
*
UserUpdateOne
)
ClearAllowedGroups
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearAllowedGroups
()
...
...
@@ -1593,6 +1834,21 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpSecretEncrypted
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
TotpSecretEncryptedCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabled
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabled
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabledAt
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
TotpEnabledAtCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1773,6 +2029,51 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
AnnouncementReadsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
RemovedAnnouncementReadsIDs
();
len
(
nodes
)
>
0
&&
!
_u
.
mutation
.
AnnouncementReadsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Clear
=
append
(
_spec
.
Edges
.
Clear
,
edge
)
}
if
nodes
:=
_u
.
mutation
.
AnnouncementReadsIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
Inverse
:
false
,
Table
:
user
.
AnnouncementReadsTable
,
Columns
:
[]
string
{
user
.
AnnouncementReadsColumn
},
Bidi
:
false
,
Target
:
&
sqlgraph
.
EdgeTarget
{
IDSpec
:
sqlgraph
.
NewFieldSpec
(
announcementread
.
FieldID
,
field
.
TypeInt64
),
},
}
for
_
,
k
:=
range
nodes
{
edge
.
Target
.
Nodes
=
append
(
edge
.
Target
.
Nodes
,
k
)
}
_spec
.
Edges
.
Add
=
append
(
_spec
.
Edges
.
Add
,
edge
)
}
if
_u
.
mutation
.
AllowedGroupsCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
M2M
,
...
...
backend/go.mod
View file @
0170d19f
module github.com/Wei-Shaw/sub2api
go 1.25.
5
go 1.25.
6
require (
entgo.io/ent v0.14.5
...
...
backend/internal/config/config.go
View file @
0170d19f
...
...
@@ -47,6 +47,7 @@ type Config struct {
Redis
RedisConfig
`mapstructure:"redis"`
Ops
OpsConfig
`mapstructure:"ops"`
JWT
JWTConfig
`mapstructure:"jwt"`
Totp
TotpConfig
`mapstructure:"totp"`
LinuxDo
LinuxDoConnectConfig
`mapstructure:"linuxdo_connect"`
Default
DefaultConfig
`mapstructure:"default"`
RateLimit
RateLimitConfig
`mapstructure:"rate_limit"`
...
...
@@ -55,6 +56,7 @@ type Config struct {
APIKeyAuth
APIKeyAuthCacheConfig
`mapstructure:"api_key_auth_cache"`
Dashboard
DashboardCacheConfig
`mapstructure:"dashboard_cache"`
DashboardAgg
DashboardAggregationConfig
`mapstructure:"dashboard_aggregation"`
UsageCleanup
UsageCleanupConfig
`mapstructure:"usage_cleanup"`
Concurrency
ConcurrencyConfig
`mapstructure:"concurrency"`
TokenRefresh
TokenRefreshConfig
`mapstructure:"token_refresh"`
RunMode
string
`mapstructure:"run_mode" yaml:"run_mode"`
...
...
@@ -267,6 +269,33 @@ type GatewayConfig struct {
// Scheduling: 账号调度相关配置
Scheduling
GatewaySchedulingConfig
`mapstructure:"scheduling"`
// TLSFingerprint: TLS指纹伪装配置
TLSFingerprint
TLSFingerprintConfig
`mapstructure:"tls_fingerprint"`
}
// TLSFingerprintConfig TLS指纹伪装配置
// 用于模拟 Claude CLI (Node.js) 的 TLS 握手特征,避免被识别为非官方客户端
type
TLSFingerprintConfig
struct
{
// Enabled: 是否全局启用TLS指纹功能
Enabled
bool
`mapstructure:"enabled"`
// Profiles: 预定义的TLS指纹配置模板
// key 为模板名称,如 "claude_cli_v2", "chrome_120" 等
Profiles
map
[
string
]
TLSProfileConfig
`mapstructure:"profiles"`
}
// TLSProfileConfig 单个TLS指纹模板的配置
type
TLSProfileConfig
struct
{
// Name: 模板显示名称
Name
string
`mapstructure:"name"`
// EnableGREASE: 是否启用GREASE扩展(Chrome使用,Node.js不使用)
EnableGREASE
bool
`mapstructure:"enable_grease"`
// CipherSuites: TLS加密套件列表(空则使用内置默认值)
CipherSuites
[]
uint16
`mapstructure:"cipher_suites"`
// Curves: 椭圆曲线列表(空则使用内置默认值)
Curves
[]
uint16
`mapstructure:"curves"`
// PointFormats: 点格式列表(空则使用内置默认值)
PointFormats
[]
uint8
`mapstructure:"point_formats"`
}
// GatewaySchedulingConfig accounts scheduling configuration.
...
...
@@ -386,6 +415,8 @@ type RedisConfig struct {
PoolSize
int
`mapstructure:"pool_size"`
// MinIdleConns: 最小空闲连接数,保持热连接减少冷启动延迟
MinIdleConns
int
`mapstructure:"min_idle_conns"`
// EnableTLS: 是否启用 TLS/SSL 连接
EnableTLS
bool
`mapstructure:"enable_tls"`
}
func
(
r
*
RedisConfig
)
Address
()
string
{
...
...
@@ -438,6 +469,16 @@ type JWTConfig struct {
ExpireHour
int
`mapstructure:"expire_hour"`
}
// TotpConfig TOTP 双因素认证配置
type
TotpConfig
struct
{
// EncryptionKey 用于加密 TOTP 密钥的 AES-256 密钥(32 字节 hex 编码)
// 如果为空,将自动生成一个随机密钥(仅适用于开发环境)
EncryptionKey
string
`mapstructure:"encryption_key"`
// EncryptionKeyConfigured 标记加密密钥是否为手动配置(非自动生成)
// 只有手动配置了密钥才允许在管理后台启用 TOTP 功能
EncryptionKeyConfigured
bool
`mapstructure:"-"`
}
type
TurnstileConfig
struct
{
Required
bool
`mapstructure:"required"`
}
...
...
@@ -504,6 +545,20 @@ type DashboardAggregationRetentionConfig struct {
DailyDays
int
`mapstructure:"daily_days"`
}
// UsageCleanupConfig 使用记录清理任务配置
type
UsageCleanupConfig
struct
{
// Enabled: 是否启用清理任务执行器
Enabled
bool
`mapstructure:"enabled"`
// MaxRangeDays: 单次任务允许的最大时间跨度(天)
MaxRangeDays
int
`mapstructure:"max_range_days"`
// BatchSize: 单批删除数量
BatchSize
int
`mapstructure:"batch_size"`
// WorkerIntervalSeconds: 后台任务轮询间隔(秒)
WorkerIntervalSeconds
int
`mapstructure:"worker_interval_seconds"`
// TaskTimeoutSeconds: 单次任务最大执行时长(秒)
TaskTimeoutSeconds
int
`mapstructure:"task_timeout_seconds"`
}
func
NormalizeRunMode
(
value
string
)
string
{
normalized
:=
strings
.
ToLower
(
strings
.
TrimSpace
(
value
))
switch
normalized
{
...
...
@@ -584,6 +639,20 @@ func Load() (*Config, error) {
log
.
Println
(
"Warning: JWT secret auto-generated. Consider setting a fixed secret for production."
)
}
// Auto-generate TOTP encryption key if not set (32 bytes = 64 hex chars for AES-256)
cfg
.
Totp
.
EncryptionKey
=
strings
.
TrimSpace
(
cfg
.
Totp
.
EncryptionKey
)
if
cfg
.
Totp
.
EncryptionKey
==
""
{
key
,
err
:=
generateJWTSecret
(
32
)
// Reuse the same random generation function
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"generate totp encryption key error: %w"
,
err
)
}
cfg
.
Totp
.
EncryptionKey
=
key
cfg
.
Totp
.
EncryptionKeyConfigured
=
false
log
.
Println
(
"Warning: TOTP encryption key auto-generated. Consider setting a fixed key for production."
)
}
else
{
cfg
.
Totp
.
EncryptionKeyConfigured
=
true
}
if
err
:=
cfg
.
Validate
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"validate config error: %w"
,
err
)
}
...
...
@@ -695,6 +764,7 @@ func setDefaults() {
viper
.
SetDefault
(
"redis.write_timeout_seconds"
,
3
)
viper
.
SetDefault
(
"redis.pool_size"
,
128
)
viper
.
SetDefault
(
"redis.min_idle_conns"
,
10
)
viper
.
SetDefault
(
"redis.enable_tls"
,
false
)
// Ops (vNext)
viper
.
SetDefault
(
"ops.enabled"
,
true
)
...
...
@@ -714,6 +784,9 @@ func setDefaults() {
viper
.
SetDefault
(
"jwt.secret"
,
""
)
viper
.
SetDefault
(
"jwt.expire_hour"
,
24
)
// TOTP
viper
.
SetDefault
(
"totp.encryption_key"
,
""
)
// Default
// Admin credentials are created via the setup flow (web wizard / CLI / AUTO_SETUP).
// Do not ship fixed defaults here to avoid insecure "known credentials" in production.
...
...
@@ -764,6 +837,13 @@ func setDefaults() {
viper
.
SetDefault
(
"dashboard_aggregation.retention.daily_days"
,
730
)
viper
.
SetDefault
(
"dashboard_aggregation.recompute_days"
,
2
)
// Usage cleanup task
viper
.
SetDefault
(
"usage_cleanup.enabled"
,
true
)
viper
.
SetDefault
(
"usage_cleanup.max_range_days"
,
31
)
viper
.
SetDefault
(
"usage_cleanup.batch_size"
,
5000
)
viper
.
SetDefault
(
"usage_cleanup.worker_interval_seconds"
,
10
)
viper
.
SetDefault
(
"usage_cleanup.task_timeout_seconds"
,
1800
)
// Gateway
viper
.
SetDefault
(
"gateway.response_header_timeout"
,
600
)
// 600秒(10分钟)等待上游响应头,LLM高负载时可能排队较久
viper
.
SetDefault
(
"gateway.log_upstream_error_body"
,
true
)
...
...
@@ -802,6 +882,8 @@ func setDefaults() {
viper
.
SetDefault
(
"gateway.scheduling.outbox_lag_rebuild_failures"
,
3
)
viper
.
SetDefault
(
"gateway.scheduling.outbox_backlog_rebuild_rows"
,
10000
)
viper
.
SetDefault
(
"gateway.scheduling.full_rebuild_interval_seconds"
,
300
)
// TLS指纹伪装配置(默认关闭,需要账号级别单独启用)
viper
.
SetDefault
(
"gateway.tls_fingerprint.enabled"
,
true
)
viper
.
SetDefault
(
"concurrency.ping_interval"
,
10
)
// TokenRefresh
...
...
@@ -1004,6 +1086,33 @@ func (c *Config) Validate() error {
return
fmt
.
Errorf
(
"dashboard_aggregation.recompute_days must be non-negative"
)
}
}
if
c
.
UsageCleanup
.
Enabled
{
if
c
.
UsageCleanup
.
MaxRangeDays
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.max_range_days must be positive"
)
}
if
c
.
UsageCleanup
.
BatchSize
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.batch_size must be positive"
)
}
if
c
.
UsageCleanup
.
WorkerIntervalSeconds
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.worker_interval_seconds must be positive"
)
}
if
c
.
UsageCleanup
.
TaskTimeoutSeconds
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.task_timeout_seconds must be positive"
)
}
}
else
{
if
c
.
UsageCleanup
.
MaxRangeDays
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.max_range_days must be non-negative"
)
}
if
c
.
UsageCleanup
.
BatchSize
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.batch_size must be non-negative"
)
}
if
c
.
UsageCleanup
.
WorkerIntervalSeconds
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.worker_interval_seconds must be non-negative"
)
}
if
c
.
UsageCleanup
.
TaskTimeoutSeconds
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.task_timeout_seconds must be non-negative"
)
}
}
if
c
.
Gateway
.
MaxBodySize
<=
0
{
return
fmt
.
Errorf
(
"gateway.max_body_size must be positive"
)
}
...
...
backend/internal/config/config_test.go
View file @
0170d19f
...
...
@@ -280,3 +280,573 @@ func TestValidateDashboardAggregationBackfillMaxDays(t *testing.T) {
t
.
Fatalf
(
"Validate() expected backfill_max_days error, got: %v"
,
err
)
}
}
func
TestLoadDefaultUsageCleanupConfig
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
if
!
cfg
.
UsageCleanup
.
Enabled
{
t
.
Fatalf
(
"UsageCleanup.Enabled = false, want true"
)
}
if
cfg
.
UsageCleanup
.
MaxRangeDays
!=
31
{
t
.
Fatalf
(
"UsageCleanup.MaxRangeDays = %d, want 31"
,
cfg
.
UsageCleanup
.
MaxRangeDays
)
}
if
cfg
.
UsageCleanup
.
BatchSize
!=
5000
{
t
.
Fatalf
(
"UsageCleanup.BatchSize = %d, want 5000"
,
cfg
.
UsageCleanup
.
BatchSize
)
}
if
cfg
.
UsageCleanup
.
WorkerIntervalSeconds
!=
10
{
t
.
Fatalf
(
"UsageCleanup.WorkerIntervalSeconds = %d, want 10"
,
cfg
.
UsageCleanup
.
WorkerIntervalSeconds
)
}
if
cfg
.
UsageCleanup
.
TaskTimeoutSeconds
!=
1800
{
t
.
Fatalf
(
"UsageCleanup.TaskTimeoutSeconds = %d, want 1800"
,
cfg
.
UsageCleanup
.
TaskTimeoutSeconds
)
}
}
func
TestValidateUsageCleanupConfigEnabled
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
UsageCleanup
.
Enabled
=
true
cfg
.
UsageCleanup
.
MaxRangeDays
=
0
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for usage_cleanup.max_range_days, got nil"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"usage_cleanup.max_range_days"
)
{
t
.
Fatalf
(
"Validate() expected max_range_days error, got: %v"
,
err
)
}
}
func
TestValidateUsageCleanupConfigDisabled
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
UsageCleanup
.
Enabled
=
false
cfg
.
UsageCleanup
.
BatchSize
=
-
1
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for usage_cleanup.batch_size, got nil"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"usage_cleanup.batch_size"
)
{
t
.
Fatalf
(
"Validate() expected batch_size error, got: %v"
,
err
)
}
}
func
TestConfigAddressHelpers
(
t
*
testing
.
T
)
{
server
:=
ServerConfig
{
Host
:
"127.0.0.1"
,
Port
:
9000
}
if
server
.
Address
()
!=
"127.0.0.1:9000"
{
t
.
Fatalf
(
"ServerConfig.Address() = %q"
,
server
.
Address
())
}
dbCfg
:=
DatabaseConfig
{
Host
:
"localhost"
,
Port
:
5432
,
User
:
"postgres"
,
Password
:
""
,
DBName
:
"sub2api"
,
SSLMode
:
"disable"
,
}
if
!
strings
.
Contains
(
dbCfg
.
DSN
(),
"password="
)
{
}
else
{
t
.
Fatalf
(
"DatabaseConfig.DSN() should not include password when empty"
)
}
dbCfg
.
Password
=
"secret"
if
!
strings
.
Contains
(
dbCfg
.
DSN
(),
"password=secret"
)
{
t
.
Fatalf
(
"DatabaseConfig.DSN() missing password"
)
}
dbCfg
.
Password
=
""
if
strings
.
Contains
(
dbCfg
.
DSNWithTimezone
(
"UTC"
),
"password="
)
{
t
.
Fatalf
(
"DatabaseConfig.DSNWithTimezone() should omit password when empty"
)
}
if
!
strings
.
Contains
(
dbCfg
.
DSNWithTimezone
(
""
),
"TimeZone=Asia/Shanghai"
)
{
t
.
Fatalf
(
"DatabaseConfig.DSNWithTimezone() should use default timezone"
)
}
if
!
strings
.
Contains
(
dbCfg
.
DSNWithTimezone
(
"UTC"
),
"TimeZone=UTC"
)
{
t
.
Fatalf
(
"DatabaseConfig.DSNWithTimezone() should use provided timezone"
)
}
redis
:=
RedisConfig
{
Host
:
"redis"
,
Port
:
6379
}
if
redis
.
Address
()
!=
"redis:6379"
{
t
.
Fatalf
(
"RedisConfig.Address() = %q"
,
redis
.
Address
())
}
}
func
TestNormalizeStringSlice
(
t
*
testing
.
T
)
{
values
:=
normalizeStringSlice
([]
string
{
" a "
,
""
,
"b"
,
" "
,
"c"
})
if
len
(
values
)
!=
3
||
values
[
0
]
!=
"a"
||
values
[
1
]
!=
"b"
||
values
[
2
]
!=
"c"
{
t
.
Fatalf
(
"normalizeStringSlice() unexpected result: %#v"
,
values
)
}
if
normalizeStringSlice
(
nil
)
!=
nil
{
t
.
Fatalf
(
"normalizeStringSlice(nil) expected nil slice"
)
}
}
func
TestGetServerAddressFromEnv
(
t
*
testing
.
T
)
{
t
.
Setenv
(
"SERVER_HOST"
,
"127.0.0.1"
)
t
.
Setenv
(
"SERVER_PORT"
,
"9090"
)
address
:=
GetServerAddress
()
if
address
!=
"127.0.0.1:9090"
{
t
.
Fatalf
(
"GetServerAddress() = %q"
,
address
)
}
}
func
TestValidateAbsoluteHTTPURL
(
t
*
testing
.
T
)
{
if
err
:=
ValidateAbsoluteHTTPURL
(
"https://example.com/path"
);
err
!=
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL valid url error: %v"
,
err
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
""
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject empty url"
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
"/relative"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject relative url"
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
"ftp://example.com"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject ftp scheme"
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
"https://example.com/#frag"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject fragment"
)
}
}
func
TestValidateFrontendRedirectURL
(
t
*
testing
.
T
)
{
if
err
:=
ValidateFrontendRedirectURL
(
"/auth/callback"
);
err
!=
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL relative error: %v"
,
err
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"https://example.com/auth"
);
err
!=
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL absolute error: %v"
,
err
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"example.com/path"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject non-absolute url"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"//evil.com"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject // prefix"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"javascript:alert(1)"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject javascript scheme"
)
}
}
func
TestWarnIfInsecureURL
(
t
*
testing
.
T
)
{
warnIfInsecureURL
(
"test"
,
"http://example.com"
)
warnIfInsecureURL
(
"test"
,
"bad://url"
)
}
func
TestGenerateJWTSecretDefaultLength
(
t
*
testing
.
T
)
{
secret
,
err
:=
generateJWTSecret
(
0
)
if
err
!=
nil
{
t
.
Fatalf
(
"generateJWTSecret error: %v"
,
err
)
}
if
len
(
secret
)
==
0
{
t
.
Fatalf
(
"generateJWTSecret returned empty string"
)
}
}
func
TestValidateOpsCleanupScheduleRequired
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
Ops
.
Cleanup
.
Enabled
=
true
cfg
.
Ops
.
Cleanup
.
Schedule
=
""
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for ops.cleanup.schedule"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"ops.cleanup.schedule"
)
{
t
.
Fatalf
(
"Validate() expected ops.cleanup.schedule error, got: %v"
,
err
)
}
}
func
TestValidateConcurrencyPingInterval
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
Concurrency
.
PingInterval
=
3
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for concurrency.ping_interval"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"concurrency.ping_interval"
)
{
t
.
Fatalf
(
"Validate() expected concurrency.ping_interval error, got: %v"
,
err
)
}
}
func
TestProvideConfig
(
t
*
testing
.
T
)
{
viper
.
Reset
()
if
_
,
err
:=
ProvideConfig
();
err
!=
nil
{
t
.
Fatalf
(
"ProvideConfig() error: %v"
,
err
)
}
}
func
TestValidateConfigWithLinuxDoEnabled
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
Security
.
CSP
.
Enabled
=
true
cfg
.
Security
.
CSP
.
Policy
=
"default-src 'self'"
cfg
.
LinuxDo
.
Enabled
=
true
cfg
.
LinuxDo
.
ClientID
=
"client"
cfg
.
LinuxDo
.
ClientSecret
=
"secret"
cfg
.
LinuxDo
.
AuthorizeURL
=
"https://example.com/oauth2/authorize"
cfg
.
LinuxDo
.
TokenURL
=
"https://example.com/oauth2/token"
cfg
.
LinuxDo
.
UserInfoURL
=
"https://example.com/oauth2/userinfo"
cfg
.
LinuxDo
.
RedirectURL
=
"https://example.com/api/v1/auth/oauth/linuxdo/callback"
cfg
.
LinuxDo
.
FrontendRedirectURL
=
"/auth/linuxdo/callback"
cfg
.
LinuxDo
.
TokenAuthMethod
=
"client_secret_post"
if
err
:=
cfg
.
Validate
();
err
!=
nil
{
t
.
Fatalf
(
"Validate() unexpected error: %v"
,
err
)
}
}
func
TestValidateJWTSecretStrength
(
t
*
testing
.
T
)
{
if
!
isWeakJWTSecret
(
"change-me-in-production"
)
{
t
.
Fatalf
(
"isWeakJWTSecret should detect weak secret"
)
}
if
isWeakJWTSecret
(
"StrongSecretValue"
)
{
t
.
Fatalf
(
"isWeakJWTSecret should accept strong secret"
)
}
}
func
TestGenerateJWTSecretWithLength
(
t
*
testing
.
T
)
{
secret
,
err
:=
generateJWTSecret
(
16
)
if
err
!=
nil
{
t
.
Fatalf
(
"generateJWTSecret error: %v"
,
err
)
}
if
len
(
secret
)
==
0
{
t
.
Fatalf
(
"generateJWTSecret returned empty string"
)
}
}
func
TestValidateAbsoluteHTTPURLMissingHost
(
t
*
testing
.
T
)
{
if
err
:=
ValidateAbsoluteHTTPURL
(
"https://"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject missing host"
)
}
}
func
TestValidateFrontendRedirectURLInvalidChars
(
t
*
testing
.
T
)
{
if
err
:=
ValidateFrontendRedirectURL
(
"/auth/
\n
callback"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject invalid chars"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"http://"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject missing host"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"mailto:user@example.com"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject mailto"
)
}
}
func
TestWarnIfInsecureURLHTTPS
(
t
*
testing
.
T
)
{
warnIfInsecureURL
(
"secure"
,
"https://example.com"
)
}
func
TestValidateConfigErrors
(
t
*
testing
.
T
)
{
buildValid
:=
func
(
t
*
testing
.
T
)
*
Config
{
t
.
Helper
()
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
return
cfg
}
cases
:=
[]
struct
{
name
string
mutate
func
(
*
Config
)
wantErr
string
}{
{
name
:
"jwt expire hour positive"
,
mutate
:
func
(
c
*
Config
)
{
c
.
JWT
.
ExpireHour
=
0
},
wantErr
:
"jwt.expire_hour must be positive"
,
},
{
name
:
"jwt expire hour max"
,
mutate
:
func
(
c
*
Config
)
{
c
.
JWT
.
ExpireHour
=
200
},
wantErr
:
"jwt.expire_hour must be <= 168"
,
},
{
name
:
"csp policy required"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Security
.
CSP
.
Enabled
=
true
;
c
.
Security
.
CSP
.
Policy
=
""
},
wantErr
:
"security.csp.policy"
,
},
{
name
:
"linuxdo client id required"
,
mutate
:
func
(
c
*
Config
)
{
c
.
LinuxDo
.
Enabled
=
true
c
.
LinuxDo
.
ClientID
=
""
},
wantErr
:
"linuxdo_connect.client_id"
,
},
{
name
:
"linuxdo token auth method"
,
mutate
:
func
(
c
*
Config
)
{
c
.
LinuxDo
.
Enabled
=
true
c
.
LinuxDo
.
ClientID
=
"client"
c
.
LinuxDo
.
ClientSecret
=
"secret"
c
.
LinuxDo
.
AuthorizeURL
=
"https://example.com/authorize"
c
.
LinuxDo
.
TokenURL
=
"https://example.com/token"
c
.
LinuxDo
.
UserInfoURL
=
"https://example.com/userinfo"
c
.
LinuxDo
.
RedirectURL
=
"https://example.com/callback"
c
.
LinuxDo
.
FrontendRedirectURL
=
"/auth/callback"
c
.
LinuxDo
.
TokenAuthMethod
=
"invalid"
},
wantErr
:
"linuxdo_connect.token_auth_method"
,
},
{
name
:
"billing circuit breaker threshold"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Billing
.
CircuitBreaker
.
FailureThreshold
=
0
},
wantErr
:
"billing.circuit_breaker.failure_threshold"
,
},
{
name
:
"billing circuit breaker reset"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Billing
.
CircuitBreaker
.
ResetTimeoutSeconds
=
0
},
wantErr
:
"billing.circuit_breaker.reset_timeout_seconds"
,
},
{
name
:
"billing circuit breaker half open"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Billing
.
CircuitBreaker
.
HalfOpenRequests
=
0
},
wantErr
:
"billing.circuit_breaker.half_open_requests"
,
},
{
name
:
"database max open conns"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Database
.
MaxOpenConns
=
0
},
wantErr
:
"database.max_open_conns"
,
},
{
name
:
"database max lifetime"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Database
.
ConnMaxLifetimeMinutes
=
-
1
},
wantErr
:
"database.conn_max_lifetime_minutes"
,
},
{
name
:
"database idle exceeds open"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Database
.
MaxIdleConns
=
c
.
Database
.
MaxOpenConns
+
1
},
wantErr
:
"database.max_idle_conns cannot exceed"
,
},
{
name
:
"redis dial timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
DialTimeoutSeconds
=
0
},
wantErr
:
"redis.dial_timeout_seconds"
,
},
{
name
:
"redis read timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
ReadTimeoutSeconds
=
0
},
wantErr
:
"redis.read_timeout_seconds"
,
},
{
name
:
"redis write timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
WriteTimeoutSeconds
=
0
},
wantErr
:
"redis.write_timeout_seconds"
,
},
{
name
:
"redis pool size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
PoolSize
=
0
},
wantErr
:
"redis.pool_size"
,
},
{
name
:
"redis idle exceeds pool"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
MinIdleConns
=
c
.
Redis
.
PoolSize
+
1
},
wantErr
:
"redis.min_idle_conns cannot exceed"
,
},
{
name
:
"dashboard cache disabled negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Dashboard
.
Enabled
=
false
;
c
.
Dashboard
.
StatsTTLSeconds
=
-
1
},
wantErr
:
"dashboard_cache.stats_ttl_seconds"
,
},
{
name
:
"dashboard cache fresh ttl positive"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Dashboard
.
Enabled
=
true
;
c
.
Dashboard
.
StatsFreshTTLSeconds
=
0
},
wantErr
:
"dashboard_cache.stats_fresh_ttl_seconds"
,
},
{
name
:
"dashboard aggregation enabled interval"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
true
;
c
.
DashboardAgg
.
IntervalSeconds
=
0
},
wantErr
:
"dashboard_aggregation.interval_seconds"
,
},
{
name
:
"dashboard aggregation backfill positive"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
true
c
.
DashboardAgg
.
BackfillEnabled
=
true
c
.
DashboardAgg
.
BackfillMaxDays
=
0
},
wantErr
:
"dashboard_aggregation.backfill_max_days"
,
},
{
name
:
"dashboard aggregation retention"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
true
;
c
.
DashboardAgg
.
Retention
.
UsageLogsDays
=
0
},
wantErr
:
"dashboard_aggregation.retention.usage_logs_days"
,
},
{
name
:
"dashboard aggregation disabled interval"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
false
;
c
.
DashboardAgg
.
IntervalSeconds
=
-
1
},
wantErr
:
"dashboard_aggregation.interval_seconds"
,
},
{
name
:
"usage cleanup max range"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
true
;
c
.
UsageCleanup
.
MaxRangeDays
=
0
},
wantErr
:
"usage_cleanup.max_range_days"
,
},
{
name
:
"usage cleanup worker interval"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
true
;
c
.
UsageCleanup
.
WorkerIntervalSeconds
=
0
},
wantErr
:
"usage_cleanup.worker_interval_seconds"
,
},
{
name
:
"usage cleanup batch size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
true
;
c
.
UsageCleanup
.
BatchSize
=
0
},
wantErr
:
"usage_cleanup.batch_size"
,
},
{
name
:
"usage cleanup disabled negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
false
;
c
.
UsageCleanup
.
BatchSize
=
-
1
},
wantErr
:
"usage_cleanup.batch_size"
,
},
{
name
:
"gateway max body size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxBodySize
=
0
},
wantErr
:
"gateway.max_body_size"
,
},
{
name
:
"gateway max idle conns"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxIdleConns
=
0
},
wantErr
:
"gateway.max_idle_conns"
,
},
{
name
:
"gateway max idle conns per host"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxIdleConnsPerHost
=
0
},
wantErr
:
"gateway.max_idle_conns_per_host"
,
},
{
name
:
"gateway idle timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
IdleConnTimeoutSeconds
=
0
},
wantErr
:
"gateway.idle_conn_timeout_seconds"
,
},
{
name
:
"gateway max upstream clients"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxUpstreamClients
=
0
},
wantErr
:
"gateway.max_upstream_clients"
,
},
{
name
:
"gateway client idle ttl"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
ClientIdleTTLSeconds
=
0
},
wantErr
:
"gateway.client_idle_ttl_seconds"
,
},
{
name
:
"gateway concurrency slot ttl"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
ConcurrencySlotTTLMinutes
=
0
},
wantErr
:
"gateway.concurrency_slot_ttl_minutes"
,
},
{
name
:
"gateway max conns per host"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxConnsPerHost
=
-
1
},
wantErr
:
"gateway.max_conns_per_host"
,
},
{
name
:
"gateway connection isolation"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
ConnectionPoolIsolation
=
"invalid"
},
wantErr
:
"gateway.connection_pool_isolation"
,
},
{
name
:
"gateway stream keepalive range"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
StreamKeepaliveInterval
=
4
},
wantErr
:
"gateway.stream_keepalive_interval"
,
},
{
name
:
"gateway stream data interval range"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
StreamDataIntervalTimeout
=
5
},
wantErr
:
"gateway.stream_data_interval_timeout"
,
},
{
name
:
"gateway stream data interval negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
StreamDataIntervalTimeout
=
-
1
},
wantErr
:
"gateway.stream_data_interval_timeout must be non-negative"
,
},
{
name
:
"gateway max line size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxLineSize
=
1024
},
wantErr
:
"gateway.max_line_size must be at least"
,
},
{
name
:
"gateway max line size negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxLineSize
=
-
1
},
wantErr
:
"gateway.max_line_size must be non-negative"
,
},
{
name
:
"gateway scheduling sticky waiting"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
StickySessionMaxWaiting
=
0
},
wantErr
:
"gateway.scheduling.sticky_session_max_waiting"
,
},
{
name
:
"gateway scheduling outbox poll"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
OutboxPollIntervalSeconds
=
0
},
wantErr
:
"gateway.scheduling.outbox_poll_interval_seconds"
,
},
{
name
:
"gateway scheduling outbox failures"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
OutboxLagRebuildFailures
=
0
},
wantErr
:
"gateway.scheduling.outbox_lag_rebuild_failures"
,
},
{
name
:
"gateway outbox lag rebuild"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
OutboxLagWarnSeconds
=
10
c
.
Gateway
.
Scheduling
.
OutboxLagRebuildSeconds
=
5
},
wantErr
:
"gateway.scheduling.outbox_lag_rebuild_seconds"
,
},
{
name
:
"ops metrics collector ttl"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Ops
.
MetricsCollectorCache
.
TTL
=
-
1
},
wantErr
:
"ops.metrics_collector_cache.ttl"
,
},
{
name
:
"ops cleanup retention"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Ops
.
Cleanup
.
ErrorLogRetentionDays
=
-
1
},
wantErr
:
"ops.cleanup.error_log_retention_days"
,
},
{
name
:
"ops cleanup minute retention"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Ops
.
Cleanup
.
MinuteMetricsRetentionDays
=
-
1
},
wantErr
:
"ops.cleanup.minute_metrics_retention_days"
,
},
}
for
_
,
tt
:=
range
cases
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
cfg
:=
buildValid
(
t
)
tt
.
mutate
(
cfg
)
err
:=
cfg
.
Validate
()
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
tt
.
wantErr
)
{
t
.
Fatalf
(
"Validate() error = %v, want %q"
,
err
,
tt
.
wantErr
)
}
})
}
}
Prev
1
2
3
4
5
6
7
…
16
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