aura/sqlquery
Database-agnostic SQL query builders for MySQL, PostgreSQL, SQLite, and SQL Server. Build SELECT/INSERT/UPDATE/DELETE statements safely and portably without tying to a specific DB library (PDO recommended). PSR-4, PHP 5.6+.
Strengths:
MySqlQuoter, PostgresQuoter) mirror Laravel’s Eloquent query builder’s abstraction layer.where(), join(), and orderBy() return the builder instance, enabling method chaining—a core Laravel pattern (e.g., User::where()->orderBy()->get()).fromSubSelect(), joinSubSelect()), which Laravel’s Eloquent lacks natively but is critical for complex joins or CTEs.:_1, :_2) for PDO compatibility, avoiding SQL injection and matching Laravel’s query binding conventions.QueryInterface and traits (e.g., WhereTrait) allow customization without modifying core logic, similar to Laravel’s Query Builder extensibility.Gaps vs. Laravel:
toJson()). These would require custom logic.DB::raw() is more flexible for dynamic SQL fragments.Laravel Stack Compatibility:
Aura\SqlQuery\QueryFactory as a singleton).AuraQuery::select()->from(...)) for consistency with DB:: or Model::query().DB::query() or extend it via a macro (e.g., DB::macro('aura', fn() => new AuraQuery())).Key Integration Points:
| Laravel Component | Aura.SqlQuery Equivalent | Integration Approach |
|---|---|---|
DB::select() |
Select class |
Wrap Select in a facade/method. |
DB::table()->where() |
Select::from()->where() |
Extend Laravel’s Builder with Aura methods. |
DB::raw() |
Manual SQL strings | Use Select::fromRaw() or whereRaw(). |
| Eloquent Relationships | Subqueries (fromSubSelect()) |
Custom accessors (e.g., hasManyThrough). |
| Query Scopes | Fluent methods | Convert scopes to Aura method chains. |
High:
where($column, $operator, $value)). Aura.SqlQuery’s where() uses array syntax (['column = ?', $value]), requiring adapter methods.orWhere, groupBy) will require extensive test coverage.Mitigation Strategies:
LaravelAuraQuery) to translate Laravel method calls to Aura.SqlQuery.Use Case Justification:
Adoption Scope:
query() method or global replacement.)Maintenance:
Performance:
Team Skills:
Laravel Ecosystem Compatibility:
QueryFactory can be registered as a Laravel singleton or contextual binding.illuminate.query).DatabaseMigrations, DatabaseTransactions).Tooling Synergy:
| Phase | Actionable Steps | Tools/Dependencies |
|---|---|---|
| Evaluation | Benchmark Aura.SqlQuery vs. Laravel Query Builder for 3–5 critical queries. | Laravel Debugbar, Blackfire. |
| Adapter Layer | Create LaravelAuraQuery facade wrapping Aura.SqlQuery methods. |
Laravel Facades, Macros. |
| Feature Parity | Implement missing Laravel methods (e.g., orWhere, groupBy) in the adapter. |
PHPUnit, Pest. |
| Testing | Write integration tests for Eloquent + Aura.SqlQuery interactions. | Laravel TestCase, Database Transactions. |
| Deprecation | Gradually replace DB::query() with AuraQuery::query() in legacy code. |
PHPStan, Rector. |
| Production | Roll out in feature flags for critical paths (e.g., reporting queries). | Laravel Horizon, Env-based feature toggles. |
Laravel Query Builder:
select(), from(), where(), join(), groupBy(), orderBy(), limit(), offset().pluck(), chunk(), cursor(), Eloquent-specific methods (e.g., with()).getStatement() to extract raw SQL for Laravel’s DB::select().pluck() via Select::getCols()).Eloquent:
Model::query()->macro('aura', fn() => new AuraQuery()).hasManyThrough).newQuery() in models to return an Aura-powered builder.Database Drivers:
OUTPUT clause) unless using SqlServerQuoter.SqlServerQuoter for missing syntax.How can I help you explore Laravel packages today?