[feature] migrate to monorepo
This commit is contained in:
commit
05ddc1f783
267 changed files with 75165 additions and 0 deletions
614
backend/ent/categorycontent_query.go
Normal file
614
backend/ent/categorycontent_query.go
Normal file
|
@ -0,0 +1,614 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"tss-rocks-be/ent/category"
|
||||
"tss-rocks-be/ent/categorycontent"
|
||||
"tss-rocks-be/ent/predicate"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CategoryContentQuery is the builder for querying CategoryContent entities.
|
||||
type CategoryContentQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []categorycontent.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.CategoryContent
|
||||
withCategory *CategoryQuery
|
||||
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 CategoryContentQuery builder.
|
||||
func (ccq *CategoryContentQuery) Where(ps ...predicate.CategoryContent) *CategoryContentQuery {
|
||||
ccq.predicates = append(ccq.predicates, ps...)
|
||||
return ccq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (ccq *CategoryContentQuery) Limit(limit int) *CategoryContentQuery {
|
||||
ccq.ctx.Limit = &limit
|
||||
return ccq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (ccq *CategoryContentQuery) Offset(offset int) *CategoryContentQuery {
|
||||
ccq.ctx.Offset = &offset
|
||||
return ccq
|
||||
}
|
||||
|
||||
// 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 (ccq *CategoryContentQuery) Unique(unique bool) *CategoryContentQuery {
|
||||
ccq.ctx.Unique = &unique
|
||||
return ccq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (ccq *CategoryContentQuery) Order(o ...categorycontent.OrderOption) *CategoryContentQuery {
|
||||
ccq.order = append(ccq.order, o...)
|
||||
return ccq
|
||||
}
|
||||
|
||||
// QueryCategory chains the current query on the "category" edge.
|
||||
func (ccq *CategoryContentQuery) QueryCategory() *CategoryQuery {
|
||||
query := (&CategoryClient{config: ccq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := ccq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := ccq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(categorycontent.Table, categorycontent.FieldID, selector),
|
||||
sqlgraph.To(category.Table, category.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, categorycontent.CategoryTable, categorycontent.CategoryColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(ccq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first CategoryContent entity from the query.
|
||||
// Returns a *NotFoundError when no CategoryContent was found.
|
||||
func (ccq *CategoryContentQuery) First(ctx context.Context) (*CategoryContent, error) {
|
||||
nodes, err := ccq.Limit(1).All(setContextOp(ctx, ccq.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{categorycontent.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) FirstX(ctx context.Context) *CategoryContent {
|
||||
node, err := ccq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first CategoryContent ID from the query.
|
||||
// Returns a *NotFoundError when no CategoryContent ID was found.
|
||||
func (ccq *CategoryContentQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ccq.Limit(1).IDs(setContextOp(ctx, ccq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{categorycontent.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := ccq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single CategoryContent entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one CategoryContent entity is found.
|
||||
// Returns a *NotFoundError when no CategoryContent entities are found.
|
||||
func (ccq *CategoryContentQuery) Only(ctx context.Context) (*CategoryContent, error) {
|
||||
nodes, err := ccq.Limit(2).All(setContextOp(ctx, ccq.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{categorycontent.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{categorycontent.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) OnlyX(ctx context.Context) *CategoryContent {
|
||||
node, err := ccq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only CategoryContent ID in the query.
|
||||
// Returns a *NotSingularError when more than one CategoryContent ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (ccq *CategoryContentQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = ccq.Limit(2).IDs(setContextOp(ctx, ccq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{categorycontent.Label}
|
||||
default:
|
||||
err = &NotSingularError{categorycontent.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := ccq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of CategoryContents.
|
||||
func (ccq *CategoryContentQuery) All(ctx context.Context) ([]*CategoryContent, error) {
|
||||
ctx = setContextOp(ctx, ccq.ctx, ent.OpQueryAll)
|
||||
if err := ccq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*CategoryContent, *CategoryContentQuery]()
|
||||
return withInterceptors[[]*CategoryContent](ctx, ccq, qr, ccq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) AllX(ctx context.Context) []*CategoryContent {
|
||||
nodes, err := ccq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of CategoryContent IDs.
|
||||
func (ccq *CategoryContentQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if ccq.ctx.Unique == nil && ccq.path != nil {
|
||||
ccq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, ccq.ctx, ent.OpQueryIDs)
|
||||
if err = ccq.Select(categorycontent.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := ccq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (ccq *CategoryContentQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, ccq.ctx, ent.OpQueryCount)
|
||||
if err := ccq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, ccq, querierCount[*CategoryContentQuery](), ccq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (ccq *CategoryContentQuery) CountX(ctx context.Context) int {
|
||||
count, err := ccq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (ccq *CategoryContentQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, ccq.ctx, ent.OpQueryExist)
|
||||
switch _, err := ccq.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 (ccq *CategoryContentQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := ccq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CategoryContentQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (ccq *CategoryContentQuery) Clone() *CategoryContentQuery {
|
||||
if ccq == nil {
|
||||
return nil
|
||||
}
|
||||
return &CategoryContentQuery{
|
||||
config: ccq.config,
|
||||
ctx: ccq.ctx.Clone(),
|
||||
order: append([]categorycontent.OrderOption{}, ccq.order...),
|
||||
inters: append([]Interceptor{}, ccq.inters...),
|
||||
predicates: append([]predicate.CategoryContent{}, ccq.predicates...),
|
||||
withCategory: ccq.withCategory.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: ccq.sql.Clone(),
|
||||
path: ccq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCategory tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "category" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (ccq *CategoryContentQuery) WithCategory(opts ...func(*CategoryQuery)) *CategoryContentQuery {
|
||||
query := (&CategoryClient{config: ccq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
ccq.withCategory = query
|
||||
return ccq
|
||||
}
|
||||
|
||||
// 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 categorycontent.LanguageCode `json:"language_code,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CategoryContent.Query().
|
||||
// GroupBy(categorycontent.FieldLanguageCode).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (ccq *CategoryContentQuery) GroupBy(field string, fields ...string) *CategoryContentGroupBy {
|
||||
ccq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CategoryContentGroupBy{build: ccq}
|
||||
grbuild.flds = &ccq.ctx.Fields
|
||||
grbuild.label = categorycontent.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 categorycontent.LanguageCode `json:"language_code,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CategoryContent.Query().
|
||||
// Select(categorycontent.FieldLanguageCode).
|
||||
// Scan(ctx, &v)
|
||||
func (ccq *CategoryContentQuery) Select(fields ...string) *CategoryContentSelect {
|
||||
ccq.ctx.Fields = append(ccq.ctx.Fields, fields...)
|
||||
sbuild := &CategoryContentSelect{CategoryContentQuery: ccq}
|
||||
sbuild.label = categorycontent.Label
|
||||
sbuild.flds, sbuild.scan = &ccq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CategoryContentSelect configured with the given aggregations.
|
||||
func (ccq *CategoryContentQuery) Aggregate(fns ...AggregateFunc) *CategoryContentSelect {
|
||||
return ccq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (ccq *CategoryContentQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range ccq.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, ccq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range ccq.ctx.Fields {
|
||||
if !categorycontent.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if ccq.path != nil {
|
||||
prev, err := ccq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ccq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ccq *CategoryContentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CategoryContent, error) {
|
||||
var (
|
||||
nodes = []*CategoryContent{}
|
||||
withFKs = ccq.withFKs
|
||||
_spec = ccq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
ccq.withCategory != nil,
|
||||
}
|
||||
)
|
||||
if ccq.withCategory != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, categorycontent.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*CategoryContent).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &CategoryContent{config: ccq.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, ccq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := ccq.withCategory; query != nil {
|
||||
if err := ccq.loadCategory(ctx, query, nodes, nil,
|
||||
func(n *CategoryContent, e *Category) { n.Edges.Category = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (ccq *CategoryContentQuery) loadCategory(ctx context.Context, query *CategoryQuery, nodes []*CategoryContent, init func(*CategoryContent), assign func(*CategoryContent, *Category)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*CategoryContent)
|
||||
for i := range nodes {
|
||||
if nodes[i].category_contents == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].category_contents
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(category.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 "category_contents" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ccq *CategoryContentQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := ccq.querySpec()
|
||||
_spec.Node.Columns = ccq.ctx.Fields
|
||||
if len(ccq.ctx.Fields) > 0 {
|
||||
_spec.Unique = ccq.ctx.Unique != nil && *ccq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, ccq.driver, _spec)
|
||||
}
|
||||
|
||||
func (ccq *CategoryContentQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(categorycontent.Table, categorycontent.Columns, sqlgraph.NewFieldSpec(categorycontent.FieldID, field.TypeInt))
|
||||
_spec.From = ccq.sql
|
||||
if unique := ccq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if ccq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := ccq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, categorycontent.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != categorycontent.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := ccq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := ccq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := ccq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := ccq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (ccq *CategoryContentQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(ccq.driver.Dialect())
|
||||
t1 := builder.Table(categorycontent.Table)
|
||||
columns := ccq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = categorycontent.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if ccq.sql != nil {
|
||||
selector = ccq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if ccq.ctx.Unique != nil && *ccq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range ccq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range ccq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := ccq.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 := ccq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// CategoryContentGroupBy is the group-by builder for CategoryContent entities.
|
||||
type CategoryContentGroupBy struct {
|
||||
selector
|
||||
build *CategoryContentQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ccgb *CategoryContentGroupBy) Aggregate(fns ...AggregateFunc) *CategoryContentGroupBy {
|
||||
ccgb.fns = append(ccgb.fns, fns...)
|
||||
return ccgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ccgb *CategoryContentGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ccgb.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := ccgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CategoryContentQuery, *CategoryContentGroupBy](ctx, ccgb.build, ccgb, ccgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (ccgb *CategoryContentGroupBy) sqlScan(ctx context.Context, root *CategoryContentQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(ccgb.fns))
|
||||
for _, fn := range ccgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*ccgb.flds)+len(ccgb.fns))
|
||||
for _, f := range *ccgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*ccgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ccgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// CategoryContentSelect is the builder for selecting fields of CategoryContent entities.
|
||||
type CategoryContentSelect struct {
|
||||
*CategoryContentQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ccs *CategoryContentSelect) Aggregate(fns ...AggregateFunc) *CategoryContentSelect {
|
||||
ccs.fns = append(ccs.fns, fns...)
|
||||
return ccs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ccs *CategoryContentSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ccs.ctx, ent.OpQuerySelect)
|
||||
if err := ccs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CategoryContentQuery, *CategoryContentSelect](ctx, ccs.CategoryContentQuery, ccs, ccs.inters, v)
|
||||
}
|
||||
|
||||
func (ccs *CategoryContentSelect) sqlScan(ctx context.Context, root *CategoryContentQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ccs.fns))
|
||||
for _, fn := range ccs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ccs.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 := ccs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue