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
Doctrine Query Document

Doctrine Query Document Laravel Package

dbstudios/doctrine-query-document

Build Doctrine DQL filters from a simple array “query document”. Apply conditions to an existing QueryBuilder (from/select required), auto-bind positional parameters, traverse relations via dot notation, and query JSON fields (MySQL 5.7+).

View on GitHub
Deep Wiki
Context7

A tool for building Doctrine queries using MongoDB-style query documents

Frequently asked questions about Doctrine Query Document
How do I install and set up doctrine-query-document in a Laravel project?
Run `composer require dbstudios/doctrine-query-document` to install. Initialize the `QueryManager` with your Doctrine `ObjectManager` and use it to apply query documents to an existing `QueryBuilder` with `from` and `select` clauses. No additional Laravel-specific configuration is required beyond Doctrine setup.
Can I use this package with Laravel’s Eloquent ORM?
No, this package is designed for Doctrine ORM only. If you’re using Eloquent, consider alternatives like query scopes or custom builder classes. For mixed projects, ensure you’re using Doctrine’s `ObjectManager` directly.
What Laravel versions and Doctrine ORM versions are supported?
The package works with any Laravel version that supports Doctrine ORM (v2.5+). Check the package’s `composer.json` for the exact Doctrine ORM version dependency, but it’s generally compatible with modern Laravel projects using Doctrine. Test thoroughly if using older versions.
How does dot notation work for relationships? Does it support nested joins?
Dot notation (e.g., `user.address.city`) automatically joins related entities and queries their fields. It supports nested relationships, but complex joins (e.g., multiple levels deep) may require manual `JOIN` clauses in the `QueryBuilder` for optimal performance. The package handles the rest.
Is there a performance overhead compared to writing raw DQL?
Yes, query documents add a layer of abstraction for parsing and parameter binding. For simple queries, the difference is negligible, but complex queries (e.g., deep joins, aggregations) may benefit from benchmarking. Cache the `QueryManager` instance to mitigate runtime overhead.
Can I query JSON fields in PostgreSQL or only MySQL?
The package supports JSON fields in MySQL 5.7+ and PostgreSQL, but the syntax for extracting nested JSON values may vary by database. MySQL uses `JSON_EXTRACT`, while PostgreSQL relies on `->` or `->>` operators. The package abstracts this for MySQL; PostgreSQL may require manual adjustments.
How do I handle MongoDB-style operators like `$gt`, `$in`, or `$regex`?
Operators like `$gt`, `$lt`, `$in`, and `$regex` are supported directly in query documents. For example, `['age': ['$gt' => 25]]` translates to `age > 25`. However, complex MongoDB operators (e.g., `$lookup`, `$unwind`) aren’t supported and require raw DQL.
What happens if my query document contains invalid field names or operators?
Invalid field names (e.g., non-existent relationships) will result in a `QueryException` during `apply()`. Unsupported operators or syntax errors are caught early, but malformed JSON or missing entities may cause runtime errors. Validate query documents before execution in production.
Can I use this package alongside existing DQL queries in the same project?
Yes, the package is designed for incremental adoption. Start by replacing simple `WHERE` clauses with query documents, then gradually migrate complex queries. The `QueryManager` integrates seamlessly with existing `QueryBuilder` instances, preserving all other DQL clauses.
Are there any alternatives for MongoDB-style querying in Laravel/Doctrine?
Alternatives include writing raw DQL, using Doctrine’s `Criteria` API, or building custom query builders. For MongoDB migrants, consider `jenssegers/laravel-mongodb` (if sticking with MongoDB) or `doctrine/orm` extensions like `API Platform’s` query filters. This package is unique for its MongoDB-like syntax in SQL.
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.
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
spatie/mailcoach-vapor
spatie/laravel-javascript-views