lib/sdbport/aws/simpledb.rb in sdbport-0.0.1 vs lib/sdbport/aws/simpledb.rb in sdbport-0.1.0
- old
+ new
@@ -3,30 +3,59 @@
module Sdbport
module AWS
class SimpleDB
def initialize(args)
- access_key = args[:access_key]
- secret_key = args[:secret_key]
- region = args[:region]
- options = { :aws_access_key_id => access_key,
- :aws_secret_access_key => secret_key,
- :region => region }
+ @access_key = args[:access_key]
+ @secret_key = args[:secret_key]
+ @region = args[:region]
+ end
- @sdb = Fog::AWS::SimpleDB.new options
+ def domains
+ sdb.list_domains.body['Domains']
end
- def export
- select "select * from heirloom"
+ def domain_exists?(domain)
+ domains.include? domain
end
+ def create_domain_unless_present(domain)
+ sdb.create_domain(domain) unless domain_exists?(domain)
+ end
+
def select(query)
- @sdb.select(query).body['Items']
+ sdb.select(query).body['Items']
end
def count(domain)
- body = @sdb.select("SELECT count(*) FROM `#{domain}`").body
+ body = sdb.select("SELECT count(*) FROM `#{domain}`").body
body['Items']['Domain']['Count'].first.to_i
+ end
+
+ def domain_empty?(domain)
+ count(domain).zero?
+ end
+
+ def put_attributes(domain, key, attributes, options = {})
+ sdb.put_attributes domain, key, attributes, options
+ end
+
+ def delete_domain(domain)
+ sdb.delete_domain(domain)
+ end
+
+ def delete(domain, key)
+ sdb.delete_attributes domain, key
+ end
+
+ private
+
+ def sdb
+ options = { :aws_access_key_id => @access_key,
+ :aws_secret_access_key => @secret_key,
+ :region => @region }
+
+ @sdb ||= Fog::AWS::SimpleDB.new options
end
end
end
end