SQL Builder for Ruby
Add the following to your Gemfile
:
gem 'sql-maker'
And then execute:
$ bundle
require 'sql-maker'
builder = SQL::Maker::Select.new(:quote_char => '"', :auto_bind => true)
builder.add_select('id').add_from('books').add_where('books.id' => 1).as_sql
#=> SELECT "id" FROM "books" WHERE "books"."id" = 1
To avoid quoting the column name, use sql_raw
.
require 'sql-maker'
include SQL::Maker::Helper # adds sql_raw, etc
builder = SQL::Maker::Select.new(:quote_char => '"', :auto_bind => true)
builder.add_select(sql_raw('COUNT(*)')).add_from('books').as_sql
# => SELECT COUNT(*) FROM "books"
Please see the doc directory.
See CHANGELOG.md for details.
- Support plugins
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright (c) 2014 Naotoshi Seo. See LICENSE.txt for details.
Ruby SQL::Maker is a ruby port of following perl modules:
Thank you very much!!!