mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
528 lines
15 KiB
Go
528 lines
15 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math"
|
|
"polaris/ent/importlist"
|
|
"polaris/ent/predicate"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ImportListQuery is the builder for querying ImportList entities.
|
|
type ImportListQuery struct {
|
|
config
|
|
ctx *QueryContext
|
|
order []importlist.OrderOption
|
|
inters []Interceptor
|
|
predicates []predicate.ImportList
|
|
// intermediate query (i.e. traversal path).
|
|
sql *sql.Selector
|
|
path func(context.Context) (*sql.Selector, error)
|
|
}
|
|
|
|
// Where adds a new predicate for the ImportListQuery builder.
|
|
func (ilq *ImportListQuery) Where(ps ...predicate.ImportList) *ImportListQuery {
|
|
ilq.predicates = append(ilq.predicates, ps...)
|
|
return ilq
|
|
}
|
|
|
|
// Limit the number of records to be returned by this query.
|
|
func (ilq *ImportListQuery) Limit(limit int) *ImportListQuery {
|
|
ilq.ctx.Limit = &limit
|
|
return ilq
|
|
}
|
|
|
|
// Offset to start from.
|
|
func (ilq *ImportListQuery) Offset(offset int) *ImportListQuery {
|
|
ilq.ctx.Offset = &offset
|
|
return ilq
|
|
}
|
|
|
|
// 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 (ilq *ImportListQuery) Unique(unique bool) *ImportListQuery {
|
|
ilq.ctx.Unique = &unique
|
|
return ilq
|
|
}
|
|
|
|
// Order specifies how the records should be ordered.
|
|
func (ilq *ImportListQuery) Order(o ...importlist.OrderOption) *ImportListQuery {
|
|
ilq.order = append(ilq.order, o...)
|
|
return ilq
|
|
}
|
|
|
|
// First returns the first ImportList entity from the query.
|
|
// Returns a *NotFoundError when no ImportList was found.
|
|
func (ilq *ImportListQuery) First(ctx context.Context) (*ImportList, error) {
|
|
nodes, err := ilq.Limit(1).All(setContextOp(ctx, ilq.ctx, ent.OpQueryFirst))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nodes) == 0 {
|
|
return nil, &NotFoundError{importlist.Label}
|
|
}
|
|
return nodes[0], nil
|
|
}
|
|
|
|
// FirstX is like First, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) FirstX(ctx context.Context) *ImportList {
|
|
node, err := ilq.First(ctx)
|
|
if err != nil && !IsNotFound(err) {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// FirstID returns the first ImportList ID from the query.
|
|
// Returns a *NotFoundError when no ImportList ID was found.
|
|
func (ilq *ImportListQuery) FirstID(ctx context.Context) (id int, err error) {
|
|
var ids []int
|
|
if ids, err = ilq.Limit(1).IDs(setContextOp(ctx, ilq.ctx, ent.OpQueryFirstID)); err != nil {
|
|
return
|
|
}
|
|
if len(ids) == 0 {
|
|
err = &NotFoundError{importlist.Label}
|
|
return
|
|
}
|
|
return ids[0], nil
|
|
}
|
|
|
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) FirstIDX(ctx context.Context) int {
|
|
id, err := ilq.FirstID(ctx)
|
|
if err != nil && !IsNotFound(err) {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// Only returns a single ImportList entity found by the query, ensuring it only returns one.
|
|
// Returns a *NotSingularError when more than one ImportList entity is found.
|
|
// Returns a *NotFoundError when no ImportList entities are found.
|
|
func (ilq *ImportListQuery) Only(ctx context.Context) (*ImportList, error) {
|
|
nodes, err := ilq.Limit(2).All(setContextOp(ctx, ilq.ctx, ent.OpQueryOnly))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch len(nodes) {
|
|
case 1:
|
|
return nodes[0], nil
|
|
case 0:
|
|
return nil, &NotFoundError{importlist.Label}
|
|
default:
|
|
return nil, &NotSingularError{importlist.Label}
|
|
}
|
|
}
|
|
|
|
// OnlyX is like Only, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) OnlyX(ctx context.Context) *ImportList {
|
|
node, err := ilq.Only(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// OnlyID is like Only, but returns the only ImportList ID in the query.
|
|
// Returns a *NotSingularError when more than one ImportList ID is found.
|
|
// Returns a *NotFoundError when no entities are found.
|
|
func (ilq *ImportListQuery) OnlyID(ctx context.Context) (id int, err error) {
|
|
var ids []int
|
|
if ids, err = ilq.Limit(2).IDs(setContextOp(ctx, ilq.ctx, ent.OpQueryOnlyID)); err != nil {
|
|
return
|
|
}
|
|
switch len(ids) {
|
|
case 1:
|
|
id = ids[0]
|
|
case 0:
|
|
err = &NotFoundError{importlist.Label}
|
|
default:
|
|
err = &NotSingularError{importlist.Label}
|
|
}
|
|
return
|
|
}
|
|
|
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) OnlyIDX(ctx context.Context) int {
|
|
id, err := ilq.OnlyID(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return id
|
|
}
|
|
|
|
// All executes the query and returns a list of ImportLists.
|
|
func (ilq *ImportListQuery) All(ctx context.Context) ([]*ImportList, error) {
|
|
ctx = setContextOp(ctx, ilq.ctx, ent.OpQueryAll)
|
|
if err := ilq.prepareQuery(ctx); err != nil {
|
|
return nil, err
|
|
}
|
|
qr := querierAll[[]*ImportList, *ImportListQuery]()
|
|
return withInterceptors[[]*ImportList](ctx, ilq, qr, ilq.inters)
|
|
}
|
|
|
|
// AllX is like All, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) AllX(ctx context.Context) []*ImportList {
|
|
nodes, err := ilq.All(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return nodes
|
|
}
|
|
|
|
// IDs executes the query and returns a list of ImportList IDs.
|
|
func (ilq *ImportListQuery) IDs(ctx context.Context) (ids []int, err error) {
|
|
if ilq.ctx.Unique == nil && ilq.path != nil {
|
|
ilq.Unique(true)
|
|
}
|
|
ctx = setContextOp(ctx, ilq.ctx, ent.OpQueryIDs)
|
|
if err = ilq.Select(importlist.FieldID).Scan(ctx, &ids); err != nil {
|
|
return nil, err
|
|
}
|
|
return ids, nil
|
|
}
|
|
|
|
// IDsX is like IDs, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) IDsX(ctx context.Context) []int {
|
|
ids, err := ilq.IDs(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return ids
|
|
}
|
|
|
|
// Count returns the count of the given query.
|
|
func (ilq *ImportListQuery) Count(ctx context.Context) (int, error) {
|
|
ctx = setContextOp(ctx, ilq.ctx, ent.OpQueryCount)
|
|
if err := ilq.prepareQuery(ctx); err != nil {
|
|
return 0, err
|
|
}
|
|
return withInterceptors[int](ctx, ilq, querierCount[*ImportListQuery](), ilq.inters)
|
|
}
|
|
|
|
// CountX is like Count, but panics if an error occurs.
|
|
func (ilq *ImportListQuery) CountX(ctx context.Context) int {
|
|
count, err := ilq.Count(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return count
|
|
}
|
|
|
|
// Exist returns true if the query has elements in the graph.
|
|
func (ilq *ImportListQuery) Exist(ctx context.Context) (bool, error) {
|
|
ctx = setContextOp(ctx, ilq.ctx, ent.OpQueryExist)
|
|
switch _, err := ilq.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 (ilq *ImportListQuery) ExistX(ctx context.Context) bool {
|
|
exist, err := ilq.Exist(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return exist
|
|
}
|
|
|
|
// Clone returns a duplicate of the ImportListQuery builder, including all associated steps. It can be
|
|
// used to prepare common query builders and use them differently after the clone is made.
|
|
func (ilq *ImportListQuery) Clone() *ImportListQuery {
|
|
if ilq == nil {
|
|
return nil
|
|
}
|
|
return &ImportListQuery{
|
|
config: ilq.config,
|
|
ctx: ilq.ctx.Clone(),
|
|
order: append([]importlist.OrderOption{}, ilq.order...),
|
|
inters: append([]Interceptor{}, ilq.inters...),
|
|
predicates: append([]predicate.ImportList{}, ilq.predicates...),
|
|
// clone intermediate query.
|
|
sql: ilq.sql.Clone(),
|
|
path: ilq.path,
|
|
}
|
|
}
|
|
|
|
// 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 {
|
|
// Name string `json:"name,omitempty"`
|
|
// Count int `json:"count,omitempty"`
|
|
// }
|
|
//
|
|
// client.ImportList.Query().
|
|
// GroupBy(importlist.FieldName).
|
|
// Aggregate(ent.Count()).
|
|
// Scan(ctx, &v)
|
|
func (ilq *ImportListQuery) GroupBy(field string, fields ...string) *ImportListGroupBy {
|
|
ilq.ctx.Fields = append([]string{field}, fields...)
|
|
grbuild := &ImportListGroupBy{build: ilq}
|
|
grbuild.flds = &ilq.ctx.Fields
|
|
grbuild.label = importlist.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 {
|
|
// Name string `json:"name,omitempty"`
|
|
// }
|
|
//
|
|
// client.ImportList.Query().
|
|
// Select(importlist.FieldName).
|
|
// Scan(ctx, &v)
|
|
func (ilq *ImportListQuery) Select(fields ...string) *ImportListSelect {
|
|
ilq.ctx.Fields = append(ilq.ctx.Fields, fields...)
|
|
sbuild := &ImportListSelect{ImportListQuery: ilq}
|
|
sbuild.label = importlist.Label
|
|
sbuild.flds, sbuild.scan = &ilq.ctx.Fields, sbuild.Scan
|
|
return sbuild
|
|
}
|
|
|
|
// Aggregate returns a ImportListSelect configured with the given aggregations.
|
|
func (ilq *ImportListQuery) Aggregate(fns ...AggregateFunc) *ImportListSelect {
|
|
return ilq.Select().Aggregate(fns...)
|
|
}
|
|
|
|
func (ilq *ImportListQuery) prepareQuery(ctx context.Context) error {
|
|
for _, inter := range ilq.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, ilq); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
for _, f := range ilq.ctx.Fields {
|
|
if !importlist.ValidColumn(f) {
|
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
}
|
|
if ilq.path != nil {
|
|
prev, err := ilq.path(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ilq.sql = prev
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (ilq *ImportListQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ImportList, error) {
|
|
var (
|
|
nodes = []*ImportList{}
|
|
_spec = ilq.querySpec()
|
|
)
|
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
|
return (*ImportList).scanValues(nil, columns)
|
|
}
|
|
_spec.Assign = func(columns []string, values []any) error {
|
|
node := &ImportList{config: ilq.config}
|
|
nodes = append(nodes, node)
|
|
return node.assignValues(columns, values)
|
|
}
|
|
for i := range hooks {
|
|
hooks[i](ctx, _spec)
|
|
}
|
|
if err := sqlgraph.QueryNodes(ctx, ilq.driver, _spec); err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nodes) == 0 {
|
|
return nodes, nil
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
func (ilq *ImportListQuery) sqlCount(ctx context.Context) (int, error) {
|
|
_spec := ilq.querySpec()
|
|
_spec.Node.Columns = ilq.ctx.Fields
|
|
if len(ilq.ctx.Fields) > 0 {
|
|
_spec.Unique = ilq.ctx.Unique != nil && *ilq.ctx.Unique
|
|
}
|
|
return sqlgraph.CountNodes(ctx, ilq.driver, _spec)
|
|
}
|
|
|
|
func (ilq *ImportListQuery) querySpec() *sqlgraph.QuerySpec {
|
|
_spec := sqlgraph.NewQuerySpec(importlist.Table, importlist.Columns, sqlgraph.NewFieldSpec(importlist.FieldID, field.TypeInt))
|
|
_spec.From = ilq.sql
|
|
if unique := ilq.ctx.Unique; unique != nil {
|
|
_spec.Unique = *unique
|
|
} else if ilq.path != nil {
|
|
_spec.Unique = true
|
|
}
|
|
if fields := ilq.ctx.Fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, importlist.FieldID)
|
|
for i := range fields {
|
|
if fields[i] != importlist.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
|
}
|
|
}
|
|
}
|
|
if ps := ilq.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if limit := ilq.ctx.Limit; limit != nil {
|
|
_spec.Limit = *limit
|
|
}
|
|
if offset := ilq.ctx.Offset; offset != nil {
|
|
_spec.Offset = *offset
|
|
}
|
|
if ps := ilq.order; len(ps) > 0 {
|
|
_spec.Order = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
return _spec
|
|
}
|
|
|
|
func (ilq *ImportListQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|
builder := sql.Dialect(ilq.driver.Dialect())
|
|
t1 := builder.Table(importlist.Table)
|
|
columns := ilq.ctx.Fields
|
|
if len(columns) == 0 {
|
|
columns = importlist.Columns
|
|
}
|
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
|
if ilq.sql != nil {
|
|
selector = ilq.sql
|
|
selector.Select(selector.Columns(columns...)...)
|
|
}
|
|
if ilq.ctx.Unique != nil && *ilq.ctx.Unique {
|
|
selector.Distinct()
|
|
}
|
|
for _, p := range ilq.predicates {
|
|
p(selector)
|
|
}
|
|
for _, p := range ilq.order {
|
|
p(selector)
|
|
}
|
|
if offset := ilq.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 := ilq.ctx.Limit; limit != nil {
|
|
selector.Limit(*limit)
|
|
}
|
|
return selector
|
|
}
|
|
|
|
// ImportListGroupBy is the group-by builder for ImportList entities.
|
|
type ImportListGroupBy struct {
|
|
selector
|
|
build *ImportListQuery
|
|
}
|
|
|
|
// Aggregate adds the given aggregation functions to the group-by query.
|
|
func (ilgb *ImportListGroupBy) Aggregate(fns ...AggregateFunc) *ImportListGroupBy {
|
|
ilgb.fns = append(ilgb.fns, fns...)
|
|
return ilgb
|
|
}
|
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
func (ilgb *ImportListGroupBy) Scan(ctx context.Context, v any) error {
|
|
ctx = setContextOp(ctx, ilgb.build.ctx, ent.OpQueryGroupBy)
|
|
if err := ilgb.build.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
return scanWithInterceptors[*ImportListQuery, *ImportListGroupBy](ctx, ilgb.build, ilgb, ilgb.build.inters, v)
|
|
}
|
|
|
|
func (ilgb *ImportListGroupBy) sqlScan(ctx context.Context, root *ImportListQuery, v any) error {
|
|
selector := root.sqlQuery(ctx).Select()
|
|
aggregation := make([]string, 0, len(ilgb.fns))
|
|
for _, fn := range ilgb.fns {
|
|
aggregation = append(aggregation, fn(selector))
|
|
}
|
|
if len(selector.SelectedColumns()) == 0 {
|
|
columns := make([]string, 0, len(*ilgb.flds)+len(ilgb.fns))
|
|
for _, f := range *ilgb.flds {
|
|
columns = append(columns, selector.C(f))
|
|
}
|
|
columns = append(columns, aggregation...)
|
|
selector.Select(columns...)
|
|
}
|
|
selector.GroupBy(selector.Columns(*ilgb.flds...)...)
|
|
if err := selector.Err(); err != nil {
|
|
return err
|
|
}
|
|
rows := &sql.Rows{}
|
|
query, args := selector.Query()
|
|
if err := ilgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|
|
|
|
// ImportListSelect is the builder for selecting fields of ImportList entities.
|
|
type ImportListSelect struct {
|
|
*ImportListQuery
|
|
selector
|
|
}
|
|
|
|
// Aggregate adds the given aggregation functions to the selector query.
|
|
func (ils *ImportListSelect) Aggregate(fns ...AggregateFunc) *ImportListSelect {
|
|
ils.fns = append(ils.fns, fns...)
|
|
return ils
|
|
}
|
|
|
|
// Scan applies the selector query and scans the result into the given value.
|
|
func (ils *ImportListSelect) Scan(ctx context.Context, v any) error {
|
|
ctx = setContextOp(ctx, ils.ctx, ent.OpQuerySelect)
|
|
if err := ils.prepareQuery(ctx); err != nil {
|
|
return err
|
|
}
|
|
return scanWithInterceptors[*ImportListQuery, *ImportListSelect](ctx, ils.ImportListQuery, ils, ils.inters, v)
|
|
}
|
|
|
|
func (ils *ImportListSelect) sqlScan(ctx context.Context, root *ImportListQuery, v any) error {
|
|
selector := root.sqlQuery(ctx)
|
|
aggregation := make([]string, 0, len(ils.fns))
|
|
for _, fn := range ils.fns {
|
|
aggregation = append(aggregation, fn(selector))
|
|
}
|
|
switch n := len(*ils.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 := ils.driver.Query(ctx, query, args, rows); err != nil {
|
|
return err
|
|
}
|
|
defer rows.Close()
|
|
return sql.ScanSlice(rows, v)
|
|
}
|