Project

sql_pluck

0.0
No commit activity in last 3 years
No release in over 3 years
Provide #pluck_by_sql for Rails ActiveRecord models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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'], ...]