aggregate (DataMapper::Aggregates::DataObjectsAdapter)

    # File lib/dm-aggregates/adapters/data_objects_adapter.rb, line 8
          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.typecast(value)
                    end
                  end

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

            records
          end