Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Database Laravel Package

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.

View on GitHub
Deep Wiki
Context7

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

Frequently asked questions about Database
Can I use nette/database in Laravel without the Nette framework?
Yes, nette/database is framework-agnostic and works standalone in Laravel. You’ll need to wrap it in a Laravel service provider to bridge the Nette DI container with Laravel’s service container. The package’s PDO-like API ensures compatibility with Laravel’s existing database connections.
How does nette/database compare to Laravel’s Eloquent for CRUD operations?
Eloquent is better suited for model-centric CRUD with its active record pattern, events, and observers. nette/database excels in complex queries (e.g., multi-table joins, dynamic SQL) via its fluent Selection API. For hybrid projects, use Eloquent for models and nette/database for reporting or legacy systems.
Does nette/database support Laravel’s query scopes or model events?
No, nette/database lacks native support for Laravel’s query scopes or Eloquent events. You’d need to create custom macros or event listeners to bridge these gaps. For example, use Laravel’s event system to trigger actions when ActiveRow records are retrieved or saved.
What Laravel versions and PHP requirements does nette/database support?
nette/database requires PHP 8.1+, which aligns with Laravel 10+. For older Laravel versions (e.g., 9.x), you’d need to manually handle PHP 8.1+ features or use a compatibility layer. Always check the package’s changelog for breaking changes, like the removal of `Connection::getPdo()` in v4.0.0.
How do I integrate nette/database with Laravel’s existing database connections?
Laravel’s DB facade or PDO connections can be passed to nette/database’s `Connection` class. Use a service provider to bind Laravel’s connections to nette/database’s `Explorer` or `Connection` instances. For example, wrap `DB::connection('mysql')` in a custom adapter to return a nette/database `Connection`.
Is nette/database faster than Eloquent for read-heavy applications?
Performance depends on the use case. nette/database’s ActiveRow and Selection APIs add abstraction layers, which may introduce overhead for high-frequency queries. Benchmark against Eloquent’s raw queries or Laravel’s query builder for your specific workloads, especially in write-heavy or rate-limited API endpoints.
Can I migrate queries from Eloquent to nette/database incrementally?
Yes, you can gradually replace Eloquent queries with nette/database’s fluent API. Start with complex queries (e.g., joins, subqueries) and refactor simpler CRUD operations last. Use adapter classes to translate Eloquent’s `Builder` to nette/database’s `Selection` where needed, but expect some manual effort for syntax differences.
Does nette/database work with Laravel’s testing tools like Pest or PHPUnit?
Yes, but you may need to adapt tests to handle nette/database’s exceptions (e.g., `DeadlockException`). Mock the `Connection` or `Explorer` interfaces in your tests to isolate database interactions. Laravel’s testing helpers (e.g., `refreshDatabase()`) should still work if you use PDO-compatible connections.
What are the alternatives to nette/database for Laravel’s query builder?
For Laravel, alternatives include Eloquent’s query builder, Laravel’s raw query builder (`DB::`), or third-party packages like Doctrine DBAL or Cycle ORM. Eloquent is the most integrated choice, while Doctrine DBAL offers similar multi-driver support but with a different API. nette/database stands out for its fluent, PDO-like syntax and advanced query features.
How do I handle transactions with nette/database in Laravel?
nette/database supports transactions via the `transaction()` method, including nested transactions. For Laravel integration, wrap the transaction in a service provider or facade to ensure compatibility with Laravel’s `DB::transaction()`. Example: `$connection->transaction(fn() => $selection->where(...)->fetch());` for a single-database transaction.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky