From 342fb45377e5e0c053c95e222ddaf45e2ea4cb62 Mon Sep 17 00:00:00 2001 From: Serhii Shpachynskyi Date: Mon, 5 Oct 2020 18:01:46 +0300 Subject: [PATCH] feat: possibility to pass request method to query --- src/InfluxDB/Client.php | 5 +++-- src/InfluxDB/Database.php | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/InfluxDB/Client.php b/src/InfluxDB/Client.php index 14c8c51..28acf6d 100644 --- a/src/InfluxDB/Client.php +++ b/src/InfluxDB/Client.php @@ -155,12 +155,13 @@ public function selectDB($name) * * @param string $database * @param string $query + * @param string $method * @param array $parameters * * @return ResultSet * @throws Exception */ - public function query($database, $query, $parameters = []) + public function query($database, $query, $parameters = [], $method = 'get') { $driver = $this->getDriver(); @@ -175,7 +176,7 @@ public function query($database, $query, $parameters = []) $parameters = [ 'url' => 'query?' . http_build_query(array_merge(['q' => $query], $parameters)), 'database' => $database, - 'method' => 'get' + 'method' => $method ]; // add authentication to the driver if needed diff --git a/src/InfluxDB/Database.php b/src/InfluxDB/Database.php index e730aff..c75f4e1 100644 --- a/src/InfluxDB/Database.php +++ b/src/InfluxDB/Database.php @@ -70,12 +70,13 @@ public function getName() * * @param string $query * @param array $params + * @param string $method * @return ResultSet * @throws Exception */ - public function query($query, $params = []) + public function query($query, $params = [], $method = 'get') { - return $this->client->query($this->name, $query, $params); + return $this->client->query($this->name, $query, $params, $method); } /** @@ -94,7 +95,7 @@ public function create(RetentionPolicy $retentionPolicy = null, $createIfNotExis try { $query = sprintf('CREATE DATABASE "%s"', $this->name); - $this->query($query); + $this->query($query, [], 'post'); if ($retentionPolicy) { $this->createRetentionPolicy($retentionPolicy); @@ -114,7 +115,7 @@ public function create(RetentionPolicy $retentionPolicy = null, $createIfNotExis */ public function createRetentionPolicy(RetentionPolicy $retentionPolicy) { - return $this->query($this->getRetentionPolicyQuery('CREATE', $retentionPolicy)); + return $this->query($this->getRetentionPolicyQuery('CREATE', $retentionPolicy), [], 'post'); } /** @@ -193,7 +194,7 @@ public function exists() */ public function alterRetentionPolicy(RetentionPolicy $retentionPolicy) { - $this->query($this->getRetentionPolicyQuery('ALTER', $retentionPolicy)); + $this->query($this->getRetentionPolicyQuery('ALTER', $retentionPolicy), [], 'post'); } /** @@ -210,7 +211,7 @@ public function listRetentionPolicies() */ public function drop() { - $this->query(sprintf('DROP DATABASE "%s"', $this->name)); + $this->query(sprintf('DROP DATABASE "%s"', $this->name), [], 'post'); } /**