This database engine does not support JSON contains operations.
public function __construct(?string $name = null, array $data = [], string $dataName = '') { parent::__construct($name, $data, $dataName); $this->iWannaMethodJsonContainsInSqlite(); } public function iWannaMethodJsonContainsInSqlite() { \Illuminate\Database\Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) { return new class($connection, $database, $prefix, $config) extends \Illuminate\Database\SQLiteConnection { protected function getDefaultQueryGrammar() { $this->getPdo()->sqliteCreateFunction('JSON_CONTAINS', function ($json, $val, $path = null) { $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR); $val = trim($val, '"'); if ($path) { return $array[$path] == $val; } return in_array($val, $array, false); }); return new class extends \Illuminate\Database\Query\Grammars\SQLiteGrammar { protected function compileJsonContains($column, $value) { [$field, $path] = $this->wrapJsonFieldAndPath($column); return 'json_contains(' . $field . ', ' . $value . $path . ')'; } }; } }; }); }
And thanks: https://stackoverflow.com/questions/50535778/php-testing-json-contains-with-sqlite/50536534
Комментарии
Отправить комментарий