tallieutallieu / dry-dbi
Improved DRY databases
3.13.3
2026-09-28 13:51 UTC
Requires
- php: ^8.4
- tallieutallieu/oak: ^3.0.8 || ^4.0
Requires (Dev)
- pestphp/pest: ^3.8
- phpstan/phpstan: ^2.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13.0
- 3.12.3
- 3.12.2
- 3.12.1
- 3.12.0
- 3.11.3
- 3.11.2
- 3.11.1
- 3.11.0
- 3.10.0
- 3.9.0
- 3.8.0
- 3.7.0
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.1
- v3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-chore/sc-11673--dry3-switch-active-packages-to-dry-ci
- dev-chore/sc-11672--dry3-backfill-changelog-md-for-active
- dev-chore/migrate-oak-to-dry3
- dev-old-dry
- dev-feature/select
- dev-raw
This package is auto-updated.
Last update: 2026-09-28 13:52:42 UTC
README
Improved DRY databases
Index
Installation
composer require tallieutallieu/dry-dbi
Usage
Define service provider
<?php namespace app\provider; use Repository\PageRepository; use Oak\Contracts\Container\ContainerInterface; use Oak\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function register(ContainerInterface $app) { $app->set( Repository\PageRepository::class, Repository\PageRepository::class ); } public function boot(ContainerInterface $app) { // } }
Repository definition
Extend from BaseRepository for some default behaviour.
<?php namespace Repository; use Tnt\Dbi\BaseRepository; use Tnt\Dbi\Criteria\OrderBy; use Tnt\Dbi\Criteria\IsTrue; use Tnt\Dbi\QueryBuilder; use Model\Page; class PageRepository extends BaseRepository { protected $model = Page::class; /** * Initial method for default actions */ public function init() { $this->addCriteria(new OrderBy('sort_index')); } public function visible() { $this->addCriteria(new IsTrue('is_visible')); return $this; } /** * Use querybuilder directly for custom actions */ public function types(array $types) { $this->useQueryBuilder(function (QueryBuilder $queryBuilder) use ( $types ) { $queryBuilder->whereGroup(function ( QueryBuilder $queryBuilder ) use ($types) { foreach ($types as $type) { $queryBuilder->where('type', '=', $type->id, 'OR'); } }); }); return $this; } /** * Use querybuilder for table joins (left, right, inner) */ public function expertise(Expertise $expertise) { $this->useQueryBuilder(function (QueryBuilder $queryBuilder) { $queryBuilder ->leftJoin('project_expertise') ->on('project', '=', 'project.id'); }); return $this; } }
Use repository
<?php namespace Controller; use app\container\Application; class pages { public static function get(Request $request) { $app = Application::get(); $pageRepository = $app->get(PageRepository::class); $visiblePages = $pageRepository->visible()->get(); } }
Testing
Run the test suite using Pest PHP:
# Run all tests make test # Run tests with verbose output make test-verbose # Run tests with coverage make test-coverage
This will execute all tests in the tests/ directory through Docker. For more information about testing, see tests/README.md.
Release Management
Releases are automatic, through dry-ci: merging a pull
request into master with a merge commit tags the next version and adds its section to
CHANGELOG.md. The pull request title, a Conventional Commit, decides the version:
| Pull request title | Release |
|---|---|
feat!: … (any type with !) |
major |
feat: … |
minor |
fix: … or any other type |
patch |
See how dry-ci works.
Criteria
| Name | Description |
|---|---|
| Equals($column, $value) | Check if column equals specific value |
| GreaterThan($column, $value) | Check if column is greater than specific value |
| GreaterThanOrEqual($column, $value) | Check if column is greater than or equals specific value |
| GroupBy($column) | Create a group by on a column |
| In($column, $values) | Check if column value is in array of values |
| IsFalse($column) | Check on falsy value |
| IsNull($column) | Check on NULL |
| IsTrue($column) | Check on truthy value |
| LessThan($column, $value) | Check if column is less than specific value |
| LessThanOrEqual($column, $value) | Check if column is less than or equals specific value |
| LimitOffset($limit, $offset) | Create a limit/offset on query |
| NotEquals($column, $value) | Check if column and value are not equals |
| NotNull($column) | Check on NOT NULL |
| OrEquals($column, $value) | Check if column equals value with OR connector |
| OrderBy($column, $order = 'ASC') | Order by column with default ordering ASC |
| Raw($value, $bindings) | Build a custom query |