August 23, 2010

Inequalities with aws_sdb

I'm using aws_sdb_proxy for accessing SBD. Since it is using ActiveResource (REST approach), querying with equalities is fairly simple. All the equalities can be passed as a hash with the :params parameter.

Balloon.find(:all, :params => {:color=> "green", :size => "5inch"})

which will be resolves to below GET request:

http://localhost:8080/Baloons.xml?color=green&size=small

In order to support all the other sql-like queries, sdb_proxy allows users to pass a hard-coded string value. Because ActiveResource is used as the underlying communication mechanism, :params value has to be a hash event though all we need to pass is a string. aws_proxy goes around this problem with only looking at the first key of the hash in the case of hard-coded query string.

Balloon.find(:all, :params => {" ['size' > '5inch'] sort 'size' " => nil})

and this will resolve to below GET request:

http://localhost:8080/Baloons/query.xml?:static_query

Note1: I added the query as static_query because I don't have my setup on this machine, but it will add corresponding UTF values for space, quotes and for brackets.. At the end will be something like http://localhost:8080/Baloons/query.xml?size**5inch**sort****size**
Note2: sdb_proxy is using site_prefix for the resource, so the object name (Baloon in this case) is not the domain name. This is a whole different point to discuss, I wrote this entry according to my altered version of sdb. If you are using sdb_proxy as it is, then your http requests will be similar to following:
http://localhost:8080/:domain_name/baloons/query.xml?:static_query
http://localhost:8080/:domain_name/baloons.xml?color=green&size=small