[9.x] InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database#44196
Merged
taylorotwell merged 8 commits intolaravel:9.xfrom Sep 19, 2022
stevebauman:feature-cast-as-json-grammar
Merged
[9.x] InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database#44196taylorotwell merged 8 commits intolaravel:9.xfrom stevebauman:feature-cast-as-json-grammar
InteractsWithDatabase::castAsJson($value) incorrectly handles SQLite Database#44196taylorotwell merged 8 commits intolaravel:9.xfrom
stevebauman:feature-cast-as-json-grammar
Conversation
browner12
reviewed
Sep 18, 2022
browner12
reviewed
Sep 19, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #43863
This PR implements a
compileJsonCast()method on the base query grammar instance to allow the transformation of a raw JSON string into a "cast" operation compatible with its database.This new method is then called in the
castAsJsontest utility method to generate a proper raw query expression into its compatible operation. Previously,castAsJsonwould only work with MySQL, as other databases do not have the same operation and will either fail, or (in SQLite's case) simply query for the whole operation's text.I've tested these cast functions in where clauses using SQL Fiddle. SQLite and Postgres do not appear to require cast functions to be called on the raw JSON to properly query.
@browner12 Let me know your thoughts on this implementation 👍