Sha256: 309cf6f08d41cd0efd09223c71d263fd5ee767fd7ca0c96c08b70eb870edacf9

Contents?: true

Size: 781 Bytes

Versions: 9

Compression:

Stored size: 781 Bytes

Contents

module Cassanity
  module ArgumentGenerators
    class ColumnFamilyInsert

      # Internal
      def call(args = {})
        name    = args.fetch(:column_family_name)
        data    = args.fetch(:data)
        using   = args[:using] || {}
        keys    = data.keys
        binders = ['?'] * keys.size

        if (keyspace_name = args[:keyspace_name])
          name = "#{keyspace_name}.#{name}"
        end

        cql = "INSERT INTO #{name} (#{keys.join(', ')}) VALUES (#{binders.join(', ')})"

        unless using.empty?
          statements = []
          using.each do |key, value|
            statements << "#{key.upcase} #{value}"
          end
          cql << " USING #{statements.join(' AND ')}"
        end

        [cql, *data.values]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cassanity-0.6.0 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.6.0.beta5 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.6.0.beta4 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.6.0.beta3 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.6.0.beta2 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.6.0.beta1 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.5.1 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.5.0 lib/cassanity/argument_generators/column_family_insert.rb
cassanity-0.4.0 lib/cassanity/argument_generators/column_family_insert.rb