Files
MonkeyCode/backend/db/intercept/intercept.go
2025-07-04 20:17:49 +08:00

660 lines
25 KiB
Go

// Code generated by ent, DO NOT EDIT.
package intercept
import (
"context"
"fmt"
"entgo.io/ent/dialect/sql"
"github.com/chaitin/MonkeyCode/backend/db"
"github.com/chaitin/MonkeyCode/backend/db/admin"
"github.com/chaitin/MonkeyCode/backend/db/adminloginhistory"
"github.com/chaitin/MonkeyCode/backend/db/apikey"
"github.com/chaitin/MonkeyCode/backend/db/billingplan"
"github.com/chaitin/MonkeyCode/backend/db/billingquota"
"github.com/chaitin/MonkeyCode/backend/db/billingrecord"
"github.com/chaitin/MonkeyCode/backend/db/billingusage"
"github.com/chaitin/MonkeyCode/backend/db/extension"
"github.com/chaitin/MonkeyCode/backend/db/invitecode"
"github.com/chaitin/MonkeyCode/backend/db/model"
"github.com/chaitin/MonkeyCode/backend/db/modelprovider"
"github.com/chaitin/MonkeyCode/backend/db/modelprovidermodel"
"github.com/chaitin/MonkeyCode/backend/db/predicate"
"github.com/chaitin/MonkeyCode/backend/db/setting"
"github.com/chaitin/MonkeyCode/backend/db/task"
"github.com/chaitin/MonkeyCode/backend/db/taskrecord"
"github.com/chaitin/MonkeyCode/backend/db/user"
"github.com/chaitin/MonkeyCode/backend/db/useridentity"
"github.com/chaitin/MonkeyCode/backend/db/userloginhistory"
)
// The Query interface represents an operation that queries a graph.
// By using this interface, users can write generic code that manipulates
// query builders of different types.
type Query interface {
// Type returns the string representation of the query type.
Type() string
// Limit the number of records to be returned by this query.
Limit(int)
// Offset to start from.
Offset(int)
// Unique configures the query builder to filter duplicate records.
Unique(bool)
// Order specifies how the records should be ordered.
Order(...func(*sql.Selector))
// WhereP appends storage-level predicates to the query builder. Using this method, users
// can use type-assertion to append predicates that do not depend on any generated package.
WhereP(...func(*sql.Selector))
}
// The Func type is an adapter that allows ordinary functions to be used as interceptors.
// Unlike traversal functions, interceptors are skipped during graph traversals. Note that the
// implementation of Func is different from the one defined in entgo.io/ent.InterceptFunc.
type Func func(context.Context, Query) error
// Intercept calls f(ctx, q) and then applied the next Querier.
func (f Func) Intercept(next db.Querier) db.Querier {
return db.QuerierFunc(func(ctx context.Context, q db.Query) (db.Value, error) {
query, err := NewQuery(q)
if err != nil {
return nil, err
}
if err := f(ctx, query); err != nil {
return nil, err
}
return next.Query(ctx, q)
})
}
// The TraverseFunc type is an adapter to allow the use of ordinary function as Traverser.
// If f is a function with the appropriate signature, TraverseFunc(f) is a Traverser that calls f.
type TraverseFunc func(context.Context, Query) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseFunc) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseFunc) Traverse(ctx context.Context, q db.Query) error {
query, err := NewQuery(q)
if err != nil {
return err
}
return f(ctx, query)
}
// The AdminFunc type is an adapter to allow the use of ordinary function as a Querier.
type AdminFunc func(context.Context, *db.AdminQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f AdminFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.AdminQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.AdminQuery", q)
}
// The TraverseAdmin type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAdmin func(context.Context, *db.AdminQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAdmin) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAdmin) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.AdminQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.AdminQuery", q)
}
// The AdminLoginHistoryFunc type is an adapter to allow the use of ordinary function as a Querier.
type AdminLoginHistoryFunc func(context.Context, *db.AdminLoginHistoryQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f AdminLoginHistoryFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.AdminLoginHistoryQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.AdminLoginHistoryQuery", q)
}
// The TraverseAdminLoginHistory type is an adapter to allow the use of ordinary function as Traverser.
type TraverseAdminLoginHistory func(context.Context, *db.AdminLoginHistoryQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseAdminLoginHistory) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseAdminLoginHistory) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.AdminLoginHistoryQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.AdminLoginHistoryQuery", q)
}
// The ApiKeyFunc type is an adapter to allow the use of ordinary function as a Querier.
type ApiKeyFunc func(context.Context, *db.ApiKeyQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f ApiKeyFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.ApiKeyQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.ApiKeyQuery", q)
}
// The TraverseApiKey type is an adapter to allow the use of ordinary function as Traverser.
type TraverseApiKey func(context.Context, *db.ApiKeyQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseApiKey) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseApiKey) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.ApiKeyQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.ApiKeyQuery", q)
}
// The BillingPlanFunc type is an adapter to allow the use of ordinary function as a Querier.
type BillingPlanFunc func(context.Context, *db.BillingPlanQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f BillingPlanFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.BillingPlanQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.BillingPlanQuery", q)
}
// The TraverseBillingPlan type is an adapter to allow the use of ordinary function as Traverser.
type TraverseBillingPlan func(context.Context, *db.BillingPlanQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseBillingPlan) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseBillingPlan) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.BillingPlanQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.BillingPlanQuery", q)
}
// The BillingQuotaFunc type is an adapter to allow the use of ordinary function as a Querier.
type BillingQuotaFunc func(context.Context, *db.BillingQuotaQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f BillingQuotaFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.BillingQuotaQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.BillingQuotaQuery", q)
}
// The TraverseBillingQuota type is an adapter to allow the use of ordinary function as Traverser.
type TraverseBillingQuota func(context.Context, *db.BillingQuotaQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseBillingQuota) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseBillingQuota) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.BillingQuotaQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.BillingQuotaQuery", q)
}
// The BillingRecordFunc type is an adapter to allow the use of ordinary function as a Querier.
type BillingRecordFunc func(context.Context, *db.BillingRecordQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f BillingRecordFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.BillingRecordQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.BillingRecordQuery", q)
}
// The TraverseBillingRecord type is an adapter to allow the use of ordinary function as Traverser.
type TraverseBillingRecord func(context.Context, *db.BillingRecordQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseBillingRecord) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseBillingRecord) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.BillingRecordQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.BillingRecordQuery", q)
}
// The BillingUsageFunc type is an adapter to allow the use of ordinary function as a Querier.
type BillingUsageFunc func(context.Context, *db.BillingUsageQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f BillingUsageFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.BillingUsageQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.BillingUsageQuery", q)
}
// The TraverseBillingUsage type is an adapter to allow the use of ordinary function as Traverser.
type TraverseBillingUsage func(context.Context, *db.BillingUsageQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseBillingUsage) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseBillingUsage) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.BillingUsageQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.BillingUsageQuery", q)
}
// The ExtensionFunc type is an adapter to allow the use of ordinary function as a Querier.
type ExtensionFunc func(context.Context, *db.ExtensionQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f ExtensionFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.ExtensionQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.ExtensionQuery", q)
}
// The TraverseExtension type is an adapter to allow the use of ordinary function as Traverser.
type TraverseExtension func(context.Context, *db.ExtensionQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseExtension) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseExtension) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.ExtensionQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.ExtensionQuery", q)
}
// The InviteCodeFunc type is an adapter to allow the use of ordinary function as a Querier.
type InviteCodeFunc func(context.Context, *db.InviteCodeQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f InviteCodeFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.InviteCodeQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.InviteCodeQuery", q)
}
// The TraverseInviteCode type is an adapter to allow the use of ordinary function as Traverser.
type TraverseInviteCode func(context.Context, *db.InviteCodeQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseInviteCode) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseInviteCode) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.InviteCodeQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.InviteCodeQuery", q)
}
// The ModelFunc type is an adapter to allow the use of ordinary function as a Querier.
type ModelFunc func(context.Context, *db.ModelQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f ModelFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.ModelQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.ModelQuery", q)
}
// The TraverseModel type is an adapter to allow the use of ordinary function as Traverser.
type TraverseModel func(context.Context, *db.ModelQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseModel) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseModel) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.ModelQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.ModelQuery", q)
}
// The ModelProviderFunc type is an adapter to allow the use of ordinary function as a Querier.
type ModelProviderFunc func(context.Context, *db.ModelProviderQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f ModelProviderFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.ModelProviderQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.ModelProviderQuery", q)
}
// The TraverseModelProvider type is an adapter to allow the use of ordinary function as Traverser.
type TraverseModelProvider func(context.Context, *db.ModelProviderQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseModelProvider) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseModelProvider) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.ModelProviderQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.ModelProviderQuery", q)
}
// The ModelProviderModelFunc type is an adapter to allow the use of ordinary function as a Querier.
type ModelProviderModelFunc func(context.Context, *db.ModelProviderModelQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f ModelProviderModelFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.ModelProviderModelQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.ModelProviderModelQuery", q)
}
// The TraverseModelProviderModel type is an adapter to allow the use of ordinary function as Traverser.
type TraverseModelProviderModel func(context.Context, *db.ModelProviderModelQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseModelProviderModel) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseModelProviderModel) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.ModelProviderModelQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.ModelProviderModelQuery", q)
}
// The SettingFunc type is an adapter to allow the use of ordinary function as a Querier.
type SettingFunc func(context.Context, *db.SettingQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f SettingFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.SettingQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.SettingQuery", q)
}
// The TraverseSetting type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSetting func(context.Context, *db.SettingQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSetting) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSetting) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.SettingQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.SettingQuery", q)
}
// The TaskFunc type is an adapter to allow the use of ordinary function as a Querier.
type TaskFunc func(context.Context, *db.TaskQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f TaskFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.TaskQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.TaskQuery", q)
}
// The TraverseTask type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTask func(context.Context, *db.TaskQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTask) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseTask) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.TaskQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.TaskQuery", q)
}
// The TaskRecordFunc type is an adapter to allow the use of ordinary function as a Querier.
type TaskRecordFunc func(context.Context, *db.TaskRecordQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f TaskRecordFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.TaskRecordQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.TaskRecordQuery", q)
}
// The TraverseTaskRecord type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTaskRecord func(context.Context, *db.TaskRecordQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTaskRecord) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseTaskRecord) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.TaskRecordQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.TaskRecordQuery", q)
}
// The UserFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserFunc func(context.Context, *db.UserQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f UserFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.UserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.UserQuery", q)
}
// The TraverseUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUser func(context.Context, *db.UserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUser) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUser) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.UserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.UserQuery", q)
}
// The UserIdentityFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserIdentityFunc func(context.Context, *db.UserIdentityQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f UserIdentityFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.UserIdentityQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.UserIdentityQuery", q)
}
// The TraverseUserIdentity type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserIdentity func(context.Context, *db.UserIdentityQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserIdentity) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserIdentity) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.UserIdentityQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.UserIdentityQuery", q)
}
// The UserLoginHistoryFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserLoginHistoryFunc func(context.Context, *db.UserLoginHistoryQuery) (db.Value, error)
// Query calls f(ctx, q).
func (f UserLoginHistoryFunc) Query(ctx context.Context, q db.Query) (db.Value, error) {
if q, ok := q.(*db.UserLoginHistoryQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *db.UserLoginHistoryQuery", q)
}
// The TraverseUserLoginHistory type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserLoginHistory func(context.Context, *db.UserLoginHistoryQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserLoginHistory) Intercept(next db.Querier) db.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseUserLoginHistory) Traverse(ctx context.Context, q db.Query) error {
if q, ok := q.(*db.UserLoginHistoryQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *db.UserLoginHistoryQuery", q)
}
// NewQuery returns the generic Query interface for the given typed query.
func NewQuery(q db.Query) (Query, error) {
switch q := q.(type) {
case *db.AdminQuery:
return &query[*db.AdminQuery, predicate.Admin, admin.OrderOption]{typ: db.TypeAdmin, tq: q}, nil
case *db.AdminLoginHistoryQuery:
return &query[*db.AdminLoginHistoryQuery, predicate.AdminLoginHistory, adminloginhistory.OrderOption]{typ: db.TypeAdminLoginHistory, tq: q}, nil
case *db.ApiKeyQuery:
return &query[*db.ApiKeyQuery, predicate.ApiKey, apikey.OrderOption]{typ: db.TypeApiKey, tq: q}, nil
case *db.BillingPlanQuery:
return &query[*db.BillingPlanQuery, predicate.BillingPlan, billingplan.OrderOption]{typ: db.TypeBillingPlan, tq: q}, nil
case *db.BillingQuotaQuery:
return &query[*db.BillingQuotaQuery, predicate.BillingQuota, billingquota.OrderOption]{typ: db.TypeBillingQuota, tq: q}, nil
case *db.BillingRecordQuery:
return &query[*db.BillingRecordQuery, predicate.BillingRecord, billingrecord.OrderOption]{typ: db.TypeBillingRecord, tq: q}, nil
case *db.BillingUsageQuery:
return &query[*db.BillingUsageQuery, predicate.BillingUsage, billingusage.OrderOption]{typ: db.TypeBillingUsage, tq: q}, nil
case *db.ExtensionQuery:
return &query[*db.ExtensionQuery, predicate.Extension, extension.OrderOption]{typ: db.TypeExtension, tq: q}, nil
case *db.InviteCodeQuery:
return &query[*db.InviteCodeQuery, predicate.InviteCode, invitecode.OrderOption]{typ: db.TypeInviteCode, tq: q}, nil
case *db.ModelQuery:
return &query[*db.ModelQuery, predicate.Model, model.OrderOption]{typ: db.TypeModel, tq: q}, nil
case *db.ModelProviderQuery:
return &query[*db.ModelProviderQuery, predicate.ModelProvider, modelprovider.OrderOption]{typ: db.TypeModelProvider, tq: q}, nil
case *db.ModelProviderModelQuery:
return &query[*db.ModelProviderModelQuery, predicate.ModelProviderModel, modelprovidermodel.OrderOption]{typ: db.TypeModelProviderModel, tq: q}, nil
case *db.SettingQuery:
return &query[*db.SettingQuery, predicate.Setting, setting.OrderOption]{typ: db.TypeSetting, tq: q}, nil
case *db.TaskQuery:
return &query[*db.TaskQuery, predicate.Task, task.OrderOption]{typ: db.TypeTask, tq: q}, nil
case *db.TaskRecordQuery:
return &query[*db.TaskRecordQuery, predicate.TaskRecord, taskrecord.OrderOption]{typ: db.TypeTaskRecord, tq: q}, nil
case *db.UserQuery:
return &query[*db.UserQuery, predicate.User, user.OrderOption]{typ: db.TypeUser, tq: q}, nil
case *db.UserIdentityQuery:
return &query[*db.UserIdentityQuery, predicate.UserIdentity, useridentity.OrderOption]{typ: db.TypeUserIdentity, tq: q}, nil
case *db.UserLoginHistoryQuery:
return &query[*db.UserLoginHistoryQuery, predicate.UserLoginHistory, userloginhistory.OrderOption]{typ: db.TypeUserLoginHistory, tq: q}, nil
default:
return nil, fmt.Errorf("unknown query type %T", q)
}
}
type query[T any, P ~func(*sql.Selector), R ~func(*sql.Selector)] struct {
typ string
tq interface {
Limit(int) T
Offset(int) T
Unique(bool) T
Order(...R) T
Where(...P) T
}
}
func (q query[T, P, R]) Type() string {
return q.typ
}
func (q query[T, P, R]) Limit(limit int) {
q.tq.Limit(limit)
}
func (q query[T, P, R]) Offset(offset int) {
q.tq.Offset(offset)
}
func (q query[T, P, R]) Unique(unique bool) {
q.tq.Unique(unique)
}
func (q query[T, P, R]) Order(orders ...func(*sql.Selector)) {
rs := make([]R, len(orders))
for i := range orders {
rs[i] = orders[i]
}
q.tq.Order(rs...)
}
func (q query[T, P, R]) WhereP(ps ...func(*sql.Selector)) {
p := make([]P, len(ps))
for i := range ps {
p[i] = ps[i]
}
q.tq.Where(p...)
}