MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Only

Method Only

ent/setting_query.go:108–121  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

106// Returns a *NotSingularError when more than one Setting entity is found.
107// Returns a *NotFoundError when no Setting entities are found.
108func (sq *SettingQuery) Only(ctx context.Context) (*Setting, error) {
109 nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only"))
110 if err != nil {
111 return nil, err
112 }
113 switch len(nodes) {
114 case 1:
115 return nodes[0], nil
116 case 0:
117 return nil, &NotFoundError{setting.Label}
118 default:
119 return nil, &NotSingularError{setting.Label}
120 }
121}
122
123// OnlyX is like Only, but panics if an error occurs.
124func (sq *SettingQuery) OnlyX(ctx context.Context) *Setting {

Callers 1

OnlyXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected