// Code generated by ent, DO NOT EDIT. package intercept import ( "context" "fmt" "entgo.io/ent/dialect/sql" "github.com/cloudreve/Cloudreve/v4/ent" "github.com/cloudreve/Cloudreve/v4/ent/davaccount" "github.com/cloudreve/Cloudreve/v4/ent/directlink" "github.com/cloudreve/Cloudreve/v4/ent/entity" "github.com/cloudreve/Cloudreve/v4/ent/file" "github.com/cloudreve/Cloudreve/v4/ent/group" "github.com/cloudreve/Cloudreve/v4/ent/metadata" "github.com/cloudreve/Cloudreve/v4/ent/node" "github.com/cloudreve/Cloudreve/v4/ent/passkey" "github.com/cloudreve/Cloudreve/v4/ent/predicate" "github.com/cloudreve/Cloudreve/v4/ent/setting" "github.com/cloudreve/Cloudreve/v4/ent/share" "github.com/cloudreve/Cloudreve/v4/ent/storagepolicy" "github.com/cloudreve/Cloudreve/v4/ent/task" "github.com/cloudreve/Cloudreve/v4/ent/user" ) // 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 DavAccountFunc type is an adapter to allow the use of ordinary function as a Querier. type DavAccountFunc func(context.Context, *ent.DavAccountQuery) (ent.Value, error) // Query calls f(ctx, q). func (f DavAccountFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.DavAccountQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.DavAccountQuery", q) } // The TraverseDavAccount type is an adapter to allow the use of ordinary function as Traverser. type TraverseDavAccount func(context.Context, *ent.DavAccountQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseDavAccount) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseDavAccount) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.DavAccountQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.DavAccountQuery", q) } // The DirectLinkFunc type is an adapter to allow the use of ordinary function as a Querier. type DirectLinkFunc func(context.Context, *ent.DirectLinkQuery) (ent.Value, error) // Query calls f(ctx, q). func (f DirectLinkFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.DirectLinkQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.DirectLinkQuery", q) } // The TraverseDirectLink type is an adapter to allow the use of ordinary function as Traverser. type TraverseDirectLink func(context.Context, *ent.DirectLinkQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseDirectLink) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseDirectLink) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.DirectLinkQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.DirectLinkQuery", q) } // The EntityFunc type is an adapter to allow the use of ordinary function as a Querier. type EntityFunc func(context.Context, *ent.EntityQuery) (ent.Value, error) // Query calls f(ctx, q). func (f EntityFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.EntityQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.EntityQuery", q) } // The TraverseEntity type is an adapter to allow the use of ordinary function as Traverser. type TraverseEntity func(context.Context, *ent.EntityQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseEntity) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseEntity) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.EntityQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.EntityQuery", q) } // The FileFunc type is an adapter to allow the use of ordinary function as a Querier. type FileFunc func(context.Context, *ent.FileQuery) (ent.Value, error) // Query calls f(ctx, q). func (f FileFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.FileQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.FileQuery", q) } // The TraverseFile type is an adapter to allow the use of ordinary function as Traverser. type TraverseFile func(context.Context, *ent.FileQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseFile) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseFile) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.FileQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.FileQuery", q) } // The GroupFunc type is an adapter to allow the use of ordinary function as a Querier. type GroupFunc func(context.Context, *ent.GroupQuery) (ent.Value, error) // Query calls f(ctx, q). func (f GroupFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.GroupQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.GroupQuery", q) } // The TraverseGroup type is an adapter to allow the use of ordinary function as Traverser. type TraverseGroup func(context.Context, *ent.GroupQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseGroup) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseGroup) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.GroupQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.GroupQuery", q) } // The MetadataFunc type is an adapter to allow the use of ordinary function as a Querier. type MetadataFunc func(context.Context, *ent.MetadataQuery) (ent.Value, error) // Query calls f(ctx, q). func (f MetadataFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.MetadataQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.MetadataQuery", q) } // The TraverseMetadata type is an adapter to allow the use of ordinary function as Traverser. type TraverseMetadata func(context.Context, *ent.MetadataQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseMetadata) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseMetadata) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.MetadataQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.MetadataQuery", q) } // The NodeFunc type is an adapter to allow the use of ordinary function as a Querier. type NodeFunc func(context.Context, *ent.NodeQuery) (ent.Value, error) // Query calls f(ctx, q). func (f NodeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.NodeQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.NodeQuery", q) } // The TraverseNode type is an adapter to allow the use of ordinary function as Traverser. type TraverseNode func(context.Context, *ent.NodeQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseNode) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseNode) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.NodeQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.NodeQuery", q) } // The PasskeyFunc type is an adapter to allow the use of ordinary function as a Querier. type PasskeyFunc func(context.Context, *ent.PasskeyQuery) (ent.Value, error) // Query calls f(ctx, q). func (f PasskeyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.PasskeyQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.PasskeyQuery", q) } // The TraversePasskey type is an adapter to allow the use of ordinary function as Traverser. type TraversePasskey func(context.Context, *ent.PasskeyQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraversePasskey) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraversePasskey) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.PasskeyQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.PasskeyQuery", q) } // The SettingFunc type is an adapter to allow the use of ordinary function as a Querier. type SettingFunc func(context.Context, *ent.SettingQuery) (ent.Value, error) // Query calls f(ctx, q). func (f SettingFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.SettingQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q) } // The TraverseSetting type is an adapter to allow the use of ordinary function as Traverser. type TraverseSetting func(context.Context, *ent.SettingQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseSetting) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseSetting) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.SettingQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.SettingQuery", q) } // The ShareFunc type is an adapter to allow the use of ordinary function as a Querier. type ShareFunc func(context.Context, *ent.ShareQuery) (ent.Value, error) // Query calls f(ctx, q). func (f ShareFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.ShareQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.ShareQuery", q) } // The TraverseShare type is an adapter to allow the use of ordinary function as Traverser. type TraverseShare func(context.Context, *ent.ShareQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseShare) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseShare) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.ShareQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.ShareQuery", q) } // The StoragePolicyFunc type is an adapter to allow the use of ordinary function as a Querier. type StoragePolicyFunc func(context.Context, *ent.StoragePolicyQuery) (ent.Value, error) // Query calls f(ctx, q). func (f StoragePolicyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.StoragePolicyQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.StoragePolicyQuery", q) } // The TraverseStoragePolicy type is an adapter to allow the use of ordinary function as Traverser. type TraverseStoragePolicy func(context.Context, *ent.StoragePolicyQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseStoragePolicy) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseStoragePolicy) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.StoragePolicyQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.StoragePolicyQuery", q) } // The TaskFunc type is an adapter to allow the use of ordinary function as a Querier. type TaskFunc func(context.Context, *ent.TaskQuery) (ent.Value, error) // Query calls f(ctx, q). func (f TaskFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.TaskQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.TaskQuery", q) } // The TraverseTask type is an adapter to allow the use of ordinary function as Traverser. type TraverseTask func(context.Context, *ent.TaskQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseTask) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseTask) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.TaskQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.TaskQuery", q) } // The UserFunc type is an adapter to allow the use of ordinary function as a Querier. type UserFunc func(context.Context, *ent.UserQuery) (ent.Value, error) // Query calls f(ctx, q). func (f UserFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) { if q, ok := q.(*ent.UserQuery); ok { return f(ctx, q) } return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserQuery", q) } // The TraverseUser type is an adapter to allow the use of ordinary function as Traverser. type TraverseUser func(context.Context, *ent.UserQuery) error // Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. func (f TraverseUser) Intercept(next ent.Querier) ent.Querier { return next } // Traverse calls f(ctx, q). func (f TraverseUser) Traverse(ctx context.Context, q ent.Query) error { if q, ok := q.(*ent.UserQuery); ok { return f(ctx, q) } return fmt.Errorf("unexpected query type %T. expect *ent.UserQuery", 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.DavAccountQuery: return &query[*ent.DavAccountQuery, predicate.DavAccount, davaccount.OrderOption]{typ: ent.TypeDavAccount, tq: q}, nil case *ent.DirectLinkQuery: return &query[*ent.DirectLinkQuery, predicate.DirectLink, directlink.OrderOption]{typ: ent.TypeDirectLink, tq: q}, nil case *ent.EntityQuery: return &query[*ent.EntityQuery, predicate.Entity, entity.OrderOption]{typ: ent.TypeEntity, tq: q}, nil case *ent.FileQuery: return &query[*ent.FileQuery, predicate.File, file.OrderOption]{typ: ent.TypeFile, tq: q}, nil case *ent.GroupQuery: return &query[*ent.GroupQuery, predicate.Group, group.OrderOption]{typ: ent.TypeGroup, tq: q}, nil case *ent.MetadataQuery: return &query[*ent.MetadataQuery, predicate.Metadata, metadata.OrderOption]{typ: ent.TypeMetadata, tq: q}, nil case *ent.NodeQuery: return &query[*ent.NodeQuery, predicate.Node, node.OrderOption]{typ: ent.TypeNode, tq: q}, nil case *ent.PasskeyQuery: return &query[*ent.PasskeyQuery, predicate.Passkey, passkey.OrderOption]{typ: ent.TypePasskey, tq: q}, nil case *ent.SettingQuery: return &query[*ent.SettingQuery, predicate.Setting, setting.OrderOption]{typ: ent.TypeSetting, tq: q}, nil case *ent.ShareQuery: return &query[*ent.ShareQuery, predicate.Share, share.OrderOption]{typ: ent.TypeShare, tq: q}, nil case *ent.StoragePolicyQuery: return &query[*ent.StoragePolicyQuery, predicate.StoragePolicy, storagepolicy.OrderOption]{typ: ent.TypeStoragePolicy, tq: q}, nil case *ent.TaskQuery: return &query[*ent.TaskQuery, predicate.Task, task.OrderOption]{typ: ent.TypeTask, tq: q}, nil case *ent.UserQuery: return &query[*ent.UserQuery, predicate.User, user.OrderOption]{typ: ent.TypeUser, 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...) }