$30 off During Our Annual Pro Sale. View Details »
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
390
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
97
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
66
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
76
Monitoring vs. Debugging
prathamesh
0
150
Handling High Cardinality in Observability
prathamesh
1
99
Setting up Monitoring for Kubernetes
prathamesh
0
290
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
84
Monitoring vs. Debugging - IG Meetup 22nd July
prathamesh
2
110
Pune_User_Group.pdf
prathamesh
0
110
Other Decks in Technology
See All in Technology
オープンソースKeycloakのMCP認可サーバの仕様の対応状況 / 20251219 OpenID BizDay #18 LT Keycloak
oidfj
0
180
M&Aで拡大し続けるGENDAのデータ活用を促すためのDatabricks権限管理 / AEON TECH HUB #22
genda
0
240
障害対応訓練、その前に
coconala_engineer
0
200
20251203_AIxIoTビジネス共創ラボ_第4回勉強会_BP山崎.pdf
iotcomjpadmin
0
140
AWS運用を効率化する!AWS Organizationsを軸にした一元管理の実践/nikkei-tech-talk-202512
nikkei_engineer_recruiting
0
170
AR Guitar: Expanding Guitar Performance from a Live House to Urban Space
ekito_station
0
230
Claude Codeを使った情報整理術
knishioka
11
6.5k
Amazon Quick Suite で始める手軽な AI エージェント
shimy
1
1.9k
Building Serverless AI Memory with Mastra × AWS
vvatanabe
0
590
日本の AI 開発と世界の潮流 / GenAI Development in Japan
hariby
1
480
業務の煩悩を祓うAI活用術108選 / AI 108 Usages
smartbank
9
12k
なぜ あなたはそんなに re:Invent に行くのか?
miu_crescent
PRO
0
210
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Facilitating Awesome Meetings
lara
57
6.7k
The Curse of the Amulet
leimatthew05
0
4.8k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
0
100
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
A better future with KSS
kneath
240
18k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1k
How to make the Groovebox
asonas
2
1.8k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
150
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
0
67
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.3k
Amusing Abliteration
ianozsvald
0
71
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