- Is Aura.SqlQuery a good alternative to Laravel's query builder?
- It can be, especially if you need database-agnostic SQL generation or features Laravel's builder lacks, such as first-class CTEs and portable upsert support. The package is deliberately low level: it produces SQL strings and bind values, with no Eloquent integration, relationships, model events, serialization, query caching, or the raw-expression ergonomics of DB::raw(). Many teams use it as a focused SQL-generation layer alongside a Laravel DB connection rather than as a drop-in replacement for Eloquent.
- How do I install aura/sqlquery with Composer?
- Run composer require aura/sqlquery; the package is PSR-4 autoloadable and maps the Aura\SqlQuery\ namespace to its src directory. You can also download a release or clone the repository and map the namespace to src yourself. It depends on external interfaces only, never implementations, so it will not pull in a database connection library.
- Which PHP versions does Aura.SqlQuery support?
- The 3.x and 6.x line requires PHP 5.6 or later and is tested on PHP 5.6 through 8.5. The 7.0.0-beta1 release raises the floor to PHP 8.4 and is CI-tested on 8.4 and 8.5, so Laravel applications pinned to PHP 8.2 or 8.3 need to stay on the older line. Always check the composer.json constraint for the exact version you install.
- Does Aura.SqlQuery support common table expressions (CTEs)?
- Yes, starting with 7.0.0-beta1. The new WithInterface adds with(), withRecursive(), resetWith() and hasWith() to all four query interfaces for select, insert, update and delete, and recursive CTEs handle org hierarchies, bill-of-materials, graph traversal and category trees. Earlier releases have no CTE API, so those queries previously required raw SQL string assembly.
- How do I use Aura.SqlQuery with PDO or a Laravel database connection?
- Instantiate a QueryFactory with a dialect, for example new Aura\SqlQuery\QueryFactory('mysql'), build the query through the fluent interface, then call getStatement() and getBindValues(). Those two values can be passed directly to PDO::prepare() and execute(), or to Laravel's DB::select() and DB::statement(). The package never requires a connection library itself, although PDO is the recommended pairing.
- Which databases does Aura.SqlQuery support, including upserts?
- It ships builders and dialect-specific quoter classes for MySQL, PostgreSQL, SQLite and Microsoft SQL Server, selected through QueryFactory, mirroring the abstraction Laravel uses. In 7.0.0-beta1 the PostgreSQL and SQLite insert builders implement Common\OnConflictUpdateInterface, giving dialect-correct ON CONFLICT semantics without hand-written SQL. Subselects and unions are supported across the dialects as well.
- Why does Aura.SqlQuery throw duplicate named placeholder errors?
- In 7.0.0-beta1, reusing the same named placeholder across different clauses now throws an exception instead of silently clobbering one binding with another. That previously caused bugs such as SET status = :status WHERE status = :status setting a column to the value intended only as a filter (issue #151). Use distinct placeholder names per clause, and treat the new exception as a fail-loud correctness improvement rather than a regression.
- What breaking changes does Aura.SqlQuery 7.0.0-beta1 introduce?
- The headline changes are a hard PHP 8.4 minimum, native parameter, return and property types across the API with 166 methods declaring static, the new Aura\SqlQuery\Exception namespace behind an ExceptionInterface marker, and exceptions on duplicate named placeholders. Several signatures also changed: reset() now returns static, union() and unionAll() accept an optional SelectInterface, join() and joinSubSelect() take an array $bind, getLastInsertIdName() is narrowed to string|null, and subSelect() moved to AbstractQuery with a $source argument. A docs/upgrading.md file lists the ordered upgrade steps.
- Can I subclass Aura.SqlQuery builders or wrap them in an adapter?
- You can, but 7.0.0-beta1 adds native parameter, return and property types to nearly all methods, so any override must match the parent signature or PHP will fatal on load. That directly affects adapter layers that previously relied on docblock-only contracts. Prefer coding against the interfaces such as SelectInterface, InsertInterface, UpdateInterface and DeleteInterface, use the provided traits like WhereTrait and WithTrait, and keep subclasses thin.
- How do I test code that uses Aura.SqlQuery?
- Because the builders are independent of any connection, you can unit test them without a database by asserting on getStatement() and getBindValues() for each dialect. The package's own suite runs with composer install followed by ./vendor/bin/phpunit at the repository root. For integration coverage, feed the generated SQL and bindings to PDO against the target database, and add cases for the new CTE and placeholder-collision behaviour if you are on 7.x.