Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add JSON grammar support to MySQL and SQLite schema usage #36510

Merged
merged 1 commit into from
Apr 1, 2021
Merged

[9.x] Add JSON grammar support to MySQL and SQLite schema usage #36510

merged 1 commit into from
Apr 1, 2021

Conversation

LarsGrevelink
Copy link
Contributor

Targets #36343 and laravel/ideas#2500. Now targets master due to the required change of the migrations as discussed in pull request #36363.

Adds JSON support for the Schema grammar when using them in virtual or stored columns. This makes the behaviour of referencing JSON columns the same as the Query grammar supports. Added support for both SQLite and MySQL since I was able to test these in real-life scenarios.

The current way of working with JSON data in columns requires to be e.g. MySQL specific;

Schema::table('my_table', function (Blueprint $table) {
    $table->string('my_extracted_value')->virtualAs('json_field->>"$.extract_me"');
});

This pull request applies the same grammar as the query grammar, already used within Laravel;

Schema::table('my_table', function (Blueprint $table) {
    $table->string('my_extracted_value')->virtualAs('json_field->extract_me');
});

If there are any questions related to the changes, please let me know.

- Move JSON related functions from query grammar to base grammar
- Add JSON wrap functions to schema grammar
- Add JSON support for MySQL and SQLite for virtualAs and storedAs columns
@taylorotwell taylorotwell merged commit 6f41768 into laravel:master Apr 1, 2021
@taylorotwell
Copy link
Member

Renamed methods to virtualAsJson and storedAsJson so that people can still drop-down to raw behavior if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants