Project

sqlparser

0.0
No commit activity in last 3 years
No release in over 3 years
Parses basic SQL statements.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.1.13, ~> 0.1
 Project Readme

Introducing the sqlparser gem

require 'sqlparser'

s = 'select *' 
a = SqlParser.new(s).to_a 
#=> [[:select_all, {:captures=>[]}, ["SELECT *"], nil]] 

s = 'select surname from employee where emp_id = "405060";'
a = SqlParser.new(s).to_a 
#=> [
      [:select, {:captures=>["surname"], :cols=>"surname"}, ["SELECT surname"], nil], 
      [:from, {:captures=>["employee"], :tables=>"employee"}, ["FROM employee"], nil], 
      [:where, {:captures=>["emp_id = \"405060\";"], :condition=>"emp_id = \"405060\";"}, ["WHERE emp_id = \"405060\";"], []]] 

s = 'select surname, lastname from employee where emp_id = "405060";'
a = SqlParser.new(s).to_a 
#=> [
      [:select, {:captures=>["surname, lastname"], :cols=>"surname, lastname"}, ["SELECT surname, lastname"], nil], 
      [:from, {:captures=>["employee"], :tables=>"employee"}, ["FROM employee"], nil], 
      [:where, {:captures=>["emp_id = \"405060\";"], :condition=>"emp_id = \"405060\";"}, ["WHERE emp_id = \"405060\";"], []]] 

Resources

sqlparser gem parser sql