From 3c1d62d55c0f29bb9597c48de2ab8ed8253880d4 Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Wed, 12 Jul 2023 22:48:22 +0200 Subject: [PATCH] Support Laravel's new toRawSql() --- src/Query/Traits/BuildsExpressionQueries.php | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Query/Traits/BuildsExpressionQueries.php b/src/Query/Traits/BuildsExpressionQueries.php index c0872fe..f038a43 100644 --- a/src/Query/Traits/BuildsExpressionQueries.php +++ b/src/Query/Traits/BuildsExpressionQueries.php @@ -69,18 +69,20 @@ protected function getQueryGrammar(Connection $connection) { $driver = $connection->getDriverName(); - switch ($driver) { - case 'mysql': - return new MySqlGrammar(); - case 'pgsql': - return new PostgresGrammar(); - case 'sqlite': - return new SQLiteGrammar(); - case 'sqlsrv': - return new SqlServerGrammar(); + $grammar = match ($driver) { + 'mysql' => new MySqlGrammar(), + 'pgsql' => new PostgresGrammar(), + 'sqlite' => new SQLiteGrammar(), + 'sqlsrv' => new SqlServerGrammar(), + default => throw new RuntimeException('This database is not supported.'), // @codeCoverageIgnore + }; + + // TODO[L11] + if (method_exists($grammar, 'setConnection')) { + $grammar->setConnection($connection); } - throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore + return $grammar; } /**