We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Southclaws/storyden'
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"
"github.com/Southclaws/storyden/internal/ent/collection"
"github.com/Southclaws/storyden/internal/ent/collectionnode"
"github.com/Southclaws/storyden/internal/ent/node"
"github.com/Southclaws/storyden/internal/ent/predicate"
"github.com/rs/xid"
)
// CollectionNodeQuery is the builder for querying CollectionNode entities.
type CollectionNodeQuery struct {
config
ctx *QueryContext
order []collectionnode.OrderOption
inters []Interceptor
predicates []predicate.CollectionNode
withCollection *CollectionQuery
withNode *NodeQuery
modifiers []func(*sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the CollectionNodeQuery builder.
func (cnq *CollectionNodeQuery) Where(ps ...predicate.CollectionNode) *CollectionNodeQuery {
cnq.predicates = append(cnq.predicates, ps...)
return cnq
}
// Limit the number of records to be returned by this query.
func (cnq *CollectionNodeQuery) Limit(limit int) *CollectionNodeQuery {
cnq.ctx.Limit = &limit
return cnq
}
// Offset to start from.
func (cnq *CollectionNodeQuery) Offset(offset int) *CollectionNodeQuery {
cnq.ctx.Offset = &offset
return cnq
}
// 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 (cnq *CollectionNodeQuery) Unique(unique bool) *CollectionNodeQuery {
cnq.ctx.Unique = &unique
return cnq
}
// Order specifies how the records should be ordered.
func (cnq *CollectionNodeQuery) Order(o ...collectionnode.OrderOption) *CollectionNodeQuery {
cnq.order = append(cnq.order, o...)
return cnq
}
// QueryCollection chains the current query on the "collection" edge.
func (cnq *CollectionNodeQuery) QueryCollection() *CollectionQuery {
query := (&CollectionClient{config: cnq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := cnq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := cnq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(collectionnode.Table, collectionnode.CollectionColumn, selector),
sqlgraph.To(collection.Table, collection.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, collectionnode.CollectionTable, collectionnode.CollectionColumn),
)
fromU = sqlgraph.SetNeighbors(cnq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// QueryNode chains the current query on the "node" edge.
func (cnq *CollectionNodeQuery) QueryNode() *NodeQuery {
query := (&NodeClient{config: cnq.config}).Query()
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := cnq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := cnq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(collectionnode.Table, collectionnode.NodeColumn, selector),
sqlgraph.To(node.Table, node.FieldID),
sqlgraph.Edge(sqlgraph.M2O, false, collectionnode.NodeTable, collectionnode.NodeColumn),
)
fromU = sqlgraph.SetNeighbors(cnq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first CollectionNode entity from the query.
// Returns a *NotFoundError when no CollectionNode was found.
func (cnq *CollectionNodeQuery) First(ctx context.Context) (*CollectionNode, error) {
nodes, err := cnq.Limit(1).All(setContextOp(ctx, cnq.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{collectionnode.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (cnq *CollectionNodeQuery) FirstX(ctx context.Context) *CollectionNode {
node, err := cnq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// Only returns a single CollectionNode entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one CollectionNode entity is found.
// Returns a *NotFoundError when no CollectionNode entities are found.
func (cnq *CollectionNodeQuery) Only(ctx context.Context) (*CollectionNode, error) {
nodes, err := cnq.Limit(2).All(setContextOp(ctx, cnq.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{collectionnode.Label}
default:
return nil, &NotSingularError{collectionnode.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (cnq *CollectionNodeQuery) OnlyX(ctx context.Context) *CollectionNode {
node, err := cnq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// All executes the query and returns a list of CollectionNodes.
func (cnq *CollectionNodeQuery) All(ctx context.Context) ([]*CollectionNode, error) {
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryAll)
if err := cnq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*CollectionNode, *CollectionNodeQuery]()
return withInterceptors[[]*CollectionNode](ctx, cnq, qr, cnq.inters)
}
// AllX is like All, but panics if an error occurs.
func (cnq *CollectionNodeQuery) AllX(ctx context.Context) []*CollectionNode {
nodes, err := cnq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// Count returns the count of the given query.
func (cnq *CollectionNodeQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryCount)
if err := cnq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, cnq, querierCount[*CollectionNodeQuery](), cnq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (cnq *CollectionNodeQuery) CountX(ctx context.Context) int {
count, err := cnq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (cnq *CollectionNodeQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, cnq.ctx, ent.OpQueryExist)
switch _, err := cnq.First(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 (cnq *CollectionNodeQuery) ExistX(ctx context.Context) bool {
exist, err := cnq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the CollectionNodeQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (cnq *CollectionNodeQuery) Clone() *CollectionNodeQuery {
if cnq == nil {
return nil
}
return &CollectionNodeQuery{
config: cnq.config,
ctx: cnq.ctx.Clone(),
order: append([]collectionnode.OrderOption{}, cnq.order...),
inters: append([]Interceptor{}, cnq.inters...),
predicates: append([]predicate.CollectionNode{}, cnq.predicates...),
withCollection: cnq.withCollection.Clone(),
withNode: cnq.withNode.Clone(),
// clone intermediate query.
sql: cnq.sql.Clone(),
path: cnq.path,
modifiers: append([]func(*sql.Selector){}, cnq.modifiers...),
}
}
// WithCollection tells the query-builder to eager-load the nodes that are connected to
// the "collection" edge. The optional arguments are used to configure the query builder of the edge.
func (cnq *CollectionNodeQuery) WithCollection(opts ...func(*CollectionQuery)) *CollectionNodeQuery {
query := (&CollectionClient{config: cnq.config}).Query()
for _, opt := range opts {
opt(query)
}
cnq.withCollection = query
return cnq
}
// WithNode tells the query-builder to eager-load the nodes that are connected to
// the "node" edge. The optional arguments are used to configure the query builder of the edge.
func (cnq *CollectionNodeQuery) WithNode(opts ...func(*NodeQuery)) *CollectionNodeQuery {
query := (&NodeClient{config: cnq.config}).Query()
for _, opt := range opts {
opt(query)
}
cnq.withNode = query
return cnq
}
// 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:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.CollectionNode.Query().
// GroupBy(collectionnode.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (cnq *CollectionNodeQuery) GroupBy(field string, fields ...string) *CollectionNodeGroupBy {
cnq.ctx.Fields = append([]string{field}, fields...)
grbuild := &CollectionNodeGroupBy{build: cnq}
grbuild.flds = &cnq.ctx.Fields
grbuild.label = collectionnode.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:"created_at,omitempty"`
// }
//
// client.CollectionNode.Query().
// Select(collectionnode.FieldCreatedAt).
// Scan(ctx, &v)
func (cnq *CollectionNodeQuery) Select(fields ...string) *CollectionNodeSelect {
cnq.ctx.Fields = append(cnq.ctx.Fields, fields...)
sbuild := &CollectionNodeSelect{CollectionNodeQuery: cnq}
sbuild.label = collectionnode.Label
sbuild.flds, sbuild.scan = &cnq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a CollectionNodeSelect configured with the given aggregations.
func (cnq *CollectionNodeQuery) Aggregate(fns ...AggregateFunc) *CollectionNodeSelect {
return cnq.Select().Aggregate(fns...)
}
func (cnq *CollectionNodeQuery) prepareQuery(ctx context.Context) error {
for _, inter := range cnq.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, cnq); err != nil {
return err
}
}
}
for _, f := range cnq.ctx.Fields {
if !collectionnode.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if cnq.path != nil {
prev, err := cnq.path(ctx)
if err != nil {
return err
}
cnq.sql = prev
}
return nil
}
func (cnq *CollectionNodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CollectionNode, error) {
var (
nodes = []*CollectionNode{}
_spec = cnq.querySpec()
loadedTypes = [2]bool{
cnq.withCollection != nil,
cnq.withNode != nil,
}
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*CollectionNode).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &CollectionNode{config: cnq.config}
nodes = append(nodes, node)
node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(cnq.modifiers) > 0 {
_spec.Modifiers = cnq.modifiers
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, cnq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
if query := cnq.withCollection; query != nil {
if err := cnq.loadCollection(ctx, query, nodes, nil,
func(n *CollectionNode, e *Collection) { n.Edges.Collection = e }); err != nil {
return nil, err
}
}
if query := cnq.withNode; query != nil {
if err := cnq.loadNode(ctx, query, nodes, nil,
func(n *CollectionNode, e *Node) { n.Edges.Node = e }); err != nil {
return nil, err
}
}
return nodes, nil
}
func (cnq *CollectionNodeQuery) loadCollection(ctx context.Context, query *CollectionQuery, nodes []*CollectionNode, init func(*CollectionNode), assign func(*CollectionNode, *Collection)) error {
ids := make([]xid.ID, 0, len(nodes))
nodeids := make(map[xid.ID][]*CollectionNode)
for i := range nodes {
fk := nodes[i].CollectionID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(collection.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 "collection_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (cnq *CollectionNodeQuery) loadNode(ctx context.Context, query *NodeQuery, nodes []*CollectionNode, init func(*CollectionNode), assign func(*CollectionNode, *Node)) error {
ids := make([]xid.ID, 0, len(nodes))
nodeids := make(map[xid.ID][]*CollectionNode)
for i := range nodes {
fk := nodes[i].NodeID
if _, ok := nodeids[fk]; !ok {
ids = append(ids, fk)
}
nodeids[fk] = append(nodeids[fk], nodes[i])
}
if len(ids) == 0 {
return nil
}
query.Where(node.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 "node_id" returned %v`, n.ID)
}
for i := range nodes {
assign(nodes[i], n)
}
}
return nil
}
func (cnq *CollectionNodeQuery) sqlCount(ctx context.Context) (int, error) {
_spec := cnq.querySpec()
if len(cnq.modifiers) > 0 {
_spec.Modifiers = cnq.modifiers
}
_spec.Unique = false
_spec.Node.Columns = nil
return sqlgraph.CountNodes(ctx, cnq.driver, _spec)
}
func (cnq *CollectionNodeQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(collectionnode.Table, collectionnode.Columns, nil)
_spec.From = cnq.sql
if unique := cnq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if cnq.path != nil {
_spec.Unique = true
}
if fields := cnq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
for i := range fields {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
if cnq.withCollection != nil {
_spec.Node.AddColumnOnce(collectionnode.FieldCollectionID)
}
if cnq.withNode != nil {
_spec.Node.AddColumnOnce(collectionnode.FieldNodeID)
}
}
if ps := cnq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := cnq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := cnq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := cnq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (cnq *CollectionNodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(cnq.driver.Dialect())
t1 := builder.Table(collectionnode.Table)
columns := cnq.ctx.Fields
if len(columns) == 0 {
columns = collectionnode.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if cnq.sql != nil {
selector = cnq.sql
selector.Select(selector.Columns(columns...)...)
}
if cnq.ctx.Unique != nil && *cnq.ctx.Unique {
selector.Distinct()
}
for _, m := range cnq.modifiers {
m(selector)
}
for _, p := range cnq.predicates {
p(selector)
}
for _, p := range cnq.order {
p(selector)
}
if offset := cnq.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 := cnq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// Modify adds a query modifier for attaching custom logic to queries.
func (cnq *CollectionNodeQuery) Modify(modifiers ...func(s *sql.Selector)) *CollectionNodeSelect {
cnq.modifiers = append(cnq.modifiers, modifiers...)
return cnq.Select()
}
// CollectionNodeGroupBy is the group-by builder for CollectionNode entities.
type CollectionNodeGroupBy struct {
selector
build *CollectionNodeQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (cngb *CollectionNodeGroupBy) Aggregate(fns ...AggregateFunc) *CollectionNodeGroupBy {
cngb.fns = append(cngb.fns, fns...)
return cngb
}
// Scan applies the selector query and scans the result into the given value.
func (cngb *CollectionNodeGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, cngb.build.ctx, ent.OpQueryGroupBy)
if err := cngb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*CollectionNodeQuery, *CollectionNodeGroupBy](ctx, cngb.build, cngb, cngb.build.inters, v)
}
func (cngb *CollectionNodeGroupBy) sqlScan(ctx context.Context, root *CollectionNodeQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(cngb.fns))
for _, fn := range cngb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*cngb.flds)+len(cngb.fns))
for _, f := range *cngb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*cngb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := cngb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// CollectionNodeSelect is the builder for selecting fields of CollectionNode entities.
type CollectionNodeSelect struct {
*CollectionNodeQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (cns *CollectionNodeSelect) Aggregate(fns ...AggregateFunc) *CollectionNodeSelect {
cns.fns = append(cns.fns, fns...)
return cns
}
// Scan applies the selector query and scans the result into the given value.
func (cns *CollectionNodeSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, cns.ctx, ent.OpQuerySelect)
if err := cns.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*CollectionNodeQuery, *CollectionNodeSelect](ctx, cns.CollectionNodeQuery, cns, cns.inters, v)
}
func (cns *CollectionNodeSelect) sqlScan(ctx context.Context, root *CollectionNodeQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(cns.fns))
for _, fn := range cns.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*cns.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 := cns.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// Modify adds a query modifier for attaching custom logic to queries.
func (cns *CollectionNodeSelect) Modify(modifiers ...func(s *sql.Selector)) *CollectionNodeSelect {
cns.modifiers = append(cns.modifiers, modifiers...)
return cns
}