Class | RightAws::SdbInterface |
In: |
lib/sdb/right_sdb_interface.rb
|
Parent: | RightAwsBase |
DEFAULT_HOST | = | 'sdb.amazonaws.com' |
DEFAULT_PORT | = | 443 |
DEFAULT_PROTOCOL | = | 'https' |
API_VERSION | = | '2007-11-07' |
Creates new RightSdb instance.
Params:
{ :server => 'sdb.amazonaws.com' # Amazon service host: 'sdb.amazonaws.com'(default) :port => 443 # Amazon service port: 80 or 443(default) :protocol => 'https' # Amazon service protocol: 'http' or 'https'(default) :signature_version => '0' # The signature version : '0' or '1'(default) :multi_thread => true|false # Multi-threaded (connection per each thread): true or false(default) :logger => Logger Object} # Logger instance: logs to STDOUT if omitted }
Example:
sdb = RightAws::SdbInterface.new('1E3GDYEOGFJPIT7XXXXXX','hgTHt68JY07JKUY08ftHYtERkjgtfERn57XXXXXX', {:multi_thread => true, :logger => Logger.new('/tmp/x.log')}) #=> #<RightSdb:0xa6b8c27c>
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/
Create new SDB domain at Amazon.
Returns a hash: { :box_usage, :request_id } on success or an exception on error. (Amazon raises no errors if the domain already exists).
Example:
sdb = RightAws::SdbInterface.new sdb.create_domain('toys') # => { :box_usage => "0.0000071759", :request_id => "976709f9-0111-2345-92cb-9ce90acd0982" }
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_CreateDomain.html
Delete value, attribute or item.
Example:
# delete 'vodka' and 'girls' from 'Jon' and 'mice' from 'cat'. sdb.delete_attributes 'family', 'toys', { 'Jon' => ['vodka', 'girls'], 'cat' => ['mice'] } # delete the all the values from attributes (i.e. delete the attributes) sdb.delete_attributes 'family', 'toys', { 'Jon' => [], 'cat' => [] } # or sdb.delete_attributes 'family', 'toys', [ 'Jon', 'cat' ] # delete all the attributes from item 'toys' (i.e. delete the item) sdb.delete_attributes 'family', 'toys'
see docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_DeleteAttributes.html
Delete SDB domain at Amazon.
Returns a hash: { :box_usage, :request_id } on success or an exception on error. (Amazon raises no errors if the domain does not exist).
Example:
sdb = RightAws::SdbInterface.new sdb.delete_domain('toys') # => { :box_usage => "0.0000071759", :request_id => "976709f9-0111-2345-92cb-9ce90acd0982" }
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_DeleteDomain.html
Use this helper to manually escape the fields in the query expressions. To escape the single quotes and backslashes and to wrap the string into the single quotes.
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API.html
Retrieve SDB item‘s attribute(s).
Returns a hash:
{ :box_usage => string, :request_id => string, :attributes => { 'nameA' => [valueA1,..., valueAN], ... , 'nameZ' => [valueZ1,..., valueZN] } }
Example:
# request all attributes sdb.get_attributes('family', 'toys') # => { :attributes => {"cat" => ["clew", "Jons_socks", "mouse"] }, "Silvia" => ["beetle", "rolling_pin", "kids"], "Jon" => ["vacuum_cleaner", "hammer", "spade"]}, :box_usage => "0.0000093222", :request_id => "81273d21-000-1111-b3f9-512d91d29ac8" } # request cat's attributes only sdb.get_attributes('family', 'toys', 'cat') # => { :attributes => {"cat" => ["clew", "Jons_socks", "mouse"] }, :box_usage => "0.0000093222", :request_id => "81273d21-001-1111-b3f9-512d91d29ac8" }
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_GetAttributes.html
Retrieve a list of SDB domains from Amazon.
Returns a hash:
{ :domains => [domain1, ..., domainN], :next_token => string || nil, :box_usage => string, :request_id => string }
Example:
sdb = RightAws::SdbInterface.new sdb.list_domains #=> { :box_usage => "0.0000071759", :request_id => "976709f9-0111-2345-92cb-9ce90acd0982", :domains => ["toys", "dolls"]}
If a block is given, this method yields to it. If the block returns true, list_domains will continue looping the request. If the block returns false, list_domains will end.
sdb.list_domains(10) do |result| # list by 10 domains per iteration puts result.inspect true end
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_ListDomains.html
Add/Replace item attributes.
Params:
domain_name = DomainName item_name = ItemName attributes = { 'nameA' => [valueA1,..., valueAN], ... 'nameZ' => [valueZ1,..., valueZN] } replace = :replace | any other value to skip replacement
Returns a hash: { :box_usage, :request_id } on success or an exception on error. (Amazon raises no errors if the attribute was not overridden, as when the :replace param is unset).
Example:
sdb = RightAws::SdbInterface.new sdb.create_domain 'family' attributes = {} # create attributes for Jon and Silvia attributes['Jon'] = %w{ car beer } attributes['Silvia'] = %w{ beetle rolling_pin kids } sdb.put_attributes 'family', 'toys', attributes #=> ok # now: Jon=>[car, beer], Silvia=>[beetle, rolling_pin, kids] # add attributes to Jon attributes.delete('Silvia') attributes['Jon'] = %w{ girls pub } sdb.put_attributes 'family', 'toys', attributes #=> ok # now: Jon=>[car, beer, girls, pub], Silvia=>[beetle, rolling_pin, kids] # replace attributes for Jon and add to a cat (the cat had no attributes before) attributes['Jon'] = %w{ vacuum_cleaner hammer spade } attributes['cat'] = %w{ mouse clew Jons_socks } sdb.put_attributes 'family', 'toys', attributes, :replace #=> ok # now: Jon=>[vacuum_cleaner, hammer, spade], Silvia=>[beetle, rolling_pin, kids], cat=>[mouse, clew, Jons_socks]
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_PutAttributes.html
Perform a query on SDB.
Returns a hash:
{ :box_usage => string, :request_id => string, :next_token => string, :items => [ItemName1,..., ItemNameN] }
Example:
query = "['cat' = 'clew']" sdb.query('family', query) #=> hash of data sdb.query('family', query, 10) #=> hash of data with max of 10 items
If a block is given, query will iteratively yield results to it as long as the block continues to return true.
# List 10 items per iteration. Don't # forget to escape single quotes and backslashes and wrap all the items in single quotes. query = "['cat'='clew'] union ['dog'='Jon\\'s boot']" sdb.query('family', query, 10) do |result| puts result.inspect true end # Same query using automatic escaping...to use the auto escape, pass the query and its params as an array: query = [ "['cat'=?] union ['dog'=?]", "clew", "Jon's boot" ] sdb.query('family', query)
see: docs.amazonwebservices.com/AmazonSimpleDB/2007-11-07/DeveloperGuide/SDB_API_Query.html