ddbcli 0.2.5 → 0.2.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.
data/README CHANGED
@@ -35,14 +35,18 @@ https://bitbucket.org/winebarrel/ddbcli
35
35
  ...
36
36
  shell> ddbcli # show prompt
37
37
 
38
+ == Use DynamoDB Local
39
+
40
+ ddbcli --uri localhost:8000
41
+
38
42
  == Help
39
43
 
40
44
  ##### Query #####
41
45
 
42
- SHOW TABLES
46
+ SHOW TABLES [LIMIT num] [LIKE '...']
43
47
  displays a table list
44
48
 
45
- SHOW TABLE STATUS
49
+ SHOW TABLE STATUS [LIKE '...']
46
50
  displays table statues
47
51
 
48
52
  SHOW REGIONS
@@ -69,7 +73,7 @@ https://bitbucket.org/winebarrel/ddbcli
69
73
  ALTER TABLE table_name READ = num, WRITE = num
70
74
  updates the provisioned throughput
71
75
 
72
- GET {*|attrs} FROM table_name WHERE key1 = '...' AND ...
76
+ GET {*|attr1,attr2,...} FROM table_name WHERE key1 = '...' AND ...
73
77
  gets items
74
78
 
75
79
  INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
@@ -153,10 +157,13 @@ https://bitbucket.org/winebarrel/ddbcli
153
157
  ...
154
158
 
155
159
 
156
- ##### Save #####
160
+ ##### Output to a file #####
161
+
162
+ Overwrite
163
+ SELECT ALL * FROM employees > 'foo.json';
157
164
 
158
- SELECT ALL * FROM employees > 'foo.json';
159
- SELECT ALL * FROM employees >> 'foo.json';
165
+ Append
166
+ SELECT ALL * FROM employees >> 'foo.json';
160
167
 
161
168
 
162
169
  ##### Command #####
data/bin/ddbcli CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
3
 
4
- Version = '0.2.5'
4
+ Version = '0.2.6'
5
5
 
6
6
  HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.ddbcli_history')
7
7
  HISTSIZE = 500
@@ -41,7 +41,7 @@ elsif not $stdin.tty? or options.command
41
41
  end
42
42
 
43
43
  begin
44
- evaluate_query(driver, src)
44
+ evaluate_query(driver, src, :strip => true)
45
45
  rescue => e
46
46
  print_error(e.message)
47
47
  print_error(e.backtrace) if driver.debug
@@ -34,7 +34,7 @@ def evaluate_query(driver, src, opts = {})
34
34
  elapsed = Time.now - start_time
35
35
 
36
36
  if out.kind_of?(DynamoDB::Driver::Rownum)
37
- print_rownum(out, :time => elapsed)
37
+ print_rownum(out, opts.merge(:time => elapsed))
38
38
  elsif out.kind_of?(String)
39
39
  puts out
40
40
  elsif out
@@ -9,7 +9,8 @@ def print_rownum(data, opts = {})
9
9
  rownum = data.to_i
10
10
  msg = "// #{rownum} #{rownum > 1 ? 'rows' : 'row'} changed"
11
11
  msg << " (%.2f sec)" % opts[:time] if opts[:time]
12
- msg << "\n\n"
12
+ msg << "\n"
13
+ msg << "\n" unless opts[:strip]
13
14
  puts msg
14
15
  end
15
16
 
@@ -61,7 +62,7 @@ def print_json(data, out, opts = {})
61
62
  str << "// has more\n"
62
63
  end
63
64
 
64
- str << "\n"
65
+ str << "\n" unless opts[:strip]
65
66
  out.puts(str)
66
67
  end
67
68
 
@@ -73,7 +74,7 @@ def evaluate_command(driver, cmd_arg)
73
74
 
74
75
  commands = {
75
76
  'help' => lambda {
76
- print_help
77
+ print_help(:pagerize => true)
77
78
  },
78
79
 
79
80
  ['exit', 'quit'] => lambda {
@@ -4,10 +4,10 @@ def print_help(options = {})
4
4
  doc =<<EOS
5
5
  ##### Query #####
6
6
 
7
- SHOW TABLES
7
+ SHOW TABLES [LIMIT num] [LIKE '...']
8
8
  displays a table list
9
9
 
10
- SHOW TABLE STATUS
10
+ SHOW TABLE STATUS [LIKE '...']
11
11
  displays table statues
12
12
 
13
13
  SHOW REGIONS
@@ -34,7 +34,7 @@ DROP TABLE table_name
34
34
  ALTER TABLE table_name READ = num, WRITE = num
35
35
  updates the provisioned throughput
36
36
 
37
- GET {*|attrs} FROM table_name WHERE key1 = '...' AND ...
37
+ GET {*|attr1,attr2,...} FROM table_name WHERE key1 = '...' AND ...
38
38
  gets items
39
39
 
40
40
  INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
@@ -117,10 +117,13 @@ Shell
117
117
  {"birth_date"=>"1964-04-30", "emp_no"=>225407,...
118
118
  ...
119
119
 
120
- ##### Save #####
120
+ ##### Output to a file #####
121
121
 
122
- SELECT ALL * FROM employees > 'foo.json';
123
- SELECT ALL * FROM employees >> 'foo.json';
122
+ Overwrite
123
+ SELECT ALL * FROM employees > 'foo.json';
124
+
125
+ Append
126
+ SELECT ALL * FROM employees >> 'foo.json';
124
127
 
125
128
 
126
129
  ##### Command #####
@@ -3,6 +3,7 @@ require 'ddbcli/ddb-parser.tab'
3
3
  require 'ddbcli/ddb-iteratorable'
4
4
 
5
5
  require 'forwardable'
6
+ require 'strscan'
6
7
 
7
8
  module DynamoDB
8
9
  class Driver
@@ -115,10 +116,10 @@ module DynamoDB
115
116
  f.read
116
117
  end
117
118
  when :overwrite
118
- open(script, 'wb') {|f| print_json(retval, f, opts) }
119
+ open(script, 'wb') {|f| print_json(retval, f, opts.merge(:show_rows => false, :strip => true)) }
119
120
  retval = nil
120
121
  when :append
121
- open(script, 'ab') {|f| print_json(retval, f, opts) }
122
+ open(script, 'ab') {|f| print_json(retval, f, opts.merge(:show_rows => false, :strip => true)) }
122
123
  retval = nil
123
124
  else
124
125
  retval
@@ -164,10 +165,11 @@ module DynamoDB
164
165
  private
165
166
 
166
167
  def do_show_tables(parsed)
167
- do_show_tables0(parsed.limit)
168
+ do_show_tables0(parsed.like, parsed.limit)
168
169
  end
169
170
 
170
- def do_show_tables0(limit = nil)
171
+ def do_show_tables0(like, limit = nil)
172
+ like = like ? like_to_regexp(like) : nil
171
173
  req_hash = {}
172
174
  table_names = []
173
175
 
@@ -190,11 +192,11 @@ module DynamoDB
190
192
  end
191
193
  end
192
194
 
193
- return table_names
195
+ return like ? table_names.select {|i| i =~ like } : table_names
194
196
  end
195
197
 
196
198
  def do_show_table_status(parsed)
197
- table_names = do_show_tables0
199
+ table_names = do_show_tables0(parsed.like)
198
200
  h = {}
199
201
 
200
202
  table_names.map do |table_name|
@@ -851,5 +853,29 @@ module DynamoDB
851
853
  end
852
854
  end
853
855
 
856
+ def like_to_regexp(like)
857
+ ss = StringScanner.new(like)
858
+ tok = nil
859
+ regexp = ''
860
+
861
+ until ss.eos?
862
+ if (tok = ss.scan /\\\\/)
863
+ regexp << '\\'
864
+ elsif (tok = ss.scan /\\%/)
865
+ regexp << '%'
866
+ elsif (tok = ss.scan /\\_/)
867
+ regexp << '_'
868
+ elsif (tok = ss.scan /%/)
869
+ regexp << '.*'
870
+ elsif (tok = ss.scan /_/)
871
+ regexp << '.'
872
+ elsif (tok = ss.scan /[^\\%_]+/)
873
+ regexp << tok
874
+ end
875
+ end
876
+
877
+ Regexp.compile("\\A#{regexp}\\Z")
878
+ end
879
+
854
880
  end # Driver
855
881
  end # DynamoDB