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
Building an ORM with Arel
Search
Prathamesh Sonpatki
August 22, 2014
Technology
0
380
Building an ORM with Arel
Talk given at Madison Ruby 2014 with @vipulnsward
Prathamesh Sonpatki
August 22, 2014
Tweet
Share
More Decks by Prathamesh Sonpatki
See All by Prathamesh Sonpatki
Secrets to Monitor Kubernetes Workloads
prathamesh
1
81
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
62
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
53
Monitoring vs. Debugging
prathamesh
0
120
Handling High Cardinality in Observability
prathamesh
1
80
Setting up Monitoring for Kubernetes
prathamesh
0
290
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
79
Monitoring vs. Debugging - IG Meetup 22nd July
prathamesh
2
94
Pune_User_Group.pdf
prathamesh
0
88
Other Decks in Technology
See All in Technology
医療業界に特化した音声認識モデル構築のためのアノテーションの実態
thickstem
0
420
AI とペアプロしてわかった 3 つのヒューマンエラー
takahiroikegawa
0
270
おれのAI活用の現状とこれから
tsukasagr
0
110
JavaのMCPサーバーで体験するAIエージェントの世界
tatsuya1bm
1
210
やさしいClaude Code入門
minorun365
PRO
40
32k
[zh-TW] DevOpsDays Taipei 2025 -- Creating Awesome Change in SmartNews!(machine translation)
martin_lover
1
690
入門 ESlint Typegen #TSKaigi #TSKaigi2025_kataritai
bengo4com
0
2k
うちの会社の評判は?SNSの投稿分析にAIを使ってみた
doumae
0
600
20250514_未経験から Fintech実務参画まで。学生エンジニアの挑戦録
hideto1008
0
840
Devin&Cursor、それぞれの「本質」から導く最適ユースケース戦略
empitsu
8
3k
データ戦略部門 紹介資料
sansan33
PRO
1
3.1k
ソフトウェアテストのAI活用_ver1.20
fumisuke
0
200
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
Code Reviewing Like a Champion
maltzj
524
40k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
760
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
42
2.4k
Scaling GitHub
holman
459
140k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
The Cult of Friendly URLs
andyhume
78
6.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.6k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
Transcript
Building an ORM with ARel Walking up the AS(Tree) @vipulnsward,
@_cha1tanya
Vipul @vipulnsward && Prathamesh @_cha1tanya
None
26 Hours
48 Hours
None
None
None
RubyIndia.org
None
podcast.rubyindia.org
Indian Ruby Conferences RubyConfIndia Garden City Ruby Conf DeccanRubyConf Do
visit India!
Building an ORM with ARel Walking up the (AS)Tree @vipulnsward,
@_cha1tanya
None
Build our own ORM - Why?
Object-relational mapping (ORM, O/RM, and O/R mapping) in computer science
is a programming technique for converting data between incompatible type systems in object- oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language.
Active Record “An object that wraps a row in a
database table or view, encapsulates the database access, and adds domain logic on that data.”
Components • Database connection • Query Generator • Attribute Access
• Typecasting
SQL torm_development=# select * from posts; id | name |
content | author | subject -----+-------------+---------+------------+--------- 332 | RGenGC| Restricted Generation Garbage Collection | GorbyPuff | How does RGenGC work? (1 row)
Object Post: id: 332, name: ‘RGenGC’, subject: ‘How does RGenGC
work?’ content: ‘Restricted Generation Garbage Collection’ author: ‘GorbyPuff’
Object Post: id(int): 332, name(string): ‘RGenGC’, subject(string): ‘How does RGenGC
work?’ content(string): ‘Restricted Generation Garbage Collection’ author(string): ‘GorbyPuff’
What? post = Post.new subject: 'What is RGenCG?' post.save first_post
= Post.find(1) puts first_post.subject #=> 'What is RGenCG?'
How? class Post < Torm::Model … end
Role of ARel
ARel • Relational Algebra for Ruby • ARel is a
SQL AST manager for Ruby • Can generate complex SQL queries • Adapts to multiple databases
ARel Components • AST • Visitors • Managers
ORM Database ARel
Engine • Provide information to ARel/ Attributes Access • Column
/ Table structure • Database Adapter • Data Type Mappings
Engine Skeleton
Database Connection
Columns
Schema Cache
Tests
None
Attributes • Data Types • Casting from / to database
types • Attribute Maps for table • Accessors for a model
Types • Types • TypeMap • Attribute • AttributeSet
Attribute Accessors • Readers • Writes • Initializer
Database Statements • create • update • save • destroy
Querying • find • count • where • delete_all •
...
Summary • Database Connection • Creating columns/ Schema cache •
Attribute Types/ Type casting • Attributes and accessors • Database statements • Querying
Other • Associations • Migrations • Callbacks • Validations •
...
Thank You! gh: prathamesh-sonpatki/torm @vipulnsward @_cha1tanya