[5.8] Support JSON queries on MariaDB #25517
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Laravel uses the
->
operator to query JSON columns on MySQL:This operator is specific to MySQL and not available on MariaDB. We can support both databases by using the
JSON_EXTRACT()
function instead (MySQL, MariaDB):From the MySQL documentation:
The
->>
operator can be used to unquote the JSON result (User::select('options->>language')
). In this case, we have to wrapJSON_EXTRACT()
inJSON_UNQUOTE()
(MySQL, MariaDB).For
whereJsonContains()
we have to split the JSON selector into the field and the path and pass the optional path as the third parameter (MySQL, MariaDB).whereJsonLength()
already supports MariaDB.This is a breaking change for people who select JSON values without a column alias:
This PR also simplifies
SQLiteGrammar
andSqlServerGrammar
by usingwrapJsonFieldAndPath()
.