0.0
No commit activity in last 3 years
No release in over 3 years
Adds to_sql to arel table and attribute.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
~> 1.7
~> 12.0
~> 3.2

Runtime

>= 6.0
 Project Readme

Adds to_sql to arel table and attribute.

Gem Version Build Status

About

Arel::Table and Àrel::Attributes::Attribute receive to_sql method.

Example

table = Arel::Table.new(:users)
table.to_sql # => `users`
table[:name].to_sql # => `users`.`name`

Usage

Before

# Calculate total money paid.
sql = "SELECT SUM(orders.price * (100 - orders.discount) / 100) as total 
       FROM orders 
       INNER JOIN payments ON payments.order_id = orders.id;"

After

# Calculate total money paid.
t_order   = Order.arel_table
t_payment = Payment.arel_table
sql       = "SELECT SUM(#{t_order[:price]} * (100 - #{t_order[:discount]}) / 100) as total 
             FROM #{t_order} 
             INNER JOIN #{t_payment} ON #{t_payment[:order_id]} = #{t_order[:id]};"

Installing gem

Add to your Gemfile:

gem 'arel-to-sql', '~> 1.0'

Running Tests

Install bundler:

gem install bundler

Install dependencies:

cd arel-to-sql && bundle

Run tests:

cd arel-to-sql && appraisal rake test