awful 0.0.130 → 0.0.131
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 +4 -4
- data/lib/awful/dynamodb.rb +41 -21
- data/lib/awful/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9df02b3f1ece5cedce9a2932ee0f8904a1d0685c
|
4
|
+
data.tar.gz: ad7374123396d7155ec84d6cae57c07d09f98dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cd8a580e571a794911aca602cde857f4d22e6efef782fb973930aa12da8c3c79e1ad4001e4cf2b331095b855ae798b7b1693b9e523dbbec7a082f73960a9dde
|
7
|
+
data.tar.gz: 17d36acb2c6df8fd77cfaf42112358f05a982c3112befd700ce1ee74ebe08934d2a65eb96b816c537668e24c5879c570fdfb2a01cb5b33262f934d3344ab050f
|
data/lib/awful/dynamodb.rb
CHANGED
@@ -45,18 +45,18 @@ module Awful
|
|
45
45
|
if options[:long]
|
46
46
|
tables.map do |table|
|
47
47
|
dynamodb.describe_table(table_name: table).table
|
48
|
-
end.
|
48
|
+
end.output do |list|
|
49
49
|
print_table list.map { |t| [ t.table_name, color(t.table_status), t.item_count, t.table_size_bytes, t.creation_date_time ] }
|
50
50
|
end
|
51
51
|
else
|
52
|
-
tables.
|
52
|
+
tables.output(&method(:puts))
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
desc 'dump NAME', 'dump table with name'
|
57
57
|
def dump(name)
|
58
58
|
all_matching_tables(name).map do |table_name|
|
59
|
-
dynamodb.describe_table(table_name: table_name).table.to_hash.
|
59
|
+
dynamodb.describe_table(table_name: table_name).table.to_hash.output do |table|
|
60
60
|
puts YAML.dump(stringify_keys(table))
|
61
61
|
end
|
62
62
|
end
|
@@ -64,15 +64,14 @@ module Awful
|
|
64
64
|
|
65
65
|
desc 'status NAME', 'get status of NAMEd table'
|
66
66
|
def status(name)
|
67
|
-
dynamodb.describe_table(table_name: name).table.table_status.
|
67
|
+
dynamodb.describe_table(table_name: name).table.table_status.output(&method(:puts))
|
68
68
|
end
|
69
69
|
|
70
|
-
desc '
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end.attribute_name.output(&method(:puts))
|
70
|
+
desc 'keys NAME', 'get hash and range keys of named table'
|
71
|
+
def keys(name)
|
72
|
+
dynamodb.describe_table(table_name: name).table.key_schema.each_with_object({}) do |schema, h|
|
73
|
+
h[schema.key_type.downcase.to_sym] = schema.attribute_name
|
74
|
+
end.output(&method(:print_table))
|
76
75
|
end
|
77
76
|
|
78
77
|
desc 'create_table NAME', 'create table with NAME'
|
@@ -92,7 +91,7 @@ module Awful
|
|
92
91
|
## scrub unwanted keys from GSIs
|
93
92
|
if opt.has_key?(:global_secondary_indexes)
|
94
93
|
params[:global_secondary_indexes] = opt[:global_secondary_indexes].map do |gsi|
|
95
|
-
only_keys_matching(gsi, %i[index_name key_schema projection]).
|
94
|
+
only_keys_matching(gsi, %i[index_name key_schema projection]).output do |g|
|
96
95
|
if gsi[:provisioned_throughput]
|
97
96
|
g[:provisioned_throughput] = only_keys_matching(gsi[:provisioned_throughput], %i[read_capacity_units write_capacity_units])
|
98
97
|
end
|
@@ -230,42 +229,63 @@ module Awful
|
|
230
229
|
end
|
231
230
|
|
232
231
|
desc 'scan NAME', 'scan table with NAME'
|
233
|
-
method_option :output, aliases: '-o', type: :string,
|
232
|
+
method_option :output, aliases: '-o', type: :string, default: nil, desc: 'Output filename (default: stdout)'
|
233
|
+
method_option :count, aliases: '-c', type: :boolean, default: false, desc: 'Return count instead of items'
|
234
234
|
def scan(name, exclusive_start_key = nil)
|
235
235
|
fd = options[:output] ? File.open(options[:output], 'w') : $stdout.dup # open output file or stdout
|
236
236
|
exclusive_start_key = nil
|
237
|
+
count = 0
|
237
238
|
loop do
|
238
|
-
r = dynamodb_simple.scan(
|
239
|
-
|
239
|
+
r = dynamodb_simple.scan(
|
240
|
+
'TableName' => name,
|
241
|
+
'Select' => options[:count] ? 'COUNT' : 'ALL_ATTRIBUTES',
|
242
|
+
'ExclusiveStartKey' => exclusive_start_key
|
243
|
+
)
|
244
|
+
count += r.fetch('Count', 0)
|
245
|
+
r.fetch('Items', []).each do |item|
|
240
246
|
fd.puts JSON.generate(item)
|
241
247
|
end
|
242
248
|
exclusive_start_key = r['LastEvaluatedKey']
|
243
249
|
break unless exclusive_start_key
|
244
250
|
end
|
245
251
|
fd.close
|
252
|
+
puts count if options[:count]
|
246
253
|
end
|
247
254
|
|
248
255
|
desc 'query NAME', 'query table with NAME'
|
249
|
-
method_option :hash_key,
|
250
|
-
method_option :hash_key_value,
|
251
|
-
method_option :
|
256
|
+
method_option :hash_key, aliases: '-k', type: :string, default: nil, desc: 'Hash key'
|
257
|
+
method_option :hash_key_value, aliases: '-v', type: :string, default: nil, desc: 'Hash key value'
|
258
|
+
method_option :range_key, aliases: '-K', type: :string, default: nil, desc: 'Range key'
|
259
|
+
method_option :range_key_value, aliases: '-V', type: :string, default: nil, desc: 'Range key value'
|
260
|
+
method_option :output, aliases: '-o', type: :string, default: nil, desc: 'Output filename (default: stdout)'
|
261
|
+
method_option :count, aliases: '-c', type: :boolean, default: false, desc: 'Return count instead of items'
|
252
262
|
def query(name, exclusive_start_key = nil)
|
253
263
|
fd = options[:output] ? File.open(options[:output], 'w') : $stdout.dup # open output file or stdout
|
254
264
|
exclusive_start_key = nil
|
265
|
+
count = 0
|
266
|
+
condition = "#{options[:hash_key]} = :hash_key_value"
|
267
|
+
condition += " and #{options[:range_key]} = :range_key_value" if options[:range_key]
|
268
|
+
attributes = {
|
269
|
+
':hash_key_value' => { S: options[:hash_key_value] },
|
270
|
+
':range_key_value' => { S: options[:range_key_value] },
|
271
|
+
}.reject { |_,v| v[:S].nil? }
|
255
272
|
loop do
|
256
273
|
r = dynamodb_simple.query(
|
257
274
|
'TableName' => name,
|
258
275
|
'ExclusiveStartKey' => exclusive_start_key,
|
259
|
-
'
|
260
|
-
'
|
276
|
+
'Select' => options[:count] ? 'COUNT' : 'ALL_ATTRIBUTES',
|
277
|
+
'KeyConditionExpression' => condition,
|
278
|
+
'ExpressionAttributeValues' => attributes,
|
261
279
|
)
|
262
|
-
r
|
280
|
+
count += r.fetch('Count', 0)
|
281
|
+
r.fetch('Items', []).each do |item|
|
263
282
|
fd.puts JSON.generate(item)
|
264
283
|
end
|
265
284
|
exclusive_start_key = r['LastEvaluatedKey']
|
266
285
|
break unless exclusive_start_key
|
267
286
|
end
|
268
287
|
fd.close
|
288
|
+
puts count if options[:count]
|
269
289
|
end
|
270
290
|
|
271
291
|
desc 'put_items NAME', 'puts json items into the table with NAME'
|
@@ -294,7 +314,7 @@ module Awful
|
|
294
314
|
end
|
295
315
|
|
296
316
|
## return counts
|
297
|
-
[put_count, skip_count].
|
317
|
+
[put_count, skip_count].output do |put, skip|
|
298
318
|
puts "put #{put} items, skipped #{skip} items"
|
299
319
|
end
|
300
320
|
end
|
data/lib/awful/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.131
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ric Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|