lib/ddbcli/ddb-driver.rb in ddbcli-0.4.1 vs lib/ddbcli/ddb-driver.rb in ddbcli-0.4.2.beta

- old
+ new

@@ -304,10 +304,12 @@ throughput = { :read => throughput['ReadCapacityUnits'], :write => throughput['WriteCapacityUnits'], } + stream = table_info['StreamSpecification'] + quote = lambda {|i| '`' + i.gsub('`', '``') + '`' } # ` buf = "CREATE TABLE #{quote[table_name]} (" buf << "\n " + key_schema.map {|name, key_type| @@ -342,31 +344,50 @@ }.join(",\n ") end buf << "\n)" buf << ' ' + throughput.map {|k, v| "#{k}=#{v}" }.join(' ') + + if stream and stream['StreamEnabled'] + buf << " stream=#{stream['StreamViewType']}" + end + buf << "\n\n" return buf end def do_alter_table(parsed) req_hash = {'TableName' => parsed.table} - throughput = { - 'ReadCapacityUnits' => parsed.capacity[:read], - 'WriteCapacityUnits' => parsed.capacity[:write] - } if parsed.index_name req_hash['GlobalSecondaryIndexUpdates'] = [{ 'Update' => { 'IndexName' => parsed.index_name, 'ProvisionedThroughput' => throughput, }, }] else - req_hash['ProvisionedThroughput'] = throughput + if parsed.capacity + req_hash['ProvisionedThroughput'] = { + 'ReadCapacityUnits' => parsed.capacity[:read], + 'WriteCapacityUnits' => parsed.capacity[:write], + } + end + + unless parsed.stream.nil? + if parsed.stream + view_type = (parsed.stream == true) ? 'KEYS_ONLY' : parsed.stream.to_s.upcase + + req_hash['StreamSpecification'] = { + 'StreamEnabled' => true, + 'StreamViewType' => view_type, + } + else + req_hash['StreamSpecification'] = {'StreamEnabled' => false} + end + end end @client.query('UpdateTable', req_hash) nil end @@ -394,10 +415,19 @@ 'ReadCapacityUnits' => parsed.capacity[:read], 'WriteCapacityUnits' => parsed.capacity[:write], }, } + if parsed.stream + view_type = (parsed.stream == true) ? 'KEYS_ONLY' : parsed.stream.to_s.upcase + + req_hash['StreamSpecification'] = { + 'StreamEnabled' => true, + 'StreamViewType' => view_type, + } + end + # hash key req_hash['AttributeDefinitions'] = [ { 'AttributeName' => parsed.hash[:name], 'AttributeType' => parsed.hash[:type], @@ -580,9 +610,24 @@ else req_hash['ProvisionedThroughput'] = { 'ReadCapacityUnits' => table_info['ProvisionedThroughput']['ReadCapacityUnits'], 'WriteCapacityUnits' => table_info['ProvisionedThroughput']['WriteCapacityUnits'], } + end + + if not parsed.stream.nil? + if parsed.stream + view_type = (parsed.stream == true) ? 'KEYS_ONLY' : parsed.stream.to_s.upcase + + req_hash['StreamSpecification'] = { + 'StreamEnabled' => true, + 'StreamViewType' => view_type, + } + else + req_hash['StreamSpecification'] = {'StreamEnabled' => false} + end + elsif table_info['StreamSpecification'] + req_hash['StreamSpecification'] = table_info['StreamSpecification'] end @client.query('CreateTable', req_hash) nil end