Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Arel
Search
Bruno Sutic
October 28, 2014
Programming
1
270
Introduction to Arel
Arel fundamentals
Bruno Sutic
October 28, 2014
Tweet
Share
More Decks by Bruno Sutic
See All by Bruno Sutic
Readline + irb/pry = <3
brunosutic
0
140
Moreutils
brunosutic
0
59
The venerable "expect"
brunosutic
0
65
Capistrano vs Mina: Capistrano demo talk
brunosutic
0
460
Configuring tmux
brunosutic
0
100
Tmux osnove
brunosutic
0
190
Deploying Rails apps with Capistrano
brunosutic
0
110
Other Decks in Programming
See All in Programming
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
170
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
Oxlint JS plugins
kazupon
1
760
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
0
910
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
540
CSC307 Lecture 08
javiergs
PRO
0
670
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
Fragmented Architectures
denyspoltorak
0
150
Apache Iceberg V3 and migration to V3
tomtanaka
0
150
Architectural Extensions
denyspoltorak
0
270
Featured
See All Featured
Side Projects
sachag
455
43k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
[SF Ruby Conf 2025] Rails X
palkan
1
740
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
130
Docker and Python
trallard
47
3.7k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
770
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
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?