Project

i_dig_sql

0.0
No commit activity in last 3 years
No release in over 3 years
You probably want another gem: arel. Use that to generate SQL using Ruby. This gem only generates SELECT and WITH (ie CTE) statements/expressions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

> 1.0.1
 Project Readme

I_Dig_Sql

I'm still learning how to write decent SQL queries in Postgresql 9.4. I'm using this to manage sub-queries in complicated SQL queries.

You won't find this useful and I am too lazy/busy to write decent documentation for something no one but me will use for esoteric purposes.

Instead, this to for SQL + Ruby:

Usage

Please note that none of this is ready yet.

  require 'i_dig_sql'

  sql = I_Dig_Sql.new
  sql.sql :HEROES,   "SELECT id FROM hero    WHERE id = :PERSON_ID"
  sql.sql :VILLIANS, "SELECT id FROM villian WHERE id = :PERSON_ID"

  sql.sql(:SIDE_KICKS) {

    FROM :HEROES, :good_guys do
      SELECT :nick_name, :name
    end

    INNER :PEOPLE, :others do
      ON '_.heroe_id == __.id'
      SELECT :nick_name, :name
    end

    SELECT 'field' => 'a_field'

    GROUP_BY 'id DESC', 'created_at ASC'

  }

  sql.sql :SQL, %^
    SELECT *
    FROM people
    WHERE
      id IN (SELECT ID FROM {{ HEROES }} AND status = :ALIVE)
      OR
      id IN ( {{ HEROES * }} )
      OR
      id IN ( {{ VILLIANS patron_id }} )
      OR
      id IN ( {{ VILLIANS * }} )
  ^

  puts sql.pair