Return the first $limit records querying input parameters.

@param int $limit
@param array $where
@param array $with

@return Collection
423255
public function getByLimit(int $limit, array $where = [], array $with = [])
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->take($limit)->get();
    }
946728
public function firstOrFailBy(array $where = [], array $with = [])
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->firstOrFail();
    }
52109
public static function getArticleLists($where, $limit = 4, $order = 'id desc')
    {
        $where = array_merge($where, ['type' => ArticleModel::ARTICLE]);
        return ArticleModel::find()->select([])->where($where)->orderBy($order)->limit($limit)->all();
    }
340797
public function allFiltered($columns = [], array $with = [])
    {
        $params = request()->all();
        $data = $this->with($with)->select($columns);

        $orderBy = $params['orderBy'] ?? null;
        $query = $params['query'] ?? null;
        $limit = $params['limit'] ?? null;
        $page = $params['page'] ?? 1;
        $ascending = $params['ascending'] ?? 1;
        $byColumn = $params['byColumn'] ?? 0;

        if ($query !== null) {
            $data = $byColumn == 1 ? $this->filterByColumn($data, $query) :
                                     $this->filter($data, $query, $columns);
        }

        $count = $data->count();

        if ($limit !== null) {
            $data->limit($limit)->skip($limit * ($page - 1));
        }
        if ($orderBy !== null) {
            $orderBy .= $this->translatableOperator($orderBy);
            $direction = $ascending == 1 ? 'ASC' : 'DESC';
            $data->orderBy($orderBy, $direction);
        }

        $results = $data->get()
            ->translate(config('typicms.content_locale'));

        return [
            'data' => $results,
            'count' => $count,
        ];
    }
1267204
public function findLastCreated($limit = 5)
    {
        $query = $this->createQueryBuilder('c')
            ->orderBy('c.createdAt', 'DESC')
            ->setMaxResults($limit)
            ->getQuery();

        return $query->getResult();
    }
52826
public function allWith($with, $limit = null)
    {
        if ($limit) {
            return $this->model->with($with)->limit($limit)->get();
        }

        return $this->model->with($with)->get();

    }
1164804
public function deleteBatch($where = [], $limit = null)
    {
        $this->where($where);

        if (isset($limit)) {
            $this->limit($limit);
        }

        return $this->platformDeleteBatchHandler($this->builderCache);
    }
888623
public function findEmailsToSend($limit = null)
    {
        $qb = $this->createQueryBuilder('se')
            ->where('se.status = :status AND (se.sentAt IS NULL OR se.sentAt <= :sentAt)')
            ->orderBy('se.sentAt', 'ASC')
            ->setParameter('status', SpoolEmailStatus::STATUS_WAITING)
            ->setParameter('sentAt', new \DateTime())
        ;

        if ($limit > 0) {
            $qb->setMaxResults($limit);
        }

        return $qb->getQuery()->getResult();
    }
1174555
public function getNewBatch($limit = 0)
    {
        try {
            if (!is_numeric($limit) || $limit <= 0) {
                $limit = $this->limit;
            }
            return (new Query)
                    ->from($this->queueTable)
                    ->where(['status' => Email::STATUS_PENDING])
                    ->orderBy(['id' => SORT_ASC])
                    ->limit((int)$limit)
                    ->all($this->db);
        } catch (Exception $e) {
            Log::error($e->getMessage(), null, __METHOD__);
        }
    }
1083424
public function findAll($limit = 0, $offset = 0)
    {
        $limit = $this->getLimit($limit, $offset);
        $query = 'SELECT ' . $this->getFields(", ") . '
                  FROM ' . $this->tableName . '
                  ' . $limit . ' ;';
        $statement = $this->database->prepare($query);
        $statement->execute();
        return $this->buildAll($statement->fetchAll());
    }
654684
public function _getRecords($identifier, $limit, $offset) {
		return $this->Table
			->find()
			->where([$this->Table->alias() . '.model' => $identifier])
			->limit($limit)
			->offset($offset)
			->all();
	}
1287662
public function whereFirst($where)
    {
        $where = LambdaUtils::toConditionCallable($where);
        foreach($this as $record)
        {
            if(call_user_func($where, $record))
            {
                return $record;
            }
        }
        throw new \OutOfBoundsException();
    }
1200209
public function getIn(
        $whereInKey,
        array $whereIn = [],
        array $with = [],
        string $orderBy = null,
        string $order = 'desc',
        int $limit = 0
    ) {
        $query = $this->make($with);

        $query = $query->whereIn($whereInKey, $whereIn);

        if ($orderBy) {
            $query = $query->orderBy($orderBy, $order);
        }

        if ($limit) {
            $query = $query->take($limit);
        }

        return $query->get();
    }
1051985
public function getSearchRequest($filter, $limit = 1, $conditions = [])
    {
        $self = $this;
        $knownFilters = $this->_getSearchFilters();
        $request = new StorageDataRequest(
            [$filter, $limit, $conditions],
            function ($filter, $limit, $conditions) use ($self, $knownFilters) {
                $items = $self->getAllItems();
                $results = [];
                $filterRules = [];
                
                foreach ($filter as $filterRequest) {
                    if (\count($filterRequest) === 3) {
                        list ($key, $compare, $compareValue) = $filterRequest;
                        
                        if (isset($knownFilters[$compare])) {
                            $filterRules[] = [$key, $knownFilters[$compare], $compareValue];
                        } else {
                            trigger_error('Comparator not found for filter: '.json_encode($filterRequest).'');
                        }
                    } else {
                        trigger_error('Strange filter: less than 3 parameters, '.json_encode($filterRequest));
                    }
                }
                
                foreach ($items as $id) {
                    $pointer = $self->getPointer($id);
                    $isOk = true;
                    if ($pointer) {
                        $record = json_decode(stream_get_contents($pointer), true);
                        
                        if (isset($record[self::F_DATA])) {
                            foreach ($filterRules as $filterRule) {
                                list ($key, $function, $filterRequest) = $filterRule;
        
                                $isOk = $isOk && call_user_func($function, $record[self::F_DATA][$key] ?? null, $filterRequest);
        
                                if (!$isOk) {
                                    break;
                                }
                            }
    
                            if ($isOk) {
                                $results[$id] = [$this->primaryKey => $id] + $record[self::F_DATA];
                            }    
                        }
                        
                        $self->closePointer($pointer);
                        
                        if (count($results) >= $limit) {
                            break;
                        }
                    }
                }
                
                if ($results && $conditions) {
                    $self->applyConditions($results, $conditions);
                }
            
                return $results;
            }
        );
    
        return $request;
    }
358055
public function getSortedSets($key, $start = 0, $limit = 20, $with_scores = true)
    {
        return $this->getSortedSetsAsc($key, $start, $limit, $with_scores);
    }
1022544
public function findWhere(array $conditions, $limit = null)
    {
        $result = new ArrayIterator();

        $counter = 0;
        foreach ($this->storage as $row) {
            foreach ($conditions as $field => $criteria) {
                if ($row->offsetGet($field) === $criteria) {
                    $result[] = $row;
                    $counter++;
                }
            }

            if (isset($limit)) {
                if ($counter == $limit) {
                    break;
                }
            }
        }

        if ($result->count() > 0) {
            $this->result = $result;

            if ($result->count() == 1) {
                return $result->first();
            } else {
                return $this->result;
            }
        }

        return false;
    }
349516
public function limit(int $limit)
    {
        $this->query = array_merge($this->query ?? [], ['limit' => $limit]);

        return $this;
    }