Log query events (#33)

Log query events
This commit is contained in:
Jess Archer
2024-06-25 20:20:16 +05:00
committed by GitHub
parent b851f2f398
commit f5f12081af
+19 -2
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace PhpClickHouseLaravel;
use ClickHouseDB\Client;
use Closure;
use Illuminate\Database\Connection as BaseConnection;
class Connection extends BaseConnection
@@ -76,13 +77,17 @@ class Connection extends BaseConnection
{
$query = QueryGrammar::prepareParameters($query);
return $this->client->select($query, $bindings)->rows();
return $this->run($query, $bindings, function ($query, $bindings) {
return $this->client->select($query, $bindings)->rows();
});
}
/** @inheritDoc */
public function statement($query, $bindings = []): bool
{
return !$this->client->write($query, $bindings)->isError();
return $this->run($query, $bindings, function ($query, $bindings) {
return !$this->client->write($query, $bindings)->isError();
});
}
/** @inheritDoc */
@@ -90,4 +95,16 @@ class Connection extends BaseConnection
{
return (int)$this->statement($query, $bindings);
}
/** @inheritDoc */
protected function run($query, $bindings, Closure $callback)
{
$start = microtime(true);
$result = $callback($query, $bindings);
$this->logQuery($query, $bindings, $this->getElapsedTime($start));
return $result;
}
}