We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/safedep/vet'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
// 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"
"github.com/safedep/vet/ent/predicate"
"github.com/safedep/vet/ent/reportlicense"
"github.com/safedep/vet/ent/reportpackage"
)
// ReportLicenseQuery is the builder for querying ReportLicense entities.
type ReportLicenseQuery struct {
config
ctx *QueryContext
order []reportlicense.OrderOption
inters []Interceptor
predicates []predicate.ReportLicense
withPackage *ReportPackageQuery
withFKs bool
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ReportLicenseQuery builder.
func (rlq *ReportLicenseQuery) Where(ps ...predicate.ReportLicense) *ReportLicenseQuery {
rlq.predicates = append(rlq.predicates, ps...)
return rlq
}
// Limit the number of records to be returned by this query.
func (rlq *ReportLicenseQuery) Limit(limit int) *ReportLicenseQuery {
rlq.ctx.Limit = &limit
return rlq
}
// Offset to start from.
func (rlq *ReportLicenseQuery) Offset(offset int) *ReportLicenseQuery {
rlq.ctx.Offset = &offset
return rlq
}
// 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 (rlq *ReportLicenseQuery) Unique(unique bool) *ReportLicenseQuery {
rlq.ctx.Unique = &unique
return rlq
}
// Order specifies how the records should be ordered.
func (rlq *ReportLicenseQuery) Order(o ...reportlicense.OrderOption) *ReportLicenseQuery {
rlq.order = append(rlq.order, o...)
return rlq
}
// QueryPackage chains the current query on the "package" edge.
func (rlq *ReportLicenseQuery) QueryPackage() *ReportPackageQuery {
query := (&ReportPackageClient{config: rlq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := rlq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := rlq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(reportlicense.Table, reportlicense.FieldID, selector),
sqlgraph.To(reportpackage.Table, reportpackage.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, reportlicense.PackageTable, reportlicense.PackageColumn),
)
fromU = sqlgraph.SetNeighbors(rlq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first ReportLicense entity from the query.
// Returns a *NotFoundError when no ReportLicense was found.
func (rlq *ReportLicenseQuery) First(ctx context.Context) (*ReportLicense, error) {
nodes, err := rlq.Limit(1).All(setContextOp(ctx, rlq.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{reportlicense.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (rlq *ReportLicenseQuery) FirstX(ctx context.Context) *ReportLicense {
node, err := rlq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first ReportLicense ID from the query.
// Returns a *NotFoundError when no ReportLicense ID was found.
func (rlq *ReportLicenseQuery) FirstID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = rlq.Limit(1).IDs(setContextOp(ctx, rlq.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{reportlicense.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (rlq *ReportLicenseQuery) FirstIDX(ctx context.Context) int {
id, err := rlq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single ReportLicense entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one ReportLicense entity is found.
// Returns a *NotFoundError when no ReportLicense entities are found.
func (rlq *ReportLicenseQuery) Only(ctx context.Context) (*ReportLicense, error) {
nodes, err := rlq.Limit(2).All(setContextOp(ctx, rlq.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{reportlicense.Label}
default:
return nil, &NotSingularError{reportlicense.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (rlq *ReportLicenseQuery) OnlyX(ctx context.Context) *ReportLicense {
node, err := rlq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only ReportLicense ID in the query.
// Returns a *NotSingularError when more than one ReportLicense ID is found.
// Returns a *NotFoundError when no entities are found.
func (rlq *ReportLicenseQuery) OnlyID(ctx context.Context) (id int, err error) {
var ids []int
if ids, err = rlq.Limit(2).IDs(setContextOp(ctx, rlq.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{reportlicense.Label}
default:
err = &NotSingularError{reportlicense.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (rlq *ReportLicenseQuery) OnlyIDX(ctx context.Context) int {
id, err := rlq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of ReportLicenses.
func (rlq *ReportLicenseQuery) All(ctx context.Context) ([]*ReportLicense, error) {
ctx = setContextOp(ctx, rlq.ctx, ent.OpQueryAll)
if err := rlq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*ReportLicense, *ReportLicenseQuery]()
return withInterceptors[[]*ReportLicense](ctx, rlq, qr, rlq.inters)
}
// AllX is like All, but panics if an error occurs.
func (rlq *ReportLicenseQuery) AllX(ctx context.Context) []*ReportLicense {
nodes, err := rlq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of ReportLicense IDs.
func (rlq *ReportLicenseQuery) IDs(ctx context.Context) (ids []int, err error) {
if rlq.ctx.Unique == nil && rlq.path != nil {
rlq.Unique(true)
}
ctx = setContextOp(ctx, rlq.ctx, ent.OpQueryIDs)
if err = rlq.Select(reportlicense.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (rlq *ReportLicenseQuery) IDsX(ctx context.Context) []int {
ids, err := rlq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (rlq *ReportLicenseQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, rlq.ctx, ent.OpQueryCount)
if err := rlq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, rlq, querierCount[*ReportLicenseQuery](), rlq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (rlq *ReportLicenseQuery) CountX(ctx context.Context) int {
count, err := rlq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (rlq *ReportLicenseQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, rlq.ctx, ent.OpQueryExist)
switch _, err := rlq.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 (rlq *ReportLicenseQuery) ExistX(ctx context.Context) bool {
exist, err := rlq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ReportLicenseQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (rlq *ReportLicenseQuery) Clone() *ReportLicenseQuery {
if rlq == nil {
return nil
}
return &ReportLicenseQuery{
config: rlq.config,
ctx: rlq.ctx.Clone(),
order: append([]reportlicense.OrderOption{}, rlq.order...),
inters: append([]Interceptor{}, rlq.inters...),
predicates: append([]predicate.ReportLicense{}, rlq.predicates...),
withPackage: rlq.withPackage.Clone(),
// clone intermediate query.
sql: rlq.sql.Clone(),
path: rlq.path,
}
}
// WithPackage tells the query-builder to eager-load the nodes that are connected to
// the "package" edge. The optional arguments are used to configure the query builder of the edge.
func (rlq *ReportLicenseQuery) WithPackage(opts ...func(*ReportPackageQuery)) *ReportLicenseQuery {
query := (&ReportPackageClient{config: rlq.config}).Query()
for _, opt := range opts {
opt(query)
}
rlq.withPackage = query
return rlq
}
// 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 {
// LicenseID string `json:"license_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.ReportLicense.Query().
// GroupBy(reportlicense.FieldLicenseID).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (rlq *ReportLicenseQuery) GroupBy(field string, fields ...string) *ReportLicenseGroupBy {
rlq.ctx.Fields = append([]string{field}, fields...)
grbuild := &ReportLicenseGroupBy{build: rlq}
grbuild.flds = &rlq.ctx.Fields
grbuild.label = reportlicense.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 {
// LicenseID string `json:"license_id,omitempty"`
// }
//
// client.ReportLicense.Query().
// Select(reportlicense.FieldLicenseID).
// Scan(ctx, &v)
func (rlq *ReportLicenseQuery) Select(fields ...string) *ReportLicenseSelect {
rlq.ctx.Fields = append(rlq.ctx.Fields, fields...)
sbuild := &ReportLicenseSelect{ReportLicenseQuery: rlq}
sbuild.label = reportlicense.Label
sbuild.flds, sbuild.scan = &rlq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ReportLicenseSelect configured with the given aggregations.
func (rlq *ReportLicenseQuery) Aggregate(fns ...AggregateFunc) *ReportLicenseSelect {
return rlq.Select().Aggregate(fns...)
}
func (rlq *ReportLicenseQuery) prepareQuery(ctx context.Context) error {
for _, inter := range rlq.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, rlq); err != nil {
return err
}
}
}
for _, f := range rlq.ctx.Fields {
if !reportlicense.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if rlq.path != nil {
prev, err := rlq.path(ctx)
if err != nil {
return err
}
rlq.sql = prev
}
return nil
}
func (rlq *ReportLicenseQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ReportLicense, error) {
var (
nodes = []*ReportLicense{}
withFKs = rlq.withFKs
_spec = rlq.querySpec()
loadedTypes = [1]bool{
rlq.withPackage != nil,
}
)
if rlq.withPackage != nil {
withFKs = true
}
if withFKs {
_spec.Node.Columns = append(_spec.Node.Columns, reportlicense.ForeignKeys...)
}
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*ReportLicense).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &ReportLicense{config: rlq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, rlq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := rlq.withPackage; query != nil {
if err := rlq.loadPackage(ctx, query, nodes, nil,
func(n *ReportLicense, e *ReportPackage) { n.Edges.Package = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (rlq *ReportLicenseQuery) loadPackage(ctx context.Context, query *ReportPackageQuery, nodes []*ReportLicense, init func(*ReportLicense), assign func(*ReportLicense, *ReportPackage)) error {
ids := make([]int, 0, len(nodes))
nodeids := make(map[int][]*ReportLicense)
for i := range nodes {
if nodes[i].report_package_licenses == nil {
continue
}
fk := *nodes[i].report_package_licenses
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(reportpackage.IDIn(ids...))
neighbors, err := query.All(ctx)
if err != nil {
return err
}
for _, n := range neighbors {
nodes, ok := nodeids[n.ID]
if !ok {
return fmt.Errorf(`unexpected foreign-key "report_package_licenses" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (rlq *ReportLicenseQuery) sqlCount(ctx context.Context) (int, error) {
_spec := rlq.querySpec()
_spec.Node.Columns = rlq.ctx.Fields
if len(rlq.ctx.Fields) > 0 {
_spec.Unique = rlq.ctx.Unique != nil && *rlq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, rlq.driver, _spec)
}
func (rlq *ReportLicenseQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(reportlicense.Table, reportlicense.Columns, sqlgraph.NewFieldSpec(reportlicense.FieldID, field.TypeInt))
_spec.From = rlq.sql
if unique := rlq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if rlq.path != nil {
_spec.Unique = true
}
if fields := rlq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, reportlicense.FieldID)
for i := range fields {
if fields[i] != reportlicense.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := rlq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := rlq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := rlq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := rlq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (rlq *ReportLicenseQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(rlq.driver.Dialect())
t1 := builder.Table(reportlicense.Table)
columns := rlq.ctx.Fields
if len(columns) == 0 {
columns = reportlicense.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if rlq.sql != nil {
selector = rlq.sql
selector.Select(selector.Columns(columns...)...)
}
if rlq.ctx.Unique != nil && *rlq.ctx.Unique {
selector.Distinct()
}
for _, p := range rlq.predicates {
p(selector)
}
for _, p := range rlq.order {
p(selector)
}
if offset := rlq.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 := rlq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ReportLicenseGroupBy is the group-by builder for ReportLicense entities.
type ReportLicenseGroupBy struct {
selector
build *ReportLicenseQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (rlgb *ReportLicenseGroupBy) Aggregate(fns ...AggregateFunc) *ReportLicenseGroupBy {
rlgb.fns = append(rlgb.fns, fns...)
return rlgb
}
// Scan applies the selector query and scans the result into the given value.
func (rlgb *ReportLicenseGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, rlgb.build.ctx, ent.OpQueryGroupBy)
if err := rlgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ReportLicenseQuery, *ReportLicenseGroupBy](ctx, rlgb.build, rlgb, rlgb.build.inters, v)
}
func (rlgb *ReportLicenseGroupBy) sqlScan(ctx context.Context, root *ReportLicenseQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(rlgb.fns))
for _, fn := range rlgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*rlgb.flds)+len(rlgb.fns))
for _, f := range *rlgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*rlgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := rlgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ReportLicenseSelect is the builder for selecting fields of ReportLicense entities.
type ReportLicenseSelect struct {
*ReportLicenseQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (rls *ReportLicenseSelect) Aggregate(fns ...AggregateFunc) *ReportLicenseSelect {
rls.fns = append(rls.fns, fns...)
return rls
}
// Scan applies the selector query and scans the result into the given value.
func (rls *ReportLicenseSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, rls.ctx, ent.OpQuerySelect)
if err := rls.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ReportLicenseQuery, *ReportLicenseSelect](ctx, rls.ReportLicenseQuery, rls, rls.inters, v)
}
func (rls *ReportLicenseSelect) sqlScan(ctx context.Context, root *ReportLicenseQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(rls.fns))
for _, fn := range rls.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*rls.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 := rls.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}