First returns the first Model entity from the query. Returns a *NotFoundError when no Model was found.
(ctx context.Context)
| 60 | // First returns the first Model entity from the query. |
| 61 | // Returns a *NotFoundError when no Model was found. |
| 62 | func (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. |
| 74 | func (mq *ModelQuery) FirstX(ctx context.Context) *Model { |