[8.x] Add computed column support (storedAs, virtualAs) to SQLite #33618
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.
This PR adds the ability to use computed columns –
storedAs
andvirtualAs
– in SQLite.Since version 3.31.0, which released on 2020-01-22, SQLite supports computed columns.
Supporting features like useful JSON functions or computed columns can help developers to build or test concepts or ideas. Of course, in production SQLite is not the best choice. But for quickly testing an idea or a concept it can be a nice tool, especially because it's fast and no configuration – or very little – is needed.
The
Blueprint
syntax is the same as in case of MySQL, however, due to its limitations, some modification is required:default()
method on the column definition, in case if it's a computed column, thedefault
clause will be omitted from the SQL.alter table add column
clause that contains theas (...) stored
string will be omitted from the SQL.The syntax is the same as for MySQL:
This feature requires SQLite
3.31.0
or higher. According to the documentation, Laravel supports SQLite3.8.8
– which released on 2015-01-16, more than 5 years ago – or higher. As I mentioned, we already support various JSON functionality for SQLite, which requires at least3.9.0
. So the documentation is incorrect about the required version currently.Since probably no one uses SQLite in production and using homebrew it can be updated easily on a local machine, it might worth bumping the minimum supported version of SQLite for Laravel 8.x, especially if we could gain features like computed columns.
If this PR gets merged, I'll create a PR for the documentation to update the minimum required version (and the migration guide as well?).