// Paginate records returned from the database.
//
//	q = q.Paginate(2, 15)
//	q.All(&[]User{})
//	q.Paginator
763724
func (q *Query) Paginate(page int, perPage int) *Query {
	q.Paginator = NewPaginator(page, perPage)
	return q
}
78116
func (p *PostgresProvider) Count() (total int) {
	if err := p.c.QueryRow("SELECT COUNT(*) AS NUM FROM session").Scan(&total); err != nil {
		panic("session/postgres: error counting records: " + err.Error())
	}
	return total
}
490156
func Paging(curPage int, pageSize int, totalRecords int, items interface{}) Page {

	totalPages := int(totalRecords) / pageSize
	if totalPages == 0 {
		totalPages = 1
	}

	if int(totalRecords)%pageSize != 0 {
		totalPages++
	}

	return Page{
		Page:         curPage,
		Size:         pageSize,
		TotalRecords: int(totalRecords),
		TotalPages:   totalPages,
		Items:        items,
	}
}
61138
func (dds *Delayed) Query(q dsq.Query) (dsq.Results, error) {
	dds.delay.Wait()
	return dds.ds.Query(q)
}
360136
func RecordUserQuery(ctx context.Context, tableName sqlparser.TableIdent, queryType string, duration int64) {
	username := callerid.GetPrincipal(callerid.EffectiveCallerIDFromContext(ctx))
	if username == "" {
		username = callerid.GetUsername(callerid.ImmediateCallerIDFromContext(ctx))
	}
	UserTableQueryCount.Add([]string{tableName.String(), username, queryType}, 1)
	UserTableQueryTimesNs.Add([]string{tableName.String(), username, queryType}, int64(duration))
}
973278
func PagingPage(p Page, totalRecords int, items interface{}) Page {
	return Paging(p.Page, p.Size, totalRecords, items)
}
1290582
func (a postgres) query(query string, args ...interface{}) (*sql.Rows, error) {
	client, err := a.connect()
	if err != nil {
		return nil, err
	}
	defer client.Close()

	return client.Query(query, args...)
}
631086
func (impl *repoImpl) paginatedQuery(c context.Context, opts paginatedQueryOpts) (out []*api.Instance, nextTok string, err error) {
	// Validate the request, decode the cursor.
	if err := common.ValidatePackageName(opts.Package); err != nil {
		return nil, "", status.Errorf(codes.InvalidArgument, "bad 'package' - %s", err)
	}

	switch {
	case opts.PageSize < 0:
		return nil, "", status.Errorf(codes.InvalidArgument, "bad 'page_size' %d - it should be non-negative", opts.PageSize)
	case opts.PageSize == 0:
		opts.PageSize = 100
	}

	var cursor datastore.Cursor
	if opts.PageToken != "" {
		if cursor, err = datastore.DecodeCursor(c, opts.PageToken); err != nil {
			return nil, "", status.Errorf(codes.InvalidArgument, "bad 'page_token' - %s", err)
		}
	}

	if opts.Validator != nil {
		if err := opts.Validator(); err != nil {
			return nil, "", err
		}
	}

	// Check ACLs.
	if _, err := impl.checkRole(c, opts.Package, api.Role_READER); err != nil {
		return nil, "", err
	}

	// Check that the package is registered.
	if err := model.CheckPackageExists(c, opts.Package); err != nil {
		return nil, "", err
	}

	// Do the actual listing.
	inst, cursor, err := opts.Handler(cursor, opts.PageSize)
	if err != nil {
		return nil, "", errors.Annotate(err, "failed to query instances").Err()
	}

	// Convert results to proto.
	out = make([]*api.Instance, len(inst))
	for i, ent := range inst {
		out[i] = ent.Proto()
	}
	if cursor != nil {
		nextTok = cursor.String()
	}
	return
}
1021126
func QueryAll(db DB, dst interface{}, query string, args ...interface{}) error {
	return Default.QueryAll(db, dst, query, args...)
}
782583
func (db *Database) Limit(limit int) *Database {
	db = db.clone()
	db.limit = limit
	return db
}
801655
func (me *TxDatabase) QueryRow(query string, args ...interface{}) *sql.Row {
	me.Trace("QUERY ROW", query, args...)
	return me.Tx.QueryRow(query, args...)
}
810219
func (c *Client) ListRecords(domainID int) ([]*Record, error) {
	uri := fmt.Sprintf("/%d/records/", domainID)
	req, err := c.newRequest(http.MethodGet, uri, nil)
	if err != nil {
		return nil, err
	}

	var records []*Record
	_, err = c.do(req, &records)
	if err != nil {
		return nil, err
	}
	return records, nil
}
781816
func (d *domainClient) RequestDatabase(ctx context.Context, args *RequestDatabaseArgs) (reply *RequestDatabaseReply, err error) {
	reply = new(RequestDatabaseReply)
	if args != nil {
		err = rpcc.Invoke(ctx, "IndexedDB.requestDatabase", args, reply, d.conn)
	} else {
		err = rpcc.Invoke(ctx, "IndexedDB.requestDatabase", nil, reply, d.conn)
	}
	if err != nil {
		err = &internal.OpError{Domain: "IndexedDB", Op: "RequestDatabase", Err: err}
	}
	return
}
401577
func (db *DB) Query(q interface{}, args ...interface{}) (*Rows, error) {
	return db.QueryContext(db.Context(), q, args...)
}
737030
func (db *baseDB) Query(model, query interface{}, params ...interface{}) (res Result, err error) {
	return db.query(context.TODO(), model, query, params...)
}
600965
func (c *Client) AllDB(ctx context.Context) ([]chronograf.Database, error) {
	return c.showDatabases(ctx)
}
668033
func (q Query) Count() (r int) {
	next := q.Iterate()

	for _, ok := next(); ok; _, ok = next() {
		r++
	}

	return
}