Databases Reference
In-Depth Information
Finally, you could store a model instance as follows:
m_instance = MyModel.new
m_instance.key1 = “valueA”
m_instance.key2 = value1
m_instance.save
You can retrieve model instances by fi nding by id as follows:
m_instance_2 = MyModel.find(id)
Alternatively, you can fi nd for all instances that match a fi lter like so:
all_instances = MyModel?.find(:all, [“key1=?”, “valueA”],
:order=>”key2”, :limit=>10)
That should give you a hint of how you could leverage SimpleDB with your Rails application.
Other alternative libraries are available, including one from Amazon that provides a Ruby language
interface to connect to Amazon's services. You can explore the Ruby library for SimpleDB by
downloading it from http://aws.amazon.com/code/Amazon-SimpleDB/3324 .
Next, and last of all, I cover AWS SimpleDB interaction from Python. Boto, available online
at http://code.google.com/p/boto/ , is the most popular choice for connecting to SimpleDB
from Python. To get started, download the latest source of boto from its Github mirror
as follows:
git clone https://github.com/boto/boto.git
Then change into the cloned repository directory and run python install setup.py to install
boto. Once installed, fi re up a Python interactive session and you can easily create a new domain
and add items to it as follows:
import boto
sdb = boto.connect_sdb('<your aws access key>', '<your aws secret key'>)
domain = sdb.create_domain('domain2')
item = domain.new_item('item1')
item['key1'] = 'value1'
item['key2'] = 'value2'
item.save()
Beyond this, the SimpleDB commands and ways of interactions remain consistent with what you
have seen in the other cases.
SUMMARY
This chapter covered the two popular and scalable database services in the cloud, illustrating
their behavior characteristics and peculiarities. It also showed how libraries, specifi cations, and
frameworks in various languages can be used in conjunction with the NoSQL stores.
Search WWH ::




Custom Search