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

Method OnlyID

ent/setting_query.go:135–149  ·  view source on GitHub ↗

OnlyID is like Only, but returns the only Setting ID in the query. Returns a *NotSingularError when more than one Setting ID is found. Returns a *NotFoundError when no entities are found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

133// Returns a *NotSingularError when more than one Setting ID is found.
134// Returns a *NotFoundError when no entities are found.
135func (sq *SettingQuery) OnlyID(ctx context.Context) (id int, err error) {
136 var ids []int
137 if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
138 return
139 }
140 switch len(ids) {
141 case 1:
142 id = ids[0]
143 case 0:
144 err = &NotFoundError{setting.Label}
145 default:
146 err = &NotSingularError{setting.Label}
147 }
148 return
149}
150
151// OnlyIDX is like OnlyID, but panics if an error occurs.
152func (sq *SettingQuery) OnlyIDX(ctx context.Context) int {

Callers 1

OnlyIDXMethod · 0.95

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
IDsMethod · 0.45

Tested by

no test coverage detected