tss-rocks/backend/ent/postcontributor_query.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

764 lines
23 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"tss-rocks-be/ent/contributor"
"tss-rocks-be/ent/contributorrole"
"tss-rocks-be/ent/post"
"tss-rocks-be/ent/postcontributor"
"tss-rocks-be/ent/predicate"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// PostContributorQuery is the builder for querying PostContributor entities.
type PostContributorQuery struct {
config
ctx *QueryContext
order []postcontributor.OrderOption
inters []Interceptor
predicates []predicate.PostContributor
withPost *PostQuery
withContributor *ContributorQuery
withRole *ContributorRoleQuery
withFKs bool
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the PostContributorQuery builder.
func (pcq *PostContributorQuery) Where(ps ...predicate.PostContributor) *PostContributorQuery {
pcq.predicates = append(pcq.predicates, ps...)
return pcq
}
// Limit the number of records to be returned by this query.
func (pcq *PostContributorQuery) Limit(limit int) *PostContributorQuery {
pcq.ctx.Limit = &limit
return pcq
}
// Offset to start from.
func (pcq *PostContributorQuery) Offset(offset int) *PostContributorQuery {
pcq.ctx.Offset = &offset
return pcq
}
// 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 (pcq *PostContributorQuery) Unique(unique bool) *PostContributorQuery {
pcq.ctx.Unique = &unique
return pcq
}
// Order specifies how the records should be ordered.
func (pcq *PostContributorQuery) Order(o ...postcontributor.OrderOption) *PostContributorQuery {
pcq.order = append(pcq.order, o...)
return pcq
}
// QueryPost chains the current query on the "post" edge.
func (pcq *PostContributorQuery) QueryPost() *PostQuery {
query := (&PostClient{config: pcq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := pcq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := pcq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(postcontributor.Table, postcontributor.FieldID, selector),
sqlgraph.To(post.Table, post.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, postcontributor.PostTable, postcontributor.PostColumn),
)
fromU = sqlgraph.SetNeighbors(pcq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryContributor chains the current query on the "contributor" edge.
func (pcq *PostContributorQuery) QueryContributor() *ContributorQuery {
query := (&ContributorClient{config: pcq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := pcq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := pcq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(postcontributor.Table, postcontributor.FieldID, selector),
sqlgraph.To(contributor.Table, contributor.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, postcontributor.ContributorTable, postcontributor.ContributorColumn),
)
fromU = sqlgraph.SetNeighbors(pcq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryRole chains the current query on the "role" edge.
func (pcq *PostContributorQuery) QueryRole() *ContributorRoleQuery {
query := (&ContributorRoleClient{config: pcq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := pcq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := pcq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(postcontributor.Table, postcontributor.FieldID, selector),
sqlgraph.To(contributorrole.Table, contributorrole.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, postcontributor.RoleTable, postcontributor.RoleColumn),
)
fromU = sqlgraph.SetNeighbors(pcq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first PostContributor entity from the query.
// Returns a *NotFoundError when no PostContributor was found.
func (pcq *PostContributorQuery) First(ctx context.Context) (*PostContributor, error) {
nodes, err := pcq.Limit(1).All(setContextOp(ctx, pcq.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{postcontributor.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (pcq *PostContributorQuery) FirstX(ctx context.Context) *PostContributor {
node, err := pcq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first PostContributor ID from the query.
// Returns a *NotFoundError when no PostContributor ID was found.
func (pcq *PostContributorQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = pcq.Limit(1).IDs(setContextOp(ctx, pcq.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{postcontributor.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (pcq *PostContributorQuery) FirstIDX(ctx context.Context) int {
id, err := pcq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single PostContributor entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one PostContributor entity is found.
// Returns a *NotFoundError when no PostContributor entities are found.
func (pcq *PostContributorQuery) Only(ctx context.Context) (*PostContributor, error) {
nodes, err := pcq.Limit(2).All(setContextOp(ctx, pcq.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{postcontributor.Label}
default:
return nil, &NotSingularError{postcontributor.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (pcq *PostContributorQuery) OnlyX(ctx context.Context) *PostContributor {
node, err := pcq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only PostContributor ID in the query.
// Returns a *NotSingularError when more than one PostContributor ID is found.
// Returns a *NotFoundError when no entities are found.
func (pcq *PostContributorQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = pcq.Limit(2).IDs(setContextOp(ctx, pcq.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{postcontributor.Label}
default:
err = &NotSingularError{postcontributor.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (pcq *PostContributorQuery) OnlyIDX(ctx context.Context) int {
id, err := pcq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of PostContributors.
func (pcq *PostContributorQuery) All(ctx context.Context) ([]*PostContributor, error) {
ctx = setContextOp(ctx, pcq.ctx, ent.OpQueryAll)
if err := pcq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*PostContributor, *PostContributorQuery]()
return withInterceptors[[]*PostContributor](ctx, pcq, qr, pcq.inters)
}
// AllX is like All, but panics if an error occurs.
func (pcq *PostContributorQuery) AllX(ctx context.Context) []*PostContributor {
nodes, err := pcq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of PostContributor IDs.
func (pcq *PostContributorQuery) IDs(ctx context.Context) (ids []int, err error) {
if pcq.ctx.Unique == nil && pcq.path != nil {
pcq.Unique(true)
}
ctx = setContextOp(ctx, pcq.ctx, ent.OpQueryIDs)
if err = pcq.Select(postcontributor.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (pcq *PostContributorQuery) IDsX(ctx context.Context) []int {
ids, err := pcq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (pcq *PostContributorQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, pcq.ctx, ent.OpQueryCount)
if err := pcq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, pcq, querierCount[*PostContributorQuery](), pcq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (pcq *PostContributorQuery) CountX(ctx context.Context) int {
count, err := pcq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (pcq *PostContributorQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, pcq.ctx, ent.OpQueryExist)
switch _, err := pcq.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 (pcq *PostContributorQuery) ExistX(ctx context.Context) bool {
exist, err := pcq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the PostContributorQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (pcq *PostContributorQuery) Clone() *PostContributorQuery {
if pcq == nil {
return nil
}
return &PostContributorQuery{
config: pcq.config,
ctx: pcq.ctx.Clone(),
order: append([]postcontributor.OrderOption{}, pcq.order...),
inters: append([]Interceptor{}, pcq.inters...),
predicates: append([]predicate.PostContributor{}, pcq.predicates...),
withPost: pcq.withPost.Clone(),
withContributor: pcq.withContributor.Clone(),
withRole: pcq.withRole.Clone(),
// clone intermediate query.
sql: pcq.sql.Clone(),
path: pcq.path,
}
}
// WithPost tells the query-builder to eager-load the nodes that are connected to
// the "post" edge. The optional arguments are used to configure the query builder of the edge.
func (pcq *PostContributorQuery) WithPost(opts ...func(*PostQuery)) *PostContributorQuery {
query := (&PostClient{config: pcq.config}).Query()
for _, opt := range opts {
opt(query)
}
pcq.withPost = query
return pcq
}
// WithContributor tells the query-builder to eager-load the nodes that are connected to
// the "contributor" edge. The optional arguments are used to configure the query builder of the edge.
func (pcq *PostContributorQuery) WithContributor(opts ...func(*ContributorQuery)) *PostContributorQuery {
query := (&ContributorClient{config: pcq.config}).Query()
for _, opt := range opts {
opt(query)
}
pcq.withContributor = query
return pcq
}
// WithRole tells the query-builder to eager-load the nodes that are connected to
// the "role" edge. The optional arguments are used to configure the query builder of the edge.
func (pcq *PostContributorQuery) WithRole(opts ...func(*ContributorRoleQuery)) *PostContributorQuery {
query := (&ContributorRoleClient{config: pcq.config}).Query()
for _, opt := range opts {
opt(query)
}
pcq.withRole = query
return pcq
}
// 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 {
// LanguageCode postcontributor.LanguageCode `json:"language_code,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.PostContributor.Query().
// GroupBy(postcontributor.FieldLanguageCode).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (pcq *PostContributorQuery) GroupBy(field string, fields ...string) *PostContributorGroupBy {
pcq.ctx.Fields = append([]string{field}, fields...)
grbuild := &PostContributorGroupBy{build: pcq}
grbuild.flds = &pcq.ctx.Fields
grbuild.label = postcontributor.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 {
// LanguageCode postcontributor.LanguageCode `json:"language_code,omitempty"`
// }
//
// client.PostContributor.Query().
// Select(postcontributor.FieldLanguageCode).
// Scan(ctx, &v)
func (pcq *PostContributorQuery) Select(fields ...string) *PostContributorSelect {
pcq.ctx.Fields = append(pcq.ctx.Fields, fields...)
sbuild := &PostContributorSelect{PostContributorQuery: pcq}
sbuild.label = postcontributor.Label
sbuild.flds, sbuild.scan = &pcq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a PostContributorSelect configured with the given aggregations.
func (pcq *PostContributorQuery) Aggregate(fns ...AggregateFunc) *PostContributorSelect {
return pcq.Select().Aggregate(fns...)
}
func (pcq *PostContributorQuery) prepareQuery(ctx context.Context) error {
for _, inter := range pcq.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, pcq); err != nil {
return err
}
}
}
for _, f := range pcq.ctx.Fields {
if !postcontributor.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if pcq.path != nil {
prev, err := pcq.path(ctx)
if err != nil {
return err
}
pcq.sql = prev
}
return nil
}
func (pcq *PostContributorQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PostContributor, error) {
var (
nodes = []*PostContributor{}
withFKs = pcq.withFKs
_spec = pcq.querySpec()
loadedTypes = [3]bool{
pcq.withPost != nil,
pcq.withContributor != nil,
pcq.withRole != nil,
}
)
if pcq.withPost != nil || pcq.withContributor != nil || pcq.withRole != nil {
withFKs = true
}
if withFKs {
_spec.Node.Columns = append(_spec.Node.Columns, postcontributor.ForeignKeys...)
}
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*PostContributor).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &PostContributor{config: pcq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, pcq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := pcq.withPost; query != nil {
if err := pcq.loadPost(ctx, query, nodes, nil,
func(n *PostContributor, e *Post) { n.Edges.Post = e }); err != nil {
return nil, err
}
}
if query := pcq.withContributor; query != nil {
if err := pcq.loadContributor(ctx, query, nodes, nil,
func(n *PostContributor, e *Contributor) { n.Edges.Contributor = e }); err != nil {
return nil, err
}
}
if query := pcq.withRole; query != nil {
if err := pcq.loadRole(ctx, query, nodes, nil,
func(n *PostContributor, e *ContributorRole) { n.Edges.Role = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (pcq *PostContributorQuery) loadPost(ctx context.Context, query *PostQuery, nodes []*PostContributor, init func(*PostContributor), assign func(*PostContributor, *Post)) error {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*PostContributor)
for i := range nodes {
if nodes[i].post_contributors == nil {
continue
}
fk := *nodes[i].post_contributors
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(post.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "post_contributors" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (pcq *PostContributorQuery) loadContributor(ctx context.Context, query *ContributorQuery, nodes []*PostContributor, init func(*PostContributor), assign func(*PostContributor, *Contributor)) error {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*PostContributor)
for i := range nodes {
if nodes[i].contributor_posts == nil {
continue
}
fk := *nodes[i].contributor_posts
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(contributor.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "contributor_posts" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (pcq *PostContributorQuery) loadRole(ctx context.Context, query *ContributorRoleQuery, nodes []*PostContributor, init func(*PostContributor), assign func(*PostContributor, *ContributorRole)) error {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*PostContributor)
for i := range nodes {
if nodes[i].contributor_role_post_contributors == nil {
continue
}
fk := *nodes[i].contributor_role_post_contributors
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(contributorrole.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "contributor_role_post_contributors" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (pcq *PostContributorQuery) sqlCount(ctx context.Context) (int, error) {
_spec := pcq.querySpec()
_spec.Node.Columns = pcq.ctx.Fields
if len(pcq.ctx.Fields) > 0 {
_spec.Unique = pcq.ctx.Unique != nil && *pcq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, pcq.driver, _spec)
}
func (pcq *PostContributorQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(postcontributor.Table, postcontributor.Columns, sqlgraph.NewFieldSpec(postcontributor.FieldID, field.TypeInt))
_spec.From = pcq.sql
if unique := pcq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if pcq.path != nil {
_spec.Unique = true
}
if fields := pcq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, postcontributor.FieldID)
for i := range fields {
if fields[i] != postcontributor.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := pcq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := pcq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := pcq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := pcq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (pcq *PostContributorQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(pcq.driver.Dialect())
t1 := builder.Table(postcontributor.Table)
columns := pcq.ctx.Fields
if len(columns) == 0 {
columns = postcontributor.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if pcq.sql != nil {
selector = pcq.sql
selector.Select(selector.Columns(columns...)...)
}
if pcq.ctx.Unique != nil && *pcq.ctx.Unique {
selector.Distinct()
}
for _, p := range pcq.predicates {
p(selector)
}
for _, p := range pcq.order {
p(selector)
}
if offset := pcq.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 := pcq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// PostContributorGroupBy is the group-by builder for PostContributor entities.
type PostContributorGroupBy struct {
selector
build *PostContributorQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (pcgb *PostContributorGroupBy) Aggregate(fns ...AggregateFunc) *PostContributorGroupBy {
pcgb.fns = append(pcgb.fns, fns...)
return pcgb
}
// Scan applies the selector query and scans the result into the given value.
func (pcgb *PostContributorGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, pcgb.build.ctx, ent.OpQueryGroupBy)
if err := pcgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*PostContributorQuery, *PostContributorGroupBy](ctx, pcgb.build, pcgb, pcgb.build.inters, v)
}
func (pcgb *PostContributorGroupBy) sqlScan(ctx context.Context, root *PostContributorQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(pcgb.fns))
for _, fn := range pcgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*pcgb.flds)+len(pcgb.fns))
for _, f := range *pcgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*pcgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := pcgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// PostContributorSelect is the builder for selecting fields of PostContributor entities.
type PostContributorSelect struct {
*PostContributorQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (pcs *PostContributorSelect) Aggregate(fns ...AggregateFunc) *PostContributorSelect {
pcs.fns = append(pcs.fns, fns...)
return pcs
}
// Scan applies the selector query and scans the result into the given value.
func (pcs *PostContributorSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, pcs.ctx, ent.OpQuerySelect)
if err := pcs.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*PostContributorQuery, *PostContributorSelect](ctx, pcs.PostContributorQuery, pcs, pcs.inters, v)
}
func (pcs *PostContributorSelect) sqlScan(ctx context.Context, root *PostContributorQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(pcs.fns))
for _, fn := range pcs.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*pcs.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 := pcs.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}