Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 0 additions & 131 deletions .docs/README.md

This file was deleted.

130 changes: 122 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,138 @@
Website 🚀 <a href="https://contributte.org">contributte.org</a> | Contact 👨🏻‍💻 <a href="https://f3l1x.io">f3l1x.io</a> | Twitter 🐦 <a href="https://twitter.com/contributte">@contributte</a>
</p>

## Usage
Query object helpers for Nextras ORM applications, including reusable query objects, executable query objects and a Nette DI manager.

## Versions

| State | Version | Branch | Nette | PHP |
|-------------|---------|----------|-------|---------|
| dev | `^0.7` | `master` | 3.2+ | `>=8.2` |
| stable | `^0.6` | `master` | 3.2+ | `>=8.2` |

## Installation

To install latest version of `contributte/nextras-orm-query-object` use [Composer](https://getcomposer.org).

```bash
composer require contributte/nextras-orm-query-object
```

## Documentation
## Usage

For details on how to use this package, check out our [documentation](.docs).
### Simple Query Object

## Versions
```php
final class SimpleQueryObject extends QueryObject
{

| State | Version | Branch | Nette | PHP |
|-------------|---------|----------|-------|---------|
| dev | `^0.7` | `master` | 3.2+ | `>=8.2` |
| stable | `^0.6` | `master` | 3.2+ | `>=8.2` |
public function doQuery(QueryBuilder $builder)
{
return $builder->select('*')->from('foobar');
}

}
```

```php
$qo = new SimpleQueryObject();
$qom = $container->getByType(QueryObjectManager::class);
$result = $qom->fetch($qo);
```

### Full Query Object

```php
final class FullQueryObject extends QueryObject
{

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

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

}
```

```php
$qo = new FullQueryObject();
$qom = $container->getByType(QueryObjectManager::class);
$result = $qom->fetch($qo);
```

### Executable Query Object

```php
final class SimpleExecutableQueryObject extends ExecutableQueryObject
{

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

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

}
```

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

### Query Object Manager

You can register your own `QueryObjectManager` or set it up via extension.

```neon
extensions:
nextras.queryobjects: Contributte\Nextras\Orm\QueryObject\DI\NextrasQueryObjectExtension
```

```php
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);
}

}
```

```php
final class MyFacade2
{

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

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

}
```

## Development

Expand Down