influxdb-cli 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38b568164a56da1eae7c93bbcde1166c19f2faa1
4
- data.tar.gz: 548d3721361e117c98f497e6d6201d07733f85ea
3
+ metadata.gz: 99c5faca92da1f2362bcd999e8007d92d3b91e82
4
+ data.tar.gz: 7eee7f66b1b30f644d1a9b29c51142bdb909e989
5
5
  SHA512:
6
- metadata.gz: af16d981b18cae9e55794bbd2c4cdde9857ee1a947480591d49c76e4f6c66d71f177afe3bb0a863ac99595d7ec27cde6297f859f3983e8e4ab7cea19459db906
7
- data.tar.gz: 2c37000746bd70fb357e99ef5fd846f7faaf30c4d1d0245e58f04f91dcff03ba1f0f81f5121dcbda7be35ee3e32caa3aee453c5f5cdf163e020c1deaab4aa472
6
+ metadata.gz: 7839991a77721868443e099662cf3aec93a14a883158594c09584fbb7dbff239b2a7c86649558a1eeb359654950d522a61898b55cbec6a15d3b26086be0fd4b3
7
+ data.tar.gz: 0b9b02d642bbe109775e395499ac63e01030ca426d3b28aa813f6770e344236babcbc1377008bbb98c0687239041378d09e22c7c3b9571eb893efe5de9e3b93b
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  InfluxDB-CLI
2
2
  ============
3
3
 
4
- Ruby CLI for InfluxDB is a simple Ruby console (empowered with [Pry](https://github.com/pry/pry)) connected to an InfluxDB server with supplied parameters. In order to connect to InfluxDB, it uses [influxdb-ruby](https://github.com/influxdb/influxdb-ruby), so you can access any avaiable method from influxdb-ruby in the console through the `db` variable i.e.: `db.write_point(name, data)`, `db.query('SELECT value FROM response_times')` etc.
4
+ Ruby CLI for InfluxDB is a simple Ruby console (empowered with [Pry](https://github.com/pry/pry)) connected to an InfluxDB server using given parameters. In order to connect to InfluxDB, it uses [influxdb-ruby](https://github.com/influxdb/influxdb-ruby), so you can access any avaiable method from influxdb-ruby in the console through the `db` variable i.e.: `db.write_point(name, data)`, `db.query('SELECT value FROM response_times')` etc.
5
5
 
6
6
  [![Build Status](https://secure.travis-ci.org/phstc/influxdb-cli.png)](http://travis-ci.org/phstc/influxdb-cli)
7
7
 
@@ -43,7 +43,7 @@ or
43
43
 
44
44
  ```shell
45
45
  influxdb-cli -u user -p password -d database -h sandbox.influxdb.org --port 9061
46
- Connecting to {"host"=>"sandbox.influxdb.org", "port"=>"9061", "username"=>"phstc", "password"=>"RggLimEQfK36or", "database"=>"spree"}
46
+ Connecting to {"host"=>"sandbox.influxdb.org", "port"=>"9061", "username"=>"username", "password"=>"password", "database"=>"database"}
47
47
  ✔ ready
48
48
  ```
49
49
 
data/bin/influxdb-cli CHANGED
@@ -48,7 +48,9 @@ def db; InfluxDBClientTasks.db; end
48
48
  # i.e. query('select value from response_times')
49
49
  #
50
50
  # @see InfluxDB::Client#query
51
+ # @see InfluxDBClient::Client.print_tabularize
51
52
  #
53
+ # @param query [String] the query
52
54
  # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
53
55
  def query(query)
54
56
  result = db.query(query)
@@ -4,13 +4,19 @@ module InfluxDBClient
4
4
  class Client
5
5
  QUERY_LANGUAGE_MATCHER = /\A\s*((delete\s+from|select\s+.+\s+from)\s.+)\z/i
6
6
 
7
+ # Prints a tabularized output from a query result.
8
+ #
9
+ # @param result [Hash] the {InfluDB::Client#query result}
10
+ # @param output [STDOUT] the output to `puts` the results
11
+ # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
7
12
  def self.print_tabularize(result, output=$stdout)
8
13
  number_of_points = {}
9
14
  result.keys.each do |series|
10
- headings = result[series].first.keys
11
- rows = result[series].collect(&:values)
12
- table = Terminal::Table.new title: series, headings: headings, rows: rows
13
- output.puts table
15
+ if result[series].any?
16
+ output.puts generate_table(series, result)
17
+ else
18
+ output.puts "No results found for #{series}"
19
+ end
14
20
  # empty line between time series output
15
21
  output.puts
16
22
  # count total per time series
@@ -18,6 +24,15 @@ module InfluxDBClient
18
24
  end
19
25
  number_of_points
20
26
  end
27
+
28
+ private
29
+
30
+ def self.generate_table(series, result)
31
+ headings = result[series].first.keys
32
+ rows = result[series].collect(&:values)
33
+
34
+ Terminal::Table.new title: series, headings: headings, rows: rows
35
+ end
21
36
  end
22
37
  end
23
38
 
@@ -1,3 +1,3 @@
1
1
  module InfluxDBClient
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -56,6 +56,30 @@ module InfluxDBClient
56
56
 
57
57
  described_class.print_tabularize(result, output)
58
58
  end
59
+
60
+ context 'when empty results' do
61
+ let(:result) { { series1: [{ value1: 1, value2: 2 }],
62
+ series2: [] } }
63
+
64
+ it 'puts no results found' do
65
+ output = double 'Output'
66
+ table = double 'Table'
67
+ Terminal::Table.stub(new: table)
68
+
69
+ # should print series1
70
+ expect(output).to receive(:puts).once.with(table)
71
+ # no results for series 2
72
+ expect(output).to receive(:puts).once.with('No results found for series2')
73
+ # line break for series
74
+ expect(output).to receive(:puts).twice.with(no_args)
75
+
76
+ described_class.print_tabularize(result, output)
77
+ end
78
+
79
+ it 'returns series count' do
80
+ expect(described_class.print_tabularize(result)).to eq({ 'series1.count' => 1, 'series2.count' => 0 })
81
+ end
82
+ end
59
83
  end
60
84
  end
61
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero