- How does Atlas.Statement compare to Laravel’s Query Builder for multi-database support?
- Atlas.Statement explicitly supports MySQL, PostgreSQL, SQLite, and SQL Server with portable SQL generation, while Laravel’s Query Builder is optimized for MySQL and PostgreSQL. Atlas is better for projects needing cross-database consistency, but lacks Laravel-specific features like `whereRaw` or Eloquent integration.
- Can I use Atlas.Statement with raw PDO in Laravel?
- Yes. Atlas.Statement is designed to work with PDO directly, making it a seamless fit for Laravel projects using PDO for database access. It generates SQL independently of execution, so you can pass the statement to PDO or Laravel’s Query Builder.
- Will Atlas.Statement work with Laravel 10+ and PHP 8.4+?
- Atlas.Statement requires PHP 8.4+, which aligns with Laravel 10+. However, if your project uses older Laravel versions, you may need to downgrade PHP or check for compatibility updates in the Atlas ecosystem.
- How do I migrate from Laravel’s Query Builder to Atlas.Statement?
- Start by rewriting complex queries (e.g., multi-JOIN or type-heavy logic) using Atlas’ fluent API. For example, replace `DB::table('users')->where('active', true)` with `Select::from('users')->whereEquals(['active' => true])`. Use it incrementally for new features to minimize disruption.
- Does Atlas.Statement support Eloquent model queries?
- No, Atlas.Statement is for raw SQL generation. To use it with Eloquent, you’d need to manually convert model conditions (e.g., `User::where('active', true)`) into Atlas statements or build custom adapters for query translation.
- Is Atlas.Statement suitable for Laravel migrations or seeds?
- Yes. It’s ideal for constructing INSERT, UPDATE, or DELETE statements in custom migration logic. For example, you can build a bulk update statement with `Update::table('users')->set(['active' => false])->where('id', '<', 100)` and execute it via PDO or Atlas.Pdo.
- How does Atlas.Statement handle SQL injection risks?
- Atlas.Statement enforces type-safe parameter binding (e.g., `whereEquals()`, `limit()`) and generates sanitized SQL. Unlike raw `whereRaw`, it prevents accidental injection by design, making it safer for dynamic queries than Laravel’s Query Builder in some cases.
- What are the alternatives to Atlas.Statement for Laravel?
- For Laravel-specific solutions, use the built-in Query Builder or Eloquent. For multi-database portability, consider Doctrine DBAL or Atlas.Query/Atlas.Pdo. Atlas.Statement stands out for its strict API and PDO integration but lacks Laravel’s ecosystem features.
- Can I use Atlas.Statement with Atlas.Query or Atlas.Pdo?
- Absolutely. Atlas.Statement is part of the Atlas ecosystem and integrates seamlessly with Atlas.Query (for query execution) and Atlas.Pdo (for PDO wrappers). This combo offers a cohesive, type-safe alternative to Laravel’s Query Builder while maintaining portability.
- How do I test Atlas.Statement in Laravel?
- Test by mocking PDO or Atlas.Pdo to verify SQL generation. Use PHPUnit to assert statement outputs (e.g., `Select::from('users')->where('id', 1)->toSql()` should return `SELECT * FROM users WHERE id = ?`). Focus on edge cases like NULL values, subqueries, and cross-database syntax differences.