Sha256: 90815aa6c2535e00720b8d1e8d284b0830db86f6a968cb30bad5d765acee4467

Contents?: true

Size: 1.43 KB

Versions: 19

Compression:

Stored size: 1.43 KB

Contents

require 'fog'

module Heirloom
  module AWS
    class SimpleDB

      def initialize(args)
        @config = args[:config]
        @sdb = Fog::AWS::SimpleDB.new :aws_access_key_id     => @config.access_key,
                                      :aws_secret_access_key => @config.secret_key,
                                      :region                => @config.metadata_region
      end

      def domains
        @sdb.list_domains.body['Domains']
      end

      def domain_exists?(domain)
        domains.include? domain
      end

      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

      def item_count(domain, item)
        query = "SELECT count(*) FROM `#{domain}` WHERE itemName() = '#{item}'"
        @sdb.select(query).body['Items']['Domain']['Count'].first.to_i
      end

    end
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
heirloom-0.11.0.beta.2 lib/heirloom/aws/simpledb.rb
heirloom-0.11.0.beta.1 lib/heirloom/aws/simpledb.rb
heirloom-0.10.1 lib/heirloom/aws/simpledb.rb
heirloom-0.10.0 lib/heirloom/aws/simpledb.rb
heirloom-0.9.0 lib/heirloom/aws/simpledb.rb
heirloom-0.8.3 lib/heirloom/aws/simpledb.rb
heirloom-0.8.2 lib/heirloom/aws/simpledb.rb
heirloom-0.8.1 lib/heirloom/aws/simpledb.rb
heirloom-0.8.0 lib/heirloom/aws/simpledb.rb
heirloom-0.7.4 lib/heirloom/aws/simpledb.rb
heirloom-0.7.3 lib/heirloom/aws/simpledb.rb
heirloom-0.7.3rc2 lib/heirloom/aws/simpledb.rb
heirloom-0.7.3rc1 lib/heirloom/aws/simpledb.rb
heirloom-0.7.2 lib/heirloom/aws/simpledb.rb
heirloom-0.7.2rc2 lib/heirloom/aws/simpledb.rb
heirloom-0.7.2rc1 lib/heirloom/aws/simpledb.rb
heirloom-0.7.1 lib/heirloom/aws/simpledb.rb
heirloom-0.7.0 lib/heirloom/aws/simpledb.rb
heirloom-0.7.0rc1 lib/heirloom/aws/simpledb.rb