No commit activity in last 3 years
No release in over 3 years
Simple SQL search conditions parser (where clause)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

sql_search_parser

Simple SQL search conditions parser (where clause) based on RACC

Usage

SQLSearch.parse("a = 2")
=> #<SQLSearch::Comparison:0x00000000fd12e0 @left=#<SQLSearch::Atoms::Column:0x00000000fd1588 @name="a", @table=nil, @space=nil>, @right=#<SQLSearch::Atoms::Literal:0x00000000fd1380 @value=2, @type=:int>, @operator=:"=">

SQLSearch.parse("a = 2 and b = 3").to_s
=> "(`a` = 2) AND (`b` = 3)"

SQLSearch.parse("b = '2013-01-01T00:00:00Z'").right.value
=> #<DateTime: 2013-01-01T00:00:00+00:00 ((2456294j,0s,0n),+0s,2299161j)>

SQLSearch.parse("b = '2013-01-01T00:00:00-05:00'").right.value
=> #<DateTime: 2013-01-01T00:00:00-05:00 ((2456294j,18000s,0n),-18000s,2299161j)>

SQLSearch.parse("b IN(1,2,3)").right.values.map(&:value)
=> [1, 2, 3]

SQLSearch.parse("b + 1 > c").left
=> #<SQLSearch::Atoms::Scalar:0x000000016ceef8 @left=#<SQLSearch::Atoms::Column:0x000000016cf308 @name="b", @table=nil, @space=nil>, @right=#<SQLSearch::Atoms::Literal:0x000000016cf100 @value=1, @type=:int>, @operation=:+>

For more examples look at the tests :)

Installation

gem install sql_search_parser

or add in your Gemfile

gem 'sql_search_parser'

Build Dependencies

rake, rexical, racc

Build & install Gem locally

rake package

Run the tests

rake

or

rake test