Sha256: 748bc442bad9afca85b38d1595bcdb6a6e1e218d66b8bfb234b7d76e4138f1af

Contents?: true

Size: 976 Bytes

Versions: 5

Compression:

Stored size: 976 Bytes

Contents

module CassandraCQL
  class Statement
    def self.sanitize(statement, bind_vars=[])
      return statement if bind_vars.empty?

      bind_vars = bind_vars.dup
      expected_bind_vars = statement.count("?")

      raise Error::InvalidBindVariable, "Wrong number of bound variables (statement expected #{expected_bind_vars}, was #{bind_vars.size})" if expected_bind_vars != bind_vars.size

      statement.gsub(/\?/) do
        quote(cast_to_cql(bind_vars.shift))
      end
    end
  end
end

module Superstore
  module Connection
    extend ActiveSupport::Concern

    module ClassMethods
      def adapter
        @@adapter ||= adapter_class.new(config)
      end

      def adapter_class
        case config[:adapter]
        when 'hstore'
          Superstore::Adapters::HstoreAdapter
        when nil, 'cassandra'
          Superstore::Adapters::CassandraAdapter
        else
          raise "Unknown adapter #{config[:adapter]}"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
superstore-1.0.5 lib/superstore/connection.rb
superstore-1.0.4 lib/superstore/connection.rb
superstore-1.0.3 lib/superstore/connection.rb
superstore-1.0.2 lib/superstore/connection.rb
superstore-1.0.0 lib/superstore/connection.rb