MCPcopy Create free account
hub / github.com/efectn/go-orm-benchmarks / First

Method First

bench/ent/model_query.go:62–71  ·  view source on GitHub ↗

First returns the first Model entity from the query. Returns a *NotFoundError when no Model was found.

(ctx context.Context)

Source from the content-addressed store, hash-verified

60// First returns the first Model entity from the query.
61// Returns a *NotFoundError when no Model was found.
62func (mq *ModelQuery) First(ctx context.Context) (*Model, error) {
63 nodes, err := mq.Limit(1).All(setContextOp(ctx, mq.ctx, "First"))
64 if err != nil {
65 return nil, err
66 }
67 if len(nodes) == 0 {
68 return nil, &NotFoundError{model.Label}
69 }
70 return nodes[0], nil
71}
72
73// FirstX is like First, but panics if an error occurs.
74func (mq *ModelQuery) FirstX(ctx context.Context) *Model {

Callers 3

FirstXMethod · 0.95
ReadMethod · 0.80
ReadMethod · 0.80

Calls 3

LimitMethod · 0.95
setContextOpFunction · 0.85
AllMethod · 0.45

Tested by

no test coverage detected