2025-02-06 09:31:49 +01:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
2022-04-08 21:26:25 +02:00
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql/driver"
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"code.icod.de/postfix/manager/ent/account"
|
|
|
|
"code.icod.de/postfix/manager/ent/alias"
|
|
|
|
"code.icod.de/postfix/manager/ent/domain"
|
|
|
|
"code.icod.de/postfix/manager/ent/logentry"
|
|
|
|
"code.icod.de/postfix/manager/ent/mailbox"
|
|
|
|
"code.icod.de/postfix/manager/ent/predicate"
|
2025-02-06 09:31:49 +01:00
|
|
|
"entgo.io/ent"
|
2022-04-08 21:26:25 +02:00
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DomainQuery is the builder for querying Domain entities.
|
|
|
|
type DomainQuery struct {
|
|
|
|
config
|
2025-02-06 09:31:49 +01:00
|
|
|
ctx *QueryContext
|
|
|
|
order []domain.OrderOption
|
|
|
|
inters []Interceptor
|
|
|
|
predicates []predicate.Domain
|
2022-04-08 21:26:25 +02:00
|
|
|
withMailboxes *MailboxQuery
|
|
|
|
withAliases *AliasQuery
|
|
|
|
withLogs *LogentryQuery
|
|
|
|
withAccounts *AccountQuery
|
|
|
|
// intermediate query (i.e. traversal path).
|
|
|
|
sql *sql.Selector
|
|
|
|
path func(context.Context) (*sql.Selector, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Where adds a new predicate for the DomainQuery builder.
|
|
|
|
func (dq *DomainQuery) Where(ps ...predicate.Domain) *DomainQuery {
|
|
|
|
dq.predicates = append(dq.predicates, ps...)
|
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
// Limit the number of records to be returned by this query.
|
2022-04-08 21:26:25 +02:00
|
|
|
func (dq *DomainQuery) Limit(limit int) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
dq.ctx.Limit = &limit
|
2022-04-08 21:26:25 +02:00
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
// Offset to start from.
|
2022-04-08 21:26:25 +02:00
|
|
|
func (dq *DomainQuery) Offset(offset int) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
dq.ctx.Offset = &offset
|
2022-04-08 21:26:25 +02:00
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 (dq *DomainQuery) Unique(unique bool) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
dq.ctx.Unique = &unique
|
2022-04-08 21:26:25 +02:00
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
// Order specifies how the records should be ordered.
|
|
|
|
func (dq *DomainQuery) Order(o ...domain.OrderOption) *DomainQuery {
|
2022-04-08 21:26:25 +02:00
|
|
|
dq.order = append(dq.order, o...)
|
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMailboxes chains the current query on the "mailboxes" edge.
|
|
|
|
func (dq *DomainQuery) QueryMailboxes() *MailboxQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&MailboxClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
|
|
if err := dq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
selector := dq.sqlQuery(ctx)
|
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
sqlgraph.From(domain.Table, domain.FieldID, selector),
|
|
|
|
sqlgraph.To(mailbox.Table, mailbox.FieldID),
|
|
|
|
sqlgraph.Edge(sqlgraph.O2M, false, domain.MailboxesTable, domain.MailboxesColumn),
|
|
|
|
)
|
|
|
|
fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step)
|
|
|
|
return fromU, nil
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryAliases chains the current query on the "aliases" edge.
|
|
|
|
func (dq *DomainQuery) QueryAliases() *AliasQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&AliasClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
|
|
if err := dq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
selector := dq.sqlQuery(ctx)
|
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
sqlgraph.From(domain.Table, domain.FieldID, selector),
|
|
|
|
sqlgraph.To(alias.Table, alias.FieldID),
|
|
|
|
sqlgraph.Edge(sqlgraph.O2M, false, domain.AliasesTable, domain.AliasesColumn),
|
|
|
|
)
|
|
|
|
fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step)
|
|
|
|
return fromU, nil
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryLogs chains the current query on the "logs" edge.
|
|
|
|
func (dq *DomainQuery) QueryLogs() *LogentryQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&LogentryClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
|
|
if err := dq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
selector := dq.sqlQuery(ctx)
|
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
sqlgraph.From(domain.Table, domain.FieldID, selector),
|
|
|
|
sqlgraph.To(logentry.Table, logentry.FieldID),
|
|
|
|
sqlgraph.Edge(sqlgraph.O2M, false, domain.LogsTable, domain.LogsColumn),
|
|
|
|
)
|
|
|
|
fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step)
|
|
|
|
return fromU, nil
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryAccounts chains the current query on the "accounts" edge.
|
|
|
|
func (dq *DomainQuery) QueryAccounts() *AccountQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&AccountClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
|
|
if err := dq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
selector := dq.sqlQuery(ctx)
|
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
sqlgraph.From(domain.Table, domain.FieldID, selector),
|
|
|
|
sqlgraph.To(account.Table, account.FieldID),
|
|
|
|
sqlgraph.Edge(sqlgraph.M2M, true, domain.AccountsTable, domain.AccountsPrimaryKey...),
|
|
|
|
)
|
|
|
|
fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step)
|
|
|
|
return fromU, nil
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
|
|
|
// First returns the first Domain entity from the query.
|
|
|
|
// Returns a *NotFoundError when no Domain was found.
|
|
|
|
func (dq *DomainQuery) First(ctx context.Context) (*Domain, error) {
|
2025-02-06 09:31:49 +01:00
|
|
|
nodes, err := dq.Limit(1).All(setContextOp(ctx, dq.ctx, ent.OpQueryFirst))
|
2022-04-08 21:26:25 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(nodes) == 0 {
|
|
|
|
return nil, &NotFoundError{domain.Label}
|
|
|
|
}
|
|
|
|
return nodes[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstX is like First, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) FirstX(ctx context.Context) *Domain {
|
|
|
|
node, err := dq.First(ctx)
|
|
|
|
if err != nil && !IsNotFound(err) {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstID returns the first Domain ID from the query.
|
|
|
|
// Returns a *NotFoundError when no Domain ID was found.
|
|
|
|
func (dq *DomainQuery) FirstID(ctx context.Context) (id int64, err error) {
|
|
|
|
var ids []int64
|
2025-02-06 09:31:49 +01:00
|
|
|
if ids, err = dq.Limit(1).IDs(setContextOp(ctx, dq.ctx, ent.OpQueryFirstID)); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(ids) == 0 {
|
|
|
|
err = &NotFoundError{domain.Label}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return ids[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) FirstIDX(ctx context.Context) int64 {
|
|
|
|
id, err := dq.FirstID(ctx)
|
|
|
|
if err != nil && !IsNotFound(err) {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only returns a single Domain entity found by the query, ensuring it only returns one.
|
|
|
|
// Returns a *NotSingularError when more than one Domain entity is found.
|
|
|
|
// Returns a *NotFoundError when no Domain entities are found.
|
|
|
|
func (dq *DomainQuery) Only(ctx context.Context) (*Domain, error) {
|
2025-02-06 09:31:49 +01:00
|
|
|
nodes, err := dq.Limit(2).All(setContextOp(ctx, dq.ctx, ent.OpQueryOnly))
|
2022-04-08 21:26:25 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
switch len(nodes) {
|
|
|
|
case 1:
|
|
|
|
return nodes[0], nil
|
|
|
|
case 0:
|
|
|
|
return nil, &NotFoundError{domain.Label}
|
|
|
|
default:
|
|
|
|
return nil, &NotSingularError{domain.Label}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnlyX is like Only, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) OnlyX(ctx context.Context) *Domain {
|
|
|
|
node, err := dq.Only(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnlyID is like Only, but returns the only Domain ID in the query.
|
|
|
|
// Returns a *NotSingularError when more than one Domain ID is found.
|
|
|
|
// Returns a *NotFoundError when no entities are found.
|
|
|
|
func (dq *DomainQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
|
|
|
var ids []int64
|
2025-02-06 09:31:49 +01:00
|
|
|
if ids, err = dq.Limit(2).IDs(setContextOp(ctx, dq.ctx, ent.OpQueryOnlyID)); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
switch len(ids) {
|
|
|
|
case 1:
|
|
|
|
id = ids[0]
|
|
|
|
case 0:
|
|
|
|
err = &NotFoundError{domain.Label}
|
|
|
|
default:
|
|
|
|
err = &NotSingularError{domain.Label}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) OnlyIDX(ctx context.Context) int64 {
|
|
|
|
id, err := dq.OnlyID(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// All executes the query and returns a list of Domains.
|
|
|
|
func (dq *DomainQuery) All(ctx context.Context) ([]*Domain, error) {
|
2025-02-06 09:31:49 +01:00
|
|
|
ctx = setContextOp(ctx, dq.ctx, ent.OpQueryAll)
|
2022-04-08 21:26:25 +02:00
|
|
|
if err := dq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
qr := querierAll[[]*Domain, *DomainQuery]()
|
|
|
|
return withInterceptors[[]*Domain](ctx, dq, qr, dq.inters)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AllX is like All, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) AllX(ctx context.Context) []*Domain {
|
|
|
|
nodes, err := dq.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDs executes the query and returns a list of Domain IDs.
|
2025-02-06 09:31:49 +01:00
|
|
|
func (dq *DomainQuery) IDs(ctx context.Context) (ids []int64, err error) {
|
|
|
|
if dq.ctx.Unique == nil && dq.path != nil {
|
|
|
|
dq.Unique(true)
|
|
|
|
}
|
|
|
|
ctx = setContextOp(ctx, dq.ctx, ent.OpQueryIDs)
|
|
|
|
if err = dq.Select(domain.FieldID).Scan(ctx, &ids); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ids, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDsX is like IDs, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) IDsX(ctx context.Context) []int64 {
|
|
|
|
ids, err := dq.IDs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count returns the count of the given query.
|
|
|
|
func (dq *DomainQuery) Count(ctx context.Context) (int, error) {
|
2025-02-06 09:31:49 +01:00
|
|
|
ctx = setContextOp(ctx, dq.ctx, ent.OpQueryCount)
|
2022-04-08 21:26:25 +02:00
|
|
|
if err := dq.prepareQuery(ctx); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
return withInterceptors[int](ctx, dq, querierCount[*DomainQuery](), dq.inters)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CountX is like Count, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) CountX(ctx context.Context) int {
|
|
|
|
count, err := dq.Count(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exist returns true if the query has elements in the graph.
|
|
|
|
func (dq *DomainQuery) Exist(ctx context.Context) (bool, error) {
|
2025-02-06 09:31:49 +01:00
|
|
|
ctx = setContextOp(ctx, dq.ctx, ent.OpQueryExist)
|
|
|
|
switch _, err := dq.FirstID(ctx); {
|
|
|
|
case IsNotFound(err):
|
|
|
|
return false, nil
|
|
|
|
case err != nil:
|
|
|
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
|
|
|
default:
|
|
|
|
return true, nil
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExistX is like Exist, but panics if an error occurs.
|
|
|
|
func (dq *DomainQuery) ExistX(ctx context.Context) bool {
|
|
|
|
exist, err := dq.Exist(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return exist
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone returns a duplicate of the DomainQuery builder, including all associated steps. It can be
|
|
|
|
// used to prepare common query builders and use them differently after the clone is made.
|
|
|
|
func (dq *DomainQuery) Clone() *DomainQuery {
|
|
|
|
if dq == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &DomainQuery{
|
|
|
|
config: dq.config,
|
2025-02-06 09:31:49 +01:00
|
|
|
ctx: dq.ctx.Clone(),
|
|
|
|
order: append([]domain.OrderOption{}, dq.order...),
|
|
|
|
inters: append([]Interceptor{}, dq.inters...),
|
2022-04-08 21:26:25 +02:00
|
|
|
predicates: append([]predicate.Domain{}, dq.predicates...),
|
|
|
|
withMailboxes: dq.withMailboxes.Clone(),
|
|
|
|
withAliases: dq.withAliases.Clone(),
|
|
|
|
withLogs: dq.withLogs.Clone(),
|
|
|
|
withAccounts: dq.withAccounts.Clone(),
|
|
|
|
// clone intermediate query.
|
2025-02-06 09:31:49 +01:00
|
|
|
sql: dq.sql.Clone(),
|
|
|
|
path: dq.path,
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithMailboxes tells the query-builder to eager-load the nodes that are connected to
|
|
|
|
// the "mailboxes" edge. The optional arguments are used to configure the query builder of the edge.
|
|
|
|
func (dq *DomainQuery) WithMailboxes(opts ...func(*MailboxQuery)) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&MailboxClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(query)
|
|
|
|
}
|
|
|
|
dq.withMailboxes = query
|
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithAliases tells the query-builder to eager-load the nodes that are connected to
|
|
|
|
// the "aliases" edge. The optional arguments are used to configure the query builder of the edge.
|
|
|
|
func (dq *DomainQuery) WithAliases(opts ...func(*AliasQuery)) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&AliasClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(query)
|
|
|
|
}
|
|
|
|
dq.withAliases = query
|
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithLogs tells the query-builder to eager-load the nodes that are connected to
|
|
|
|
// the "logs" edge. The optional arguments are used to configure the query builder of the edge.
|
|
|
|
func (dq *DomainQuery) WithLogs(opts ...func(*LogentryQuery)) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&LogentryClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(query)
|
|
|
|
}
|
|
|
|
dq.withLogs = query
|
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithAccounts tells the query-builder to eager-load the nodes that are connected to
|
|
|
|
// the "accounts" edge. The optional arguments are used to configure the query builder of the edge.
|
|
|
|
func (dq *DomainQuery) WithAccounts(opts ...func(*AccountQuery)) *DomainQuery {
|
2025-02-06 09:31:49 +01:00
|
|
|
query := (&AccountClient{config: dq.config}).Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(query)
|
|
|
|
}
|
|
|
|
dq.withAccounts = query
|
|
|
|
return dq
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
// Created time.Time `json:"created,omitempty"`
|
|
|
|
// Count int `json:"count,omitempty"`
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// client.Domain.Query().
|
|
|
|
// GroupBy(domain.FieldCreated).
|
|
|
|
// Aggregate(ent.Count()).
|
|
|
|
// Scan(ctx, &v)
|
|
|
|
func (dq *DomainQuery) GroupBy(field string, fields ...string) *DomainGroupBy {
|
2025-02-06 09:31:49 +01:00
|
|
|
dq.ctx.Fields = append([]string{field}, fields...)
|
|
|
|
grbuild := &DomainGroupBy{build: dq}
|
|
|
|
grbuild.flds = &dq.ctx.Fields
|
|
|
|
grbuild.label = domain.Label
|
|
|
|
grbuild.scan = grbuild.Scan
|
|
|
|
return grbuild
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
// Created time.Time `json:"created,omitempty"`
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// client.Domain.Query().
|
|
|
|
// Select(domain.FieldCreated).
|
|
|
|
// Scan(ctx, &v)
|
|
|
|
func (dq *DomainQuery) Select(fields ...string) *DomainSelect {
|
2025-02-06 09:31:49 +01:00
|
|
|
dq.ctx.Fields = append(dq.ctx.Fields, fields...)
|
|
|
|
sbuild := &DomainSelect{DomainQuery: dq}
|
|
|
|
sbuild.label = domain.Label
|
|
|
|
sbuild.flds, sbuild.scan = &dq.ctx.Fields, sbuild.Scan
|
|
|
|
return sbuild
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aggregate returns a DomainSelect configured with the given aggregations.
|
|
|
|
func (dq *DomainQuery) Aggregate(fns ...AggregateFunc) *DomainSelect {
|
|
|
|
return dq.Select().Aggregate(fns...)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dq *DomainQuery) prepareQuery(ctx context.Context) error {
|
2025-02-06 09:31:49 +01:00
|
|
|
for _, inter := range dq.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, dq); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, f := range dq.ctx.Fields {
|
2022-04-08 21:26:25 +02:00
|
|
|
if !domain.ValidColumn(f) {
|
|
|
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if dq.path != nil {
|
|
|
|
prev, err := dq.path(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dq.sql = prev
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
func (dq *DomainQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Domain, error) {
|
2022-04-08 21:26:25 +02:00
|
|
|
var (
|
|
|
|
nodes = []*Domain{}
|
|
|
|
_spec = dq.querySpec()
|
|
|
|
loadedTypes = [4]bool{
|
|
|
|
dq.withMailboxes != nil,
|
|
|
|
dq.withAliases != nil,
|
|
|
|
dq.withLogs != nil,
|
|
|
|
dq.withAccounts != nil,
|
|
|
|
}
|
|
|
|
)
|
2025-02-06 09:31:49 +01:00
|
|
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
|
|
|
return (*Domain).scanValues(nil, columns)
|
|
|
|
}
|
|
|
|
_spec.Assign = func(columns []string, values []any) error {
|
2022-04-08 21:26:25 +02:00
|
|
|
node := &Domain{config: dq.config}
|
|
|
|
nodes = append(nodes, node)
|
|
|
|
node.Edges.loadedTypes = loadedTypes
|
|
|
|
return node.assignValues(columns, values)
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
for i := range hooks {
|
|
|
|
hooks[i](ctx, _spec)
|
|
|
|
}
|
2022-04-08 21:26:25 +02:00
|
|
|
if err := sqlgraph.QueryNodes(ctx, dq.driver, _spec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(nodes) == 0 {
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
if query := dq.withMailboxes; query != nil {
|
2025-02-06 09:31:49 +01:00
|
|
|
if err := dq.loadMailboxes(ctx, query, nodes,
|
|
|
|
func(n *Domain) { n.Edges.Mailboxes = []*Mailbox{} },
|
|
|
|
func(n *Domain, e *Mailbox) { n.Edges.Mailboxes = append(n.Edges.Mailboxes, e) }); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if query := dq.withAliases; query != nil {
|
2025-02-06 09:31:49 +01:00
|
|
|
if err := dq.loadAliases(ctx, query, nodes,
|
|
|
|
func(n *Domain) { n.Edges.Aliases = []*Alias{} },
|
|
|
|
func(n *Domain, e *Alias) { n.Edges.Aliases = append(n.Edges.Aliases, e) }); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if query := dq.withLogs; query != nil {
|
2025-02-06 09:31:49 +01:00
|
|
|
if err := dq.loadLogs(ctx, query, nodes,
|
|
|
|
func(n *Domain) { n.Edges.Logs = []*Logentry{} },
|
|
|
|
func(n *Domain, e *Logentry) { n.Edges.Logs = append(n.Edges.Logs, e) }); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
}
|
|
|
|
if query := dq.withAccounts; query != nil {
|
|
|
|
if err := dq.loadAccounts(ctx, query, nodes,
|
|
|
|
func(n *Domain) { n.Edges.Accounts = []*Account{} },
|
|
|
|
func(n *Domain, e *Account) { n.Edges.Accounts = append(n.Edges.Accounts, e) }); err != nil {
|
|
|
|
return nil, err
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
return nodes, nil
|
|
|
|
}
|
2022-04-08 21:26:25 +02:00
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
func (dq *DomainQuery) loadMailboxes(ctx context.Context, query *MailboxQuery, nodes []*Domain, init func(*Domain), assign func(*Domain, *Mailbox)) error {
|
|
|
|
fks := make([]driver.Value, 0, len(nodes))
|
|
|
|
nodeids := make(map[int64]*Domain)
|
|
|
|
for i := range nodes {
|
|
|
|
fks = append(fks, nodes[i].ID)
|
|
|
|
nodeids[nodes[i].ID] = nodes[i]
|
|
|
|
if init != nil {
|
|
|
|
init(nodes[i])
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
}
|
|
|
|
if len(query.ctx.Fields) > 0 {
|
|
|
|
query.ctx.AppendFieldOnce(mailbox.FieldDomainID)
|
|
|
|
}
|
|
|
|
query.Where(predicate.Mailbox(func(s *sql.Selector) {
|
|
|
|
s.Where(sql.InValues(s.C(domain.MailboxesColumn), fks...))
|
|
|
|
}))
|
|
|
|
neighbors, err := query.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, n := range neighbors {
|
|
|
|
fk := n.DomainID
|
|
|
|
node, ok := nodeids[fk]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf(`unexpected referenced foreign-key "domain_id" returned %v for node %v`, fk, n.ID)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
assign(node, n)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (dq *DomainQuery) loadAliases(ctx context.Context, query *AliasQuery, nodes []*Domain, init func(*Domain), assign func(*Domain, *Alias)) error {
|
|
|
|
fks := make([]driver.Value, 0, len(nodes))
|
|
|
|
nodeids := make(map[int64]*Domain)
|
|
|
|
for i := range nodes {
|
|
|
|
fks = append(fks, nodes[i].ID)
|
|
|
|
nodeids[nodes[i].ID] = nodes[i]
|
|
|
|
if init != nil {
|
|
|
|
init(nodes[i])
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
}
|
|
|
|
if len(query.ctx.Fields) > 0 {
|
|
|
|
query.ctx.AppendFieldOnce(alias.FieldDomainID)
|
|
|
|
}
|
|
|
|
query.Where(predicate.Alias(func(s *sql.Selector) {
|
|
|
|
s.Where(sql.InValues(s.C(domain.AliasesColumn), fks...))
|
|
|
|
}))
|
|
|
|
neighbors, err := query.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, n := range neighbors {
|
|
|
|
fk := n.DomainID
|
|
|
|
node, ok := nodeids[fk]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf(`unexpected referenced foreign-key "domain_id" returned %v for node %v`, fk, n.ID)
|
|
|
|
}
|
|
|
|
assign(node, n)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (dq *DomainQuery) loadLogs(ctx context.Context, query *LogentryQuery, nodes []*Domain, init func(*Domain), assign func(*Domain, *Logentry)) error {
|
|
|
|
fks := make([]driver.Value, 0, len(nodes))
|
|
|
|
nodeids := make(map[int64]*Domain)
|
|
|
|
for i := range nodes {
|
|
|
|
fks = append(fks, nodes[i].ID)
|
|
|
|
nodeids[nodes[i].ID] = nodes[i]
|
|
|
|
if init != nil {
|
|
|
|
init(nodes[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(query.ctx.Fields) > 0 {
|
|
|
|
query.ctx.AppendFieldOnce(logentry.FieldDomainID)
|
|
|
|
}
|
|
|
|
query.Where(predicate.Logentry(func(s *sql.Selector) {
|
|
|
|
s.Where(sql.InValues(s.C(domain.LogsColumn), fks...))
|
|
|
|
}))
|
|
|
|
neighbors, err := query.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, n := range neighbors {
|
|
|
|
fk := n.DomainID
|
|
|
|
node, ok := nodeids[fk]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf(`unexpected referenced foreign-key "domain_id" returned %v for node %v`, fk, n.ID)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
assign(node, n)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
func (dq *DomainQuery) loadAccounts(ctx context.Context, query *AccountQuery, nodes []*Domain, init func(*Domain), assign func(*Domain, *Account)) error {
|
|
|
|
edgeIDs := make([]driver.Value, len(nodes))
|
|
|
|
byID := make(map[int64]*Domain)
|
|
|
|
nids := make(map[int64]map[*Domain]struct{})
|
|
|
|
for i, node := range nodes {
|
|
|
|
edgeIDs[i] = node.ID
|
|
|
|
byID[node.ID] = node
|
|
|
|
if init != nil {
|
|
|
|
init(node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
query.Where(func(s *sql.Selector) {
|
|
|
|
joinT := sql.Table(domain.AccountsTable)
|
|
|
|
s.Join(joinT).On(s.C(account.FieldID), joinT.C(domain.AccountsPrimaryKey[0]))
|
|
|
|
s.Where(sql.InValues(joinT.C(domain.AccountsPrimaryKey[1]), edgeIDs...))
|
|
|
|
columns := s.SelectedColumns()
|
|
|
|
s.Select(joinT.C(domain.AccountsPrimaryKey[1]))
|
|
|
|
s.AppendSelect(columns...)
|
|
|
|
s.SetDistinct(false)
|
|
|
|
})
|
|
|
|
if err := query.prepareQuery(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
|
|
|
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
|
|
|
assign := spec.Assign
|
|
|
|
values := spec.ScanValues
|
|
|
|
spec.ScanValues = func(columns []string) ([]any, error) {
|
|
|
|
values, err := values(columns[1:])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append([]any{new(sql.NullInt64)}, values...), nil
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
spec.Assign = func(columns []string, values []any) error {
|
|
|
|
outValue := values[0].(*sql.NullInt64).Int64
|
|
|
|
inValue := values[1].(*sql.NullInt64).Int64
|
|
|
|
if nids[inValue] == nil {
|
|
|
|
nids[inValue] = map[*Domain]struct{}{byID[outValue]: {}}
|
|
|
|
return assign(columns[1:], values[1:])
|
|
|
|
}
|
|
|
|
nids[inValue][byID[outValue]] = struct{}{}
|
|
|
|
return nil
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
neighbors, err := withInterceptors[[]*Account](ctx, query, qr, query.inters)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, n := range neighbors {
|
|
|
|
nodes, ok := nids[n.ID]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf(`unexpected "accounts" node returned %v`, n.ID)
|
|
|
|
}
|
|
|
|
for kn := range nodes {
|
|
|
|
assign(kn, n)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
return nil
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dq *DomainQuery) sqlCount(ctx context.Context) (int, error) {
|
|
|
|
_spec := dq.querySpec()
|
2025-02-06 09:31:49 +01:00
|
|
|
_spec.Node.Columns = dq.ctx.Fields
|
|
|
|
if len(dq.ctx.Fields) > 0 {
|
|
|
|
_spec.Unique = dq.ctx.Unique != nil && *dq.ctx.Unique
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
return sqlgraph.CountNodes(ctx, dq.driver, _spec)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dq *DomainQuery) querySpec() *sqlgraph.QuerySpec {
|
2025-02-06 09:31:49 +01:00
|
|
|
_spec := sqlgraph.NewQuerySpec(domain.Table, domain.Columns, sqlgraph.NewFieldSpec(domain.FieldID, field.TypeInt64))
|
|
|
|
_spec.From = dq.sql
|
|
|
|
if unique := dq.ctx.Unique; unique != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
_spec.Unique = *unique
|
2025-02-06 09:31:49 +01:00
|
|
|
} else if dq.path != nil {
|
|
|
|
_spec.Unique = true
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if fields := dq.ctx.Fields; len(fields) > 0 {
|
2022-04-08 21:26:25 +02:00
|
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, domain.FieldID)
|
|
|
|
for i := range fields {
|
|
|
|
if fields[i] != domain.FieldID {
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ps := dq.predicates; len(ps) > 0 {
|
|
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if limit := dq.ctx.Limit; limit != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
_spec.Limit = *limit
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if offset := dq.ctx.Offset; offset != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
_spec.Offset = *offset
|
|
|
|
}
|
|
|
|
if ps := dq.order; len(ps) > 0 {
|
|
|
|
_spec.Order = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _spec
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dq *DomainQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|
|
|
builder := sql.Dialect(dq.driver.Dialect())
|
|
|
|
t1 := builder.Table(domain.Table)
|
2025-02-06 09:31:49 +01:00
|
|
|
columns := dq.ctx.Fields
|
2022-04-08 21:26:25 +02:00
|
|
|
if len(columns) == 0 {
|
|
|
|
columns = domain.Columns
|
|
|
|
}
|
|
|
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
|
|
|
if dq.sql != nil {
|
|
|
|
selector = dq.sql
|
|
|
|
selector.Select(selector.Columns(columns...)...)
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if dq.ctx.Unique != nil && *dq.ctx.Unique {
|
2022-04-08 21:26:25 +02:00
|
|
|
selector.Distinct()
|
|
|
|
}
|
|
|
|
for _, p := range dq.predicates {
|
|
|
|
p(selector)
|
|
|
|
}
|
|
|
|
for _, p := range dq.order {
|
|
|
|
p(selector)
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if offset := dq.ctx.Offset; offset != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
// limit is mandatory for offset clause. We start
|
|
|
|
// with default value, and override it below if needed.
|
|
|
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if limit := dq.ctx.Limit; limit != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
selector.Limit(*limit)
|
|
|
|
}
|
|
|
|
return selector
|
|
|
|
}
|
|
|
|
|
|
|
|
// DomainGroupBy is the group-by builder for Domain entities.
|
|
|
|
type DomainGroupBy struct {
|
2025-02-06 09:31:49 +01:00
|
|
|
selector
|
|
|
|
build *DomainQuery
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Aggregate adds the given aggregation functions to the group-by query.
|
|
|
|
func (dgb *DomainGroupBy) Aggregate(fns ...AggregateFunc) *DomainGroupBy {
|
|
|
|
dgb.fns = append(dgb.fns, fns...)
|
|
|
|
return dgb
|
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
|
|
func (dgb *DomainGroupBy) Scan(ctx context.Context, v any) error {
|
|
|
|
ctx = setContextOp(ctx, dgb.build.ctx, ent.OpQueryGroupBy)
|
|
|
|
if err := dgb.build.prepareQuery(ctx); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return err
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
return scanWithInterceptors[*DomainQuery, *DomainGroupBy](ctx, dgb.build, dgb, dgb.build.inters, v)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
func (dgb *DomainGroupBy) sqlScan(ctx context.Context, root *DomainQuery, v any) error {
|
|
|
|
selector := root.sqlQuery(ctx).Select()
|
|
|
|
aggregation := make([]string, 0, len(dgb.fns))
|
|
|
|
for _, fn := range dgb.fns {
|
|
|
|
aggregation = append(aggregation, fn(selector))
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
if len(selector.SelectedColumns()) == 0 {
|
|
|
|
columns := make([]string, 0, len(*dgb.flds)+len(dgb.fns))
|
|
|
|
for _, f := range *dgb.flds {
|
|
|
|
columns = append(columns, selector.C(f))
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
columns = append(columns, aggregation...)
|
|
|
|
selector.Select(columns...)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
selector.GroupBy(selector.Columns(*dgb.flds...)...)
|
2022-04-08 21:26:25 +02:00
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rows := &sql.Rows{}
|
|
|
|
query, args := selector.Query()
|
2025-02-06 09:31:49 +01:00
|
|
|
if err := dgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
2022-04-08 21:26:25 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
return sql.ScanSlice(rows, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DomainSelect is the builder for selecting fields of Domain entities.
|
|
|
|
type DomainSelect struct {
|
|
|
|
*DomainQuery
|
2025-02-06 09:31:49 +01:00
|
|
|
selector
|
|
|
|
}
|
|
|
|
|
|
|
|
// Aggregate adds the given aggregation functions to the selector query.
|
|
|
|
func (ds *DomainSelect) Aggregate(fns ...AggregateFunc) *DomainSelect {
|
|
|
|
ds.fns = append(ds.fns, fns...)
|
|
|
|
return ds
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
2025-02-06 09:31:49 +01:00
|
|
|
func (ds *DomainSelect) Scan(ctx context.Context, v any) error {
|
|
|
|
ctx = setContextOp(ctx, ds.ctx, ent.OpQuerySelect)
|
2022-04-08 21:26:25 +02:00
|
|
|
if err := ds.prepareQuery(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
return scanWithInterceptors[*DomainQuery, *DomainSelect](ctx, ds.DomainQuery, ds, ds.inters, v)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
|
2025-02-06 09:31:49 +01:00
|
|
|
func (ds *DomainSelect) sqlScan(ctx context.Context, root *DomainQuery, v any) error {
|
|
|
|
selector := root.sqlQuery(ctx)
|
|
|
|
aggregation := make([]string, 0, len(ds.fns))
|
|
|
|
for _, fn := range ds.fns {
|
|
|
|
aggregation = append(aggregation, fn(selector))
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
2025-02-06 09:31:49 +01:00
|
|
|
switch n := len(*ds.selector.flds); {
|
|
|
|
case n == 0 && len(aggregation) > 0:
|
|
|
|
selector.Select(aggregation...)
|
|
|
|
case n != 0 && len(aggregation) > 0:
|
|
|
|
selector.AppendSelect(aggregation...)
|
2022-04-08 21:26:25 +02:00
|
|
|
}
|
|
|
|
rows := &sql.Rows{}
|
2025-02-06 09:31:49 +01:00
|
|
|
query, args := selector.Query()
|
2022-04-08 21:26:25 +02:00
|
|
|
if err := ds.driver.Query(ctx, query, args, rows); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
return sql.ScanSlice(rows, v)
|
|
|
|
}
|