ddbcli 0.1.6 → 0.1.7

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/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.1.6'
4
+ Version = '0.1.7'
5
5
 
6
6
  HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.ddbcli_history')
7
7
  HISTSIZE = 500
@@ -46,8 +46,13 @@ def print_json(data, opts = {})
46
46
 
47
47
  str.sub!(/(?:\r\n|\r|\n)*\Z/, "\n")
48
48
 
49
- if opts[:show_rows] and data.kind_of?(Array)
50
- str << "// #{data.length} #{data.length > 1 ? 'rows' : 'row'} in set"
49
+ if opts[:show_rows]
50
+ if [Array, Hash].any? {|i| data.kind_of?(i) }
51
+ str << "// #{data.length} #{data.length > 1 ? 'rows' : 'row'} in set"
52
+ else
53
+ str << '// 1 row in set'
54
+ end
55
+
51
56
  str << " (%.2f sec)" % opts[:time] if opts[:time]
52
57
  str << "\n"
53
58
  end
@@ -193,7 +193,10 @@ module DynamoDB
193
193
 
194
194
  table_names.map do |table_name|
195
195
  table_info = @client.query('DescribeTable', 'TableName' => table_name)['Table']
196
- h[table_name] = table_info['TableStatus']
196
+ h[table_name] = {
197
+ 'TableStatus' => table_info['TableStatus'],
198
+ 'ItemCount' => table_info['ItemCount'],
199
+ }
197
200
  end
198
201
 
199
202
  return h
@@ -479,17 +482,27 @@ module DynamoDB
479
482
  end
480
483
  else
481
484
  retval = block_given? ? res_data['Items'].map {|i| yield(i) } : res_data['Items']
485
+ limit_orig = parsed.limit
486
+
487
+ if @iteratable or opts[:iteratable] or (parsed.limit and retval.length < parsed.limit)
488
+ parsed.limit -= retval.length if parsed.limit
482
489
 
483
- if (@iteratable or opts[:iteratable]) and not parsed.limit
484
490
  while res_data['LastEvaluatedKey']
485
491
  res_data = select_proc.call(res_data['LastEvaluatedKey'])
486
- retval.concat(
487
- block_given? ? res_data['Items'].map {|i| yield(i) } : res_data['Items']
488
- )
492
+ items = block_given? ? res_data['Items'].map {|i| yield(i) } : res_data['Items']
493
+
494
+ retval.concat(items)
495
+
496
+ if parsed.limit
497
+ parsed.limit -= items.length
498
+ break if parsed.limit < 1
499
+ end
489
500
  end
490
501
  end
491
502
  end
492
503
 
504
+ parsed.limit = limit_orig;
505
+
493
506
  if res_data['LastEvaluatedKey']
494
507
  @last_action = action
495
508
  @last_parsed = parsed
@@ -667,7 +680,9 @@ module DynamoDB
667
680
  end # scan filter
668
681
 
669
682
  res_data = @client.query('Scan', req_hash)
670
- items.concat(res_data['Items'])
683
+ res_data_items = res_data['Items']
684
+ parsed.limit -= res_data_items.length if parsed.limit
685
+ items.concat(res_data_items)
671
686
  res_data['LastEvaluatedKey']
672
687
  end
673
688
 
@@ -675,7 +690,10 @@ module DynamoDB
675
690
 
676
691
  loop do
677
692
  lek = scan.call(lek)
678
- break unless lek
693
+
694
+ if not lek or (parsed.limit and parsed.limit < 1)
695
+ break
696
+ end
679
697
  end
680
698
 
681
699
  return items
@@ -761,7 +779,13 @@ module DynamoDB
761
779
  end
762
780
 
763
781
  def do_insert_select(action, parsed)
782
+ if parsed.count
783
+ raise DynamoDB::Error, '"COUNT(*)" cannot be inserted.'
784
+ end
785
+
764
786
  items = do_select0(action, parsed.select, :iteratable => true)
787
+ items = items.data if items.kind_of?(Iteratorable)
788
+
765
789
  n = 0
766
790
 
767
791
  until (chunk = items.slice!(0, MAX_NUMBER_BATCH_PROCESS_ITEMS)).empty?
@@ -758,7 +758,7 @@ module_eval(<<'.,.,', 'ddb-parser.y', 40)
758
758
 
759
759
  module_eval(<<'.,.,', 'ddb-parser.y', 44)
760
760
  def _reduce_20(val, _values)
761
- struct(:SHOW_TABLE_STATUS, :limit => val[2])
761
+ struct(:SHOW_TABLE_STATUS)
762
762
 
763
763
  end
764
764
  .,.,
@@ -40,9 +40,9 @@ rule
40
40
  {
41
41
  struct(:SHOW_TABLES, :limit => val[2])
42
42
  }
43
- show_stmt : SHOW TABLE STATUS
43
+ | SHOW TABLE STATUS
44
44
  {
45
- struct(:SHOW_TABLE_STATUS, :limit => val[2])
45
+ struct(:SHOW_TABLE_STATUS)
46
46
  }
47
47
  | SHOW REGIONS
48
48
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddbcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-12 00:00:00.000000000 Z
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json