ddbcli 0.2.4 → 0.2.5

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
@@ -116,6 +116,9 @@ https://bitbucket.org/winebarrel/ddbcli
116
116
  Identifier
117
117
  `ABCD...` or Non-keywords
118
118
 
119
+ Array
120
+ ('String', 'String', ...), (1, 2, 3, ...)
121
+
119
122
 
120
123
  ##### Operator #####
121
124
 
@@ -150,6 +153,12 @@ https://bitbucket.org/winebarrel/ddbcli
150
153
  ...
151
154
 
152
155
 
156
+ ##### Save #####
157
+
158
+ SELECT ALL * FROM employees > 'foo.json';
159
+ SELECT ALL * FROM employees >> 'foo.json';
160
+
161
+
153
162
  ##### Command #####
154
163
 
155
164
  .help displays this message
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.4'
4
+ Version = '0.2.5'
5
5
 
6
6
  HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.ddbcli_history')
7
7
  HISTSIZE = 500
@@ -30,7 +30,7 @@ def evaluate_query(driver, src, opts = {})
30
30
  end
31
31
 
32
32
  start_time = Time.new
33
- out = driver.execute(query)
33
+ out = driver.execute(query, opts.merge(:inline => (tok != '\G')))
34
34
  elapsed = Time.now - start_time
35
35
 
36
36
  if out.kind_of?(DynamoDB::Driver::Rownum)
@@ -39,7 +39,7 @@ def evaluate_query(driver, src, opts = {})
39
39
  puts out
40
40
  elsif out
41
41
  opts = opts.merge(:inline => (tok != '\G'), :time => elapsed)
42
- print_json(out, opts)
42
+ print_json(out, $stdout, opts)
43
43
  end
44
44
  elsif (tok = ss.scan /./)
45
45
  buf << tok # 落ち穂拾い
@@ -17,7 +17,7 @@ def print_version
17
17
  puts "#{File.basename($0)} #{Version}"
18
18
  end
19
19
 
20
- def print_json(data, opts = {})
20
+ def print_json(data, out, opts = {})
21
21
  str = nil
22
22
  last_evaluated_key = nil
23
23
 
@@ -62,7 +62,7 @@ def print_json(data, opts = {})
62
62
  end
63
63
 
64
64
  str << "\n"
65
- puts str
65
+ out.puts(str)
66
66
  end
67
67
 
68
68
  def evaluate_command(driver, cmd_arg)
@@ -81,6 +81,9 @@ Binary
81
81
  Identifier
82
82
  `ABCD...` or Non-keywords
83
83
 
84
+ Array
85
+ ('String', 'String', ...), (1, 2, 3, ...)
86
+
84
87
 
85
88
  ##### Operator #####
86
89
 
@@ -114,6 +117,11 @@ Shell
114
117
  {"birth_date"=>"1964-04-30", "emp_no"=>225407,...
115
118
  ...
116
119
 
120
+ ##### Save #####
121
+
122
+ SELECT ALL * FROM employees > 'foo.json';
123
+ SELECT ALL * FROM employees >> 'foo.json';
124
+
117
125
 
118
126
  ##### Command #####
119
127
 
@@ -114,6 +114,12 @@ module DynamoDB
114
114
  f.close_write
115
115
  f.read
116
116
  end
117
+ when :overwrite
118
+ open(script, 'wb') {|f| print_json(retval, f, opts) }
119
+ retval = nil
120
+ when :append
121
+ open(script, 'ab') {|f| print_json(retval, f, opts) }
122
+ retval = nil
117
123
  else
118
124
  retval
119
125
  end