# Nextras\ORM Query Objects

# Content

# Usage

# Simple Query Object

final class SimpleQueryObject extends QueryObject
{

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

}
1
2
3
4
5
6
7
8
9
$qo = new SimpleQueryObject();
$qom = $container->getByType(QueryObjectManager::class);
$result = $qom->fetch($qo);
1
2
3

# Full Query Object


final class FullQueryObject extends QueryObject
{

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

	protected function postQuery(QueryBuilder $builder)
	{
		return $builder;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$qo = new FullQueryObject();
$qom = $container->getByType(QueryObjectManager::class);
$result = $qom->fetch($qo);
1
2
3

# Executable Query Object


final class SimpleExecutableQueryObject extends ExecutableQueryObject
{

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

	protected function postResult(Result $result)
	{
		return $result;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$qo = new SimpleExecutableQueryObject($connection);
$result = $qo->execute();
1
2

# Query Object Manager

You can register your own QueryObjectManager or setup via extension.

extensions:
	nextras.queryobjects: Contributte\Nextras\Orm\QueryObject\DI\NextrasQueryObjectExtension
1
2
use Contributte\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);
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
final class MyFacade2
{

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

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

}
1
2
3
4
5
6
7
8
9
10
11
12
13

Thanks for testing, reporting and contributing.