nette/database
Nette Database is a lightweight PHP database layer with a safe, fluent SQL builder, easy connection and result handling, and handy helpers for queries and transactions. Designed to work smoothly with the Nette framework while usable standalone.
Selection API enables method chaining (e.g., $selection->where()->orderBy()), which is intuitive for Laravel developers accustomed to Eloquent’s query builder.Table, Column, ForeignKey) can complement Laravel’s migrations and model metadata, though Eloquent already handles this via Schema and Blueprint.transaction() support with nested transactions is a plus for Laravel’s service-layer use cases, though Laravel’s DB::transaction() is already robust.DB facade or PDO connections as nette/database Connection instances.nette/database:
ActiveRow ≈ Eloquent models), and migrations.nette/database is more procedural/fluent.nette/database for complex queries (e.g., multi-table joins, dynamic SQL) while keeping Eloquent for model-centric CRUD.nette/database’s uniform API across drivers could simplify multi-database projects (e.g., read replicas, analytics databases).Connection::getPdo() and getDsn() could break Laravel’s DB::connection() integration if not abstracted.Connection to nette/database’s Explorer.ActiveRow and Selection add abstraction layers. Benchmark against Eloquent’s raw queries for write-heavy workloads.retrieved, saved).nette/database being considered for complex reporting queries, legacy system migration, or replacing Eloquent entirely?ActiveRow.nette/database’s exceptions (e.g., DeadlockException)?nette/database, or is a big-bang rewrite required?DB facade via PDO abstraction (all supported drivers are PDO-compatible).Selection::joinLeft()).Table, Column) can generate migration files or validate existing ones.ActiveRow can mirror Eloquent’s active record pattern with custom traits.ActiveRow events or custom logic).Selection macros).hasMany): Would require manual Selection chaining or a custom ORM layer.nette/database methods.Phase 1: Query Layer Replacement
nette/database’s Selection.// Eloquent
User::whereHas('posts')->with(['posts' => fn($q) => $q->where('published', true)])->get();
// nette/database
$selection = $db->table('users')
->join('posts', 'users.id = posts.user_id')
->where('posts.published', true)
->fetchAll();
Phase 2: Model Layer Adaptation
ActiveRow with traits for shared behavior:
class User extends ActiveRow
{
use \Nette\Database\ActiveRowTrait;
public function getPosts()
{
return $this->related('posts', fn($db) => $db->where('published', true));
}
}
user->posts) require manual implementation.Phase 3: Full ORM Replacement (Optional)
nette/database to unify APIs:
// Hypothetical facade
$users = DB::table('users')->where(...)->get(); // Uses nette/database internally
DB::connection() returns a Connection object. nette/database’s Connection can wrap this:
$pdo = DB::connection()->getPdo();
$netteConnection = new \Nette\Database\Connection($pdo, $driver);
ATTR_EMULATE_PREPARES) may not translate cleanly.nette/database’s granular exceptions (e.g., DeadlockException) can be caught and re-thrown as Laravel’s QueryException for consistency.nette/database align with Laravel 10+, but return types (e.g., ActiveRow) may clash with Eloquent’s Model expectations.SELECT queries first (lowest risk).INSERT/UPDATE/DELETE with ActiveRow and transactions.Table reflection to generate migration files or validate schemas.nette/database for analytics queries.nette/database for greenfield components.nette/database is independent of Laravel, reducing vendor lock-in but increasing manual integration effort.nette/database’s releases (e.g., v3.x → v4.x).^3.2) and monitor for Laravel-breaking changes.How can I help you explore Laravel packages today?