Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Introduction to Arel
Search
Bruno Sutic
October 28, 2014
Programming
350
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Arel
Arel fundamentals
Bruno Sutic
October 28, 2014
More Decks by Bruno Sutic
See All by Bruno Sutic
Readline + irb/pry = <3
brunosutic
0
190
Moreutils
brunosutic
0
91
The venerable "expect"
brunosutic
0
85
Capistrano vs Mina: Capistrano demo talk
brunosutic
0
490
Configuring tmux
brunosutic
0
130
Tmux osnove
brunosutic
0
260
Deploying Rails apps with Capistrano
brunosutic
0
150
Other Decks in Programming
See All in Programming
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.3k
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
460
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
570
最近”作らせてる” ローカルAIアプリの話
akit37
0
450
ジョジョの世界をXRで再現する
mofurune
0
150
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
360
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
280
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
180
phperだってパンチカードでコーディングしたい
o0h
PRO
0
280
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.3k
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
540
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
470
Between Models and Reality
mayunak
4
490
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Chasing Engaging Ingredients in Design
codingconduct
0
350
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
Claude Code のすすめ
schroneko
67
230k
Into the Great Unknown - MozCon
thekraken
41
2.8k
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Transcript
Introduction to Arel
Bruno Sutic Rails & Javascript developer Ideal Project Group,
Chicago github.com/bruno- @brunosutic
What is Arel? • github.com/rails/arel • “Simplifies generation of complex
SQL” You write Ruby, out comes the SQL • dependency of ActiveRecord • can be used together with ActiveRecord
How I learned about Arel? • credit: Janko Marohnic •
used Arel to optimize a feature on a project
Demo to get you interested :)
Prerequisites for the examples • ‘Customer’ is an ActiveRecord model
• Arel api for a column: Customer.arel_table[:name] • A “convention”: class Customer def self.[](column) arel_table[column] end end Customer[:name]
Basic example • ActiveRecord Customer.where(name: variable) • Arel Customer.where(Customer[:name].eq(variable))
A bit more useful example • ActiveRecord Customer.joins(:sales) .where(“sales.price” =>
variable) or Customer.joins(:sales) .where(sales: { price: variable }) • Arel Customer.joins(:sales) .where(Sale[:price].eq(variable))
SQL comparisons example • ActiveRecord Customer.where(“credits > ?”, credits_variable) •
Arel Customer.where( Customer[:credits].gt(credits_variable) ) • All comparison operators: gt, lt, gteq, lteq
OR condition example • ActiveRecord Customer.where(“credits > ? OR credits
< ?”, var1, var2) • Arel Customer.where( Customer[:credits].gt(var1).or( Customer[:credits].lt(var2) ) )
Complex conditions example • ActiveRecord Customer.where( “credits > ? OR
(name = ? AND credits < ?)”, var1, var2, var3 ) • Arel Customer.where( Customer[:credits].gt(var1).or( Customer[:name].eq(var2).and( Customer[:credits].lt(var3) ) ) )
LIKE example • ActiveRecord Customer.where(“name LIKE ?”, “%#{variable}%”) • Arel
Customer.where(Customer[:name].matches(“%#{variable}%”))
Other features • support for all SQL ‘join’ types •
SQL literals • writing only a part of a bigger query as SQL • example: CASE statement
Benefits of using Arel • pure Ruby, nicer looking code
• proper code highlighting • ruby exceptions • completely avoids SQL injection
Arel resources • github repo: https://github.com/rails/arel • great speech: https://www.youtube.com/watch?v=ShPAxNcLm3o
• source code walkthrough: https://www.youtube.com/watch?v=EJ6b_2S9Ids • examples from this talk: https://gist.github.com/bruno-/5964403476c791331c49
Questions?