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