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

[12.x] Add support for native JSON/JSONB column types in SQLite Schema builder #54984

Closed
wants to merge 2 commits into from

Conversation

fuwasegu
Copy link
Contributor

Overview

SQLite has supported JSON data type as a built-in feature since version 3.38.0, but prior to that, users needed to opt-in by installing an extension.
Additionally, native support for JSONB type began with version 3.45.
Since Laravel 12 supports SQLite 3.26.0 and above, it should not be designed with the assumption that JSON/JSONB support is always available.
While Query\Grammars\SQLiteGrammar::class includes support for JSON functions, Schema\Grammars\SQLiteGrammar::class does not offer this option.
This PullRequest allows injecting configuration from the database connection config to enable the use of native JSON columns when defining Schema.

Details

This feature allows the following configuration in config/database.php:

'sqlite' => [
    'driver' => 'sqlite',
    'url' => env('DATABASE_URL'),
    ...,
    'schema' => [
    	'use_native_json' => true,
    	'use_native_jsonb' => true,
    ],
],

JSON

By setting schema.use_native_json in a connection with sqlite driver, the following DDL changes will occur:

schema.use_native_json = false (default)

Schema::create('sample', function (Blueprint $table) {
    $table->json('column_1');
});
create table sample
(
    column_1 text not null
);

schema.use_native_json = true

Schema::create('sample', function (Blueprint $table) {
    $table->json('column_1');
});
create table sample
(
    column_1 json not null
);

JSONB

The same applies to JSONB:

schema.use_native_jsonb = false (default)

Schema::create('sample', function (Blueprint $table) {
    $table->jsonb('column_1');
});
create table sample
(
    column_1 text not null
);

schema.use_native_jsonb = true

Schema::create('sample', function (Blueprint $table) {
    $table->jsonb('column_1');
});
create table sample
(
    column_1 jsonb not null
);

@fuwasegu fuwasegu changed the title [12.x] Add support for native JSON/JSONB column types in Schema builder [12.x] Add support for native JSON/JSONB column types in SQLite Schema builder Mar 12, 2025
@taylorotwell
Copy link
Member

Your PR has a var_dump.

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