Skip to content

Commit 18bc9f4

Browse files
committed
chore: use backported toRawSql functionality
1 parent 2c38d61 commit 18bc9f4

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

src/Support/Helpers/Query.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
namespace Tpetry\PostgresqlEnhanced\Support\Helpers;
66

7-
use Illuminate\Database\Connection;
87
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
98
use Illuminate\Database\Query\Builder as QueryBuilder;
10-
use RuntimeException;
119

1210
class Query
1311
{
@@ -20,29 +18,8 @@ public static function toSql(EloquentBuilder|QueryBuilder|string $query): string
2018
return $query;
2119
}
2220

23-
/** @var Connection $connection */
24-
$connection = $query->getConnection();
25-
26-
$bindings = $connection->prepareBindings($query->getBindings());
27-
$sql = preg_replace_callback('/(?<!\?)\?(?!\?)/', function () use (&$bindings, $connection) {
28-
if (0 === \count($bindings)) {
29-
throw new RuntimeException('Number of bindings does not match the number of placeholders');
30-
}
31-
32-
$value = array_shift($bindings);
33-
34-
return (string) match (true) {
35-
null === $value => 'null',
36-
\is_bool($value) => $value ? 'true' : 'false',
37-
is_numeric($value) => $value,
38-
default => $connection->getPdo()->quote((string) $value),
39-
};
40-
}, $query->toSql());
41-
42-
if (\count($bindings) > 0) {
43-
throw new RuntimeException('Number of bindings does not match the number of placeholders');
44-
}
45-
46-
return $sql;
21+
return $query->getGrammar()->substituteBindingsIntoRawSql(
22+
$query->toSql(), $query->getConnection()->prepareBindings($query->getBindings())
23+
);
4724
}
4825
}

0 commit comments

Comments
 (0)