- Can Cycle Database replace Laravel’s Eloquent ORM for production APIs?
- Cycle Database is not a direct Eloquent replacement but excels in schema governance and raw query performance. Use it for data-heavy operations (e.g., bulk inserts, complex joins) while keeping Eloquent for CRUD logic. Benchmark critical paths to compare latency with Eloquent or raw PDO.
- How do I integrate Cycle Database with Laravel’s existing PDO connections?
- Cycle Database works seamlessly with Laravel’s PDO connections. Bind the `DatabaseManager` to Laravel’s service container (e.g., `bind('cycle.db', fn() => new DatabaseManager($config))`) and reuse existing `.env` configurations for connections like MySQL or PostgreSQL.
- Does Cycle Database support Laravel’s Artisan migrations?
- No, Cycle Database uses its own migration system via CLI tools. For Laravel projects, you’ll need to either replace Artisan migrations with Cycle’s CLI or use a facade layer to bridge both systems. Cycle’s migrations are schema-first, so they’re ideal for teams enforcing strict database governance.
- How does Cycle Database handle PostgreSQL’s ON CONFLICT clause?
- Cycle Database includes native support for PostgreSQL’s `ON CONFLICT` via the `onConflict()` method in its query builder. This eliminates the need for raw SQL and integrates smoothly with Laravel’s transaction management. Example: `$users->insert(...)->onConflict(['id'])->doUpdate(['updated_at' => now()]).`
- Will Cycle Database work with Laravel 10+ and PHP 8.2?
- Cycle Database supports PHP 8.0+ and is compatible with Laravel 10+. However, test thoroughly with your specific Laravel version, as some advanced features (e.g., query builder macros) may require custom integration. Check the [Cycle ORM docs](https://cycle-orm.dev/) for version-specific notes.
- Can I use Cycle Database for schema introspection in Laravel?
- Yes, Cycle Database provides robust schema introspection via `$table->getSchema()`. This is useful for generating Laravel migrations dynamically or validating existing schemas against declarative definitions. It’s particularly valuable for multi-database projects where schema consistency is critical.
- How do I handle transactions with Cycle Database in Laravel?
- Cycle Database supports transactions via `DatabaseManager::transaction()`. For Laravel integration, wrap Cycle transactions in Laravel’s `DB::transaction()` or use a facade to unify syntax. Example: `$dbm->transaction(fn() => $users->insert(...));` for nested or isolated transactions.
- Are there performance benefits over Laravel’s Query Builder for large datasets?
- Yes, Cycle Database optimizes for performance with features like server-side cursors (for streaming) and efficient pagination. For large datasets, use `->limit()->offset()` or `->cursor()` to reduce memory usage. Benchmark against Laravel’s Query Builder for your specific workloads, especially in read-heavy applications.
- How do I migrate from raw PDO or Eloquent to Cycle Database?
- Start by replacing raw PDO queries with Cycle’s query builder (e.g., `select()`, `insert()`). For Eloquent, use Cycle for schema declarations and complex queries while keeping models for relationships. Gradually refactor migrations to Cycle’s CLI tool. Document the transition to avoid schema drift between systems.
- What are the alternatives to Cycle Database for Laravel?
- Alternatives include Laravel’s built-in Query Builder (for simplicity), Doctrine DBAL (for enterprise projects), or raw PDO (for maximum control). Cycle Database stands out for its multi-dialect support, schema-first design, and advanced query features like nested queries and `ON CONFLICT`. Choose based on your need for strict schema governance or performance.