kenny1911 / doctrine-sqlx
0.1.0
2025-05-24 08:48 UTC
Requires
- php: ^8.1
- doctrine/dbal: ^3.0 || ^4.0
Requires (Dev)
- phpunit/phpunit: ^12.1
README
[ English | Русский ]
A library that provides a convenient syntax for working with parameters in Doctrine DBAL SQL queries, allowing direct parameter embedding in SQL strings.
Installation
composer require kenny1911/doctrine-dbal-sqlx
Usage
Basic Example
use Doctrine\DBAL\Connection; use Kenny1911\DoctrineSqlx\Sqlx; use Kenny1911\DoctrineSqlx\Ctx; /** @var Connection $connection */ $sqlx = new Sqlx($connection); $result = $connection->executeQuery(static fn(Ctx $ctx): string => <<<SQL "SELECT * FROM users WHERE id = {$ctx(1)}" SQL); );
Instead of the traditional approach:
$result = $connection->executeQuery( sql: 'SELECT * FROM users WHERE id = :id', params: ['id' => 1], );
Benefits
- More readable code - parameters are visible directly in SQL strings
- Easier refactoring - no need to synchronize parameter names
- Security - all parameters are properly escaped
- Type support - explicit parameter type specification
Limitations
- Requires PHP 8.1+
- Works only with Doctrine DBAL 3.x and 4.x