class DKV::CLI

Public Instance Methods

clear(table, key) click to toggle source
# File lib/dkv/cli.rb, line 37
def clear(table, key)
  client.delete_item table_name: table, key: {"DataKey" => key.to_s}
end
get(table, key) click to toggle source
# File lib/dkv/cli.rb, line 27
def get(table, key)
  result = client.get_item table_name: table, key: {"DataKey" => key.to_s}
  if result.item.nil?
    exit 1
  else
    puts result.item['DataValue']
  end
end
init(table) click to toggle source
# File lib/dkv/cli.rb, line 8
def init(table)
  # Will make a dynamo db database with the minimum configuration...
  client.create_table({
    attribute_definitions: [{attribute_name: "DataKey", attribute_type: "S"}],
    table_name: table.to_s,
    key_schema: [{attribute_name: "DataKey", key_type: "HASH"}],
    provisioned_throughput: {read_capacity_units: 1, write_capacity_units: 1}
  })
end
set(table, key, value) click to toggle source
# File lib/dkv/cli.rb, line 19
def set(table, key, value)
  client.put_item({
    table_name: table,
    item: {"DataKey" => key.to_s, "DataValue" => value.to_s}
  })
end

Private Instance Methods

client() click to toggle source
# File lib/dkv/cli.rb, line 43
def client
  @client ||= Aws::DynamoDB::Client.new
end