All Projects → delonnewman → activerecord-setops

delonnewman / activerecord-setops

Licence: MIT license
Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to activerecord-setops

rails cursor pagination
Add cursor pagination to your ActiveRecord backed application
Stars: ✭ 21 (+0%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
Ransack
Object-based searching.
Stars: ✭ 5,020 (+23804.76%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
filtered
Filters ActiveRecord queries in a nice way
Stars: ✭ 28 (+33.33%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
activerecord-crate-adapter
Ruby on Rails ActiveRecord adapter for CrateDB
Stars: ✭ 27 (+28.57%)
Mutual labels:  ruby-gem, activerecord, ruby-on-rails
Matestack Ui Core
Matestack enables you to create sophisticated, reactive UIs in pure Ruby, without touching JavaScript and HTML. You end up writing 50% less code while increasing productivity, maintainability and developer happiness.
Stars: ✭ 469 (+2133.33%)
Mutual labels:  ruby-gem, ruby-on-rails
Cloudinary gem
Cloudinary GEM for Ruby on Rails integration
Stars: ✭ 394 (+1776.19%)
Mutual labels:  ruby-gem, ruby-on-rails
React on rails
Integration of React + Webpack + Rails + rails/webpacker including server-side rendering of React, enabling a better developer experience and faster client performance.
Stars: ✭ 4,815 (+22828.57%)
Mutual labels:  ruby-gem, ruby-on-rails
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+2966.67%)
Mutual labels:  ruby-gem, activerecord
Unscoped associations
🔦 Skip the default_scope in your associations (ActiveRecord)
Stars: ✭ 53 (+152.38%)
Mutual labels:  ruby-gem, activerecord
Sidekiq Cron
Scheduler / Cron for Sidekiq jobs
Stars: ✭ 1,383 (+6485.71%)
Mutual labels:  ruby-gem, ruby-on-rails
Filestack Rails
Official Ruby on Rails plugin for Filestack File Picker that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
Stars: ✭ 220 (+947.62%)
Mutual labels:  ruby-gem, ruby-on-rails
prefixed ids
Friendly Prefixed IDs for your Ruby on Rails models
Stars: ✭ 159 (+657.14%)
Mutual labels:  activerecord, ruby-on-rails
Postgresql cursor
ActiveRecord PostgreSQL Adapter extension for using a cursor to return a large result set
Stars: ✭ 384 (+1728.57%)
Mutual labels:  ruby-gem, activerecord
Motion
Reactive frontend UI components for Rails in pure Ruby
Stars: ✭ 498 (+2271.43%)
Mutual labels:  ruby-gem, ruby-on-rails
Devise masquerade
Extension for devise, enable login as functionality. Add link to the masquerade_path(resource) and use it.
Stars: ✭ 380 (+1709.52%)
Mutual labels:  ruby-gem, ruby-on-rails
Pattern
A collection of lightweight, standardized, rails-oriented patterns.
Stars: ✭ 377 (+1695.24%)
Mutual labels:  ruby-gem, ruby-on-rails
Rorvswild
Ruby on Rails app monitoring: performances & exceptions insights for rails developers.
Stars: ✭ 159 (+657.14%)
Mutual labels:  ruby-gem, ruby-on-rails
superglue
A productive library for Classic Rails, React and Redux
Stars: ✭ 106 (+404.76%)
Mutual labels:  ruby-gem, ruby-on-rails
Pluck to hash
Extend ActiveRecord pluck to return array of hashes
Stars: ✭ 275 (+1209.52%)
Mutual labels:  ruby-gem, activerecord
Loaf
Manages and displays breadcrumb trails in Rails app - lean & mean.
Stars: ✭ 360 (+1614.29%)
Mutual labels:  ruby-gem, ruby-on-rails

Ruby Gem Version

ActiveRecord::Setops

Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll). Has only been tested with Rails 5.

Synopsis

class Student < ActiveRecord::Base; end
class Employee < ActiveRecord::Base; end

(Student.select(:name, :birth_date) | Employee.select(:name, :birth_date)).where("name like John%")

Why?

Joins can be difficult to reason about in Arel (and SQL for that matter). Many joins can be replaced with set operations which are much simpler beasts, may offer performance gains, and have consistent mathematical properties. But these operations while present in Arel are missing in ActiveRecord. This module attempts to correct this lack.

Installation

Add this line to your application's Gemfile:

gem 'activerecord-setops'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-setops

Non-Installation

If you'd like the functionality, but would prefer to avoid yet another dependency, please fill free to paste the following code into your nearest lib directory, I'm certain it's not perfect but it has been tested with Rails 5, and is being used in production.

module ActiveRecord
  class Relation
    def union(other)
      binary_operation(Arel::Nodes::Union, other)
    end
    alias | union

    def union_all(other)
      binary_operation(Arel::Nodes::UnionAll, other)
    end
    alias + union_all

    def intersect(other)
      binary_operation(Arel::Nodes::Intersect, other)
    end
    alias & intersect

    def difference(other)
      binary_operation(Arel::Nodes::Except, other)
    end
    alias - difference

    private

    def binary_operation(op_class, other)
      @klass.unscoped.from(Arel::Nodes::TableAlias.new(op_class.new(self.arel.ast, other.arel.ast), @klass.arel_table.name))
    end
  end
end

See Also

Support

Buy Me A Coffee

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].