Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 5e8840dc01
Fetching contributors…

Cannot retrieve contributors at this time

78 lines (57 sloc) 2.976 kB

Veritas SQL Generator

Relational algebra SQL generator

Build Status

Installation

With Rubygems:

$ gem install veritas-sql-generator
$ irb -rubygems
>> require 'veritas-sql-generator'
=> true

With git and local working copy:

$ git clone git://github.com/dkubb/veritas-sql-generator.git
$ cd veritas-sql-generator
$ rake install
$ irb -rubygems
>> require 'veritas-sql-generator'
=> true

NOTE: This gem works best with ruby 1.9, however if you are using ruby 1.8 you must also install backports, then require backports and backports/basic_object, eg:

$ ruby -e 'puts RUBY_VERSION'
=> 1.8.7
$ gem install backports
$ irb -rubygems
>> require 'backports'
=> true
>> require 'backports/basic_object'
=> true
>> require 'veritas-sql-generator'  # assuming it was installed by one of the two methods above
=> true

Usage

# visit every node in the relation AST
generator = Veritas::SQL::Generator::Relation.visit(relation)

# generate an SQL string
sql = generator.to_sql

# generate an SQL subquery string
subquery_sql = generator.to_subquery

Description

The purpose of this gem is to produce valid SQL from a veritas relation. A relation is a representation of a query constructed using relational algebra organized into an AST. Each node in the AST corresponds to an operation defined in the algebra.

The SQL produced has been verified and tested against PostgreSQL 9.0.4. Dialects for MySQL, SQLite, Oracle and SQL Server are planned.

Note on Patches/Pull Requests

  • If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. This library is still in early development, and it may not always be clear the direction it is going. Some features may not be appropriate yet, may need to be deferred until later when the foundation for them is laid, or may be more applicable in a plugin.
  • Fork the project.
  • Make your feature addition or bug fix.
  • Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
  • Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged.
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010-2011 Dan Kubb. See LICENSE for details.

Jump to Line
Something went wrong with that request. Please try again.