Commit 07b09817 authored by Ohad Dahan's avatar Ohad Dahan

Added ORDER BY, GROUP BY, LIMIT, OFFSET

parent ea78109a
......@@ -30,9 +30,16 @@ module Nativepluck
raise ArgumentError.new('No columns to pluck were provided') if columns.size == 0
begin
Nativepluck.set_pg_native_casters
results = ActiveRecord::Base.connection.raw_connection.async_exec(
"select #{columns.join(',')} from #{self.table_name} #{"limit #{opts[:limit]}" if opts[:limit]}"
)
sql = "
SELECT #{columns.join(',')}
FROM #{self.table_name}
#{"GROUP BY #{opts[:group].zip.map { |i| i.join(' ') }.join(',')}" if opts[:group]}
#{"ORDER BY #{opts[:order].zip.map { |i| i.join(' ') }.join(',')}" if opts[:order]}
#{"LIMIT #{opts[:limit]}" if opts[:limit]}
#{"OFFSET #{opts[:offset]}" if opts[:offset]}
"
results = ActiveRecord::Base.connection.raw_connection.async_exec(sql)
puts "#{__method__} sql = #{sql}" if opts[:verbose]
columns.size == 1 ? out = results.column_values(0) : out = results.values
ensure
Nativepluck.return_original_casters
......
......@@ -58,4 +58,5 @@ Rails.application.configure do
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment