MCPcopy Create free account
hub / github.com/Comfy-Org/registry-backend / Only

Method Only

ent/gitcommit_query.go:137–150  ·  view source on GitHub ↗

Only returns a single GitCommit entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one GitCommit entity is found. Returns a *NotFoundError when no GitCommit entities are found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

135// Returns a *NotSingularError when more than one GitCommit entity is found.
136// Returns a *NotFoundError when no GitCommit entities are found.
137func (gcq *GitCommitQuery) Only(ctx context.Context) (*GitCommit, error) {
138 nodes, err := gcq.Limit(2).All(setContextOp(ctx, gcq.ctx, ent.OpQueryOnly))
139 if err != nil {
140 return nil, err
141 }
142 switch len(nodes) {
143 case 1:
144 return nodes[0], nil
145 case 0:
146 return nil, &NotFoundError{gitcommit.Label}
147 default:
148 return nil, &NotSingularError{gitcommit.Label}
149 }
150}
151
152// OnlyX is like Only, but panics if an error occurs.
153func (gcq *GitCommitQuery) OnlyX(ctx context.Context) *GitCommit {

Callers 1

OnlyXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected