Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Query/Grammars/MariaDbGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public function compileJoinLateral(JoinLateralClause $join, string $expression):
throw new RuntimeException('This database engine does not support lateral joins.');
}

/**
* Compile a "JSON value cast" statement into SQL.
*
* @param string $value
* @return string
*/
public function compileJsonValueCast($value)
{
return "json_query({$value}, '$')";
}

/**
* Determine whether to use a legacy group limit clause for MySQL < 8.0.
*
Expand Down
24 changes: 24 additions & 0 deletions tests/Testing/Concerns/InteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Query\Grammars\MariaDbGrammar;
use Illuminate\Database\Query\Grammars\MySqlGrammar;
use Illuminate\Database\Query\Grammars\PostgresGrammar;
use Illuminate\Database\Query\Grammars\SQLiteGrammar;
Expand Down Expand Up @@ -119,6 +120,29 @@ public function testCastToJsonMySql()
);
}

public function testCastToJsonMariaDb()
{
$grammar = new MariaDbGrammar();

$this->assertEquals(<<<'TEXT'
json_query('["foo","bar"]', '$')
TEXT,
$this->castAsJson(['foo', 'bar'], $grammar)
);

$this->assertEquals(<<<'TEXT'
json_query('["foo","bar"]', '$')
TEXT,
$this->castAsJson(collect(['foo', 'bar']), $grammar)
);

$this->assertEquals(<<<'TEXT'
json_query('{"foo":"bar"}', '$')
TEXT,
$this->castAsJson((object) ['foo' => 'bar'], $grammar)
);
}

protected function castAsJson($value, $grammar)
{
$connection = m::mock(ConnectionInterface::class);
Expand Down