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 Json Functions Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Development: Enables complex JSON query capabilities in Doctrine ORM, allowing teams to build sophisticated filtering, aggregation, and transformation logic for JSON-stored data without manual SQL. This directly supports:
    • Search-as-a-feature: Full-text search within nested JSON fields (e.g., JSON_SEARCH for unstructured data).
    • Dynamic data modeling: Storing flexible schemas (e.g., user preferences, configurations) as JSON and querying them efficiently.
    • Analytics pipelines: Aggregating JSON data (e.g., JSON_ARRAYAGG, JSON_OBJECTAGG) for reporting or ML feature extraction.
  • Roadmap Prioritization:
    • Build vs. Buy: Justifies not building custom JSON query logic from scratch, reducing technical debt and accelerating feature delivery.
    • Database Agnosticism: Supports multi-database strategies (e.g., PostgreSQL for analytics, MySQL for transactions) by abstracting JSON functions behind a single ORM layer.
    • Future-Proofing: Aligns with modern data trends (e.g., GraphQL-like flexibility, NoSQL-like schemas in SQL databases).
  • Use Cases:
    • E-Commerce: Querying product attributes (e.g., JSON_CONTAINS_PATH for multi-variant filters).
    • SaaS Platforms: Role-based access control via JSON-stored permissions (JSON_CONTAINS for user roles).
    • IoT/Telemetry: Time-series data stored as JSON arrays with JSON_ARRAYAGG for batch processing.
    • Legacy Modernization: Migrating from NoSQL (MongoDB) to SQL while preserving query patterns.

When to Consider This Package

  • Adopt if:
    • Your application stores structured or semi-structured data as JSON in SQL databases (e.g., PostgreSQL, MySQL 8+, SQLite with json1).
    • You need DQL-native JSON queries to avoid raw SQL or manual parsing (e.g., JSON_EXTRACT, JSON_CONTAINS_PATH).
    • Your team uses Doctrine ORM and wants to leverage its query builder without sacrificing JSON functionality.
    • You require database-specific optimizations (e.g., PostgreSQL’s jsonb operators via JSONB_CONTAINS).
    • Your roadmap includes complex JSON transformations (e.g., merging, patching, or aggregating JSON data).
  • Look elsewhere if:
    • You’re using MongoDB or pure NoSQL: Native drivers offer better performance for JSON operations.
    • Your JSON data is static or trivial: Simple LIKE or SERIALIZE/JSON_EXTRACT in raw SQL may suffice.
    • You need real-time JSON processing: Consider a dedicated JSON database (e.g., Elasticsearch) for search-heavy workloads.
    • Your stack doesn’t use Doctrine ORM: Alternatives like Laravel Scout or raw SQL may be simpler.
    • You require schema validation: Pair with a library like JSON Schema for runtime validation.

How to Pitch It (Stakeholders)

For Executives:

"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:

  • Faster feature delivery: No more waiting for custom SQL or ORM workarounds.
  • Cost savings: Avoids building/maintaining proprietary JSON query logic.
  • Scalability: Supports multi-database strategies (e.g., PostgreSQL for analytics, MySQL for transactions).
  • Competitive edge: Enables richer search, personalization, and dynamic data features (e.g., "find all products with attribute X or Y").

For Engineers:

*"This fills a critical gap in Doctrine ORM: native support for database JSON functions. With it, we can:

  • Write cleaner queries: Replace raw SQL like JSON_EXTRACT(column, '$.nested.field') with DQL: JSON_EXTRACT(u.attributes, '$.nested.field').
  • Leverage database optimizations: PostgreSQL’s jsonb operators, MySQL’s JSON_SEARCH, etc., are exposed as DQL functions.
  • Aggregate JSON data: Use JSON_ARRAYAGG or JSON_OBJECTAGG for complex reporting without post-processing.
  • Future-proof our code: Works across MySQL, PostgreSQL, SQLite, and SQL Server with minimal changes.

Trade-offs:

  • Requires registering functions upfront (one-time config).
  • Boolean functions need explicit = true comparisons due to Doctrine’s DQL limitations.
  • Not a replacement for full-text search (pair with PostgreSQL’s 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) = 1 in a reusable query builder method.

Next Steps:

  1. Spike: Test with a high-priority JSON-heavy feature (e.g., product filtering).
  2. Integration: Add to Doctrine config (Symfony or vanilla ORM).
  3. Document: Create internal guides for common patterns (e.g., nested JSON queries)."*
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