Skip to content

Docs state, that "whereJsonContains" method can be used in SQLite3.38 or higher, but "compileJsonContains" method is not implemented in Illuminate\Database\Query\Grammars\SQLiteGrammar.php #49217

@Sagmedjo

Description

@Sagmedjo

Laravel Version

10.34.2

PHP Version

8.2.3

Database Driver & Version

3.39

Description

When testing I am using sqlite.

When now trying to use the "whenJsonContains" method or any derived method, it throws the error message:
"This database engine does not support JSON contains operations."

In the docs on the other hand you can find this example:

$users = DB::table('users') ->whereJsonContains('options->languages', 'en') ->get();
Right above you can find this text: "You may use whereJsonContains to query JSON arrays. This feature is not supported by SQLite database versions less than 3.38.0:"

SQLite still has no "json_contains" method. Another approach would be to use the json_each method as follows:

SELECT {table}.* from {table}, json_each({table}.{column}, {path}) as {table}{column}Each WHERE {table}{column}Each.value = {value};

It would still have the same restriction, that you can only search for a non array value but it should work

Steps To Reproduce

https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions