Module: DataMapper::Aggregates::DataObjectsAdapter

### Home Classes Methods

### In Files

- lib/dm-aggregates/adapters/dm-do-adapter.rb

### Methods

- #aggregate

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Aggregates
- DataMapper::Aggregates::Collection
- DataMapper::Aggregates::DataObjectsAdapter
- DataMapper::Aggregates::Functions
- DataMapper::Aggregates::Model
- DataMapper::Aggregates::Operators
- DataMapper::Aggregates::Query
- DataMapper::Aggregates::Repository
- Symbol

No matching classes.

# DataMapper::Aggregates::DataObjectsAdapter

### Public Instance Methods

aggregate(query) click to toggle source

    # File lib/dm-aggregates/adapters/dm-do-adapter.rb, line 6
    def aggregate(query)
      fields = query.fields
      types  = fields.map { |p| p.respond_to?(:operator) ? String : p.primitive }

      field_size = fields.size

      records = []

      with_connection do |connection|
        statement, bind_values = select_statement(query)

        command = connection.create_command(statement)
        command.set_types(types)

        reader = command.execute_reader(*bind_values)

        begin
          while(reader.next!)
            row = fields.zip(reader.values).map do |field, value|
              if field.respond_to?(:operator)
                send(field.operator, field.target, value)
              else
                field.load(value)
              end
            end

            records << (field_size > 1 ? row : row[0])
          end
        ensure
          reader.close
        end
      end

      records
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.