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

[8.x] Add invisible modifier for MySQL columns #40002

Merged

Conversation

lupinitylabs
Copy link
Contributor

This PR adds support for the new invisible modifier for columns introduced in MySQL 8.0.23: https://dev.mysql.com/doc/refman/8.0/en/invisible-columns.html

Columns marked as invisible are not implicitly selected by SELECT * and therefore, the columns will also not be automatically hydrated in a Laravel model. Those columns can still be selected explicitly, however, making it useful for columns that contain data that should only be fetched if really needed.

A concrete use case might be a model that contains several big JSON structures (e.g. with translation strings in multiple languages), but you only want to select specific keys out of those structures (only translations for the current language and a fallback language, for example). If you always fetched the whole translation structure, a lot of bandwidth and memory are wasted, and you will quickly run into sort buffer limits (which is the main reason why I would love to see this supported).

With this, you can use a new ->invisible() method on the table Blueprint:

Schema::table('users', function (Blueprint $table) {
    $table->string('secret')->nullable()->invisible();
});

This feature is not available in PostgreSQL and I am not aware of any other DBMS supporting this.
I am not sure if you want any modifiers in that are not widely supported, so this is only a suggestion.

However, I do not see an easy way to turn this into a package?

@GrahamCampbell GrahamCampbell changed the title [8.x] Add invisible modifier for MySQL columns. [8.x] Add invisible modifier for MySQL columns Dec 12, 2021
@taylorotwell taylorotwell merged commit 6ffc63a into laravel:8.x Dec 13, 2021
jaulz pushed a commit to jaulz/framework that referenced this pull request Dec 14, 2021
* add invisible modifier for MySQL columns.

* Update ColumnDefinition.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
@ahmedsayedabdelsalam
Copy link
Contributor

how to retrieve invisible columns for queued jobs?

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.

3 participants