/**
  * Returns all instances of the type meeting $distinctFields values.
  *
  * @param Fields      $distinctFields
  * @param Filter|null $filter
  * @param Sort|null   $sort
  *
  * @return array
  */
 public function findByDistinct(Fields $distinctFields, Filter $filter = null, Sort $sort = null) : array
 {
     $query = $this->queryBuilder();
     $query->select($distinctFields ? 'DISTINCT ' . implode(', ', $this->getColumns($distinctFields)) : ['DISTINCT *'])->from($this->mapping->name());
     if ($filter) {
         SqlFilter::filter($query, $filter, $this->mapping);
     }
     if ($sort) {
         SqlSorter::sort($query, $sort, $this->mapping);
     }
     return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
 }
 /**
  * Returns a Page of entities meeting the paging restriction provided in the Pageable object.
  *
  * @param Pageable $pageable
  *
  * @return Page
  */
 public function findAll(Pageable $pageable = null) : Page
 {
     $query = $this->queryBuilder();
     if ($pageable) {
         $columns = $this->getPageColumns($pageable);
         $query->select($columns)->from($this->mapping->name());
         if ($filter = $pageable->filters()) {
             SqlFilter::filter($query, $filter, $this->mapping);
         }
         if ($sort = $pageable->sortings()) {
             SqlSorter::sort($query, $sort, $this->mapping);
         }
         $total = $this->count($pageable->filters());
         return new ResultPage($query->getConnection()->executeQuery(sprintf($query->getSQL() . ' LIMIT %s, %s', (int) ($pageable->offset() - $pageable->pageSize()), (int) $pageable->pageSize()), $query->getParameters())->fetchAll(PDO::FETCH_ASSOC), $total, $pageable->pageNumber(), ceil($total / ($pageable->pageSize() > 0) ? $pageable->pageSize() : 1));
     }
     $query->select('*')->from($this->mapping->name());
     return new ResultPage($query->getConnection()->executeQuery($query->getSQL(), $query->getParameters())->fetchAll(PDO::FETCH_ASSOC), $this->count(), 1, 1);
 }