Statistics
5092
2
1
278d
Badges
Dependencies

Nextras\ORM QueryObjects

QueryObjects for Nextras\ORM.


Build Status Code coverage Downloads this Month Downloads total Latest stable HHVM Status

Discussion / Help

Join the chat

Install

composer require minetro/nextras-orm-query-object

Usage

Simple Query Object


final class SimpleQueryObject extends QueryObject
{

    /**
     * @param QueryBuilder $builder
     * @return QueryBuilder
     */
    public function doQuery(QueryBuilder $builder)
    {
        return $builder->select('*')->from('foobar');
    }

}
$qo = new SimpleQueryObject();
$qom = new QueryObjectManager();
$result = $qom->fetch($qo);

Full Query Object


final class FullQueryObject extends QueryObject
{

    /**
     * @param QueryBuilder $builder
     * @return QueryBuilder
     */
    public function doQuery(QueryBuilder $builder)
    {
        return $builder->select('*')->from('foobar');
    }
    
    /**
     * @param QueryBuilder $builder
     * @return QueryBuilder
     */
    protected function postQuery(QueryBuilder $builder)
    {
        return $builder;
    }

}
$qo = new FullQueryObject();
$qom = new QueryObjectManager();
$result = $qom->fetch($qo);

Executable Query Object


final class SimpleExecutableQueryObject extends ExecutableQueryObject
{

    /**
     * @param QueryBuilder $builder
     * @return QueryBuilder
     */
    public function doQuery(QueryBuilder $builder)
    {
        return $builder->select('*')->from('foobar');
    }

    /**
     * @param Result $result
     * @return Result
     */
    protected function postResult(Result $result)
    {
        return $result;
    }

}
$qo = new SimpleExecutableQueryObject($connection);
$result = $qo->execute();

Query Object Manager

You can register your own QueryObjectManager or setup via extension.

extensions:
    nextrasqueryobject: Minetro\Nextras\Orm\QueryObject\DI\NextrasQueryObjectExtension
use Minetro\Nextras\Orm\QueryObject\QueryObjectManager;

final class MyFacade1
{

    /** @var QueryObjectManager **/
    private $qom;

    public function foo()
    {
        $qo = $this->qom->create(MyExtraQueryObject::class);
        $qo->setBar(1);
        $qo->setBaz(TRUE);
        $result = $this->qom->fetch($qo);
    }

}
final class MyFacade2
{

    /** @var IMyQueryObjectFactory @inject **/
    public $myQueryObjectFactory;

    public function foobar()
    {
        $qo = $this->myQueryObjectFactory->create(1, TRUE);
        $result = $this->qom->fetch($qo);
    }

}

Thanks for testing, reporting and contributing.

  • 0.1 v0.1

    First bump! 🔪

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com