Skip to content

Pagination

Brian Zou edited this page Jan 9, 2019 · 2 revisions

Hunt Entity version 2.1.0 added pagination / offset && limit for EQL's createQuery();

Example 1 for pagination:

class User
{
    mixin MakeModel;

    @AutoIncrement
    @PrimaryKey
    int id;

    string name;
}

auto query = em.createQuery!User("SELECT u FROM User", new Pageable(0, 10));
auto page = query.getPageResult();

logDebug("Page NO: %s, size of Page: %s, Total Pages: %s, Total: %s".format(page.getNumber(), page.getSize(), page.getTotalPages(), page.getTotalElements()));

foreach (user; page.getContent())
{
    logDebug("User[%s] is: %s".format(user.id, user.name));
}

Example 2 for limit && offset :

class User
{
    mixin MakeModel;

    @AutoIncrement
    @PrimaryKey
    int id;

    string name;
}

auto query = em.createQuery!User("SELECT u FROM User").setFirstResult(10).setMaxResults(20);

foreach (user; query.getResultList())
{
    logDebug("User[%s] is: %s".format(user.id, user.name));
}
Clone this wiki locally