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