0.0
No commit activity in last 3 years
No release in over 3 years
a sql where string builder, can ignore nil and black string.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

WhereBuilder

use this tool can build a where sentence for sql, it's can ignore a condition when it's para is nil or black string. my purpose is not check nil for every condition, don't repeat so much if else.

Installation

Add this line to your application's Gemfile:

gem 'where_builder'

And then execute:

$ bundle

Or install it yourself as:

$ gem install where_builder

Usage

require 'where_builder'
f = WhereBuilder::WhereBuilder.new()
where = f.build(
f.add('a.name = ?', 'zd'),
f.OR('a.id=?', 1),
f.AND,
f.bracket(
f.add('key like ?', 'zd'),
f.AND('value=?', '2')
)
)

puts "where=#{where}"

output: where=["WHERE a.name = ? OR a.id=? AND ( key like ? AND value=?)", ["zd", 1, "zd", "2"]]
=> nil

============================== where = f.build(
f.add('a.name = b.name'),
f.OR('a.id=?', 1),
f.AND,
f.bracket(
f.add('key like ?', 'zd'),
f.AND('value=?', '2')
)
)
=> ["WHERE a.name = b.name OR a.id=? AND ( key like ? AND value=?)", [1, "zd", "2"]]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request