OpenID Connect (OIDC) identity and OAuth 2.0 provider with pluggable connectors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

526 lines
15 KiB

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