From c7d30ae8bbbb7aeecf8ae6324ce097163231d65f Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Tue, 11 Jul 2023 20:23:33 +0200 Subject: [PATCH] feat: support raw sql --- src/Payloads/ExecutedQueryPayload.php | 9 ++++++++- src/Payloads/QueryPayload.php | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Payloads/ExecutedQueryPayload.php b/src/Payloads/ExecutedQueryPayload.php index 5173538..ba022c9 100644 --- a/src/Payloads/ExecutedQueryPayload.php +++ b/src/Payloads/ExecutedQueryPayload.php @@ -22,7 +22,14 @@ public function getType(): string public function getContent(): array { - $properties = [ + $grammar = $this->query->connection->getQueryGrammar(); + + $properties = method_exists($grammar, 'substituteBindingsIntoRawSql') ? [ + 'sql' => $grammar->substituteBindingsIntoRawSql( + $this->query->sql, + $this->query->connection->prepareBindings($this->query->bindings) + ), + ] : [ 'sql' => $this->query->sql, 'bindings' => $this->query->bindings, ]; diff --git a/src/Payloads/QueryPayload.php b/src/Payloads/QueryPayload.php index 18e7ccb..f130914 100644 --- a/src/Payloads/QueryPayload.php +++ b/src/Payloads/QueryPayload.php @@ -22,6 +22,12 @@ public function getType(): string public function getContent(): array { + if (method_exists($this->query, 'toRawSql')) { + return [ + 'sql' => $this->query->toRawSql(), + ]; + } + return [ 'sql' => $this->query->toSql(), 'bindings' => $this->query->getBindings(),