Код: Выделить всё
namespace App\Infrastructure\Services;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\MyModel
class FetchResultFromDb
{
public function __construct(public EntityManagerInterface $entityManager)
{
}
public function getEarliestResult(int $rowNum)
{
$queryBuilder = $this->entityManager->getRepository(MyModel::class)->createQueryBuilder('m');
return $queryBuilder
->from(MyModel::class, 'm')
->select('m.id')
->orderBy('m.sentTimestamp', 'ASC')
->setMaxResults($rowNum)
->getQuery()
->getResult();
}
}
Код: Выделить всё
SELECT id from my_model order by sent_timestamp LIMIT :row_num
< /code>
Сущность доктрины, которая используется для запроса: < /p>
namespace App\Entity;
use App\Infrastructure\Repository\MailLogRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class MyModel
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(name:'sent_timestamp',type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeInterface $sentTimestamp = null;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... e-executed
Мобильная версия