Project

nql

0.0
No commit activity in last 3 years
No release in over 3 years
Natural Query Language built on top of ActiveRecord and Ransack
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.0
~> 1.3.0

Runtime

>= 3.2.0
~> 0.7
~> 1.4.0
 Project Readme

NQL

Gem Version Build Status Coverage Status Code Climate

Natural Query Language built on top of ActiveRecord and Ransack

Installation

Add this line to your application's Gemfile:

gem 'nql'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nql

Supported comparators

--------------------------------------
| Symbol | Description               |
--------------------------------------
| :      | Contains                  |
| !:     | Not contains              |
| =      | Equals                    |
| !=     | Not equals                |
| >      | Grater than               |
| >=     | Grater or equals than     |
| <      | Less than                 |
| <=     | Less or equals than       |
| ~      | Matches (eq ignore case)  |
--------------------------------------

Usage

Converts from natural language to query expression

Country.nql('(name: arg | name: br) & region = south').to_sql
=> "SELECT coutries.* FROM countries WHERE (countries.name LIKE '%arg%' OR countries.name LIKE '%br%') AND region = 'south'"

Joins support

Country.nql('cities.name: buenos').to_sql
=> "SELECT countries.* FROM countries LEFT OUTER JOIN cities ON countries.id = cities.country_id WHERE cities.name LIKE '%buenos%'"

Invalid expressions handling

Safe query

Country.nql('xyz').to_sql
=> "SELECT coutries.* FROM countries WHERE (1=2)

Raising exceptions

Country.nql!('xyz') => raise NQL::SyntaxError

Country.nql!('xyz: arg') => raise NQL::AttributesNotFoundError

Country.nql!(1234) => raise NQL::DataTypeError

Contributing

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