Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/georgetaveras1231/easy_union_set
easily create unions and intersections in ActiveRecord.
https://github.com/georgetaveras1231/easy_union_set
Last synced: about 2 months ago
JSON representation
easily create unions and intersections in ActiveRecord.
- Host: GitHub
- URL: https://github.com/georgetaveras1231/easy_union_set
- Owner: GeorgeTaveras1231
- License: mit
- Created: 2014-08-04T14:22:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-10T22:54:27.000Z (over 10 years ago)
- Last Synced: 2024-10-27T22:54:43.122Z (3 months ago)
- Language: Ruby
- Size: 516 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
[easy_union_set](https://rubygems.org/gems/easy_union_set)
==============easily create unions and intersections in ActiveRecord.
Setup
```ruby
gem 'easy_union_set'
```Easy to use, So I'll jump straight into the examples
to create a UNION
```ruby
Project.where("title LIKE '%a%'") | Project.having("LENGTH(description) > 10").group(:id)# => SELECT "projects".* FROM ( SELECT "projects".* FROM "projects" WHERE (title LIKE '%a%') UNION SELECT "projects".* FROM "projects" GROUP BY id HAVING LENGTH(description) > 10 ) "projects"
```to create an INTERSECT
```ruby
Project.where("title LIKE '%a%'") & Project.having("LENGTH(description) > 10").group(:id)# => SELECT "projects".* FROM ( SELECT "projects".* FROM "projects" WHERE (title LIKE '%a%') INTERSECT SELECT "projects".* FROM "projects" GROUP BY id HAVING LENGTH(description) > 10 ) "projects"
```to create a UNION ALL
```ruby
Project.where("title LIKE '%a%'") | {:all => Project.having("LENGTH(description) > 10").group(:id)}# => SELECT "projects".* FROM ( SELECT "projects".* FROM "projects" WHERE (title LIKE '%a%') UNION ALL SELECT "projects".* FROM "projects" GROUP BY id HAVING LENGTH(description) > 10 ) "projects"
```if for some reason you'd still rather make multiple queries and make a ruby union simply call #to_a on the AR:Relation object before using the #& or #| methods.