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
370
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
51
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
25
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
16
Monitoring vs. Debugging
prathamesh
0
44
Handling High Cardinality in Observability
prathamesh
1
49
Setting up Monitoring for Kubernetes
prathamesh
0
230
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
52
Monitoring vs. Debugging - IG Meetup 22nd July
prathamesh
2
66
Pune_User_Group.pdf
prathamesh
0
68
Other Decks in Technology
See All in Technology
Databricksを活用してDELISH KITCHENのレシピレコメンドを開発した話
furu8
0
250
Tableau事例紹介 / Tableau Case Study of Eureka
kazuya_araki_tokyo
1
170
HEXA OSINT CTF V3 作戦会議
meow_noisy
0
110
人間の尊厳、幸福、アクセシビリティ / 第116回「WEB TOUCH MEETING」アクセシビリティSP
nulabinc
PRO
2
180
AWS を使う上で知っておきたいオンプレミス知識/aws-on-premise-essentials
emiki
1
4.2k
なぜ NOT A HOTEL が Web3 に取り組むのか - NOT A HOTEL TECH TALK
ynunokawa
0
160
テストプロセスで大事にしていること #jasstnano
makky_tyuyan
0
130
日本におけるデータエンジニアリングのこれまでとこれから
foursue
12
2.5k
Java EE/Jakarta EEの現状と将来―クラウドネイティブ時代にJava EEは対応できるのか?―
takakiyo
1
100
DevOpsメトリクスとアウトカムの接続にトライ!開発プロセスを通して計測できるメトリクスの活用方法
ham0215
2
200
Tebiki株式会社 エンジニア採用資料
tebiki
0
4.1k
Data and AI Governance: Existing Challenges and Emerging Trends
scotthsieh825
0
160
Featured
See All Featured
Designing the Hi-DPI Web
ddemaree
276
33k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
For a Future-Friendly Web
brad_frost
171
8.9k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
Large-scale JavaScript Application Architecture
addyosmani
503
110k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
Agile that works and the tools we love
rasmusluckow
324
20k
Six Lessons from altMBA
skipperchong
20
3k
A designer walks into a library…
pauljervisheath
199
23k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
Designing for Performance
lara
601
67k
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