Class RightAws::ActiveSdb
In: lib/sdb/active_sdb.rb
Parent: Object

RightAws::ActiveSdb — RightScale SDB interface (alpha release)

The RightAws::ActiveSdb class provides a complete interface to Amazon‘s Simple Database Service.

ActiveSdb is in alpha and does not load by default with the rest of RightAws. You must use an additional require statement to load the ActiveSdb class. For example:

  require 'right_aws'
  require 'sdb/active_sdb'

Additionally, the ActiveSdb class requires the ‘uuidtools’ gem; this gem is not normally required by RightAws and is not installed as a dependency of RightAws.

Simple ActiveSdb usage example:

 class Client < RightAws::ActiveSdb::Base
 end

 # connect to SDB
 RightAws::ActiveSdb.establish_connection

 # create domain
 Client.create_domain

 # create initial DB
 Client.create 'name' => 'Bush',     'country' => 'USA',    'gender' => 'male',   'expiration' => '2009', 'post' => 'president'
 Client.create 'name' => 'Putin',    'country' => 'Russia', 'gender' => 'male',   'expiration' => '2008', 'post' => 'president'
 Client.create 'name' => 'Medvedev', 'country' => 'Russia', 'gender' => 'male',   'expiration' => '2012', 'post' => 'president'
 Client.create 'name' => 'Mary',     'country' => 'USA',    'gender' => 'female', 'hobby' => ['patchwork', 'bundle jumping']
 Client.create 'name' => 'Mary',     'country' => 'Russia', 'gender' => 'female', 'hobby' => ['flowers', 'cats', 'cooking']
 sandy_id = Client.create('name' => 'Sandy', 'country' => 'Russia', 'gender' => 'female', 'hobby' => ['flowers', 'cats', 'cooking']).id

 # find all Bushes in USA
 Client.find(:all, :conditions => ["['name'=?] intersection ['country'=?]",'Bush','USA']).each do |client|
   client.reload
   puts client.attributes.inspect
 end

 # find all Maries through the world
 Client.find_all_by_name_and_gender('Mary','female').each do |mary|
   mary.reload
   puts "#{mary[:name]}, gender: #{mary[:gender]}, hobbies: #{mary[:hobby].join(',')}"
 end

 # find new russian president
 medvedev = Client.find_by_post_and_country_and_expiration('president','Russia','2012')
 if medvedev
   medvedev.reload
   medvedev.save_attributes('age' => '42', 'hobby' => 'Gazprom')
 end

 # retire old president
 Client.find_by_name('Putin').delete

 # Sandy disappointed in 'cooking' and decided to hide her 'gender' and 'country' ()
 sandy = Client.find(sandy_id)
 sandy.reload
 sandy.delete_values('hobby' => ['cooking'] )
 sandy.delete_attributes('country', 'gender')

 # remove domain
 Client.delete_domain

Methods

Included Modules

ActiveSdbConnect

Classes and Modules

Module RightAws::ActiveSdb::ActiveSdbConnect
Class RightAws::ActiveSdb::ActiveSdbError
Class RightAws::ActiveSdb::Base

Public Class methods

Create new domain. Raises no errors if the domain already exists.

 RightAws::ActiveSdb.create_domain('alpha')  #=> {:request_id=>"6fc652a0-0000-41d5-91f4-3ed390a3d3b2", :box_usage=>"0.0055590278"}

Remove domain from SDB. Raises no errors if the domain does not exist.

 RightAws::ActiveSdb.create_domain('alpha')  #=> {:request_id=>"6fc652a0-0000-41c6-91f4-3ed390a3d3b2", :box_usage=>"0.0055590001"}

Retreive a list of domains.

 put RightAws::ActiveSdb.domains #=> ['co-workers','family','friends','clients']

[Validate]