Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setHelperSet($this->getApplication()->getHelperSet());
     $db = $input->getOption("db");
     $query = $input->getOption("execute");
     $port = $input->getOption("port");
     $host = $input->getOption("host");
     $user = $input->getOption("user");
     $password = $input->getOption("password");
     $verbose = $input->getOption("verbose");
     $c = new Client(sprintf("http://%s:%s", $host, $port), $user, $password, $db);
     if ($verbose) {
         $c->setDebug(true);
     }
     $dialog = $this->getHelperSet()->get('dialog');
     try {
         ///$query = $dialog->ask($output, sprintf('influx: %s> ', $db));
         $begin = microtime(true);
         $result = $c->query($query);
         $end = microtime(true);
         if (empty($result)) {
             $output->writeln(sprintf("Empty set (%f sec)", round($end - $begin, 4)));
             return;
         }
         $total = 0;
         foreach ($result as $chunk) {
             $keys = $chunk->getColumns();
             $table = $this->getHelperSet()->get('table');
             $table->setHeaders($keys);
             $table->setRows($chunk->getPoints());
             $table->render($output);
             $total += count($chunk);
         }
         $output->writeln(sprintf("%d rows in set (%f sec)", $total, round($end - $begin, 4)));
     } catch (\Exception $e) {
         $output->writeln($e->getMessage());
     }
 }