SimpleMysqlApi
TODO: Write a gem description
Installation
Add this line to your application's Gemfile:
gem 'simple_mysql_api', "~> 0.0.4"
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple_mysql_api
Usage
Method name: mysql_search(options={})
options:
Simple search
User.mysql_search({search_params: {name: "alex", address: "new"}})
It will return Users having name matching alex:(mysql like "%alex%") and address matching "new"
Search in associated models
-
If model has has_many relations with other models then
Ex. User has_many cities =>
User.mysql_search({search_params: {name: "alex", city_name_: "new"}, has_many: true}) -
If model has belongs_to relations with other model then
Ex. Project belongs_to users =>
Project.mysql_search({search_params: {name: "my_p", user_name_: "ale"}, belongs_to: true}) -
Search by ranges(Integer and decimals): Ex. If Item has price field then search for price by range Item.mysql_search({search_params: {price: "1000-2500"}}) # for items having price between 1000 to 2500 Item.mysql_search({search_params: {price: "<2500"}}) # for items having price less than 2500
Operators: <, >, <= , >=, - #for integer and floating attributes
-
Search by ranges(Datetime):
Ex. If Item has posted_at field then search for posted_at by range
Item.mysql_search({search_params: {posted_at: "2012-09-08 15:28:21 +0530..2012-09-10 15:27:27 +0530"}}) # for items having posted_at date between the given dates
Item.mysql_search({search_params: {posted_at: "<2012-09-08 15:28:21 +0530"}}) # for items having posted_at date earlier than given dateOperators: <, >, <= , >=, ..(for range) #for datetime attributes
-
It joins the tables automatically (Please specify primary & foreign keys if you are using custom keys)
Contributing
- 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