influxdb-cli 0.1.0 → 0.1.1

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: f7a4f8e0419999de09aa047254204462f8150b6d
4
- data.tar.gz: f468e14d522630cc1e4b6de1970e3484ba2b8051
3
+ metadata.gz: 281b2fa707050411c4122d9d0baec8bb71eb7df9
4
+ data.tar.gz: 7c8db30a7593ce61d5568b736db0e14d5a89deea
5
5
  SHA512:
6
- metadata.gz: 83f22cfbe7d9c64fb8189cf2b37f0dbbf66db33aef45d658e251c77179fca54c18a0b6ffa79d57d439c7a65eea83e1be17d9034e6432c19e5992e1615162a723
7
- data.tar.gz: 714a92645856fecd8e2cc3f8b85ef0ab3e6bdce44c7183c4ce274e214834ed235235a7c18a1969f8b0e8951fbdeae4e5d77a528652f90ec5df9ef35e683ee7d8
6
+ metadata.gz: 0755bf563ec3a8bcf1d3253b833f76668ac72e67f474cdaa6304e2247cc0cb17b292f601830bf6676eee4deba3e356185182d6b328e2d4fa7ba64f076050f2a6
7
+ data.tar.gz: ebb47210f603cad89deee719c23681db14695a999c39a8218922972b0ca75d38f57f42dbc74aed8a81ac80a89edee192e618130a91fd847f3321da149dd3b095
data/README.md CHANGED
@@ -31,10 +31,10 @@ Options:
31
31
 
32
32
  ### Usage
33
33
 
34
- Connect to a database:
34
+ #### Connect to a database
35
35
 
36
36
  ```shell
37
- influxdb-cli
37
+ $ influxdb-cli
38
38
  Connecting to {"host"=>"localhost", "port"=>8086, "username"=>"root", "password"=>"root", "database"=>"db"}
39
39
  ✔ ready
40
40
  ```
@@ -42,16 +42,63 @@ Connecting to {"host"=>"localhost", "port"=>8086, "username"=>"root", "password"
42
42
  or
43
43
 
44
44
  ```shell
45
- influxdb-cli -u user -p password -d database -h sandbox.influxdb.org --port 9061
45
+ $ influxdb-cli -u user -p password -d database -h sandbox.influxdb.org --port 9061
46
46
  Connecting to {"host"=>"sandbox.influxdb.org", "port"=>"9061", "username"=>"username", "password"=>"password", "database"=>"database"}
47
47
  ✔ ready
48
48
  ```
49
49
 
50
50
  [InfluxDB Playground](http://play.influxdb.org) :metal:
51
51
 
52
- Query with a [tabularized](https://github.com/visionmedia/terminal-table) output:
52
+ #### Create a database and user
53
53
 
54
- ```shell
54
+ ```ruby
55
+ 2.0.0 (main)> db.create_database 'db'
56
+ 2.0.0 (main)> db.create_database_user 'db', 'root', 'root'
57
+ ```
58
+
59
+ #### List databases
60
+
61
+ ```ruby
62
+ 2.0.0 (main)> db.get_database_list
63
+ ```
64
+
65
+ #### Switch databases
66
+
67
+ ```ruby
68
+ 2.0.0 (main)> use other_database
69
+ 2.0.0 (main)> db.database
70
+ => "other_database"
71
+ ```
72
+
73
+ #### Write a point
74
+
75
+ ```ruby
76
+ 2.0.0 (main)> db.write_point('test', { message: 'Hello Pablo' })
77
+
78
+ 2.0.0 (main)> SELECT * FROM test
79
+
80
+ +---------------+-----------------+-------------+
81
+ | test |
82
+ +---------------+-----------------+-------------+
83
+ | time | sequence_number | message |
84
+ +---------------+-----------------+-------------+
85
+ | 1387287723816 | 1 | Hello Pablo |
86
+ +---------------+-----------------+-------------+
87
+ 1 result found for test
88
+
89
+ Query duration: 0.0s
90
+ ```
91
+
92
+ #### Return the last point from every time series in the database
93
+
94
+ ```ruby
95
+ 2.0.0 (main)> SELECT * FROM /.*/
96
+ ```
97
+
98
+
99
+ #### Query with a [tabularized output](https://github.com/visionmedia/terminal-table)
100
+
101
+ ```ruby
55
102
  2.0.0 (main)> SELECT * FROM deploys
56
103
  +---------------+-----------------+-----------------+--------+-----------------+-------------------+----------+
57
104
  | deploys |
@@ -61,15 +108,14 @@ Query with a [tabularized](https://github.com/visionmedia/terminal-table) output
61
108
  | ... | ... | ... | ... | ... | ... | ... |
62
109
  +---------------+-----------------+-----------------+--------+-----------------+-------------------+----------+
63
110
 
64
- => {
65
- "deploys.count" => 1
66
- }
67
- ```
111
+ 1 result found for deploys
68
112
 
113
+ Query duration: 0.49s
114
+ ```
69
115
 
70
- Query with a Ruby Hash output ([awesome_print](https://github.com/michaeldv/awesome_print)):
116
+ #### Query with a [Ruby Hash output](https://github.com/michaeldv/awesome_print)
71
117
 
72
- ```shell
118
+ ```ruby
73
119
  2.0.0 (main)> db.query('SELECT * FROM deploys')
74
120
  => {
75
121
  "deploys" => [
@@ -84,9 +130,9 @@ Query with a Ruby Hash output ([awesome_print](https://github.com/michaeldv/awes
84
130
  },
85
131
  ```
86
132
 
87
- Other methods:
133
+ #### Other methods
88
134
 
89
- ```shell
135
+ ```ruby
90
136
  2.0.0 (main)> db.write_point(name, data)
91
137
  2.0.0 (main)> db.get_database_list
92
138
  2.0.0 (main)> ls -q db
@@ -101,7 +147,9 @@ instance variables: @database @host @http @password @port @queue @username
101
147
 
102
148
  As influxdb-cli is empowered with Pry, all Pry awesome commands are avaiable in the console.
103
149
 
104
- ```shell
150
+ #### show-source
151
+
152
+ ```ruby
105
153
  2.0.0 (main)> show-source InfluxDB::Client#query
106
154
 
107
155
  From: /Users/pablo/.gem/ruby/2.0.0/gems/influxdb-0.0.11/lib/influxdb/client.rb @ line 152:
@@ -128,7 +176,9 @@ def query(query)
128
176
  end
129
177
  ```
130
178
 
131
- ```shel
179
+ #### show-doc
180
+
181
+ ```ruby
132
182
 
133
183
  2.0.0 (main)> show-doc InfluxDB::Client#initialize
134
184
 
@@ -12,7 +12,9 @@ require 'influxdb_client/version'
12
12
  require 'influxdb_client/client'
13
13
 
14
14
  class InfluxDBClientTasks < Thor
15
- desc 'db', 'Connect to InfluxDB'
15
+ @@db = nil
16
+
17
+ desc 'db', 'Connect to InfluxDB (default command)'
16
18
  method_option :host, :default => 'localhost', :aliases => '-h', :desc => 'Hostname'
17
19
  method_option :port, :default => 8086, :desc => 'Port'
18
20
  method_option :username, :default => 'root', :aliases => '-u', :desc => 'Username'
@@ -28,13 +30,11 @@ class InfluxDBClientTasks < Thor
28
30
  desc 'version', 'Show influxdb-cli version'
29
31
  def version
30
32
  puts "influxdb-cli #{InfluxDBClient::VERSION}"
31
- # skip `pry` console
32
- exit 0
33
33
  end
34
34
 
35
35
  def self.db; @@db; end
36
36
 
37
- default_task :db
37
+ default_command :db
38
38
  end
39
39
 
40
40
  # Returns {InfluxDB::Client} instance using given parameters.
@@ -44,11 +44,14 @@ def db; InfluxDBClientTasks.db; end
44
44
 
45
45
  InfluxDBClientTasks.start
46
46
 
47
+ # exit if the db command wasn't called
48
+ exit 0 unless db
49
+
47
50
  # allow typing queries directly from console i.e.`select * from deploys` instead of `query('select * from deploys')`.
48
51
  # matches `delete from ...` and `select ... from ...`
49
- Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Execute a query' do |cmd|
52
+ Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Execute a query' do |query|
50
53
  start = Time.now
51
- result = db.query(cmd)
54
+ result = db.query(query)
52
55
  duration = Time.now - start
53
56
 
54
57
  InfluxDBClient::Client.print_tabularize(result)
@@ -57,6 +60,11 @@ Pry::Commands.block_command InfluxDBClient::Client::QUERY_LANGUAGE_MATCHER, 'Exe
57
60
  puts "Query duration: #{duration.round(2)}s"
58
61
  end
59
62
 
63
+ # switch databases `use db_name`
64
+ Pry::Commands.block_command InfluxDBClient::Client::SWITCH_DATABASE_MATCHER, 'Switch databases' do |db_name|
65
+ db.database = db_name
66
+ end
67
+
60
68
  # awesome_print
61
69
  Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
62
70
 
@@ -2,7 +2,8 @@ require 'terminal-table'
2
2
 
3
3
  module InfluxDBClient
4
4
  class Client
5
- QUERY_LANGUAGE_MATCHER = /\A\s*((delete\s+from|select\s+.+\s+from)\s.+)\z/i
5
+ QUERY_LANGUAGE_MATCHER = /\A\s*((delete\s+from|select\s+.+\s+from)\s.+)\z/i
6
+ SWITCH_DATABASE_MATCHER = /\A\s*use\s+(\S+)\s*\z/i
6
7
 
7
8
  # Prints a tabularized output from a query result.
8
9
  #
@@ -10,9 +11,15 @@ module InfluxDBClient
10
11
  # @param output [STDOUT] the output to `puts` the results
11
12
  # @return [Hash] the number of points per time series i.e. { 'response_times.count' => 10 }
12
13
  def self.print_tabularize(result, output=$stdout)
13
- (result || {}).keys.each do |series|
14
- result_series = result[series]
14
+ result ||= {}
15
+
16
+ if result.keys.empty?
17
+ output.puts 'No results found'
18
+ return
19
+ end
15
20
 
21
+ result.keys.each do |series|
22
+ result_series = result[series]
16
23
  if result_series.any?
17
24
  output.puts generate_table(series, result_series)
18
25
  output.puts "#{result_series.size} #{pluralize(result_series.size, 'result')} found for #{series}"
@@ -1,3 +1,3 @@
1
1
  module InfluxDBClient
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -25,6 +25,17 @@ module InfluxDBClient
25
25
  end
26
26
  end
27
27
 
28
+ describe '.SWITCH_DATABASE_MATCHER' do
29
+ subject { Client::SWITCH_DATABASE_MATCHER }
30
+ it { should match('use response_times') }
31
+ it { should match(' use response_times ') }
32
+
33
+ it { should_not match('use') }
34
+ it { should_not match(' use ') }
35
+ it { should_not match('use response_times tests') }
36
+ it { should_not match('useresponse_times') }
37
+ end
38
+
28
39
  describe '.print_tabularize' do
29
40
  let(:result) { { series1: [{ value1: 1, value2: 2 }],
30
41
  series2: [{ value3: 3, value4: 4, value5: nil, value6: nil },
@@ -56,11 +67,18 @@ module InfluxDBClient
56
67
  described_class.print_tabularize(result, output)
57
68
  end
58
69
 
59
- context 'when empty results' do
70
+ context 'when no results' do
60
71
  let(:result) { { series1: [{ value1: 1, value2: 2 }],
61
72
  series2: [] } }
62
73
 
63
- it 'prints no results found' do
74
+ it 'prints generic no results found' do
75
+ output = double 'Output'
76
+ result = {}
77
+ expect(output).to receive(:puts).once.with('No results found')
78
+ described_class.print_tabularize(result, output)
79
+ end
80
+
81
+ it 'prints specific no results found per series' do
64
82
  output = double 'Output'
65
83
  table = double 'Table'
66
84
  Terminal::Table.stub(new: table)
@@ -77,6 +95,15 @@ module InfluxDBClient
77
95
  described_class.print_tabularize(result, output)
78
96
  end
79
97
  end
98
+
99
+ context 'when result is null' do
100
+ it 'prints generic no results found' do
101
+ output = double 'Output'
102
+ result = nil
103
+ expect(output).to receive(:puts).once.with('No results found')
104
+ described_class.print_tabularize(result, output)
105
+ end
106
+ end
80
107
  end
81
108
  end
82
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-15 00:00:00.000000000 Z
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: influxdb