Files

658 lines
19 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"registry-backend/ent/comfynode"
"registry-backend/ent/nodeversion"
"registry-backend/ent/predicate"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// ComfyNodeQuery is the builder for querying ComfyNode entities.
type ComfyNodeQuery struct {
config
ctx *QueryContext
order []comfynode.OrderOption
inters []Interceptor
predicates []predicate.ComfyNode
withVersions *NodeVersionQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ComfyNodeQuery builder.
func (cnq *ComfyNodeQuery) Where(ps ...predicate.ComfyNode) *ComfyNodeQuery {
cnq.predicates = append(cnq.predicates, ps...)
return cnq
}
// Limit the number of records to be returned by this query.
func (cnq *ComfyNodeQuery) Limit(limit int) *ComfyNodeQuery {
cnq.ctx.Limit = &limit
return cnq
}
// Offset to start from.
func (cnq *ComfyNodeQuery) Offset(offset int) *ComfyNodeQuery {
cnq.ctx.Offset = &offset
return cnq
}
// 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 (cnq *ComfyNodeQuery) Unique(unique bool) *ComfyNodeQuery {
cnq.ctx.Unique = &unique
return cnq
}
// Order specifies how the records should be ordered.
func (cnq *ComfyNodeQuery) Order(o ...comfynode.OrderOption) *ComfyNodeQuery {
cnq.order = append(cnq.order, o...)
return cnq
}
// QueryVersions chains the current query on the "versions" edge.
func (cnq *ComfyNodeQuery) QueryVersions() *NodeVersionQuery {
query := (&NodeVersionClient{config: cnq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := cnq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := cnq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(comfynode.Table, comfynode.FieldID, selector),
sqlgraph.To(nodeversion.Table, nodeversion.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, comfynode.VersionsTable, comfynode.VersionsColumn),
)
fromU = sqlgraph.SetNeighbors(cnq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first ComfyNode entity from the query.
// Returns a *NotFoundError when no ComfyNode was found.
func (cnq *ComfyNodeQuery) First(ctx context.Context) (*ComfyNode, error) {
nodes, err := cnq.Limit(1).All(setContextOp(ctx, cnq.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{comfynode.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (cnq *ComfyNodeQuery) FirstX(ctx context.Context) *ComfyNode {
node, err := cnq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first ComfyNode ID from the query.
// Returns a *NotFoundError when no ComfyNode ID was found.
func (cnq *ComfyNodeQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = cnq.Limit(1).IDs(setContextOp(ctx, cnq.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{comfynode.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (cnq *ComfyNodeQuery) FirstIDX(ctx context.Context) uuid.UUID {
id, err := cnq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single ComfyNode entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one ComfyNode entity is found.
// Returns a *NotFoundError when no ComfyNode entities are found.
func (cnq *ComfyNodeQuery) Only(ctx context.Context) (*ComfyNode, error) {
nodes, err := cnq.Limit(2).All(setContextOp(ctx, cnq.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{comfynode.Label}
default:
return nil, &NotSingularError{comfynode.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (cnq *ComfyNodeQuery) OnlyX(ctx context.Context) *ComfyNode {
node, err := cnq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only ComfyNode ID in the query.
// Returns a *NotSingularError when more than one ComfyNode ID is found.
// Returns a *NotFoundError when no entities are found.
func (cnq *ComfyNodeQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = cnq.Limit(2).IDs(setContextOp(ctx, cnq.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{comfynode.Label}
default:
err = &NotSingularError{comfynode.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (cnq *ComfyNodeQuery) OnlyIDX(ctx context.Context) uuid.UUID {
id, err := cnq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of ComfyNodes.
func (cnq *ComfyNodeQuery) All(ctx context.Context) ([]*ComfyNode, error) {
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryAll)
if err := cnq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*ComfyNode, *ComfyNodeQuery]()
return withInterceptors[[]*ComfyNode](ctx, cnq, qr, cnq.inters)
}
// AllX is like All, but panics if an error occurs.
func (cnq *ComfyNodeQuery) AllX(ctx context.Context) []*ComfyNode {
nodes, err := cnq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of ComfyNode IDs.
func (cnq *ComfyNodeQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
if cnq.ctx.Unique == nil && cnq.path != nil {
cnq.Unique(true)
}
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryIDs)
if err = cnq.Select(comfynode.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (cnq *ComfyNodeQuery) IDsX(ctx context.Context) []uuid.UUID {
ids, err := cnq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (cnq *ComfyNodeQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryCount)
if err := cnq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, cnq, querierCount[*ComfyNodeQuery](), cnq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (cnq *ComfyNodeQuery) CountX(ctx context.Context) int {
count, err := cnq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (cnq *ComfyNodeQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryExist)
switch _, err := cnq.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 (cnq *ComfyNodeQuery) ExistX(ctx context.Context) bool {
exist, err := cnq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ComfyNodeQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (cnq *ComfyNodeQuery) Clone() *ComfyNodeQuery {
if cnq == nil {
return nil
}
return &ComfyNodeQuery{
config: cnq.config,
ctx: cnq.ctx.Clone(),
order: append([]comfynode.OrderOption{}, cnq.order...),
inters: append([]Interceptor{}, cnq.inters...),
predicates: append([]predicate.ComfyNode{}, cnq.predicates...),
withVersions: cnq.withVersions.Clone(),
// clone intermediate query.
sql: cnq.sql.Clone(),
path: cnq.path,
modifiers: append([]func(*sql.Selector){}, cnq.modifiers...),
}
}
// WithVersions tells the query-builder to eager-load the nodes that are connected to
// the "versions" edge. The optional arguments are used to configure the query builder of the edge.
func (cnq *ComfyNodeQuery) WithVersions(opts ...func(*NodeVersionQuery)) *ComfyNodeQuery {
query := (&NodeVersionClient{config: cnq.config}).Query()
for _, opt := range opts {
opt(query)
}
cnq.withVersions = query
return cnq
}
// 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 {
// CreateTime time.Time `json:"create_time,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.ComfyNode.Query().
// GroupBy(comfynode.FieldCreateTime).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (cnq *ComfyNodeQuery) GroupBy(field string, fields ...string) *ComfyNodeGroupBy {
cnq.ctx.Fields = append([]string{field}, fields...)
grbuild := &ComfyNodeGroupBy{build: cnq}
grbuild.flds = &cnq.ctx.Fields
grbuild.label = comfynode.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 {
// CreateTime time.Time `json:"create_time,omitempty"`
// }
//
// client.ComfyNode.Query().
// Select(comfynode.FieldCreateTime).
// Scan(ctx, &v)
func (cnq *ComfyNodeQuery) Select(fields ...string) *ComfyNodeSelect {
cnq.ctx.Fields = append(cnq.ctx.Fields, fields...)
sbuild := &ComfyNodeSelect{ComfyNodeQuery: cnq}
sbuild.label = comfynode.Label
sbuild.flds, sbuild.scan = &cnq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ComfyNodeSelect configured with the given aggregations.
func (cnq *ComfyNodeQuery) Aggregate(fns ...AggregateFunc) *ComfyNodeSelect {
return cnq.Select().Aggregate(fns...)
}
func (cnq *ComfyNodeQuery) prepareQuery(ctx context.Context) error {
for _, inter := range cnq.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, cnq); err != nil {
return err
}
}
}
for _, f := range cnq.ctx.Fields {
if !comfynode.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if cnq.path != nil {
prev, err := cnq.path(ctx)
if err != nil {
return err
}
cnq.sql = prev
}
return nil
}
func (cnq *ComfyNodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ComfyNode, error) {
var (
nodes = []*ComfyNode{}
_spec = cnq.querySpec()
loadedTypes = [1]bool{
cnq.withVersions != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*ComfyNode).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &ComfyNode{config: cnq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(cnq.modifiers) > 0 {
_spec.Modifiers = cnq.modifiers
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, cnq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := cnq.withVersions; query != nil {
if err := cnq.loadVersions(ctx, query, nodes, nil,
func(n *ComfyNode, e *NodeVersion) { n.Edges.Versions = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (cnq *ComfyNodeQuery) loadVersions(ctx context.Context, query *NodeVersionQuery, nodes []*ComfyNode, init func(*ComfyNode), assign func(*ComfyNode, *NodeVersion)) error {
ids := make([]uuid.UUID, 0, len(nodes))
nodeids := make(map[uuid.UUID][]*ComfyNode)
for i := range nodes {
fk := nodes[i].NodeVersionID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(nodeversion.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 "node_version_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (cnq *ComfyNodeQuery) sqlCount(ctx context.Context) (int, error) {
_spec := cnq.querySpec()
if len(cnq.modifiers) > 0 {
_spec.Modifiers = cnq.modifiers
}
_spec.Node.Columns = cnq.ctx.Fields
if len(cnq.ctx.Fields) > 0 {
_spec.Unique = cnq.ctx.Unique != nil && *cnq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, cnq.driver, _spec)
}
func (cnq *ComfyNodeQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(comfynode.Table, comfynode.Columns, sqlgraph.NewFieldSpec(comfynode.FieldID, field.TypeUUID))
_spec.From = cnq.sql
if unique := cnq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if cnq.path != nil {
_spec.Unique = true
}
if fields := cnq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, comfynode.FieldID)
for i := range fields {
if fields[i] != comfynode.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
if cnq.withVersions != nil {
_spec.Node.AddColumnOnce(comfynode.FieldNodeVersionID)
}
}
if ps := cnq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := cnq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := cnq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := cnq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (cnq *ComfyNodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(cnq.driver.Dialect())
t1 := builder.Table(comfynode.Table)
columns := cnq.ctx.Fields
if len(columns) == 0 {
columns = comfynode.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if cnq.sql != nil {
selector = cnq.sql
selector.Select(selector.Columns(columns...)...)
}
if cnq.ctx.Unique != nil && *cnq.ctx.Unique {
selector.Distinct()
}
for _, m := range cnq.modifiers {
m(selector)
}
for _, p := range cnq.predicates {
p(selector)
}
for _, p := range cnq.order {
p(selector)
}
if offset := cnq.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 := cnq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func (cnq *ComfyNodeQuery) ForUpdate(opts ...sql.LockOption) *ComfyNodeQuery {
if cnq.driver.Dialect() == dialect.Postgres {
cnq.Unique(false)
}
cnq.modifiers = append(cnq.modifiers, func(s *sql.Selector) {
s.ForUpdate(opts...)
})
return cnq
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func (cnq *ComfyNodeQuery) ForShare(opts ...sql.LockOption) *ComfyNodeQuery {
if cnq.driver.Dialect() == dialect.Postgres {
cnq.Unique(false)
}
cnq.modifiers = append(cnq.modifiers, func(s *sql.Selector) {
s.ForShare(opts...)
})
return cnq
}
// Modify adds a query modifier for attaching custom logic to queries.
func (cnq *ComfyNodeQuery) Modify(modifiers ...func(s *sql.Selector)) *ComfyNodeSelect {
cnq.modifiers = append(cnq.modifiers, modifiers...)
return cnq.Select()
}
// ComfyNodeGroupBy is the group-by builder for ComfyNode entities.
type ComfyNodeGroupBy struct {
selector
build *ComfyNodeQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (cngb *ComfyNodeGroupBy) Aggregate(fns ...AggregateFunc) *ComfyNodeGroupBy {
cngb.fns = append(cngb.fns, fns...)
return cngb
}
// Scan applies the selector query and scans the result into the given value.
func (cngb *ComfyNodeGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, cngb.build.ctx, ent.OpQueryGroupBy)
if err := cngb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ComfyNodeQuery, *ComfyNodeGroupBy](ctx, cngb.build, cngb, cngb.build.inters, v)
}
func (cngb *ComfyNodeGroupBy) sqlScan(ctx context.Context, root *ComfyNodeQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(cngb.fns))
for _, fn := range cngb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*cngb.flds)+len(cngb.fns))
for _, f := range *cngb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*cngb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := cngb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ComfyNodeSelect is the builder for selecting fields of ComfyNode entities.
type ComfyNodeSelect struct {
*ComfyNodeQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (cns *ComfyNodeSelect) Aggregate(fns ...AggregateFunc) *ComfyNodeSelect {
cns.fns = append(cns.fns, fns...)
return cns
}
// Scan applies the selector query and scans the result into the given value.
func (cns *ComfyNodeSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, cns.ctx, ent.OpQuerySelect)
if err := cns.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ComfyNodeQuery, *ComfyNodeSelect](ctx, cns.ComfyNodeQuery, cns, cns.inters, v)
}
func (cns *ComfyNodeSelect) sqlScan(ctx context.Context, root *ComfyNodeQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(cns.fns))
for _, fn := range cns.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*cns.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 := cns.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Modify adds a query modifier for attaching custom logic to queries.
func (cns *ComfyNodeSelect) Modify(modifiers ...func(s *sql.Selector)) *ComfyNodeSelect {
cns.modifiers = append(cns.modifiers, modifiers...)
return cns
}