2022-10-07 02:54:09 +00:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
"github.com/google/uuid"
|
2022-10-30 04:05:38 +00:00
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
|
|
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
2022-10-07 02:54:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// GroupInvitationTokenQuery is the builder for querying GroupInvitationToken entities.
|
|
|
|
type GroupInvitationTokenQuery struct {
|
|
|
|
config
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx *QueryContext
|
2023-07-23 03:57:51 +00:00
|
|
|
order []groupinvitationtoken.OrderOption
|
2023-01-19 05:44:06 +00:00
|
|
|
inters []Interceptor
|
2022-10-07 02:54:09 +00:00
|
|
|
predicates []predicate.GroupInvitationToken
|
|
|
|
withGroup *GroupQuery
|
|
|
|
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 GroupInvitationTokenQuery builder.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Where(ps ...predicate.GroupInvitationToken) *GroupInvitationTokenQuery {
|
|
|
|
gitq.predicates = append(gitq.predicates, ps...)
|
|
|
|
return gitq
|
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
// Limit the number of records to be returned by this query.
|
2022-10-07 02:54:09 +00:00
|
|
|
func (gitq *GroupInvitationTokenQuery) Limit(limit int) *GroupInvitationTokenQuery {
|
2023-01-28 21:03:51 +00:00
|
|
|
gitq.ctx.Limit = &limit
|
2022-10-07 02:54:09 +00:00
|
|
|
return gitq
|
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
// Offset to start from.
|
2022-10-07 02:54:09 +00:00
|
|
|
func (gitq *GroupInvitationTokenQuery) Offset(offset int) *GroupInvitationTokenQuery {
|
2023-01-28 21:03:51 +00:00
|
|
|
gitq.ctx.Offset = &offset
|
2022-10-07 02:54:09 +00:00
|
|
|
return gitq
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 (gitq *GroupInvitationTokenQuery) Unique(unique bool) *GroupInvitationTokenQuery {
|
2023-01-28 21:03:51 +00:00
|
|
|
gitq.ctx.Unique = &unique
|
2022-10-07 02:54:09 +00:00
|
|
|
return gitq
|
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
// Order specifies how the records should be ordered.
|
2023-07-23 03:57:51 +00:00
|
|
|
func (gitq *GroupInvitationTokenQuery) Order(o ...groupinvitationtoken.OrderOption) *GroupInvitationTokenQuery {
|
2022-10-07 02:54:09 +00:00
|
|
|
gitq.order = append(gitq.order, o...)
|
|
|
|
return gitq
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryGroup chains the current query on the "group" edge.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) QueryGroup() *GroupQuery {
|
2023-01-19 05:44:06 +00:00
|
|
|
query := (&GroupClient{config: gitq.config}).Query()
|
2022-10-07 02:54:09 +00:00
|
|
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
|
|
if err := gitq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
selector := gitq.sqlQuery(ctx)
|
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
step := sqlgraph.NewStep(
|
|
|
|
sqlgraph.From(groupinvitationtoken.Table, groupinvitationtoken.FieldID, selector),
|
|
|
|
sqlgraph.To(group.Table, group.FieldID),
|
|
|
|
sqlgraph.Edge(sqlgraph.M2O, true, groupinvitationtoken.GroupTable, groupinvitationtoken.GroupColumn),
|
|
|
|
)
|
|
|
|
fromU = sqlgraph.SetNeighbors(gitq.driver.Dialect(), step)
|
|
|
|
return fromU, nil
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
|
|
|
// First returns the first GroupInvitationToken entity from the query.
|
|
|
|
// Returns a *NotFoundError when no GroupInvitationToken was found.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) First(ctx context.Context) (*GroupInvitationToken, error) {
|
2023-01-28 21:03:51 +00:00
|
|
|
nodes, err := gitq.Limit(1).All(setContextOp(ctx, gitq.ctx, "First"))
|
2022-10-07 02:54:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(nodes) == 0 {
|
|
|
|
return nil, &NotFoundError{groupinvitationtoken.Label}
|
|
|
|
}
|
|
|
|
return nodes[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstX is like First, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) FirstX(ctx context.Context) *GroupInvitationToken {
|
|
|
|
node, err := gitq.First(ctx)
|
|
|
|
if err != nil && !IsNotFound(err) {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstID returns the first GroupInvitationToken ID from the query.
|
|
|
|
// Returns a *NotFoundError when no GroupInvitationToken ID was found.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
|
|
|
var ids []uuid.UUID
|
2023-01-28 21:03:51 +00:00
|
|
|
if ids, err = gitq.Limit(1).IDs(setContextOp(ctx, gitq.ctx, "FirstID")); err != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(ids) == 0 {
|
|
|
|
err = &NotFoundError{groupinvitationtoken.Label}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return ids[0], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
|
|
|
id, err := gitq.FirstID(ctx)
|
|
|
|
if err != nil && !IsNotFound(err) {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only returns a single GroupInvitationToken entity found by the query, ensuring it only returns one.
|
|
|
|
// Returns a *NotSingularError when more than one GroupInvitationToken entity is found.
|
|
|
|
// Returns a *NotFoundError when no GroupInvitationToken entities are found.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Only(ctx context.Context) (*GroupInvitationToken, error) {
|
2023-01-28 21:03:51 +00:00
|
|
|
nodes, err := gitq.Limit(2).All(setContextOp(ctx, gitq.ctx, "Only"))
|
2022-10-07 02:54:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
switch len(nodes) {
|
|
|
|
case 1:
|
|
|
|
return nodes[0], nil
|
|
|
|
case 0:
|
|
|
|
return nil, &NotFoundError{groupinvitationtoken.Label}
|
|
|
|
default:
|
|
|
|
return nil, &NotSingularError{groupinvitationtoken.Label}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnlyX is like Only, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) OnlyX(ctx context.Context) *GroupInvitationToken {
|
|
|
|
node, err := gitq.Only(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnlyID is like Only, but returns the only GroupInvitationToken ID in the query.
|
|
|
|
// Returns a *NotSingularError when more than one GroupInvitationToken ID is found.
|
|
|
|
// Returns a *NotFoundError when no entities are found.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
|
|
|
var ids []uuid.UUID
|
2023-01-28 21:03:51 +00:00
|
|
|
if ids, err = gitq.Limit(2).IDs(setContextOp(ctx, gitq.ctx, "OnlyID")); err != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
switch len(ids) {
|
|
|
|
case 1:
|
|
|
|
id = ids[0]
|
|
|
|
case 0:
|
|
|
|
err = &NotFoundError{groupinvitationtoken.Label}
|
|
|
|
default:
|
|
|
|
err = &NotSingularError{groupinvitationtoken.Label}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
|
|
|
id, err := gitq.OnlyID(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
// All executes the query and returns a list of GroupInvitationTokens.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) All(ctx context.Context) ([]*GroupInvitationToken, error) {
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx = setContextOp(ctx, gitq.ctx, "All")
|
2022-10-07 02:54:09 +00:00
|
|
|
if err := gitq.prepareQuery(ctx); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
qr := querierAll[[]*GroupInvitationToken, *GroupInvitationTokenQuery]()
|
|
|
|
return withInterceptors[[]*GroupInvitationToken](ctx, gitq, qr, gitq.inters)
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AllX is like All, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) AllX(ctx context.Context) []*GroupInvitationToken {
|
|
|
|
nodes, err := gitq.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return nodes
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDs executes the query and returns a list of GroupInvitationToken IDs.
|
2023-02-18 06:41:01 +00:00
|
|
|
func (gitq *GroupInvitationTokenQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
|
|
|
if gitq.ctx.Unique == nil && gitq.path != nil {
|
|
|
|
gitq.Unique(true)
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx = setContextOp(ctx, gitq.ctx, "IDs")
|
2023-02-18 06:41:01 +00:00
|
|
|
if err = gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ids, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDsX is like IDs, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) IDsX(ctx context.Context) []uuid.UUID {
|
|
|
|
ids, err := gitq.IDs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count returns the count of the given query.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Count(ctx context.Context) (int, error) {
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx = setContextOp(ctx, gitq.ctx, "Count")
|
2022-10-07 02:54:09 +00:00
|
|
|
if err := gitq.prepareQuery(ctx); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
return withInterceptors[int](ctx, gitq, querierCount[*GroupInvitationTokenQuery](), gitq.inters)
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CountX is like Count, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) CountX(ctx context.Context) int {
|
|
|
|
count, err := gitq.Count(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exist returns true if the query has elements in the graph.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Exist(ctx context.Context) (bool, error) {
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx = setContextOp(ctx, gitq.ctx, "Exist")
|
2023-01-19 05:44:06 +00:00
|
|
|
switch _, err := gitq.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-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExistX is like Exist, but panics if an error occurs.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) ExistX(ctx context.Context) bool {
|
|
|
|
exist, err := gitq.Exist(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return exist
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone returns a duplicate of the GroupInvitationTokenQuery builder, including all associated steps. It can be
|
|
|
|
// used to prepare common query builders and use them differently after the clone is made.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Clone() *GroupInvitationTokenQuery {
|
|
|
|
if gitq == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &GroupInvitationTokenQuery{
|
|
|
|
config: gitq.config,
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx: gitq.ctx.Clone(),
|
2023-07-23 03:57:51 +00:00
|
|
|
order: append([]groupinvitationtoken.OrderOption{}, gitq.order...),
|
2023-01-19 05:44:06 +00:00
|
|
|
inters: append([]Interceptor{}, gitq.inters...),
|
2022-10-07 02:54:09 +00:00
|
|
|
predicates: append([]predicate.GroupInvitationToken{}, gitq.predicates...),
|
|
|
|
withGroup: gitq.withGroup.Clone(),
|
|
|
|
// clone intermediate query.
|
2023-01-28 21:03:51 +00:00
|
|
|
sql: gitq.sql.Clone(),
|
|
|
|
path: gitq.path,
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
|
|
|
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) WithGroup(opts ...func(*GroupQuery)) *GroupInvitationTokenQuery {
|
2023-01-19 05:44:06 +00:00
|
|
|
query := (&GroupClient{config: gitq.config}).Query()
|
2022-10-07 02:54:09 +00:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(query)
|
|
|
|
}
|
|
|
|
gitq.withGroup = query
|
|
|
|
return gitq
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
|
|
|
// Count int `json:"count,omitempty"`
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// client.GroupInvitationToken.Query().
|
|
|
|
// GroupBy(groupinvitationtoken.FieldCreatedAt).
|
|
|
|
// Aggregate(ent.Count()).
|
|
|
|
// Scan(ctx, &v)
|
|
|
|
func (gitq *GroupInvitationTokenQuery) GroupBy(field string, fields ...string) *GroupInvitationTokenGroupBy {
|
2023-01-28 21:03:51 +00:00
|
|
|
gitq.ctx.Fields = append([]string{field}, fields...)
|
2023-01-19 05:44:06 +00:00
|
|
|
grbuild := &GroupInvitationTokenGroupBy{build: gitq}
|
2023-01-28 21:03:51 +00:00
|
|
|
grbuild.flds = &gitq.ctx.Fields
|
2022-10-07 02:54:09 +00:00
|
|
|
grbuild.label = groupinvitationtoken.Label
|
2023-01-19 05:44:06 +00:00
|
|
|
grbuild.scan = grbuild.Scan
|
2022-10-07 02:54:09 +00:00
|
|
|
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 {
|
|
|
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// client.GroupInvitationToken.Query().
|
|
|
|
// Select(groupinvitationtoken.FieldCreatedAt).
|
|
|
|
// Scan(ctx, &v)
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Select(fields ...string) *GroupInvitationTokenSelect {
|
2023-01-28 21:03:51 +00:00
|
|
|
gitq.ctx.Fields = append(gitq.ctx.Fields, fields...)
|
2023-01-19 05:44:06 +00:00
|
|
|
sbuild := &GroupInvitationTokenSelect{GroupInvitationTokenQuery: gitq}
|
|
|
|
sbuild.label = groupinvitationtoken.Label
|
2023-01-28 21:03:51 +00:00
|
|
|
sbuild.flds, sbuild.scan = &gitq.ctx.Fields, sbuild.Scan
|
2023-01-19 05:44:06 +00:00
|
|
|
return sbuild
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 01:45:28 +00:00
|
|
|
// Aggregate returns a GroupInvitationTokenSelect configured with the given aggregations.
|
|
|
|
func (gitq *GroupInvitationTokenQuery) Aggregate(fns ...AggregateFunc) *GroupInvitationTokenSelect {
|
|
|
|
return gitq.Select().Aggregate(fns...)
|
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
func (gitq *GroupInvitationTokenQuery) prepareQuery(ctx context.Context) error {
|
2023-01-19 05:44:06 +00:00
|
|
|
for _, inter := range gitq.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, gitq); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
for _, f := range gitq.ctx.Fields {
|
2022-10-07 02:54:09 +00:00
|
|
|
if !groupinvitationtoken.ValidColumn(f) {
|
|
|
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if gitq.path != nil {
|
|
|
|
prev, err := gitq.path(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
gitq.sql = prev
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gitq *GroupInvitationTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GroupInvitationToken, error) {
|
|
|
|
var (
|
|
|
|
nodes = []*GroupInvitationToken{}
|
|
|
|
withFKs = gitq.withFKs
|
|
|
|
_spec = gitq.querySpec()
|
|
|
|
loadedTypes = [1]bool{
|
|
|
|
gitq.withGroup != nil,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
if gitq.withGroup != nil {
|
|
|
|
withFKs = true
|
|
|
|
}
|
|
|
|
if withFKs {
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, groupinvitationtoken.ForeignKeys...)
|
|
|
|
}
|
|
|
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
|
|
|
return (*GroupInvitationToken).scanValues(nil, columns)
|
|
|
|
}
|
|
|
|
_spec.Assign = func(columns []string, values []any) error {
|
|
|
|
node := &GroupInvitationToken{config: gitq.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, gitq.driver, _spec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(nodes) == 0 {
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
if query := gitq.withGroup; query != nil {
|
|
|
|
if err := gitq.loadGroup(ctx, query, nodes, nil,
|
|
|
|
func(n *GroupInvitationToken, e *Group) { n.Edges.Group = e }); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gitq *GroupInvitationTokenQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*GroupInvitationToken, init func(*GroupInvitationToken), assign func(*GroupInvitationToken, *Group)) error {
|
|
|
|
ids := make([]uuid.UUID, 0, len(nodes))
|
|
|
|
nodeids := make(map[uuid.UUID][]*GroupInvitationToken)
|
|
|
|
for i := range nodes {
|
|
|
|
if nodes[i].group_invitation_tokens == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fk := *nodes[i].group_invitation_tokens
|
|
|
|
if _, ok := nodeids[fk]; !ok {
|
|
|
|
ids = append(ids, fk)
|
|
|
|
}
|
|
|
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if len(ids) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2022-10-07 02:54:09 +00:00
|
|
|
query.Where(group.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 "group_invitation_tokens" returned %v`, n.ID)
|
|
|
|
}
|
|
|
|
for i := range nodes {
|
|
|
|
assign(nodes[i], n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gitq *GroupInvitationTokenQuery) sqlCount(ctx context.Context) (int, error) {
|
|
|
|
_spec := gitq.querySpec()
|
2023-01-28 21:03:51 +00:00
|
|
|
_spec.Node.Columns = gitq.ctx.Fields
|
|
|
|
if len(gitq.ctx.Fields) > 0 {
|
|
|
|
_spec.Unique = gitq.ctx.Unique != nil && *gitq.ctx.Unique
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
return sqlgraph.CountNodes(ctx, gitq.driver, _spec)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec {
|
2023-02-18 06:41:01 +00:00
|
|
|
_spec := sqlgraph.NewQuerySpec(groupinvitationtoken.Table, groupinvitationtoken.Columns, sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID))
|
|
|
|
_spec.From = gitq.sql
|
2023-01-28 21:03:51 +00:00
|
|
|
if unique := gitq.ctx.Unique; unique != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
_spec.Unique = *unique
|
2023-02-18 06:41:01 +00:00
|
|
|
} else if gitq.path != nil {
|
|
|
|
_spec.Unique = true
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if fields := gitq.ctx.Fields; len(fields) > 0 {
|
2022-10-07 02:54:09 +00:00
|
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, groupinvitationtoken.FieldID)
|
|
|
|
for i := range fields {
|
|
|
|
if fields[i] != groupinvitationtoken.FieldID {
|
|
|
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ps := gitq.predicates; len(ps) > 0 {
|
|
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if limit := gitq.ctx.Limit; limit != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
_spec.Limit = *limit
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if offset := gitq.ctx.Offset; offset != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
_spec.Offset = *offset
|
|
|
|
}
|
|
|
|
if ps := gitq.order; len(ps) > 0 {
|
|
|
|
_spec.Order = func(selector *sql.Selector) {
|
|
|
|
for i := range ps {
|
|
|
|
ps[i](selector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _spec
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gitq *GroupInvitationTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|
|
|
builder := sql.Dialect(gitq.driver.Dialect())
|
|
|
|
t1 := builder.Table(groupinvitationtoken.Table)
|
2023-01-28 21:03:51 +00:00
|
|
|
columns := gitq.ctx.Fields
|
2022-10-07 02:54:09 +00:00
|
|
|
if len(columns) == 0 {
|
|
|
|
columns = groupinvitationtoken.Columns
|
|
|
|
}
|
|
|
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
|
|
|
if gitq.sql != nil {
|
|
|
|
selector = gitq.sql
|
|
|
|
selector.Select(selector.Columns(columns...)...)
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if gitq.ctx.Unique != nil && *gitq.ctx.Unique {
|
2022-10-07 02:54:09 +00:00
|
|
|
selector.Distinct()
|
|
|
|
}
|
|
|
|
for _, p := range gitq.predicates {
|
|
|
|
p(selector)
|
|
|
|
}
|
|
|
|
for _, p := range gitq.order {
|
|
|
|
p(selector)
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if offset := gitq.ctx.Offset; offset != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
// limit is mandatory for offset clause. We start
|
|
|
|
// with default value, and override it below if needed.
|
|
|
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
|
|
|
}
|
2023-01-28 21:03:51 +00:00
|
|
|
if limit := gitq.ctx.Limit; limit != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
selector.Limit(*limit)
|
|
|
|
}
|
|
|
|
return selector
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupInvitationTokenGroupBy is the group-by builder for GroupInvitationToken entities.
|
|
|
|
type GroupInvitationTokenGroupBy struct {
|
|
|
|
selector
|
2023-01-19 05:44:06 +00:00
|
|
|
build *GroupInvitationTokenQuery
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Aggregate adds the given aggregation functions to the group-by query.
|
|
|
|
func (gitgb *GroupInvitationTokenGroupBy) Aggregate(fns ...AggregateFunc) *GroupInvitationTokenGroupBy {
|
|
|
|
gitgb.fns = append(gitgb.fns, fns...)
|
|
|
|
return gitgb
|
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
2022-10-07 02:54:09 +00:00
|
|
|
func (gitgb *GroupInvitationTokenGroupBy) Scan(ctx context.Context, v any) error {
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx = setContextOp(ctx, gitgb.build.ctx, "GroupBy")
|
2023-01-19 05:44:06 +00:00
|
|
|
if err := gitgb.build.prepareQuery(ctx); err != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
return scanWithInterceptors[*GroupInvitationTokenQuery, *GroupInvitationTokenGroupBy](ctx, gitgb.build, gitgb, gitgb.build.inters, v)
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
func (gitgb *GroupInvitationTokenGroupBy) sqlScan(ctx context.Context, root *GroupInvitationTokenQuery, v any) error {
|
|
|
|
selector := root.sqlQuery(ctx).Select()
|
|
|
|
aggregation := make([]string, 0, len(gitgb.fns))
|
|
|
|
for _, fn := range gitgb.fns {
|
|
|
|
aggregation = append(aggregation, fn(selector))
|
|
|
|
}
|
|
|
|
if len(selector.SelectedColumns()) == 0 {
|
|
|
|
columns := make([]string, 0, len(*gitgb.flds)+len(gitgb.fns))
|
|
|
|
for _, f := range *gitgb.flds {
|
|
|
|
columns = append(columns, selector.C(f))
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
columns = append(columns, aggregation...)
|
|
|
|
selector.Select(columns...)
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
selector.GroupBy(selector.Columns(*gitgb.flds...)...)
|
2022-10-07 02:54:09 +00:00
|
|
|
if err := selector.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rows := &sql.Rows{}
|
|
|
|
query, args := selector.Query()
|
2023-01-19 05:44:06 +00:00
|
|
|
if err := gitgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
2022-10-07 02:54:09 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
return sql.ScanSlice(rows, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupInvitationTokenSelect is the builder for selecting fields of GroupInvitationToken entities.
|
|
|
|
type GroupInvitationTokenSelect struct {
|
|
|
|
*GroupInvitationTokenQuery
|
|
|
|
selector
|
|
|
|
}
|
|
|
|
|
2022-12-02 01:45:28 +00:00
|
|
|
// Aggregate adds the given aggregation functions to the selector query.
|
|
|
|
func (gits *GroupInvitationTokenSelect) Aggregate(fns ...AggregateFunc) *GroupInvitationTokenSelect {
|
|
|
|
gits.fns = append(gits.fns, fns...)
|
|
|
|
return gits
|
|
|
|
}
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
|
|
func (gits *GroupInvitationTokenSelect) Scan(ctx context.Context, v any) error {
|
2023-01-28 21:03:51 +00:00
|
|
|
ctx = setContextOp(ctx, gits.ctx, "Select")
|
2022-10-07 02:54:09 +00:00
|
|
|
if err := gits.prepareQuery(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-19 05:44:06 +00:00
|
|
|
return scanWithInterceptors[*GroupInvitationTokenQuery, *GroupInvitationTokenSelect](ctx, gits.GroupInvitationTokenQuery, gits, gits.inters, v)
|
2022-10-07 02:54:09 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 05:44:06 +00:00
|
|
|
func (gits *GroupInvitationTokenSelect) sqlScan(ctx context.Context, root *GroupInvitationTokenQuery, v any) error {
|
|
|
|
selector := root.sqlQuery(ctx)
|
2022-12-02 01:45:28 +00:00
|
|
|
aggregation := make([]string, 0, len(gits.fns))
|
|
|
|
for _, fn := range gits.fns {
|
2023-01-19 05:44:06 +00:00
|
|
|
aggregation = append(aggregation, fn(selector))
|
2022-12-02 01:45:28 +00:00
|
|
|
}
|
|
|
|
switch n := len(*gits.selector.flds); {
|
|
|
|
case n == 0 && len(aggregation) > 0:
|
2023-01-19 05:44:06 +00:00
|
|
|
selector.Select(aggregation...)
|
2022-12-02 01:45:28 +00:00
|
|
|
case n != 0 && len(aggregation) > 0:
|
2023-01-19 05:44:06 +00:00
|
|
|
selector.AppendSelect(aggregation...)
|
2022-12-02 01:45:28 +00:00
|
|
|
}
|
2022-10-07 02:54:09 +00:00
|
|
|
rows := &sql.Rows{}
|
2023-01-19 05:44:06 +00:00
|
|
|
query, args := selector.Query()
|
2022-10-07 02:54:09 +00:00
|
|
|
if err := gits.driver.Query(ctx, query, args, rows); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
return sql.ScanSlice(rows, v)
|
|
|
|
}
|