529 lines
14 KiB
Go
529 lines
14 KiB
Go
// 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/FrankenBotDev/FrankenAPI/ent/predicate"
|
|
"github.com/FrankenBotDev/FrankenAPI/ent/supportresponse"
|
|
)
|
|
|
|
// SupportResponseQuery is the builder for querying SupportResponse entities.
|
|
type SupportResponseQuery struct {
|
|
config
|
|
limit *int
|
|
offset *int
|
|
unique *bool
|
|
order []OrderFunc
|
|
fields []string
|
|
predicates []predicate.SupportResponse
|
|
// intermediate query (i.e. traversal path).
|
|
sql *sql.Selector
|
|
path func(context.Context) (*sql.Selector, error)
|
|
}
|
|
|
|
// Where adds a new predicate for the SupportResponseQuery builder.
|
|
func (srq *SupportResponseQuery) Where(ps ...predicate.SupportResponse) *SupportResponseQuery {
|
|
srq.predicates = append(srq.predicates, ps...)
|
|
return srq
|
|
}
|
|
|
|
// Limit adds a limit step to the query.
|
|
func (srq *SupportResponseQuery) Limit(limit int) *SupportResponseQuery {
|
|
srq.limit = &limit
|
|
return srq
|
|
}
|
|
|
|
// Offset adds an offset step to the query.
|
|
func (srq *SupportResponseQuery) Offset(offset int) *SupportResponseQuery {
|
|
srq.offset = &offset
|
|
return srq
|
|
}
|
|
|
|
// 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 (srq *SupportResponseQuery) Unique(unique bool) *SupportResponseQuery {
|
|
srq.unique = &unique
|
|
return srq
|
|
}
|
|
|
|
// Order adds an order step to the query.
|
|
func (srq *SupportResponseQuery) Order(o ...OrderFunc) *SupportResponseQuery {
|
|
srq.order = append(srq.order, o...)
|
|
return srq
|
|
}
|
|
|
|
// First returns the first SupportResponse entity from the query.
|
|
// Returns a *NotFoundError when no SupportResponse was found.
|
|
func (srq *SupportResponseQuery) First(ctx context.Context) (*SupportResponse, error) {
|
|
nodes, err := srq.Limit(1).All(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nodes) == 0 {
|
|
return nil, &NotFoundError{supportresponse.Label}
|
|
}
|
|
return nodes[0], nil
|
|
}
|
|
|
|
// FirstX is like First, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) FirstX(ctx context.Context) *SupportResponse {
|
|
node, err := srq.First(ctx)
|
|
if err != nil && !IsNotFound(err) {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// FirstID returns the first SupportResponse ID from the query.
|
|
// Returns a *NotFoundError when no SupportResponse ID was found.
|
|
func (srq *SupportResponseQuery) FirstID(ctx context.Context) (id int, err error) {
|
|
var ids []int
|
|
if ids, err = srq.Limit(1).IDs(ctx); err != nil {
|
|
return
|
|
}
|
|
if len(ids) == 0 {
|
|
err = &NotFoundError{supportresponse.Label}
|
|
return
|
|
}
|
|
return ids[0], nil
|
|
}
|
|
|
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) FirstIDX(ctx context.Context) int {
|
|
id, err := srq.FirstID(ctx)
|
|
if err != nil && !IsNotFound(err) {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// Only returns a single SupportResponse entity found by the query, ensuring it only returns one.
|
|
// Returns a *NotSingularError when more than one SupportResponse entity is found.
|
|
// Returns a *NotFoundError when no SupportResponse entities are found.
|
|
func (srq *SupportResponseQuery) Only(ctx context.Context) (*SupportResponse, error) {
|
|
nodes, err := srq.Limit(2).All(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch len(nodes) {
|
|
case 1:
|
|
return nodes[0], nil
|
|
case 0:
|
|
return nil, &NotFoundError{supportresponse.Label}
|
|
default:
|
|
return nil, &NotSingularError{supportresponse.Label}
|
|
}
|
|
}
|
|
|
|
// OnlyX is like Only, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) OnlyX(ctx context.Context) *SupportResponse {
|
|
node, err := srq.Only(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// OnlyID is like Only, but returns the only SupportResponse ID in the query.
|
|
// Returns a *NotSingularError when more than one SupportResponse ID is found.
|
|
// Returns a *NotFoundError when no entities are found.
|
|
func (srq *SupportResponseQuery) OnlyID(ctx context.Context) (id int, err error) {
|
|
var ids []int
|
|
if ids, err = srq.Limit(2).IDs(ctx); err != nil {
|
|
return
|
|
}
|
|
switch len(ids) {
|
|
case 1:
|
|
id = ids[0]
|
|
case 0:
|
|
err = &NotFoundError{supportresponse.Label}
|
|
default:
|
|
err = &NotSingularError{supportresponse.Label}
|
|
}
|
|
return
|
|
}
|
|
|
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) OnlyIDX(ctx context.Context) int {
|
|
id, err := srq.OnlyID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// All executes the query and returns a list of SupportResponses.
|
|
func (srq *SupportResponseQuery) All(ctx context.Context) ([]*SupportResponse, error) {
|
|
if err := srq.prepareQuery(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
return srq.sqlAll(ctx)
|
|
}
|
|
|
|
// AllX is like All, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) AllX(ctx context.Context) []*SupportResponse {
|
|
nodes, err := srq.All(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return nodes
|
|
}
|
|
|
|
// IDs executes the query and returns a list of SupportResponse IDs.
|
|
func (srq *SupportResponseQuery) IDs(ctx context.Context) ([]int, error) {
|
|
var ids []int
|
|
if err := srq.Select(supportresponse.FieldID).Scan(ctx, &ids); err != nil {
|
|
return nil, err
|
|
}
|
|
return ids, nil
|
|
}
|
|
|
|
// IDsX is like IDs, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) IDsX(ctx context.Context) []int {
|
|
ids, err := srq.IDs(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return ids
|
|
}
|
|
|
|
// Count returns the count of the given query.
|
|
func (srq *SupportResponseQuery) Count(ctx context.Context) (int, error) {
|
|
if err := srq.prepareQuery(ctx); err != nil {
|
|
return 0, err
|
|
}
|
|
return srq.sqlCount(ctx)
|
|
}
|
|
|
|
// CountX is like Count, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) CountX(ctx context.Context) int {
|
|
count, err := srq.Count(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return count
|
|
}
|
|
|
|
// Exist returns true if the query has elements in the graph.
|
|
func (srq *SupportResponseQuery) Exist(ctx context.Context) (bool, error) {
|
|
if err := srq.prepareQuery(ctx); err != nil {
|
|
return false, err
|
|
}
|
|
return srq.sqlExist(ctx)
|
|
}
|
|
|
|
// ExistX is like Exist, but panics if an error occurs.
|
|
func (srq *SupportResponseQuery) ExistX(ctx context.Context) bool {
|
|
exist, err := srq.Exist(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return exist
|
|
}
|
|
|
|
// Clone returns a duplicate of the SupportResponseQuery builder, including all associated steps. It can be
|
|
// used to prepare common query builders and use them differently after the clone is made.
|
|
func (srq *SupportResponseQuery) Clone() *SupportResponseQuery {
|
|
if srq == nil {
|
|
return nil
|
|
}
|
|
return &SupportResponseQuery{
|
|
config: srq.config,
|
|
limit: srq.limit,
|
|
offset: srq.offset,
|
|
order: append([]OrderFunc{}, srq.order...),
|
|
predicates: append([]predicate.SupportResponse{}, srq.predicates...),
|
|
// clone intermediate query.
|
|
sql: srq.sql.Clone(),
|
|
path: srq.path,
|
|
unique: srq.unique,
|
|
}
|
|
}
|
|
|
|
// 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 {
|
|
// Refid string `json:"refid,omitempty"`
|
|
// Count int `json:"count,omitempty"`
|
|
// }
|
|
//
|
|
// client.SupportResponse.Query().
|
|
// GroupBy(supportresponse.FieldRefid).
|
|
// Aggregate(ent.Count()).
|
|
// Scan(ctx, &v)
|
|
//
|
|
func (srq *SupportResponseQuery) GroupBy(field string, fields ...string) *SupportResponseGroupBy {
|
|
grbuild := &SupportResponseGroupBy{config: srq.config}
|
|
grbuild.fields = append([]string{field}, fields...)
|
|
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
|
if err := srq.prepareQuery(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
return srq.sqlQuery(ctx), nil
|
|
}
|
|
grbuild.label = supportresponse.Label
|
|
grbuild.flds, grbuild.scan = &grbuild.fields, 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 {
|
|
// Refid string `json:"refid,omitempty"`
|
|
// }
|
|
//
|
|
// client.SupportResponse.Query().
|
|
// Select(supportresponse.FieldRefid).
|
|
// Scan(ctx, &v)
|
|
//
|
|
func (srq *SupportResponseQuery) Select(fields ...string) *SupportResponseSelect {
|
|
srq.fields = append(srq.fields, fields...)
|
|
selbuild := &SupportResponseSelect{SupportResponseQuery: srq}
|
|
selbuild.label = supportresponse.Label
|
|
selbuild.flds, selbuild.scan = &srq.fields, selbuild.Scan
|
|
return selbuild
|
|
}
|
|
|
|
func (srq *SupportResponseQuery) prepareQuery(ctx context.Context) error {
|
|
for _, f := range srq.fields {
|
|
if !supportresponse.ValidColumn(f) {
|
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
}
|
|
if srq.path != nil {
|
|
prev, err := srq.path(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
srq.sql = prev
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (srq *SupportResponseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SupportResponse, error) {
|
|
var (
|
|
nodes = []*SupportResponse{}
|
|
_spec = srq.querySpec()
|
|
)
|
|
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
|
return (*SupportResponse).scanValues(nil, columns)
|
|
}
|
|
_spec.Assign = func(columns []string, values []interface{}) error {
|
|
node := &SupportResponse{config: srq.config}
|
|
nodes = append(nodes, node)
|
|
return node.assignValues(columns, values)
|
|
}
|
|
for i := range hooks {
|
|
hooks[i](ctx, _spec)
|
|
}
|
|
if err := sqlgraph.QueryNodes(ctx, srq.driver, _spec); err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nodes) == 0 {
|
|
return nodes, nil
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
func (srq *SupportResponseQuery) sqlCount(ctx context.Context) (int, error) {
|
|
_spec := srq.querySpec()
|
|
_spec.Node.Columns = srq.fields
|
|
if len(srq.fields) > 0 {
|
|
_spec.Unique = srq.unique != nil && *srq.unique
|
|
}
|
|
return sqlgraph.CountNodes(ctx, srq.driver, _spec)
|
|
}
|
|
|
|
func (srq *SupportResponseQuery) sqlExist(ctx context.Context) (bool, error) {
|
|
n, err := srq.sqlCount(ctx)
|
|
if err != nil {
|
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
|
}
|
|
return n > 0, nil
|
|
}
|
|
|
|
func (srq *SupportResponseQuery) querySpec() *sqlgraph.QuerySpec {
|
|
_spec := &sqlgraph.QuerySpec{
|
|
Node: &sqlgraph.NodeSpec{
|
|
Table: supportresponse.Table,
|
|
Columns: supportresponse.Columns,
|
|
ID: &sqlgraph.FieldSpec{
|
|
Type: field.TypeInt,
|
|
Column: supportresponse.FieldID,
|
|
},
|
|
},
|
|
From: srq.sql,
|
|
Unique: true,
|
|
}
|
|
if unique := srq.unique; unique != nil {
|
|
_spec.Unique = *unique
|
|
}
|
|
if fields := srq.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, supportresponse.FieldID)
|
|
for i := range fields {
|
|
if fields[i] != supportresponse.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
|
}
|
|
}
|
|
}
|
|
if ps := srq.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if limit := srq.limit; limit != nil {
|
|
_spec.Limit = *limit
|
|
}
|
|
if offset := srq.offset; offset != nil {
|
|
_spec.Offset = *offset
|
|
}
|
|
if ps := srq.order; len(ps) > 0 {
|
|
_spec.Order = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
return _spec
|
|
}
|
|
|
|
func (srq *SupportResponseQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|
builder := sql.Dialect(srq.driver.Dialect())
|
|
t1 := builder.Table(supportresponse.Table)
|
|
columns := srq.fields
|
|
if len(columns) == 0 {
|
|
columns = supportresponse.Columns
|
|
}
|
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
|
if srq.sql != nil {
|
|
selector = srq.sql
|
|
selector.Select(selector.Columns(columns...)...)
|
|
}
|
|
if srq.unique != nil && *srq.unique {
|
|
selector.Distinct()
|
|
}
|
|
for _, p := range srq.predicates {
|
|
p(selector)
|
|
}
|
|
for _, p := range srq.order {
|
|
p(selector)
|
|
}
|
|
if offset := srq.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 := srq.limit; limit != nil {
|
|
selector.Limit(*limit)
|
|
}
|
|
return selector
|
|
}
|
|
|
|
// SupportResponseGroupBy is the group-by builder for SupportResponse entities.
|
|
type SupportResponseGroupBy struct {
|
|
config
|
|
selector
|
|
fields []string
|
|
fns []AggregateFunc
|
|
// intermediate query (i.e. traversal path).
|
|
sql *sql.Selector
|
|
path func(context.Context) (*sql.Selector, error)
|
|
}
|
|
|
|
// Aggregate adds the given aggregation functions to the group-by query.
|
|
func (srgb *SupportResponseGroupBy) Aggregate(fns ...AggregateFunc) *SupportResponseGroupBy {
|
|
srgb.fns = append(srgb.fns, fns...)
|
|
return srgb
|
|
}
|
|
|
|
// Scan applies the group-by query and scans the result into the given value.
|
|
func (srgb *SupportResponseGroupBy) Scan(ctx context.Context, v interface{}) error {
|
|
query, err := srgb.path(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
srgb.sql = query
|
|
return srgb.sqlScan(ctx, v)
|
|
}
|
|
|
|
func (srgb *SupportResponseGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
|
for _, f := range srgb.fields {
|
|
if !supportresponse.ValidColumn(f) {
|
|
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
|
}
|
|
}
|
|
selector := srgb.sqlQuery()
|
|
if err := selector.Err(); err != nil {
|
|
return err
|
|
}
|
|
rows := &sql.Rows{}
|
|
query, args := selector.Query()
|
|
if err := srgb.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|
|
|
|
func (srgb *SupportResponseGroupBy) sqlQuery() *sql.Selector {
|
|
selector := srgb.sql.Select()
|
|
aggregation := make([]string, 0, len(srgb.fns))
|
|
for _, fn := range srgb.fns {
|
|
aggregation = append(aggregation, fn(selector))
|
|
}
|
|
// If no columns were selected in a custom aggregation function, the default
|
|
// selection is the fields used for "group-by", and the aggregation functions.
|
|
if len(selector.SelectedColumns()) == 0 {
|
|
columns := make([]string, 0, len(srgb.fields)+len(srgb.fns))
|
|
for _, f := range srgb.fields {
|
|
columns = append(columns, selector.C(f))
|
|
}
|
|
columns = append(columns, aggregation...)
|
|
selector.Select(columns...)
|
|
}
|
|
return selector.GroupBy(selector.Columns(srgb.fields...)...)
|
|
}
|
|
|
|
// SupportResponseSelect is the builder for selecting fields of SupportResponse entities.
|
|
type SupportResponseSelect struct {
|
|
*SupportResponseQuery
|
|
selector
|
|
// intermediate query (i.e. traversal path).
|
|
sql *sql.Selector
|
|
}
|
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
func (srs *SupportResponseSelect) Scan(ctx context.Context, v interface{}) error {
|
|
if err := srs.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
srs.sql = srs.SupportResponseQuery.sqlQuery(ctx)
|
|
return srs.sqlScan(ctx, v)
|
|
}
|
|
|
|
func (srs *SupportResponseSelect) sqlScan(ctx context.Context, v interface{}) error {
|
|
rows := &sql.Rows{}
|
|
query, args := srs.sql.Query()
|
|
if err := srs.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|