660 lines
19 KiB
Go
660 lines
19 KiB
Go
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql/driver"
|
||
|
"fmt"
|
||
|
"math"
|
||
|
"thesis/ent/key"
|
||
|
"thesis/ent/predicate"
|
||
|
"thesis/ent/validators"
|
||
|
"thesis/ent/whitelist"
|
||
|
|
||
|
"entgo.io/ent/dialect/sql"
|
||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
"entgo.io/ent/schema/field"
|
||
|
)
|
||
|
|
||
|
// WhiteListQuery is the builder for querying WhiteList entities.
|
||
|
type WhiteListQuery struct {
|
||
|
config
|
||
|
ctx *QueryContext
|
||
|
order []whitelist.OrderOption
|
||
|
inters []Interceptor
|
||
|
predicates []predicate.WhiteList
|
||
|
withSponsor *ValidatorsQuery
|
||
|
withAccount *KeyQuery
|
||
|
// intermediate query (i.e. traversal path).
|
||
|
sql *sql.Selector
|
||
|
path func(context.Context) (*sql.Selector, error)
|
||
|
}
|
||
|
|
||
|
// Where adds a new predicate for the WhiteListQuery builder.
|
||
|
func (wlq *WhiteListQuery) Where(ps ...predicate.WhiteList) *WhiteListQuery {
|
||
|
wlq.predicates = append(wlq.predicates, ps...)
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// Limit the number of records to be returned by this query.
|
||
|
func (wlq *WhiteListQuery) Limit(limit int) *WhiteListQuery {
|
||
|
wlq.ctx.Limit = &limit
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// Offset to start from.
|
||
|
func (wlq *WhiteListQuery) Offset(offset int) *WhiteListQuery {
|
||
|
wlq.ctx.Offset = &offset
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// 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 (wlq *WhiteListQuery) Unique(unique bool) *WhiteListQuery {
|
||
|
wlq.ctx.Unique = &unique
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// Order specifies how the records should be ordered.
|
||
|
func (wlq *WhiteListQuery) Order(o ...whitelist.OrderOption) *WhiteListQuery {
|
||
|
wlq.order = append(wlq.order, o...)
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// QuerySponsor chains the current query on the "Sponsor" edge.
|
||
|
func (wlq *WhiteListQuery) QuerySponsor() *ValidatorsQuery {
|
||
|
query := (&ValidatorsClient{config: wlq.config}).Query()
|
||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||
|
if err := wlq.prepareQuery(ctx); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
selector := wlq.sqlQuery(ctx)
|
||
|
if err := selector.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(whitelist.Table, whitelist.FieldID, selector),
|
||
|
sqlgraph.To(validators.Table, validators.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, whitelist.SponsorTable, whitelist.SponsorColumn),
|
||
|
)
|
||
|
fromU = sqlgraph.SetNeighbors(wlq.driver.Dialect(), step)
|
||
|
return fromU, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// QueryAccount chains the current query on the "Account" edge.
|
||
|
func (wlq *WhiteListQuery) QueryAccount() *KeyQuery {
|
||
|
query := (&KeyClient{config: wlq.config}).Query()
|
||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||
|
if err := wlq.prepareQuery(ctx); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
selector := wlq.sqlQuery(ctx)
|
||
|
if err := selector.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
step := sqlgraph.NewStep(
|
||
|
sqlgraph.From(whitelist.Table, whitelist.FieldID, selector),
|
||
|
sqlgraph.To(key.Table, key.FieldID),
|
||
|
sqlgraph.Edge(sqlgraph.O2M, false, whitelist.AccountTable, whitelist.AccountColumn),
|
||
|
)
|
||
|
fromU = sqlgraph.SetNeighbors(wlq.driver.Dialect(), step)
|
||
|
return fromU, nil
|
||
|
}
|
||
|
return query
|
||
|
}
|
||
|
|
||
|
// First returns the first WhiteList entity from the query.
|
||
|
// Returns a *NotFoundError when no WhiteList was found.
|
||
|
func (wlq *WhiteListQuery) First(ctx context.Context) (*WhiteList, error) {
|
||
|
nodes, err := wlq.Limit(1).All(setContextOp(ctx, wlq.ctx, "First"))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(nodes) == 0 {
|
||
|
return nil, &NotFoundError{whitelist.Label}
|
||
|
}
|
||
|
return nodes[0], nil
|
||
|
}
|
||
|
|
||
|
// FirstX is like First, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) FirstX(ctx context.Context) *WhiteList {
|
||
|
node, err := wlq.First(ctx)
|
||
|
if err != nil && !IsNotFound(err) {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// FirstID returns the first WhiteList ID from the query.
|
||
|
// Returns a *NotFoundError when no WhiteList ID was found.
|
||
|
func (wlq *WhiteListQuery) FirstID(ctx context.Context) (id int, err error) {
|
||
|
var ids []int
|
||
|
if ids, err = wlq.Limit(1).IDs(setContextOp(ctx, wlq.ctx, "FirstID")); err != nil {
|
||
|
return
|
||
|
}
|
||
|
if len(ids) == 0 {
|
||
|
err = &NotFoundError{whitelist.Label}
|
||
|
return
|
||
|
}
|
||
|
return ids[0], nil
|
||
|
}
|
||
|
|
||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) FirstIDX(ctx context.Context) int {
|
||
|
id, err := wlq.FirstID(ctx)
|
||
|
if err != nil && !IsNotFound(err) {
|
||
|
panic(err)
|
||
|
}
|
||
|
return id
|
||
|
}
|
||
|
|
||
|
// Only returns a single WhiteList entity found by the query, ensuring it only returns one.
|
||
|
// Returns a *NotSingularError when more than one WhiteList entity is found.
|
||
|
// Returns a *NotFoundError when no WhiteList entities are found.
|
||
|
func (wlq *WhiteListQuery) Only(ctx context.Context) (*WhiteList, error) {
|
||
|
nodes, err := wlq.Limit(2).All(setContextOp(ctx, wlq.ctx, "Only"))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
switch len(nodes) {
|
||
|
case 1:
|
||
|
return nodes[0], nil
|
||
|
case 0:
|
||
|
return nil, &NotFoundError{whitelist.Label}
|
||
|
default:
|
||
|
return nil, &NotSingularError{whitelist.Label}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// OnlyX is like Only, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) OnlyX(ctx context.Context) *WhiteList {
|
||
|
node, err := wlq.Only(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return node
|
||
|
}
|
||
|
|
||
|
// OnlyID is like Only, but returns the only WhiteList ID in the query.
|
||
|
// Returns a *NotSingularError when more than one WhiteList ID is found.
|
||
|
// Returns a *NotFoundError when no entities are found.
|
||
|
func (wlq *WhiteListQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||
|
var ids []int
|
||
|
if ids, err = wlq.Limit(2).IDs(setContextOp(ctx, wlq.ctx, "OnlyID")); err != nil {
|
||
|
return
|
||
|
}
|
||
|
switch len(ids) {
|
||
|
case 1:
|
||
|
id = ids[0]
|
||
|
case 0:
|
||
|
err = &NotFoundError{whitelist.Label}
|
||
|
default:
|
||
|
err = &NotSingularError{whitelist.Label}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) OnlyIDX(ctx context.Context) int {
|
||
|
id, err := wlq.OnlyID(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return id
|
||
|
}
|
||
|
|
||
|
// All executes the query and returns a list of WhiteLists.
|
||
|
func (wlq *WhiteListQuery) All(ctx context.Context) ([]*WhiteList, error) {
|
||
|
ctx = setContextOp(ctx, wlq.ctx, "All")
|
||
|
if err := wlq.prepareQuery(ctx); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
qr := querierAll[[]*WhiteList, *WhiteListQuery]()
|
||
|
return withInterceptors[[]*WhiteList](ctx, wlq, qr, wlq.inters)
|
||
|
}
|
||
|
|
||
|
// AllX is like All, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) AllX(ctx context.Context) []*WhiteList {
|
||
|
nodes, err := wlq.All(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return nodes
|
||
|
}
|
||
|
|
||
|
// IDs executes the query and returns a list of WhiteList IDs.
|
||
|
func (wlq *WhiteListQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||
|
if wlq.ctx.Unique == nil && wlq.path != nil {
|
||
|
wlq.Unique(true)
|
||
|
}
|
||
|
ctx = setContextOp(ctx, wlq.ctx, "IDs")
|
||
|
if err = wlq.Select(whitelist.FieldID).Scan(ctx, &ids); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return ids, nil
|
||
|
}
|
||
|
|
||
|
// IDsX is like IDs, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) IDsX(ctx context.Context) []int {
|
||
|
ids, err := wlq.IDs(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return ids
|
||
|
}
|
||
|
|
||
|
// Count returns the count of the given query.
|
||
|
func (wlq *WhiteListQuery) Count(ctx context.Context) (int, error) {
|
||
|
ctx = setContextOp(ctx, wlq.ctx, "Count")
|
||
|
if err := wlq.prepareQuery(ctx); err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
return withInterceptors[int](ctx, wlq, querierCount[*WhiteListQuery](), wlq.inters)
|
||
|
}
|
||
|
|
||
|
// CountX is like Count, but panics if an error occurs.
|
||
|
func (wlq *WhiteListQuery) CountX(ctx context.Context) int {
|
||
|
count, err := wlq.Count(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return count
|
||
|
}
|
||
|
|
||
|
// Exist returns true if the query has elements in the graph.
|
||
|
func (wlq *WhiteListQuery) Exist(ctx context.Context) (bool, error) {
|
||
|
ctx = setContextOp(ctx, wlq.ctx, "Exist")
|
||
|
switch _, err := wlq.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 (wlq *WhiteListQuery) ExistX(ctx context.Context) bool {
|
||
|
exist, err := wlq.Exist(ctx)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return exist
|
||
|
}
|
||
|
|
||
|
// Clone returns a duplicate of the WhiteListQuery builder, including all associated steps. It can be
|
||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||
|
func (wlq *WhiteListQuery) Clone() *WhiteListQuery {
|
||
|
if wlq == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return &WhiteListQuery{
|
||
|
config: wlq.config,
|
||
|
ctx: wlq.ctx.Clone(),
|
||
|
order: append([]whitelist.OrderOption{}, wlq.order...),
|
||
|
inters: append([]Interceptor{}, wlq.inters...),
|
||
|
predicates: append([]predicate.WhiteList{}, wlq.predicates...),
|
||
|
withSponsor: wlq.withSponsor.Clone(),
|
||
|
withAccount: wlq.withAccount.Clone(),
|
||
|
// clone intermediate query.
|
||
|
sql: wlq.sql.Clone(),
|
||
|
path: wlq.path,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithSponsor tells the query-builder to eager-load the nodes that are connected to
|
||
|
// the "Sponsor" edge. The optional arguments are used to configure the query builder of the edge.
|
||
|
func (wlq *WhiteListQuery) WithSponsor(opts ...func(*ValidatorsQuery)) *WhiteListQuery {
|
||
|
query := (&ValidatorsClient{config: wlq.config}).Query()
|
||
|
for _, opt := range opts {
|
||
|
opt(query)
|
||
|
}
|
||
|
wlq.withSponsor = query
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// WithAccount tells the query-builder to eager-load the nodes that are connected to
|
||
|
// the "Account" edge. The optional arguments are used to configure the query builder of the edge.
|
||
|
func (wlq *WhiteListQuery) WithAccount(opts ...func(*KeyQuery)) *WhiteListQuery {
|
||
|
query := (&KeyClient{config: wlq.config}).Query()
|
||
|
for _, opt := range opts {
|
||
|
opt(query)
|
||
|
}
|
||
|
wlq.withAccount = query
|
||
|
return wlq
|
||
|
}
|
||
|
|
||
|
// 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.
|
||
|
func (wlq *WhiteListQuery) GroupBy(field string, fields ...string) *WhiteListGroupBy {
|
||
|
wlq.ctx.Fields = append([]string{field}, fields...)
|
||
|
grbuild := &WhiteListGroupBy{build: wlq}
|
||
|
grbuild.flds = &wlq.ctx.Fields
|
||
|
grbuild.label = whitelist.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.
|
||
|
func (wlq *WhiteListQuery) Select(fields ...string) *WhiteListSelect {
|
||
|
wlq.ctx.Fields = append(wlq.ctx.Fields, fields...)
|
||
|
sbuild := &WhiteListSelect{WhiteListQuery: wlq}
|
||
|
sbuild.label = whitelist.Label
|
||
|
sbuild.flds, sbuild.scan = &wlq.ctx.Fields, sbuild.Scan
|
||
|
return sbuild
|
||
|
}
|
||
|
|
||
|
// Aggregate returns a WhiteListSelect configured with the given aggregations.
|
||
|
func (wlq *WhiteListQuery) Aggregate(fns ...AggregateFunc) *WhiteListSelect {
|
||
|
return wlq.Select().Aggregate(fns...)
|
||
|
}
|
||
|
|
||
|
func (wlq *WhiteListQuery) prepareQuery(ctx context.Context) error {
|
||
|
for _, inter := range wlq.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, wlq); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for _, f := range wlq.ctx.Fields {
|
||
|
if !whitelist.ValidColumn(f) {
|
||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
}
|
||
|
}
|
||
|
if wlq.path != nil {
|
||
|
prev, err := wlq.path(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
wlq.sql = prev
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (wlq *WhiteListQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*WhiteList, error) {
|
||
|
var (
|
||
|
nodes = []*WhiteList{}
|
||
|
_spec = wlq.querySpec()
|
||
|
loadedTypes = [2]bool{
|
||
|
wlq.withSponsor != nil,
|
||
|
wlq.withAccount != nil,
|
||
|
}
|
||
|
)
|
||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||
|
return (*WhiteList).scanValues(nil, columns)
|
||
|
}
|
||
|
_spec.Assign = func(columns []string, values []any) error {
|
||
|
node := &WhiteList{config: wlq.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, wlq.driver, _spec); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(nodes) == 0 {
|
||
|
return nodes, nil
|
||
|
}
|
||
|
if query := wlq.withSponsor; query != nil {
|
||
|
if err := wlq.loadSponsor(ctx, query, nodes,
|
||
|
func(n *WhiteList) { n.Edges.Sponsor = []*Validators{} },
|
||
|
func(n *WhiteList, e *Validators) { n.Edges.Sponsor = append(n.Edges.Sponsor, e) }); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
if query := wlq.withAccount; query != nil {
|
||
|
if err := wlq.loadAccount(ctx, query, nodes,
|
||
|
func(n *WhiteList) { n.Edges.Account = []*Key{} },
|
||
|
func(n *WhiteList, e *Key) { n.Edges.Account = append(n.Edges.Account, e) }); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
return nodes, nil
|
||
|
}
|
||
|
|
||
|
func (wlq *WhiteListQuery) loadSponsor(ctx context.Context, query *ValidatorsQuery, nodes []*WhiteList, init func(*WhiteList), assign func(*WhiteList, *Validators)) error {
|
||
|
fks := make([]driver.Value, 0, len(nodes))
|
||
|
nodeids := make(map[int]*WhiteList)
|
||
|
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.Validators(func(s *sql.Selector) {
|
||
|
s.Where(sql.InValues(s.C(whitelist.SponsorColumn), fks...))
|
||
|
}))
|
||
|
neighbors, err := query.All(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for _, n := range neighbors {
|
||
|
fk := n.white_list_sponsor
|
||
|
if fk == nil {
|
||
|
return fmt.Errorf(`foreign-key "white_list_sponsor" is nil for node %v`, n.ID)
|
||
|
}
|
||
|
node, ok := nodeids[*fk]
|
||
|
if !ok {
|
||
|
return fmt.Errorf(`unexpected referenced foreign-key "white_list_sponsor" returned %v for node %v`, *fk, n.ID)
|
||
|
}
|
||
|
assign(node, n)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
func (wlq *WhiteListQuery) loadAccount(ctx context.Context, query *KeyQuery, nodes []*WhiteList, init func(*WhiteList), assign func(*WhiteList, *Key)) error {
|
||
|
fks := make([]driver.Value, 0, len(nodes))
|
||
|
nodeids := make(map[int]*WhiteList)
|
||
|
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.Key(func(s *sql.Selector) {
|
||
|
s.Where(sql.InValues(s.C(whitelist.AccountColumn), fks...))
|
||
|
}))
|
||
|
neighbors, err := query.All(ctx)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for _, n := range neighbors {
|
||
|
fk := n.white_list_account
|
||
|
if fk == nil {
|
||
|
return fmt.Errorf(`foreign-key "white_list_account" is nil for node %v`, n.ID)
|
||
|
}
|
||
|
node, ok := nodeids[*fk]
|
||
|
if !ok {
|
||
|
return fmt.Errorf(`unexpected referenced foreign-key "white_list_account" returned %v for node %v`, *fk, n.ID)
|
||
|
}
|
||
|
assign(node, n)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (wlq *WhiteListQuery) sqlCount(ctx context.Context) (int, error) {
|
||
|
_spec := wlq.querySpec()
|
||
|
_spec.Node.Columns = wlq.ctx.Fields
|
||
|
if len(wlq.ctx.Fields) > 0 {
|
||
|
_spec.Unique = wlq.ctx.Unique != nil && *wlq.ctx.Unique
|
||
|
}
|
||
|
return sqlgraph.CountNodes(ctx, wlq.driver, _spec)
|
||
|
}
|
||
|
|
||
|
func (wlq *WhiteListQuery) querySpec() *sqlgraph.QuerySpec {
|
||
|
_spec := sqlgraph.NewQuerySpec(whitelist.Table, whitelist.Columns, sqlgraph.NewFieldSpec(whitelist.FieldID, field.TypeInt))
|
||
|
_spec.From = wlq.sql
|
||
|
if unique := wlq.ctx.Unique; unique != nil {
|
||
|
_spec.Unique = *unique
|
||
|
} else if wlq.path != nil {
|
||
|
_spec.Unique = true
|
||
|
}
|
||
|
if fields := wlq.ctx.Fields; len(fields) > 0 {
|
||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, whitelist.FieldID)
|
||
|
for i := range fields {
|
||
|
if fields[i] != whitelist.FieldID {
|
||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if ps := wlq.predicates; len(ps) > 0 {
|
||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if limit := wlq.ctx.Limit; limit != nil {
|
||
|
_spec.Limit = *limit
|
||
|
}
|
||
|
if offset := wlq.ctx.Offset; offset != nil {
|
||
|
_spec.Offset = *offset
|
||
|
}
|
||
|
if ps := wlq.order; len(ps) > 0 {
|
||
|
_spec.Order = func(selector *sql.Selector) {
|
||
|
for i := range ps {
|
||
|
ps[i](selector)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return _spec
|
||
|
}
|
||
|
|
||
|
func (wlq *WhiteListQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||
|
builder := sql.Dialect(wlq.driver.Dialect())
|
||
|
t1 := builder.Table(whitelist.Table)
|
||
|
columns := wlq.ctx.Fields
|
||
|
if len(columns) == 0 {
|
||
|
columns = whitelist.Columns
|
||
|
}
|
||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||
|
if wlq.sql != nil {
|
||
|
selector = wlq.sql
|
||
|
selector.Select(selector.Columns(columns...)...)
|
||
|
}
|
||
|
if wlq.ctx.Unique != nil && *wlq.ctx.Unique {
|
||
|
selector.Distinct()
|
||
|
}
|
||
|
for _, p := range wlq.predicates {
|
||
|
p(selector)
|
||
|
}
|
||
|
for _, p := range wlq.order {
|
||
|
p(selector)
|
||
|
}
|
||
|
if offset := wlq.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 := wlq.ctx.Limit; limit != nil {
|
||
|
selector.Limit(*limit)
|
||
|
}
|
||
|
return selector
|
||
|
}
|
||
|
|
||
|
// WhiteListGroupBy is the group-by builder for WhiteList entities.
|
||
|
type WhiteListGroupBy struct {
|
||
|
selector
|
||
|
build *WhiteListQuery
|
||
|
}
|
||
|
|
||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||
|
func (wlgb *WhiteListGroupBy) Aggregate(fns ...AggregateFunc) *WhiteListGroupBy {
|
||
|
wlgb.fns = append(wlgb.fns, fns...)
|
||
|
return wlgb
|
||
|
}
|
||
|
|
||
|
// Scan applies the selector query and scans the result into the given value.
|
||
|
func (wlgb *WhiteListGroupBy) Scan(ctx context.Context, v any) error {
|
||
|
ctx = setContextOp(ctx, wlgb.build.ctx, "GroupBy")
|
||
|
if err := wlgb.build.prepareQuery(ctx); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return scanWithInterceptors[*WhiteListQuery, *WhiteListGroupBy](ctx, wlgb.build, wlgb, wlgb.build.inters, v)
|
||
|
}
|
||
|
|
||
|
func (wlgb *WhiteListGroupBy) sqlScan(ctx context.Context, root *WhiteListQuery, v any) error {
|
||
|
selector := root.sqlQuery(ctx).Select()
|
||
|
aggregation := make([]string, 0, len(wlgb.fns))
|
||
|
for _, fn := range wlgb.fns {
|
||
|
aggregation = append(aggregation, fn(selector))
|
||
|
}
|
||
|
if len(selector.SelectedColumns()) == 0 {
|
||
|
columns := make([]string, 0, len(*wlgb.flds)+len(wlgb.fns))
|
||
|
for _, f := range *wlgb.flds {
|
||
|
columns = append(columns, selector.C(f))
|
||
|
}
|
||
|
columns = append(columns, aggregation...)
|
||
|
selector.Select(columns...)
|
||
|
}
|
||
|
selector.GroupBy(selector.Columns(*wlgb.flds...)...)
|
||
|
if err := selector.Err(); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
rows := &sql.Rows{}
|
||
|
query, args := selector.Query()
|
||
|
if err := wlgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
return sql.ScanSlice(rows, v)
|
||
|
}
|
||
|
|
||
|
// WhiteListSelect is the builder for selecting fields of WhiteList entities.
|
||
|
type WhiteListSelect struct {
|
||
|
*WhiteListQuery
|
||
|
selector
|
||
|
}
|
||
|
|
||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||
|
func (wls *WhiteListSelect) Aggregate(fns ...AggregateFunc) *WhiteListSelect {
|
||
|
wls.fns = append(wls.fns, fns...)
|
||
|
return wls
|
||
|
}
|
||
|
|
||
|
// Scan applies the selector query and scans the result into the given value.
|
||
|
func (wls *WhiteListSelect) Scan(ctx context.Context, v any) error {
|
||
|
ctx = setContextOp(ctx, wls.ctx, "Select")
|
||
|
if err := wls.prepareQuery(ctx); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return scanWithInterceptors[*WhiteListQuery, *WhiteListSelect](ctx, wls.WhiteListQuery, wls, wls.inters, v)
|
||
|
}
|
||
|
|
||
|
func (wls *WhiteListSelect) sqlScan(ctx context.Context, root *WhiteListQuery, v any) error {
|
||
|
selector := root.sqlQuery(ctx)
|
||
|
aggregation := make([]string, 0, len(wls.fns))
|
||
|
for _, fn := range wls.fns {
|
||
|
aggregation = append(aggregation, fn(selector))
|
||
|
}
|
||
|
switch n := len(*wls.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 := wls.driver.Query(ctx, query, args, rows); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
return sql.ScanSlice(rows, v)
|
||
|
}
|