Skip to content

InfluxDB Manager

Compare
Choose a tag to compare
@wdalmut wdalmut released this 18 Oct 13:42
· 15 commits to master since this release

In order to supports different database related queries like:

  • create database
  • list database
  • delete database
  • and so on...

We should have to fill the base client InfluxDB\Client with several methods:

public function createDatabase($name) { /* ... */ }
public function deleteDatabase($name) { /* ... */ }
public function getDatabases() { /* ... */ }
public function createRetentionPolicy($name) { /* ... */ }
// ...

As many as InfluxDB prepared queries. Instead of that we drop the database management query from the InfluxDB\Client and add a new layer: InfluxDB\Manager that will support InfluxDB prepared queries.

The manager

$manager = new Manager($client);

The manager accepts any query via callables:

$manager->addQuery("queryName", function($arg1, $arg2) {
    return sprintf("THIS IS MY QUERY WITH: {$arg1} and {$arg2}");
});

// late in your code: 
$manager->queryName(1, 2); // THIS IS MY QUERY WITH: 1 and 2

In order to create and share different database management query, objects can used:

class MyCustomQuery
{
    public function __invoke($arg1, $arg2)
    {
        return sprintf("THIS IS MY QUERY WITH: {$arg1} and {$arg2}");
    }

    public function __toString()
    {
        return "myCustomQuery";
    }
}

// add it
$manager->addQuery(new MyCustomQuery());

// use it
$manager->myCustomQuery(1, 2);