// First sorts rows by primary key and selects the first row.
// It is a shortcut for:
//
//    q.OrderExpr("id ASC").Limit(1)
963201
func (q *Query) First() error {
	err := q.model.Table().checkPKs()
	if err != nil {
		return err
	}

	b := appendColumns(nil, q.model.Table().Alias, q.model.Table().PKs)
	return q.OrderExpr(internal.BytesToString(b)).Limit(1).Select()
}
562045
func (h *hmnodeSeq) First() interface{} {
	if h.s != nil {
		return h.s.First()
	}
	return MapEntry{h.array[h.i], h.array[h.i+1]}
}
454145
func (me *DefaultAdapter) OrderedExpressionSql(buf *SqlBuilder, order OrderedExpression) error {
	if err := me.Literal(buf, order.SortExpression()); err != nil {
		return err
	}
	if order.Direction() == SORT_DESC {
		buf.Write(me.DescFragment)
	} else {
		buf.Write(me.AscFragment)
	}
	switch order.NullSortType() {
	case NULLS_FIRST:
		buf.Write(me.NullsFirstFragment)
	case NULLS_LAST:
		buf.Write(me.NullsLastFragment)
	}
	return nil
}
727363
func (mvl *MetricsList) First() *MetricValue {
	if len(mvl.data) > 0 {
		mvl.Sort()
		return mvl.data[0]
	}
	return nil
}
603159
func (q *Query) OrderExpr(order string, params ...interface{}) *Query {
	if order != "" {
		q.order = append(q.order, &queryParamsAppender{order, params})
	}
	return q
}
542244
func (qre *QueryExecutor) execSelect() (*sqltypes.Result, error) {
	if qre.plan.Fields != nil {
		result, err := qre.qFetch(qre.logStats, qre.plan.FullQuery, qre.bindVars)
		if err != nil {
			return nil, err
		}
		// result is read-only. So, let's copy it before modifying.
		newResult := *result
		newResult.Fields = qre.plan.Fields
		return &newResult, nil
	}
	conn, err := qre.getConn()
	if err != nil {
		return nil, err
	}
	defer conn.Recycle()
	return qre.dbConnFetch(conn, qre.plan.FullQuery, qre.bindVars, "", true)
}
404634
func (ti *TagIterator) First(ctx context.Context, items *[]Tag) bool {
	if ti.err != nil {
		return false
	}
	ti.err = ti.fetch(ctx, ti.Paging.First)
	if ti.err != nil {
		return false
	}
	*items = ti.Items
	return true
}
454156
func (t *PrimaryTree) First() (k uint64, v SecondaryLayer) {
	if q := t.first; q != nil {
		q := &q.d[0]
		k, v = q.k, q.v
	}
	return
}
820473
func (t *SecondaryTree) First() (k RouteInfo, v *FinalizerList) {
	if q := t.first; q != nil {
		q := &q.d[0]
		k, v = q.k, q.v
	}
	return
}
539256
func (a *HistogramAggregation) Order(order string, asc bool) *HistogramAggregation {
	a.order = order
	a.orderAsc = asc
	return a
}
920954
func (r *QueryResults) First(t *testing.T) *QueryResult {
	r.HasTableCount(t, 1)
	for _, result := range r.Results {
		return &QueryResult{t: t, q: result}
	}
	return nil
}
68266
func orderbyExecutor(attr *parser.Decl, tables []*Table) (selectFunctor, error) {
	f := &orderbyFunctor{}
	f.buffer = make(map[int64][][]string)

	// first subdecl should be attribute
	if len(attr.Decl) < 1 {
		return nil, fmt.Errorf("ordering attribute not provided")
	}

	// FIXME we should find for sure the table of the attribute
	if len(tables) < 1 {
		return nil, fmt.Errorf("cannot guess the table of attribute %s for order", attr.Decl[0].Lexeme)
	}
	if len(attr.Decl[0].Decl) > 0 {
		f.orderby = attr.Decl[0].Decl[0].Lexeme + "." + attr.Decl[0].Lexeme
	} else {
		f.orderby = tables[0].name + "." + attr.Decl[0].Lexeme
	}
	// if second subdecl is present, it's either asc or desc
	// default is asc anyway
	if len(attr.Decl) == 2 && attr.Decl[1].Token == parser.AscToken {
		f.asc = true
	}

	log.Debug("orderbyExecutor> you must order by '%s', asc: %v\n", f.orderby, f.asc)
	return f, nil
}
798665
func (session *Session) OrderBy(order string) *Session {
	session.statement.OrderBy(order)
	return session
}
684034
func (t *Tree) First() (k generic.T, v generic.U) {
	if q := t.first; q != nil {
		q := &q.d[0]
		k, v = q.k, q.v
	}
	return
}
1123875
func (a *CompositeAggregationTermsValuesSource) Order(order string) *CompositeAggregationTermsValuesSource {
	a.order = order
	return a
}
806960
func first(db *gorm.DB, scope scope, v interface{}) error {
	return scope.scope(db).First(v).Error
}
5881
func (c *Cursor) First() *Position {
	return &Position{IP: c.ps[0].IP, Prefix: c.ps[0]}
}