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