Class: Aws::ActiveSdb

Inherits:
Object show all
Extended by:
ActiveSdbConnect
Defined in:
lib/sdb/active_sdb.rb

Overview

Aws::ActiveSdb – RightScale SDB interface (alpha release)

The Aws::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 Aws. 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 Aws and is not installed as a dependency of Aws.

Simple ActiveSdb usage example:

class Client < Aws::ActiveSdb::Base
end

# connect to SDB
Aws::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

Defined Under Namespace

Modules: ActiveSdbConnect Classes: ActiveSdbError, Base

Class Method Summary collapse

Methods included from ActiveSdbConnect

close_connection, connection, establish_connection

Class Method Details

.create_domain(domain_name) ⇒ Object

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

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


154
155
156
# File 'lib/sdb/active_sdb.rb', line 154

def create_domain(domain_name)
    connection.create_domain(domain_name)
end

.delete_domain(domain_name) ⇒ Object

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

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


163
164
165
# File 'lib/sdb/active_sdb.rb', line 163

def delete_domain(domain_name)
    connection.delete_domain(domain_name)
end

.domainsObject

Retreive a list of domains.

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


145
146
147
# File 'lib/sdb/active_sdb.rb', line 145

def domains
    connection.list_domains[:domains]
end