Files
likedream/internal/ent/intercept/intercept.go
T
sugarBecomer 73b6c01cf9 ✨ 刷课表
2025-11-26 10:58:22 +08:00

481 lines
17 KiB
Go

// ENT数据库文件,请勿编辑。
package intercept
import (
"context"
"fmt"
"likedream-goframe/internal/ent"
"likedream-goframe/internal/ent/courseentity"
"likedream-goframe/internal/ent/cpimage"
"likedream-goframe/internal/ent/cpschool"
"likedream-goframe/internal/ent/cptask"
"likedream-goframe/internal/ent/cptasklog"
"likedream-goframe/internal/ent/cpuser"
"likedream-goframe/internal/ent/predicate"
"likedream-goframe/internal/ent/sysagent"
"likedream-goframe/internal/ent/syscard"
"likedream-goframe/internal/ent/sysmenu"
"likedream-goframe/internal/ent/sysrole"
"likedream-goframe/internal/ent/sysuser"
"likedream-goframe/internal/ent/sysuserlog"
"entgo.io/ent/dialect/sql"
)
// 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 ent.Querier) ent.Querier {
return ent.QuerierFunc(func(ctx context.Context, q ent.Query) (ent.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 ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
query, err := NewQuery(q)
if err != nil {
return err
}
return f(ctx, query)
}
// The CourseEntityFunc type is an adapter to allow the use of ordinary function as a Querier.
type CourseEntityFunc func(context.Context, *ent.CourseEntityQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CourseEntityFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CourseEntityQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CourseEntityQuery", q)
}
// The TraverseCourseEntity type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCourseEntity func(context.Context, *ent.CourseEntityQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCourseEntity) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCourseEntity) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CourseEntityQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CourseEntityQuery", q)
}
// The CpImageFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpImageFunc func(context.Context, *ent.CpImageQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CpImageFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CpImageQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpImageQuery", q)
}
// The TraverseCpImage type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCpImage func(context.Context, *ent.CpImageQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCpImage) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCpImage) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpImageQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CpImageQuery", q)
}
// The CpSchoolFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpSchoolFunc func(context.Context, *ent.CpSchoolQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CpSchoolFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CpSchoolQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpSchoolQuery", q)
}
// The TraverseCpSchool type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCpSchool func(context.Context, *ent.CpSchoolQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCpSchool) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCpSchool) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpSchoolQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CpSchoolQuery", q)
}
// The CpTaskFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpTaskFunc func(context.Context, *ent.CpTaskQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CpTaskFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CpTaskQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpTaskQuery", q)
}
// The TraverseCpTask type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCpTask func(context.Context, *ent.CpTaskQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCpTask) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCpTask) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpTaskQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CpTaskQuery", q)
}
// The CpTaskLogFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpTaskLogFunc func(context.Context, *ent.CpTaskLogQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CpTaskLogFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CpTaskLogQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpTaskLogQuery", q)
}
// The TraverseCpTaskLog type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCpTaskLog func(context.Context, *ent.CpTaskLogQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCpTaskLog) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCpTaskLog) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpTaskLogQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CpTaskLogQuery", q)
}
// The CpUserFunc type is an adapter to allow the use of ordinary function as a Querier.
type CpUserFunc func(context.Context, *ent.CpUserQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f CpUserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.CpUserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.CpUserQuery", q)
}
// The TraverseCpUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCpUser func(context.Context, *ent.CpUserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCpUser) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseCpUser) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.CpUserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.CpUserQuery", q)
}
// The SysAgentFunc type is an adapter to allow the use of ordinary function as a Querier.
type SysAgentFunc func(context.Context, *ent.SysAgentQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SysAgentFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SysAgentQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysAgentQuery", q)
}
// The TraverseSysAgent type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSysAgent func(context.Context, *ent.SysAgentQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSysAgent) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSysAgent) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SysAgentQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SysAgentQuery", q)
}
// The SysCardFunc type is an adapter to allow the use of ordinary function as a Querier.
type SysCardFunc func(context.Context, *ent.SysCardQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SysCardFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SysCardQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysCardQuery", q)
}
// The TraverseSysCard type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSysCard func(context.Context, *ent.SysCardQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSysCard) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSysCard) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SysCardQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SysCardQuery", q)
}
// The SysMenuFunc type is an adapter to allow the use of ordinary function as a Querier.
type SysMenuFunc func(context.Context, *ent.SysMenuQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SysMenuFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SysMenuQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysMenuQuery", q)
}
// The TraverseSysMenu type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSysMenu func(context.Context, *ent.SysMenuQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSysMenu) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSysMenu) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SysMenuQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SysMenuQuery", q)
}
// The SysRoleFunc type is an adapter to allow the use of ordinary function as a Querier.
type SysRoleFunc func(context.Context, *ent.SysRoleQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SysRoleFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SysRoleQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysRoleQuery", q)
}
// The TraverseSysRole type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSysRole func(context.Context, *ent.SysRoleQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSysRole) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSysRole) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SysRoleQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SysRoleQuery", q)
}
// The SysUserFunc type is an adapter to allow the use of ordinary function as a Querier.
type SysUserFunc func(context.Context, *ent.SysUserQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SysUserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SysUserQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysUserQuery", q)
}
// The TraverseSysUser type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSysUser func(context.Context, *ent.SysUserQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSysUser) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSysUser) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SysUserQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SysUserQuery", q)
}
// The SysUserLogFunc type is an adapter to allow the use of ordinary function as a Querier.
type SysUserLogFunc func(context.Context, *ent.SysUserLogQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f SysUserLogFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.SysUserLogQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.SysUserLogQuery", q)
}
// The TraverseSysUserLog type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSysUserLog func(context.Context, *ent.SysUserLogQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSysUserLog) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseSysUserLog) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.SysUserLogQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.SysUserLogQuery", q)
}
// NewQuery returns the generic Query interface for the given typed query.
func NewQuery(q ent.Query) (Query, error) {
switch q := q.(type) {
case *ent.CourseEntityQuery:
return &query[*ent.CourseEntityQuery, predicate.CourseEntity, courseentity.OrderOption]{typ: ent.TypeCourseEntity, tq: q}, nil
case *ent.CpImageQuery:
return &query[*ent.CpImageQuery, predicate.CpImage, cpimage.OrderOption]{typ: ent.TypeCpImage, tq: q}, nil
case *ent.CpSchoolQuery:
return &query[*ent.CpSchoolQuery, predicate.CpSchool, cpschool.OrderOption]{typ: ent.TypeCpSchool, tq: q}, nil
case *ent.CpTaskQuery:
return &query[*ent.CpTaskQuery, predicate.CpTask, cptask.OrderOption]{typ: ent.TypeCpTask, tq: q}, nil
case *ent.CpTaskLogQuery:
return &query[*ent.CpTaskLogQuery, predicate.CpTaskLog, cptasklog.OrderOption]{typ: ent.TypeCpTaskLog, tq: q}, nil
case *ent.CpUserQuery:
return &query[*ent.CpUserQuery, predicate.CpUser, cpuser.OrderOption]{typ: ent.TypeCpUser, tq: q}, nil
case *ent.SysAgentQuery:
return &query[*ent.SysAgentQuery, predicate.SysAgent, sysagent.OrderOption]{typ: ent.TypeSysAgent, tq: q}, nil
case *ent.SysCardQuery:
return &query[*ent.SysCardQuery, predicate.SysCard, syscard.OrderOption]{typ: ent.TypeSysCard, tq: q}, nil
case *ent.SysMenuQuery:
return &query[*ent.SysMenuQuery, predicate.SysMenu, sysmenu.OrderOption]{typ: ent.TypeSysMenu, tq: q}, nil
case *ent.SysRoleQuery:
return &query[*ent.SysRoleQuery, predicate.SysRole, sysrole.OrderOption]{typ: ent.TypeSysRole, tq: q}, nil
case *ent.SysUserQuery:
return &query[*ent.SysUserQuery, predicate.SysUser, sysuser.OrderOption]{typ: ent.TypeSysUser, tq: q}, nil
case *ent.SysUserLogQuery:
return &query[*ent.SysUserLogQuery, predicate.SysUserLog, sysuserlog.OrderOption]{typ: ent.TypeSysUserLog, 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...)
}