public function readSet($offset = 0, $limit = 10, $params = [])
    {
        $select = $this->getTable()::select();

        // select only required fields
        if (\count($this->getFields())) {
            $fields = $this->getFields();
            $name = $this->getTable()->getName();
            $fields = array_map(
                function ($field) use ($name) {
                    return $name .'.'. $field;
                },
                $fields
            );
            $select->select(implode(', ', $fields));
        }

        // switch statement for DB type
        $type = Proxy\Db::getOption('connect', 'type');
        switch ($type) {
            case 'mysql':
                $selectPart = $select->getSelect();
                $selectPart[0] = 'SQL_CALC_FOUND_ROWS ' . $selectPart[0];
                $select->select(...$selectPart);
                $totalSQL = 'SELECT FOUND_ROWS()';
                break;
            case 'pgsql':
            default:
                $selectTotal = clone $select;
                $selectTotal->select('COUNT(*)');
                $totalSQL = $selectTotal->getSql();
                break;
        }

        $select->setLimit($limit);
        $select->setOffset($offset);

        $result = [];
        $total = 0;

        // run queries
        // use transaction to avoid errors
        Proxy\Db::transaction(
            function () use (&$result, &$total, $select, $totalSQL) {
                $result = $select->execute();
                $total = Proxy\Db::fetchOne($totalSQL);
            }
        );

        return [$result, $total];
    }
public function readSet($offset = 0, $limit = 10, $params = [])
    {
        $select = $this->getTable()::select();

        // select only required fields
        if (\count($this->getFields())) {
            $fields = $this->getFields();
            $name = $this->getTable()->getName();
            $fields = array_map(
                function ($field) use ($name) {
                    return $name .'.'. $field;
                },
                $fields
            );
            $select->select(implode(', ', $fields));
        }

        // switch statement for DB type
        $type = Proxy\Db::getOption('connect', 'type');
        switch ($type) {
            case 'mysql':
                $selectPart = $select->getSelect();
                $selectPart[0] = 'SQL_CALC_FOUND_ROWS ' . $selectPart[0];
                $select->select(...$selectPart);
                $totalSQL = 'SELECT FOUND_ROWS()';
                break;
            case 'pgsql':
            default:
                $selectTotal = clone $select;
                $selectTotal->select('COUNT(*)');
                $totalSQL = $selectTotal->getSql();
                break;
        }

        $select->setLimit($limit);
        $select->setOffset($offset);

        $result = [];
        $total = 0;

        // run queries
        // use transaction to avoid errors
        Proxy\Db::transaction(
            function () use (&$result, &$total, $select, $totalSQL) {
                $result = $select->execute();
                $total = Proxy\Db::fetchOne($totalSQL);
            }
        );

        return [$result, $total];
    }
public function readSet ( $ offset = 0 , $ limit = 10 , $ params = [ ] ) { $ select = $ this -> getTable ( ) :: select ( ) ; // select only required fields if ( \ count ( $ this -> getFields ( ) ) ) { $ fields = $ this -> getFields ( ) ; $ name = $ this -> getTable ( ) -> getName ( ) ; $ fields = array_map ( function ( $ field ) use ( $ name ) { return $ name . '.' . $ field ; } , $ fields ) ; $ select -> select ( implode ( ', ' , $ fields ) ) ; } // switch statement for DB type $ type = Proxy \ Db :: getOption ( 'connect' , 'type' ) ; switch ( $ type ) { case 'mysql' : $ selectPart = $ select -> getSelect ( ) ; $ selectPart [ 0 ] = 'SQL_CALC_FOUND_ROWS ' . $ selectPart [ 0 ] ; $ select -> select ( ... $ selectPart ) ; $ totalSQL = 'SELECT FOUND_ROWS()' ; break ; case 'pgsql' : default : $ selectTotal = clone $ select ; $ selectTotal -> select ( 'COUNT(*)' ) ; $ totalSQL = $ selectTotal -> getSql ( ) ; break ; } $ select -> setLimit ( $ limit ) ; $ select -> setOffset ( $ offset ) ; $ result = [ ] ; $ total = 0 ; // run queries // use transaction to avoid errors Proxy \ Db :: transaction ( function ( ) use ( & $ result , & $ total , $ select , $ totalSQL ) { $ result = $ select -> execute ( ) ; $ total = Proxy \ Db :: fetchOne ( $ totalSQL ) ; } ) ; return [ $ result , $ total ] ; }
Get set of records

@param int   $offset
@param int   $limit
@param array $params

@return array[Row[], integer]
@throws TableNotFoundException
Get set of records