610 lines
18 KiB
Go
610 lines
18 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"database/sql/driver"
|
|
"fmt"
|
|
"math"
|
|
"schisandra-album-cloud-microservices/common/ent/predicate"
|
|
"schisandra-album-cloud-microservices/common/ent/scaauthpermissionrule"
|
|
"schisandra-album-cloud-microservices/common/ent/scaauthrole"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ScaAuthRoleQuery is the builder for querying ScaAuthRole entities.
|
|
type ScaAuthRoleQuery struct {
|
|
config
|
|
ctx *QueryContext
|
|
order []scaauthrole.OrderOption
|
|
inters []Interceptor
|
|
predicates []predicate.ScaAuthRole
|
|
withScaAuthPermissionRule *ScaAuthPermissionRuleQuery
|
|
// intermediate query (i.e. traversal path).
|
|
sql *sql.Selector
|
|
path func(context.Context) (*sql.Selector, error)
|
|
}
|
|
|
|
// Where adds a new predicate for the ScaAuthRoleQuery builder.
|
|
func (sarq *ScaAuthRoleQuery) Where(ps ...predicate.ScaAuthRole) *ScaAuthRoleQuery {
|
|
sarq.predicates = append(sarq.predicates, ps...)
|
|
return sarq
|
|
}
|
|
|
|
// Limit the number of records to be returned by this query.
|
|
func (sarq *ScaAuthRoleQuery) Limit(limit int) *ScaAuthRoleQuery {
|
|
sarq.ctx.Limit = &limit
|
|
return sarq
|
|
}
|
|
|
|
// Offset to start from.
|
|
func (sarq *ScaAuthRoleQuery) Offset(offset int) *ScaAuthRoleQuery {
|
|
sarq.ctx.Offset = &offset
|
|
return sarq
|
|
}
|
|
|
|
// 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 (sarq *ScaAuthRoleQuery) Unique(unique bool) *ScaAuthRoleQuery {
|
|
sarq.ctx.Unique = &unique
|
|
return sarq
|
|
}
|
|
|
|
// Order specifies how the records should be ordered.
|
|
func (sarq *ScaAuthRoleQuery) Order(o ...scaauthrole.OrderOption) *ScaAuthRoleQuery {
|
|
sarq.order = append(sarq.order, o...)
|
|
return sarq
|
|
}
|
|
|
|
// QueryScaAuthPermissionRule chains the current query on the "sca_auth_permission_rule" edge.
|
|
func (sarq *ScaAuthRoleQuery) QueryScaAuthPermissionRule() *ScaAuthPermissionRuleQuery {
|
|
query := (&ScaAuthPermissionRuleClient{config: sarq.config}).Query()
|
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
if err := sarq.prepareQuery(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
selector := sarq.sqlQuery(ctx)
|
|
if err := selector.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(scaauthrole.Table, scaauthrole.FieldID, selector),
|
|
sqlgraph.To(scaauthpermissionrule.Table, scaauthpermissionrule.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, scaauthrole.ScaAuthPermissionRuleTable, scaauthrole.ScaAuthPermissionRuleColumn),
|
|
)
|
|
fromU = sqlgraph.SetNeighbors(sarq.driver.Dialect(), step)
|
|
return fromU, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// First returns the first ScaAuthRole entity from the query.
|
|
// Returns a *NotFoundError when no ScaAuthRole was found.
|
|
func (sarq *ScaAuthRoleQuery) First(ctx context.Context) (*ScaAuthRole, error) {
|
|
nodes, err := sarq.Limit(1).All(setContextOp(ctx, sarq.ctx, ent.OpQueryFirst))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nodes) == 0 {
|
|
return nil, &NotFoundError{scaauthrole.Label}
|
|
}
|
|
return nodes[0], nil
|
|
}
|
|
|
|
// FirstX is like First, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) FirstX(ctx context.Context) *ScaAuthRole {
|
|
node, err := sarq.First(ctx)
|
|
if err != nil && !IsNotFound(err) {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// FirstID returns the first ScaAuthRole ID from the query.
|
|
// Returns a *NotFoundError when no ScaAuthRole ID was found.
|
|
func (sarq *ScaAuthRoleQuery) FirstID(ctx context.Context) (id int64, err error) {
|
|
var ids []int64
|
|
if ids, err = sarq.Limit(1).IDs(setContextOp(ctx, sarq.ctx, ent.OpQueryFirstID)); err != nil {
|
|
return
|
|
}
|
|
if len(ids) == 0 {
|
|
err = &NotFoundError{scaauthrole.Label}
|
|
return
|
|
}
|
|
return ids[0], nil
|
|
}
|
|
|
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) FirstIDX(ctx context.Context) int64 {
|
|
id, err := sarq.FirstID(ctx)
|
|
if err != nil && !IsNotFound(err) {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// Only returns a single ScaAuthRole entity found by the query, ensuring it only returns one.
|
|
// Returns a *NotSingularError when more than one ScaAuthRole entity is found.
|
|
// Returns a *NotFoundError when no ScaAuthRole entities are found.
|
|
func (sarq *ScaAuthRoleQuery) Only(ctx context.Context) (*ScaAuthRole, error) {
|
|
nodes, err := sarq.Limit(2).All(setContextOp(ctx, sarq.ctx, ent.OpQueryOnly))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch len(nodes) {
|
|
case 1:
|
|
return nodes[0], nil
|
|
case 0:
|
|
return nil, &NotFoundError{scaauthrole.Label}
|
|
default:
|
|
return nil, &NotSingularError{scaauthrole.Label}
|
|
}
|
|
}
|
|
|
|
// OnlyX is like Only, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) OnlyX(ctx context.Context) *ScaAuthRole {
|
|
node, err := sarq.Only(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// OnlyID is like Only, but returns the only ScaAuthRole ID in the query.
|
|
// Returns a *NotSingularError when more than one ScaAuthRole ID is found.
|
|
// Returns a *NotFoundError when no entities are found.
|
|
func (sarq *ScaAuthRoleQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
|
var ids []int64
|
|
if ids, err = sarq.Limit(2).IDs(setContextOp(ctx, sarq.ctx, ent.OpQueryOnlyID)); err != nil {
|
|
return
|
|
}
|
|
switch len(ids) {
|
|
case 1:
|
|
id = ids[0]
|
|
case 0:
|
|
err = &NotFoundError{scaauthrole.Label}
|
|
default:
|
|
err = &NotSingularError{scaauthrole.Label}
|
|
}
|
|
return
|
|
}
|
|
|
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) OnlyIDX(ctx context.Context) int64 {
|
|
id, err := sarq.OnlyID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// All executes the query and returns a list of ScaAuthRoles.
|
|
func (sarq *ScaAuthRoleQuery) All(ctx context.Context) ([]*ScaAuthRole, error) {
|
|
ctx = setContextOp(ctx, sarq.ctx, ent.OpQueryAll)
|
|
if err := sarq.prepareQuery(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
qr := querierAll[[]*ScaAuthRole, *ScaAuthRoleQuery]()
|
|
return withInterceptors[[]*ScaAuthRole](ctx, sarq, qr, sarq.inters)
|
|
}
|
|
|
|
// AllX is like All, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) AllX(ctx context.Context) []*ScaAuthRole {
|
|
nodes, err := sarq.All(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return nodes
|
|
}
|
|
|
|
// IDs executes the query and returns a list of ScaAuthRole IDs.
|
|
func (sarq *ScaAuthRoleQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
|
if sarq.ctx.Unique == nil && sarq.path != nil {
|
|
sarq.Unique(true)
|
|
}
|
|
ctx = setContextOp(ctx, sarq.ctx, ent.OpQueryIDs)
|
|
if err = sarq.Select(scaauthrole.FieldID).Scan(ctx, &ids); err != nil {
|
|
return nil, err
|
|
}
|
|
return ids, nil
|
|
}
|
|
|
|
// IDsX is like IDs, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) IDsX(ctx context.Context) []int64 {
|
|
ids, err := sarq.IDs(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return ids
|
|
}
|
|
|
|
// Count returns the count of the given query.
|
|
func (sarq *ScaAuthRoleQuery) Count(ctx context.Context) (int, error) {
|
|
ctx = setContextOp(ctx, sarq.ctx, ent.OpQueryCount)
|
|
if err := sarq.prepareQuery(ctx); err != nil {
|
|
return 0, err
|
|
}
|
|
return withInterceptors[int](ctx, sarq, querierCount[*ScaAuthRoleQuery](), sarq.inters)
|
|
}
|
|
|
|
// CountX is like Count, but panics if an error occurs.
|
|
func (sarq *ScaAuthRoleQuery) CountX(ctx context.Context) int {
|
|
count, err := sarq.Count(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return count
|
|
}
|
|
|
|
// Exist returns true if the query has elements in the graph.
|
|
func (sarq *ScaAuthRoleQuery) Exist(ctx context.Context) (bool, error) {
|
|
ctx = setContextOp(ctx, sarq.ctx, ent.OpQueryExist)
|
|
switch _, err := sarq.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 (sarq *ScaAuthRoleQuery) ExistX(ctx context.Context) bool {
|
|
exist, err := sarq.Exist(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return exist
|
|
}
|
|
|
|
// Clone returns a duplicate of the ScaAuthRoleQuery builder, including all associated steps. It can be
|
|
// used to prepare common query builders and use them differently after the clone is made.
|
|
func (sarq *ScaAuthRoleQuery) Clone() *ScaAuthRoleQuery {
|
|
if sarq == nil {
|
|
return nil
|
|
}
|
|
return &ScaAuthRoleQuery{
|
|
config: sarq.config,
|
|
ctx: sarq.ctx.Clone(),
|
|
order: append([]scaauthrole.OrderOption{}, sarq.order...),
|
|
inters: append([]Interceptor{}, sarq.inters...),
|
|
predicates: append([]predicate.ScaAuthRole{}, sarq.predicates...),
|
|
withScaAuthPermissionRule: sarq.withScaAuthPermissionRule.Clone(),
|
|
// clone intermediate query.
|
|
sql: sarq.sql.Clone(),
|
|
path: sarq.path,
|
|
}
|
|
}
|
|
|
|
// WithScaAuthPermissionRule tells the query-builder to eager-load the nodes that are connected to
|
|
// the "sca_auth_permission_rule" edge. The optional arguments are used to configure the query builder of the edge.
|
|
func (sarq *ScaAuthRoleQuery) WithScaAuthPermissionRule(opts ...func(*ScaAuthPermissionRuleQuery)) *ScaAuthRoleQuery {
|
|
query := (&ScaAuthPermissionRuleClient{config: sarq.config}).Query()
|
|
for _, opt := range opts {
|
|
opt(query)
|
|
}
|
|
sarq.withScaAuthPermissionRule = query
|
|
return sarq
|
|
}
|
|
|
|
// 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 {
|
|
// RoleName string `json:"role_name,omitempty"`
|
|
// Count int `json:"count,omitempty"`
|
|
// }
|
|
//
|
|
// client.ScaAuthRole.Query().
|
|
// GroupBy(scaauthrole.FieldRoleName).
|
|
// Aggregate(ent.Count()).
|
|
// Scan(ctx, &v)
|
|
func (sarq *ScaAuthRoleQuery) GroupBy(field string, fields ...string) *ScaAuthRoleGroupBy {
|
|
sarq.ctx.Fields = append([]string{field}, fields...)
|
|
grbuild := &ScaAuthRoleGroupBy{build: sarq}
|
|
grbuild.flds = &sarq.ctx.Fields
|
|
grbuild.label = scaauthrole.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 {
|
|
// RoleName string `json:"role_name,omitempty"`
|
|
// }
|
|
//
|
|
// client.ScaAuthRole.Query().
|
|
// Select(scaauthrole.FieldRoleName).
|
|
// Scan(ctx, &v)
|
|
func (sarq *ScaAuthRoleQuery) Select(fields ...string) *ScaAuthRoleSelect {
|
|
sarq.ctx.Fields = append(sarq.ctx.Fields, fields...)
|
|
sbuild := &ScaAuthRoleSelect{ScaAuthRoleQuery: sarq}
|
|
sbuild.label = scaauthrole.Label
|
|
sbuild.flds, sbuild.scan = &sarq.ctx.Fields, sbuild.Scan
|
|
return sbuild
|
|
}
|
|
|
|
// Aggregate returns a ScaAuthRoleSelect configured with the given aggregations.
|
|
func (sarq *ScaAuthRoleQuery) Aggregate(fns ...AggregateFunc) *ScaAuthRoleSelect {
|
|
return sarq.Select().Aggregate(fns...)
|
|
}
|
|
|
|
func (sarq *ScaAuthRoleQuery) prepareQuery(ctx context.Context) error {
|
|
for _, inter := range sarq.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, sarq); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
for _, f := range sarq.ctx.Fields {
|
|
if !scaauthrole.ValidColumn(f) {
|
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
}
|
|
if sarq.path != nil {
|
|
prev, err := sarq.path(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sarq.sql = prev
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sarq *ScaAuthRoleQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ScaAuthRole, error) {
|
|
var (
|
|
nodes = []*ScaAuthRole{}
|
|
_spec = sarq.querySpec()
|
|
loadedTypes = [1]bool{
|
|
sarq.withScaAuthPermissionRule != nil,
|
|
}
|
|
)
|
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
|
return (*ScaAuthRole).scanValues(nil, columns)
|
|
}
|
|
_spec.Assign = func(columns []string, values []any) error {
|
|
node := &ScaAuthRole{config: sarq.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, sarq.driver, _spec); err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nodes) == 0 {
|
|
return nodes, nil
|
|
}
|
|
if query := sarq.withScaAuthPermissionRule; query != nil {
|
|
if err := sarq.loadScaAuthPermissionRule(ctx, query, nodes,
|
|
func(n *ScaAuthRole) { n.Edges.ScaAuthPermissionRule = []*ScaAuthPermissionRule{} },
|
|
func(n *ScaAuthRole, e *ScaAuthPermissionRule) {
|
|
n.Edges.ScaAuthPermissionRule = append(n.Edges.ScaAuthPermissionRule, e)
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
func (sarq *ScaAuthRoleQuery) loadScaAuthPermissionRule(ctx context.Context, query *ScaAuthPermissionRuleQuery, nodes []*ScaAuthRole, init func(*ScaAuthRole), assign func(*ScaAuthRole, *ScaAuthPermissionRule)) error {
|
|
fks := make([]driver.Value, 0, len(nodes))
|
|
nodeids := make(map[int64]*ScaAuthRole)
|
|
for i := range nodes {
|
|
fks = append(fks, nodes[i].ID)
|
|
nodeids[nodes[i].ID] = nodes[i]
|
|
if init != nil {
|
|
init(nodes[i])
|
|
}
|
|
}
|
|
query.withFKs = true
|
|
query.Where(predicate.ScaAuthPermissionRule(func(s *sql.Selector) {
|
|
s.Where(sql.InValues(s.C(scaauthrole.ScaAuthPermissionRuleColumn), fks...))
|
|
}))
|
|
neighbors, err := query.All(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, n := range neighbors {
|
|
fk := n.sca_auth_role_sca_auth_permission_rule
|
|
if fk == nil {
|
|
return fmt.Errorf(`foreign-key "sca_auth_role_sca_auth_permission_rule" is nil for node %v`, n.ID)
|
|
}
|
|
node, ok := nodeids[*fk]
|
|
if !ok {
|
|
return fmt.Errorf(`unexpected referenced foreign-key "sca_auth_role_sca_auth_permission_rule" returned %v for node %v`, *fk, n.ID)
|
|
}
|
|
assign(node, n)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (sarq *ScaAuthRoleQuery) sqlCount(ctx context.Context) (int, error) {
|
|
_spec := sarq.querySpec()
|
|
_spec.Node.Columns = sarq.ctx.Fields
|
|
if len(sarq.ctx.Fields) > 0 {
|
|
_spec.Unique = sarq.ctx.Unique != nil && *sarq.ctx.Unique
|
|
}
|
|
return sqlgraph.CountNodes(ctx, sarq.driver, _spec)
|
|
}
|
|
|
|
func (sarq *ScaAuthRoleQuery) querySpec() *sqlgraph.QuerySpec {
|
|
_spec := sqlgraph.NewQuerySpec(scaauthrole.Table, scaauthrole.Columns, sqlgraph.NewFieldSpec(scaauthrole.FieldID, field.TypeInt64))
|
|
_spec.From = sarq.sql
|
|
if unique := sarq.ctx.Unique; unique != nil {
|
|
_spec.Unique = *unique
|
|
} else if sarq.path != nil {
|
|
_spec.Unique = true
|
|
}
|
|
if fields := sarq.ctx.Fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, scaauthrole.FieldID)
|
|
for i := range fields {
|
|
if fields[i] != scaauthrole.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
|
}
|
|
}
|
|
}
|
|
if ps := sarq.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if limit := sarq.ctx.Limit; limit != nil {
|
|
_spec.Limit = *limit
|
|
}
|
|
if offset := sarq.ctx.Offset; offset != nil {
|
|
_spec.Offset = *offset
|
|
}
|
|
if ps := sarq.order; len(ps) > 0 {
|
|
_spec.Order = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
return _spec
|
|
}
|
|
|
|
func (sarq *ScaAuthRoleQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|
builder := sql.Dialect(sarq.driver.Dialect())
|
|
t1 := builder.Table(scaauthrole.Table)
|
|
columns := sarq.ctx.Fields
|
|
if len(columns) == 0 {
|
|
columns = scaauthrole.Columns
|
|
}
|
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
|
if sarq.sql != nil {
|
|
selector = sarq.sql
|
|
selector.Select(selector.Columns(columns...)...)
|
|
}
|
|
if sarq.ctx.Unique != nil && *sarq.ctx.Unique {
|
|
selector.Distinct()
|
|
}
|
|
for _, p := range sarq.predicates {
|
|
p(selector)
|
|
}
|
|
for _, p := range sarq.order {
|
|
p(selector)
|
|
}
|
|
if offset := sarq.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 := sarq.ctx.Limit; limit != nil {
|
|
selector.Limit(*limit)
|
|
}
|
|
return selector
|
|
}
|
|
|
|
// ScaAuthRoleGroupBy is the group-by builder for ScaAuthRole entities.
|
|
type ScaAuthRoleGroupBy struct {
|
|
selector
|
|
build *ScaAuthRoleQuery
|
|
}
|
|
|
|
// Aggregate adds the given aggregation functions to the group-by query.
|
|
func (sargb *ScaAuthRoleGroupBy) Aggregate(fns ...AggregateFunc) *ScaAuthRoleGroupBy {
|
|
sargb.fns = append(sargb.fns, fns...)
|
|
return sargb
|
|
}
|
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
func (sargb *ScaAuthRoleGroupBy) Scan(ctx context.Context, v any) error {
|
|
ctx = setContextOp(ctx, sargb.build.ctx, ent.OpQueryGroupBy)
|
|
if err := sargb.build.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
return scanWithInterceptors[*ScaAuthRoleQuery, *ScaAuthRoleGroupBy](ctx, sargb.build, sargb, sargb.build.inters, v)
|
|
}
|
|
|
|
func (sargb *ScaAuthRoleGroupBy) sqlScan(ctx context.Context, root *ScaAuthRoleQuery, v any) error {
|
|
selector := root.sqlQuery(ctx).Select()
|
|
aggregation := make([]string, 0, len(sargb.fns))
|
|
for _, fn := range sargb.fns {
|
|
aggregation = append(aggregation, fn(selector))
|
|
}
|
|
if len(selector.SelectedColumns()) == 0 {
|
|
columns := make([]string, 0, len(*sargb.flds)+len(sargb.fns))
|
|
for _, f := range *sargb.flds {
|
|
columns = append(columns, selector.C(f))
|
|
}
|
|
columns = append(columns, aggregation...)
|
|
selector.Select(columns...)
|
|
}
|
|
selector.GroupBy(selector.Columns(*sargb.flds...)...)
|
|
if err := selector.Err(); err != nil {
|
|
return err
|
|
}
|
|
rows := &sql.Rows{}
|
|
query, args := selector.Query()
|
|
if err := sargb.build.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|
|
|
|
// ScaAuthRoleSelect is the builder for selecting fields of ScaAuthRole entities.
|
|
type ScaAuthRoleSelect struct {
|
|
*ScaAuthRoleQuery
|
|
selector
|
|
}
|
|
|
|
// Aggregate adds the given aggregation functions to the selector query.
|
|
func (sars *ScaAuthRoleSelect) Aggregate(fns ...AggregateFunc) *ScaAuthRoleSelect {
|
|
sars.fns = append(sars.fns, fns...)
|
|
return sars
|
|
}
|
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
func (sars *ScaAuthRoleSelect) Scan(ctx context.Context, v any) error {
|
|
ctx = setContextOp(ctx, sars.ctx, ent.OpQuerySelect)
|
|
if err := sars.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
return scanWithInterceptors[*ScaAuthRoleQuery, *ScaAuthRoleSelect](ctx, sars.ScaAuthRoleQuery, sars, sars.inters, v)
|
|
}
|
|
|
|
func (sars *ScaAuthRoleSelect) sqlScan(ctx context.Context, root *ScaAuthRoleQuery, v any) error {
|
|
selector := root.sqlQuery(ctx)
|
|
aggregation := make([]string, 0, len(sars.fns))
|
|
for _, fn := range sars.fns {
|
|
aggregation = append(aggregation, fn(selector))
|
|
}
|
|
switch n := len(*sars.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 := sars.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|