arel-helpers alternatives and similar gems
Based on the "ORM/ODM Extensions" category.
Alternatively, view arel-helpers alternatives based on common mentions on social networks and blogs.
-
ActsAsTaggableOn
A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts. -
ActiveRecord Import
A library for bulk insertion of data into your database using ActiveRecord. -
Audited
Audited (formerly acts_as_audited) is an ORM extension that logs all changes to your Rails models. -
Apartment
Database multi-tenancy for Rack (and Rails) applications -
PublicActivity
Easy activity tracking for models - similar to Github's Public Activity -
Awesome Nested Set
An awesome replacement for acts_as_nested_set and better_nested_set. -
Closure Tree
Easily and efficiently make your ActiveRecord models support hierarchies -
Enumerize
Enumerated attributes with I18n and ActiveRecord/Mongoid support -
Acts As Tennant
Easy multi-tenancy for Rails in a shared database setup. -
Ruby JSON Schema Validator
Ruby JSON Schema Validator -
ActiveRecord Reputation System
An Active Record Reputation System for Rails -
ActsAsParanoid
ActiveRecord plugin allowing you to hide and restore records without actually deleting them. -
dry-validation
Validation library with type-safe schemas and rules -
ranked-model
An acts_as_sortable/acts_as_list replacement built for Rails 4+ -
acts_as_follower
A Gem to add Follow functionality for models -
ActiveRecordExtended
Adds additional postgres functionality to an ActiveRecord / Rails application -
Acts As Commentable
The ActiveRecord acts_as_commentable plugin -
Rails PG Extras
Rails PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more. -
StoreModel
Work with JSON-backed attributes as ActiveRecord-ish models -
Acts As Commentable with Threading
Similar to acts_as_commentable; however, utilizes awesome_nested_set to provide threaded comments -
activerecord-multi-tenant
Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus -
Unread
Handle unread records and mark them as read with Ruby on Rails -
ActsAsTree
ActsAsTree -- Extends ActiveRecord to add simple support for organizing items into parent–children relationships. -
mongoid-history
Multi-user non-linear history tracking, auditing, undo, redo for mongoid. -
ArLazyPreload
Lazy loading associations for the ActiveRecord models -
activerecord_json_validator
🔩 ActiveRecord::JSONValidator makes it easy to validate JSON attributes against a JSON schema. -
ActiveImporter
Define importers that load tabular data from spreadsheets or CSV files into any ActiveRecord-like ORM. -
Mongoid Tree
A tree structure for Mongoid documents using the materialized path pattern -
ActiveValidators
Collection of ActiveModel/ActiveRecord validators -
PermenantRecords
Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid -
ActiveRecord::Turntable
ActiveRecord Sharding Plugin -
data_miner
Download, unpack from a ZIP/TAR/GZ/BZ2 archive, parse, correct, convert units and import Google Spreadsheets, XLS, ODS, XML, CSV, HTML, etc. into your ActiveRecord models. Uses RemoteTable gem internally. -
Espinita
Audit activerecord models like a boss (and works with rails 4!) -
mini_record
ActiveRecord meets DataMapper, with MiniRecord you are be able to write schema inside your models.
InfluxDB - Power Real-Time Data Analytics at Scale
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of arel-helpers or a related project?
README
arel-helpers
Useful tools to help construct database queries with ActiveRecord and Arel.
Installation
gem install arel-helpers
Usage
require 'arel-helpers'
ArelTable Helper
Usually you'd reference database columns in Arel via the #arel_table
method on your ActiveRecord models. For example:
class Post < ActiveRecord::Base
...
end
Post.where(Post.arel_table[:id].eq(1))
Typing ".arel_table" over and over again can get pretty old and make constructing queries unnecessarily verbose. Try using the ArelTable
helper to clean things up a bit:
class Post < ActiveRecord::Base
include ArelHelpers::ArelTable
...
end
Post.where(Post[:id].eq(1))
JoinAssociation Helper
Using pure Arel is one of the only ways to do an outer join with ActiveRecord. For example, let's say we have these two models:
class Author < ActiveRecord::Base
has_many :posts
# attribute id
# attribute username
end
class Post < ActiveRecord::Base
belongs_to :author
has_many :comments
# attribute id
# attribute author_id
# attribute subject
end
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :author
# attribute id
# attribute post_id
# attribute author_id
end
A join between posts and comments might look like this:
Post.joins(:comments)
ActiveRecord introspects the association between posts and comments and automatically chooses the right columns to use in the join conditions.
Things start to get messy however if you want to do an outer join instead of the default inner join. Your query might look like this:
Post.joins(
Post.arel_table.join(Comment.arel_table, Arel::Nodes::OuterJoin)
.on(Post[:id].eq(Comment[:post_id]))
.join_sources
)
Such verbose. Much code. Very bloat. Wow. We've lost all the awesome association introspection that ActiveRecord would otherwise have given us. Enter ArelHelpers.join_association
:
Post.joins(
ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin)
)
Easy peasy.
Note that pretty much anything you can pass to ActiveRecord's #join
method you can also pass to #join_association
's second argument. For example, you can pass a hash to indicate a set of nested associations:
Post.joins(
ArelHelpers.join_association(Post, { comments: :author })
)
This might execute the following query:
SELECT "posts".*
FROM "posts"
INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
INNER JOIN "authors" ON "authors"."id" = "comments"."author_id"
#join_association
also allows you to customize the join conditions via a block:
Post.joins(
ArelHelpers.join_association(Post, :comments, Arel::Nodes::OuterJoin) do |assoc_name, join_conditions|
join_conditions.and(Post[:author_id].eq(4))
end
)
But wait, there's more! Include the ArelHelpers::JoinAssociation
concern into your models to have access to the join_association
method directly from the model's class:
include ArelHelpers::JoinAssociation
Post.joins(
Post.join_association(:comments, Arel::Nodes::OuterJoin) do |assoc_name, join_conditions|
join_conditions.and(Post[:author_id].eq(4))
end
)
Query Builders
ArelHelpers also contains a very simple class that's designed to provide a light framework for constructing queries using the builder pattern. For example, let's write a class that encapsulates generating queries for blog posts:
class PostQueryBuilder < ArelHelpers::QueryBuilder
def initialize(query = nil)
# whatever you want your initial query to be
super(query || post.unscoped)
end
def with_title_matching(title)
reflect(
query.where(post[:title].matches("%#{title}%"))
)
end
def with_comments_by(usernames)
reflect(
query
.joins(comments: :author)
.where(author[:username].in(usernames))
)
end
def since_yesterday
reflect(
query.where(post[:created_at].gteq(Date.yesterday))
)
end
private
def author
Author
end
def post
Post
end
end
The #reflect
method creates a new instance of PostQueryBuilder
, copies the query into it and returns the new query builder instance. This allows you to chain your method calls:
PostQueryBuilder.new
.with_comments_by(['camertron', 'catwithtail'])
.with_title_matching("arel rocks")
.since_yesterday
Conditional reflections
If you have parts of a query that should only be added under certain conditions you can return reflect(query)
from your method. E.g:
def with_comments_by(usernames)
if usernames
reflect(
query.where(post[:title].matches("%#{title}%"))
)
else
reflect(query)
end
end
This can become repetitive, and as an alternative you can choose to prepend not_nil
to your method definition:
class PostQueryBuilder < ArelHelpers::QueryBuilder
not_nil def with_comments_by(usernames)
reflect(query.where(post[:title].matches("%#{title}%"))) if usernames
end
end
Requirements
Requires ActiveRecord >= 3.1.0, < 6, tested against Ruby 2.2.4. Depends on SQLite for testing purposes.
Running Tests
bundle exec rspec
Authors
- Cameron C. Dutro: http://github.com/camertron