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