Skip to content
This repository

Sample usage:


>> require 'sql_tree'
=> false

# Start by parsing a query
>> tree = SQLTree["select * from table where field='value'"]
=> SQLTree::Node::SelectQuery[SELECT * FROM "table" WHERE ("field" = 'value')]

# Inspect some parts of the query
>> tree.from
=> [SQLTree::Node::TableImport["table"]]
>> tree.where
=> SQLTree::Node::ComparisonExpression[("field" = 'value')]
>> tree.where.rhs
=> SQLTree::Node::Value['value']

# Now, lets change the query somewhat
>> tree.from.first.table = 'another_table'
=> "another_table"
>> tree.where.rhs.value = "Something different"
=> "Something different"

# Return the new query as a string
>> tree.to_sql
=> "SELECT * FROM \"another_table\" WHERE (\"field\" = 'Something different')"
Something went wrong with that request. Please try again.