// Limit specifies an upper limit on the number of models to return. If amount
// is 0, no limit will be applied and any number of models may be returned. The
// default value is 0.
188517
func (q *Query) Limit(amount uint) *Query {
	q.query.Limit(amount)
	return q
}
1177016
func (bldr *SampleQueryBuilder) Limit(limit int) *SampleQueryBuilder {
	bldr.q = bldr.q.Limit(limit)
	if bldr.plugin != nil {
		bldr.plugin.Limit(limit)
	}
	return bldr
}
782583
func (db *Database) Limit(limit int) *Database {
	db = db.clone()
	db.limit = limit
	return db
}
621804
func (session *Session) Limit(limit int, start ...int) *Session {
	session.statement.Limit(limit, start...)
	return session
}
424921
func ReleaseListLimit(limit int) ReleaseListOption {
	return func(opts *options) {
		opts.listReq.Limit = int64(limit)
	}
}
634687
func (p Pages) Limit(n int) Pages {
	if len(p) > n {
		return p[0:n]
	}
	return p
}
1095115
func (bldr *UserQueryBuilder) Limit(limit int) *UserQueryBuilder {
	bldr.q = bldr.q.Limit(limit)
	if bldr.plugin != nil {
		bldr.plugin.Limit(limit)
	}
	return bldr
}
510137
func (bldr *aeBackupInformationQueryBuilder) Limit(limit int) *aeBackupInformationQueryBuilder {
	bldr.q = bldr.q.Limit(limit)
	if bldr.plugin != nil {
		bldr.plugin.Limit(limit)
	}
	return bldr
}
1268672
func (mc MongoClient) getEventsLimit(q bson.M, limit int) (me []models.Event, err error) {
	s := mc.getSessionCopy()
	defer s.Close()

	// Check if limit is 0
	if limit == 0 {
		return []models.Event{}, nil
	}

	err = s.DB(mc.database.Name).C(db.EventsCollection).Find(q).Sort("-modified").Limit(limit).All(&me)
	if err != nil {
		return []models.Event{}, errorMap(err)
	}
	return
}
1292590
func (bldr *iisQueryBuilder) Limit(limit int) *iisQueryBuilder {
	bldr.q = bldr.q.Limit(limit)
	if bldr.plugin != nil {
		bldr.plugin.Limit(limit)
	}
	return bldr
}
613262
func (stmt SelectStmt) Limit(limit int) SelectStmt {
	stmt.limit = limit
	return stmt
}
988743
func queryLimit(query url.Values, name string, def int) (int, error) {
	str := query.Get(name)
	if str == "" {
		return def, nil
	}
	limit, err := strconv.Atoi(str)
	if err != nil {
		return 0, trace.BadParameter("failed to parse %v as limit: %v", name, str)
	}
	return limit, nil
}
1292121
func Limit(limit int) DeviceRequestOption {
	return func(opts *deviceRequestOpts) error {
		if limit > 1000 {
			return fmt.Errorf("Limit must not be higher than 1000")
		}
		opts.Limit = limit
		return nil
	}
}
491632
func NaiveLimit(qr Results, limit int) Results {
	if limit == 0 {
		// 0 means no limit
		return qr
	}
	closed := false
	return ResultsFromIterator(qr.Query(), Iterator{
		Next: func() (Result, bool) {
			if limit == 0 {
				if !closed {
					closed = true
					err := qr.Close()
					if err != nil {
						return Result{Error: err}, true
					}
				}
				return Result{}, false
			}
			limit--
			return qr.NextSync()
		},
		Close: func() error {
			if closed {
				return nil
			}
			closed = true
			return qr.Close()
		},
	})
}
1118951
func Limits(argv []string) error {
	usage := `
Valid commands for limits:

limits:list        list resource limits for an app
limits:set         set resource limits for an app
limits:unset       unset resource limits for an app

Use 'deis help [command]' to learn more.
`

	switch argv[0] {
	case "limits:list":
		return limitsList(argv)
	case "limits:set":
		return limitSet(argv)
	case "limits:unset":
		return limitUnset(argv)
	default:
		if printHelp(argv, usage) {
			return nil
		}

		if argv[0] == "limits" {
			argv[0] = "limits:list"
			return limitsList(argv)
		}

		PrintUsage()
		return nil
	}
}
722081
func (b *SelectBuilder) Limit(count interface{}) *SelectBuilder {
	if b.Select.Limit == nil {
		b.Select.Limit = &Limit{}
	}
	b.Select.Limit.Rowcount = makeValExpr(count)
	return b
}
93676
func validateLimit(v, min, max int) error {

	// ensure the value for `limit` is valid
	if v < min || v > max {
		err := fmt.Errorf("%d is not a valid value for `limit`, must be between %d-%d (inclusive).", v, min, max)
		return err
	}

	return nil
}