laminas/laminas-db
Laminas\Db is a flexible database abstraction for PHP, providing adapters for major databases, SQL builders, table gateways, result sets, metadata tools, and a profiler to help build portable, testable data access layers.
Pros:
mysql, pgsql, sqlsrv).Select, Insert, Update) mirrors Laravel’s Query Builder but offers more explicit control over SQL syntax, useful for performance-critical or vendor-specific optimizations.RowDataGateway and TableDataGateway provide a structured way to interact with tables/rows, which could integrate with Laravel’s repository pattern or service layers.Cons:
Select::from()->where() vs. DB::table()->where()). May require developer buy-in for adoption.Illuminate\Database\Connection) with Laminas\Db\Adapter\Adapter for raw queries.Illuminate\Database\Query\Builder for complex queries, though would need custom syntax adapters (e.g., mapping Laminas\Db\Sql\Select to Laravel’s fluent interface).Why Adopt?
Maintenance Plan
Performance Impact
laminas-db with Laravel’s Query Builder for target use cases?Team Readiness
Long-Term Viability
laminas-db becomes unsustainable? (e.g., migrating to Doctrine DBAL or Laravel’s native tools).Illuminate\Database components for raw SQL operations. For example:
Laminas\Db\Adapter\Adapter as the underlying connection driver in Laravel’s Connection class.Query Builder facade that wraps Laminas\Db\Sql\Sql.TableDataGateway/RowDataGateway in repository patterns alongside Eloquent models.Laminas\Db\Sql for vendor-specific SQL in custom migration logic (though not for Laravel’s migration system directly).pdo_mysql, pdo_pgsql). Laravel already handles this, so no additional setup.tinker, artisan, and migrate commands for development/testing, though custom wrappers may be needed for Laminas\Db-specific features.Phase 1: Proof of Concept
Laminas\Db to validate performance and developer experience.// Current Laravel Query Builder
$users = DB::table('users')
->join('orders', 'users.id', '=', 'orders.user_id')
->where('orders.status', 'active')
->select('users.*', 'orders.total')
->get();
// Proposed Laminas\Db
$sql = new \Laminas\Db\Sql\Sql($adapter);
$select = $sql->select()
->from(['u' => 'users'])
->join(['o' => 'orders'], 'u.id = o.user_id', ['total' => 'orders.total'])
->where(['status' => 'active']);
$statement = $sql->prepareStatementForSqlObject($select);
$results = $statement->execute();
Phase 2: Hybrid Integration
Laminas\Db for specific use cases (e.g., complex queries) while falling back to Laravel’s Query Builder for simplicity.// app/Providers/AppServiceProvider.php
use Laminas\Db\Sql\Sql;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('laminas.db.sql', function ($app) {
$adapter = $app['db']->connection()->getPdo();
return new Sql($adapter);
});
}
}
DB::extend('laminas', function ($config) {
$adapter = new \Laminas\Db\Adapter\Adapter($config['dsn'], $config['username'], $config['password']);
return new \Laminas\Db\Query\Builder($adapter);
});
Phase 3: Full Adoption
Query Builder with a custom wrapper for all database operations in the application.laminas-db integration tests (e.g., unit tests for query objects, integration tests with Vagrant databases).Laminas\Db’s API and debugging workflows.doctrine/dbal or other database abstraction layers.spatie/laravel-query-builder) would need updates to work with Laminas\Db.How can I help you explore Laravel packages today?