scienta/doctrine-json-functions
Adds JSON function support to Doctrine ORM DQL by registering custom function nodes for multiple databases. Use MySQL/MariaDB, PostgreSQL, SQLite (json1), or SQL Server JSON functions directly in DQL with platform validation.
JSON_SEARCH for unstructured data).JSON_ARRAYAGG, JSON_OBJECTAGG) for reporting or ML feature extraction.JSON_CONTAINS_PATH for multi-variant filters).JSON_CONTAINS for user roles).JSON_ARRAYAGG for batch processing.json1).JSON_EXTRACT, JSON_CONTAINS_PATH).jsonb operators via JSONB_CONTAINS).LIKE or SERIALIZE/JSON_EXTRACT in raw SQL may suffice."This package lets us query JSON data stored in SQL databases using Doctrine ORM—just like we’d query regular columns. For example, instead of writing custom SQL to search user preferences or product attributes, we can use JSON_CONTAINS_PATH directly in our query builder. This reduces backend complexity, speeds up development, and future-proofs our data model for flexible schemas. It’s a low-risk way to adopt modern data patterns without switching databases."
Key Outcomes:
*"This fills a critical gap in Doctrine ORM: native support for database JSON functions. With it, we can:
JSON_EXTRACT(column, '$.nested.field') with DQL: JSON_EXTRACT(u.attributes, '$.nested.field').jsonb operators, MySQL’s JSON_SEARCH, etc., are exposed as DQL functions.JSON_ARRAYAGG or JSON_OBJECTAGG for complex reporting without post-processing.Trade-offs:
= true comparisons due to Doctrine’s DQL limitations.tsvector or Elasticsearch if needed).Example Win:
Before: Custom SQL parser for filtering user roles stored as JSON. After:
WHERE JSON_CONTAINS(u.roles, :role) = 1in a reusable query builder method.
Next Steps:
How can I help you explore Laravel packages today?