Repository navigation
Replies: 1 comment
|
There is a path-handling detail to settle before wiring this into the grammar. The proposed I exercised the original The first selects a literal property named There are also two different JSON operations involved. For a first implementation, I'd keep scalar values bound as parameters and build the RHS as a JSON extraction. I wouldn't reuse the normal Tests worth including are integer |
Uh oh!
There was an error while loading. Please reload this page.
MySQL supports multi-valued indexes on JSON arrays, for example:
These indexes can be used efficiently with
MEMBER OF()queries:Laravel currently provides JSON query methods such as
whereJsonContains(), but there does not appear to be a Query Builder method for expressingMEMBER OF()directly. This means using a MySQL multi-valued index like the above currently requireswhereRaw():It would be useful to have first-class Query Builder support for this operation, with proper identifier/path handling and parameter binding.
For example, an API could look roughly like:
The proposed argument order here is:
whereJsonMemberOf(string $path, mixed $value)That is, the JSON column/path comes first and the value to test for membership comes second, consistent with methods such as
whereJsonContains($column, $value).Conceptually, the example above would compile to:
'feature' MEMBER OF (configuration->'$[*].name')The exact method name and signature could of course be adjusted to better match Laravel's existing Query Builder conventions.
The primary motivation is not only avoiding raw SQL, but enabling idiomatic Laravel queries for MySQL's multi-valued JSON indexes.
whereJsonContains()is not always an equivalent replacement, particularly when the indexed expression targets values selected through a wildcard JSON path such as$[*].name.Ideally, the feature could also support the corresponding
orWhere... / negated variants in the same way as Laravel's other JSON query predicates.All reactions