Sha256: 32b7b3c70090c37690a7c264fbb2716bd81ab06ec56a2423be4d624a6e3338ae

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

require 'rom/commands'

module Rom
  module Dynamo
    module Commands
      # DynamoDB create command
      class Create < ROM::Commands::Create
        def execute(tuples)
          Array([tuples]).flatten.map do |tuple|
            attributes = input[tuple]
            dataset.insert(attributes.to_h)
          end
        end

        def dataset
          relation.dataset
        end
      end

      # DynamoDB update command
      class Update < ROM::Commands::Update
        def execute(params)
          attributes = input[params]
          relation.map do |tuple|
            dataset.update(tuple, attributes.to_h)
          end
        end

        def dataset
          relation.dataset
        end
      end

      # DynamoDB delete command
      class Delete < ROM::Commands::Delete
        def execute
          relation.to_a.tap do |tuples|
            tuples.each { |t| dataset.delete(t) }
          end
        end

        def dataset
          relation.dataset
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-dynamo-0.14.0 lib/rom/dynamo/commands.rb