Skip to content

Commit

Permalink
ensure existence of setConnection method
Browse files Browse the repository at this point in the history
  • Loading branch information
Uyan712 committed Jan 23, 2024
1 parent d077e48 commit 37557fc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Colopl\TiDB\Schema\Grammar as SchemaGrammar;
use Illuminate\Database\Grammar;
use Illuminate\Database\MySqlConnection;
use function method_exists;

class Connection extends MySqlConnection
{
Expand All @@ -31,7 +32,10 @@ class Connection extends MySqlConnection
*/
protected function getDefaultQueryGrammar()
{
($grammar = new QueryGrammar)->setConnection($this);
$grammar = new QueryGrammar;
if (method_exists($grammar, 'setConnection')) {
$grammar->setConnection($this);
}

return $this->withTablePrefix($grammar);
}
Expand All @@ -41,7 +45,10 @@ protected function getDefaultQueryGrammar()
*/
protected function getDefaultSchemaGrammar()
{
($grammar = new SchemaGrammar)->setConnection($this);
$grammar = new SchemaGrammar;
if (method_exists($grammar, 'setConnection')) {
$grammar->setConnection($this);
}

return $this->withTablePrefix($grammar);
}
Expand Down

0 comments on commit 37557fc

Please sign in to comment.