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
89
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
64
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
56
Monitoring vs. Debugging
prathamesh
0
140
Handling High Cardinality in Observability
prathamesh
1
86
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
96
Other Decks in Technology
See All in Technology
そのコンポーネント、サーバー?クライアント?App Router開発のモヤモヤを可視化する補助輪
makotot
4
630
コスト削減の基本の「キ」~ コスト消費3大リソースへの対策 ~
smt7174
2
200
AIエージェントの開発に必須な「コンテキスト・エンジニアリング」とは何か──プロンプト・エンジニアリングとの違いを手がかりに考える
masayamoriofficial
0
420
浸透しなさいRFC 5322&7208
hinono
0
120
VPC Latticeのサービスエンドポイント機能を使用した複数VPCアクセス
duelist2020jp
0
260
Goss: New Production-Ready Go Binding for Faiss #coefl_go_jp
bengo4com
0
1.1k
Webアクセシビリティ入門
recruitengineers
PRO
2
470
事業価値と Engineering
recruitengineers
PRO
3
1k
Claude Code x Androidアプリ 開発
kgmyshin
1
600
現場が抱える様々な問題は “組織設計上” の問題によって生じていることがある / Team-oriented Organization Design 20250827
mtx2s
6
1.5k
Backboneとしてのtimm2025
yu4u
4
1.6k
JuniorからSeniorまで: DevOpsエンジニアの成長ロードマップ
yuriemori
1
240
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Documentation Writing (for coders)
carmenintech
73
5k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Making Projects Easy
brettharned
117
6.3k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
How to Ace a Technical Interview
jacobian
279
23k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Mobile First: as difficult as doing things right
swwweet
223
9.9k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
20k
RailsConf 2023
tenderlove
30
1.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
780
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.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