lib/heirloom/aws/simpledb.rb in heirloom-0.3.1 vs lib/heirloom/aws/simpledb.rb in heirloom-0.4.0
- old
+ new
@@ -4,13 +4,13 @@
module AWS
class SimpleDB
def initialize(args)
@config = args[:config]
- @sdb = Fog::AWS::SimpleDB.new :aws_access_key_id => @config.access_key,
+ @sdb = Fog::AWS::SimpleDB.new :aws_access_key_id => @config.access_key,
:aws_secret_access_key => @config.secret_key,
- :region => @config.primary_region
+ :region => @config.primary_region
end
def domains
@sdb.list_domains.body['Domains']
end
@@ -21,19 +21,32 @@
def create_domain(domain)
@sdb.create_domain(domain) unless domain_exists?(domain)
end
+ def delete_domain(domain)
+ @sdb.delete_domain(domain)
+ 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 select(query)
@sdb.select(query).body['Items']
end
def delete(domain, key)
@sdb.delete_attributes domain, key
+ end
+
+ def count(domain)
+ body = @sdb.select("SELECT count(*) FROM #{domain}").body
+ body['Items']['Domain']['Count'].first.to_i
end
end
end