module Dynamoid::Adapter::AwsSdk
Public Instance Methods
batch_get_item(options)
click to toggle source
BatchGetItem
# File lib/dynamoid/adapter/aws_sdk.rb, line 18 def batch_get_item(options) batch = AWS::DynamoDB::BatchGet.new(:config => @@connection.config) options.each do |t, ids| batch.table(t, :all, Array(ids)) end hash = Hash.new{|h, k| h[k] = []} batch.each do |table_name, attributes| hash[table_name] << attributes.symbolize_keys! end hash end
connect!()
click to toggle source
# File lib/dynamoid/adapter/aws_sdk.rb, line 9 def connect! @@connection = AWS::DynamoDB.new(:access_key_id => Dynamoid::Config.access_key, :secret_access_key => Dynamoid::Config.secret_key) end
connection()
click to toggle source
# File lib/dynamoid/adapter/aws_sdk.rb, line 13 def connection @@connection end
create_table(table_name, key)
click to toggle source
CreateTable
# File lib/dynamoid/adapter/aws_sdk.rb, line 31 def create_table(table_name, key) table = @@connection.tables.create(table_name, 10, 5, :hash_key => {key.to_sym => :string}) sleep 0.5 while table.status == :creating return table end
delete_item(table_name, key)
click to toggle source
DeleteItem
# File lib/dynamoid/adapter/aws_sdk.rb, line 38 def delete_item(table_name, key) table = @@connection.tables[table_name] table.load_schema result = table.items[key] result.delete unless result.attributes.to_h.empty? true end
delete_table(table_name)
click to toggle source
DeleteTable
# File lib/dynamoid/adapter/aws_sdk.rb, line 47 def delete_table(table_name) @@connection.tables[table_name].delete end
get_item(table_name, key)
click to toggle source
GetItem
# File lib/dynamoid/adapter/aws_sdk.rb, line 54 def get_item(table_name, key) table = @@connection.tables[table_name] table.load_schema result = table.items[key].attributes.to_h if result.empty? nil else result.symbolize_keys! end end
list_tables()
click to toggle source
ListTables
# File lib/dynamoid/adapter/aws_sdk.rb, line 66 def list_tables @@connection.tables.collect(&:name) end
put_item(table_name, object)
click to toggle source
PutItem
# File lib/dynamoid/adapter/aws_sdk.rb, line 71 def put_item(table_name, object) table = @@connection.tables[table_name] table.load_schema table.items.create(object.delete_if{|k, v| v.nil?}) end
query(table_name, id)
click to toggle source
Query
# File lib/dynamoid/adapter/aws_sdk.rb, line 78 def query(table_name, id) get_item(table_name, id) end
scan(table_name, scan_hash)
click to toggle source
Scan
# File lib/dynamoid/adapter/aws_sdk.rb, line 83 def scan(table_name, scan_hash) table = @@connection.tables[table_name] table.load_schema results = [] table.items.select do |data| attributes = data.attributes.symbolize_keys! results << attributes if scan_hash.all?{|k, v| !attributes[k].nil? && attributes[k] == v} end results end