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
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
90
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
64
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
62
Monitoring vs. Debugging
prathamesh
0
140
Handling High Cardinality in Observability
prathamesh
1
92
Setting up Monitoring for Kubernetes
prathamesh
0
290
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
82
Monitoring vs. Debugging - IG Meetup 22nd July
prathamesh
2
100
Pune_User_Group.pdf
prathamesh
0
100
Other Decks in Technology
See All in Technology
Node.js 2025: What's new and what's next
ruyadorno
0
120
BI ツールはもういらない?Amazon RedShift & MCP Server で試みる新しいデータ分析アプローチ
cdataj
0
120
Performance Insights 廃止から Database Insights 利用へ/transition-from-performance-insights-to-database-insights
emiki
0
250
小学4年生夏休みの自由研究「ぼくと Copilot エージェント」
taichinakamura
0
690
新規事業におけるGORM+SQLx併用アーキテクチャ
hacomono
PRO
0
220
AWS 잘하는 개발자 되기 - AWS 시작하기: 클라우드 개념부터 IAM까지
kimjaewook
0
130
ガバメントクラウドの概要と自治体事例(名古屋市)
techniczna
2
240
これがLambdaレス時代のChatOpsだ!実例で学ぶAmazon Q Developerカスタムアクション活用法
iwamot
PRO
6
1k
Developer Advocate / Community Managerなるには?
tsho
0
140
能登半島地震で見えた災害対応の課題と組織変革の重要性
ditccsugii
0
710
ユーザーの声とAI検証で進める、プロダクトディスカバリー
sansantech
PRO
1
130
AIツールでどこまでデザインを忠実に実装できるのか
oikon48
6
3.3k
Featured
See All Featured
Scaling GitHub
holman
463
140k
Side Projects
sachag
455
43k
GitHub's CSS Performance
jonrohan
1032
470k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
115
20k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
900
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
20
1.2k
For a Future-Friendly Web
brad_frost
180
9.9k
Fireside Chat
paigeccino
40
3.7k
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