class Kcl::Proxies::DynamoDbProxy
Attributes
client[R]
Public Class Methods
new(config)
click to toggle source
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 7 def initialize(config) @client = Aws::DynamoDB::Client.new( { access_key_id: config.aws_access_key_id, secret_access_key: config.aws_secret_access_key, region: config.aws_region, endpoint: config.dynamodb_endpoint, ssl_verify_peer: config.use_ssl } ) end
Public Instance Methods
conditional_update_item(table_name, item, condition_expression, expression_attributes)
click to toggle source
@params [String] table_name @params [Hash] item @params [String] condition_expression @params [Hash] expression_attributes @return [Boolean]
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 103 def conditional_update_item(table_name, item, condition_expression, expression_attributes) @client.put_item( { table_name: table_name, item: item, condition_expression: condition_expression, expression_attribute_values: expression_attributes } ) true rescue Aws::DynamoDB::Errors::ResourceNotFoundException false end
create_table(table_name, attributes = [], schema = [], throughputs = {})
click to toggle source
@params [String] table_name @params [Array] attributes @params [Array] schema @params [Hash] throughputs
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 32 def create_table(table_name, attributes = [], schema = [], throughputs = {}) @client.create_table( { table_name: table_name, attribute_definitions: attributes, key_schema: schema, provisioned_throughput: throughputs } ) end
delete_table(table_name)
click to toggle source
@params [String] table_name
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 44 def delete_table(table_name) @client.delete_table({ table_name: table_name }) true rescue Aws::DynamoDB::Errors::ResourceNotFoundException false end
exists?(table_name)
click to toggle source
@params [String] table_name
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 20 def exists?(table_name) @client.describe_table({ table_name: table_name }) true rescue Aws::DynamoDB::Errors::NotFound, Aws::DynamoDB::Errors::ResourceNotFoundException false end
get_item(table_name, conditions)
click to toggle source
@params [String] table_name @params [Hash] conditions @return [Hash]
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 54 def get_item(table_name, conditions) response = @client.get_item( { table_name: table_name, key: conditions } ) response.item rescue Aws::DynamoDB::Errors::ResourceNotFoundException nil end
put_item(table_name, item)
click to toggle source
@params [String] table_name @params [Hash] item @return [Boolean]
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 69 def put_item(table_name, item) @client.put_item( { table_name: table_name, item: item } ) true rescue Aws::DynamoDB::Errors::ResourceNotFoundException false end
remove_item(table_name, conditions)
click to toggle source
@params [String] table_name @params [Hash] conditions @return [Boolean]
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 120 def remove_item(table_name, conditions) @client.delete_item( { table_name: table_name, key: conditions } ) true rescue Aws::DynamoDB::Errors::ResourceNotFoundException false end
update_item(table_name, conditions, update_expression)
click to toggle source
@params [String] table_name @params [Hash] conditions @params [String] update_expression @return [Boolean]
# File lib/kcl/proxies/dynamo_db_proxy.rb, line 85 def update_item(table_name, conditions, update_expression) @client.update_item( { table_name: table_name, key: conditions, update_expression: update_expression } ) true rescue Aws::DynamoDB::Errors::ResourceNotFoundException false end