class AWS::DynamoDB::TableCollection
table = dynamo_db.tables[‘mytable’]
@example Getting a Table by Name
dynamo_db.tables.each {|table| puts table.name }
@example Enumerating Tables
table = dynamo_db.tables.create(‘mytable’, 10, 10, :hash_key => { :id => :string })
@example Creating a Table
table.hash_key = [:id, :string]
table = dynamo_db.tables[‘mytable’]
a table.
You do this by calling #hash_key= (and optionally #range_key=) on
Before you can operate on items in a table you must specify the schema.
## Schemas
represented by an instance of the {Table} class.
Represents the tables in your account. Each table is
def [] name
-
(Table)
- Returns the table with the given name.
Parameters:
-
name
(String
) --
def [] name Table.new(name, :config => config) end
def _each_item next_token, limit, options = {}, &block
def _each_item next_token, limit, options = {}, &block options[:limit] = limit if limit options[:exclusive_start_table_name] = next_token if next_token response = client.list_tables(options) response.data['TableNames'].each do |name| yield Table.new(name, :config => config) end response.data['LastEvaluatedTableName'] end
def create name, read_capacity_units, write_capacity_units, options = {}
-
(Table)
- The newly created table.
Options Hash:
(**options)
-
:range_key
(String
) -- You can setup a table to use -
:hash_key
(Hash
) -- A hash key is a combination
Parameters:
-
options
(Hash
) -- -
write_capacity_units
(Integer
) -- Sets the minimum -
read_capacity_units
(Integer
) -- Sets the minimum -
name
(String
) -- The name of the table.
Other tags:
- Note: - Creating a table is an eventualy consistent operation. You
def create name, read_capacity_units, write_capacity_units, options = {} client_opts = { :table_name => name.to_s, :key_schema => key_schema(options), :provisioned_throughput => { :read_capacity_units => read_capacity_units, :write_capacity_units => write_capacity_units, }, } response = client.create_table(client_opts) Table.new(name, :config => config) end
def key_schema options
def key_schema options hash_key, range_key = options.values_at(:hash_key, :range_key) # default options for :hash_key hash_key ||= { :id => :string } schema = {} schema[:hash_key_element] = schema_element(hash_key, "hash") if range_key schema[:range_key_element] = schema_element(range_key, "range") end schema end
def schema_element desc, key_type
def schema_element desc, key_type (name, type) = desc.to_a.first unless [:string, :number, :binary].include?(type) msg = "invalid #{key_type} key type, expected :string, :number or :binary" raise ArgumentError, msg end { :attribute_name => name.to_s, :attribute_type => type.to_s[0,1].upcase } end