christiangerdes's avatar

Can't query json field when testing with sqlite (:inmemory)

Im having issue querying a json field using eloquent when using sqlite for testing.

Here is my code:

return Project::where('data->name', $name)->firstOrFail();

Error:

PDOException: SQLSTATE[HY000]: General error: 1 no such function: json_extract

From what I can tell, I have to enable JSON1 for sqlite, but im not sure... Can someone point me in the right direction?

0 likes
2 replies
Mithrandir's avatar

It is somewhat troublesome. From what I can tell, the JSON1 extension is not enabled by default in PDO Sqlite - and I have not found a way to enable it at runtime when using PDO.

I believe the only way to get this is to compile your own PHP/PDO with json1 enabled, but I have not done so - I simply use a different query when driver is sqlite - this is suboptimal for testing, but it gets the (rest of the) job done

Please or to participate in this conversation.