Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 567 Bytes

README.md

File metadata and controls

19 lines (14 loc) · 567 Bytes

sql_pluck gem

Provide #pluck_by_sql method for Rails ActiveRecord models. You can execute arbitrary SQL and get bare attribute values without creating ActiveRecord objects, while values are casted to appropreate types.

Usage:

class SomeModel < ActiveRecord::Base
  extend SQLPluck
end

SomeModel.pluck_by_sql('select id, name from some_model where id % 777 = 0')
# => [[777, 'name777'], [1554, 'name1554'], ...]

SomeModel.pluck_by_sql(['select id, name from some_model where created_at > ?', time])
# => [[1901, 'name1901'], [1902, 'name1902'], ...]