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 28, 2014
Technology
0
47
Building an ORM with Arel
This talk was presented at RubyConf Brasil 2014 with @vipulnsward
Prathamesh Sonpatki
August 28, 2014
Tweet
Share
More Decks by Prathamesh Sonpatki
See All by Prathamesh Sonpatki
Secrets to Monitor Kubernetes Workloads
prathamesh
1
65
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
50
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
40
Monitoring vs. Debugging
prathamesh
0
92
Handling High Cardinality in Observability
prathamesh
1
71
Setting up Monitoring for Kubernetes
prathamesh
0
260
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
72
Monitoring vs. Debugging - IG Meetup 22nd July
prathamesh
2
86
Pune_User_Group.pdf
prathamesh
0
73
Other Decks in Technology
See All in Technology
『Firebase Dynamic Links終了に備える』 FlutterアプリでのAdjust導入とDeeplink最適化
techiro
0
190
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
320
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
130
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
120
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
200
日経電子版のStoreKit2フルリニューアル
shimastripe
1
150
"とにかくやってみる"で始めるAWS Security Hub
maimyyym
2
100
あなたの知らない Function.prototype.toString() の世界
mizdra
PRO
2
550
Application Development WG Intro at AppDeveloperCon
salaboy
0
200
Mastering Quickfix
daisuzu
1
300
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
1
310
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
17k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
A Tale of Four Properties
chriscoyier
156
23k
A better future with KSS
kneath
238
17k
What's new in Ruby 2.0
geeforr
343
31k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Transcript
Olá
Building an ORM with ARel Walking up the AS(Tree) @vipulnsward,
@_cha1tanya
Vipul @vipulnsward && Prathamesh @_cha1tanya
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
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
None
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 •
...
Obrigado! gh: prathamesh-sonpatki/torm @vipulnsward @_cha1tanya