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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Prathamesh Sonpatki
August 22, 2014
Technology
390
0
Share
Building an ORM with Arel
Talk given at Madison Ruby 2014 with @vipulnsward
Prathamesh Sonpatki
August 22, 2014
More Decks by Prathamesh Sonpatki
See All by Prathamesh Sonpatki
Secrets to Monitor Kubernetes Workloads
prathamesh
1
110
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
75
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
97
Monitoring vs. Debugging
prathamesh
0
170
Handling High Cardinality in Observability
prathamesh
1
110
Setting up Monitoring for Kubernetes
prathamesh
0
300
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
92
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
Sansanの認証基盤を支えるアーキテクチャとその振り返り
sansantech
PRO
1
150
LLMに何を任せ、何を任せないか
cap120
11
6.9k
Cortex Code君、今日から内製化支援担当ね。
coco_se
0
190
FlutterでPiP再生を実装した話
s9a17
0
240
FASTでAIエージェントを作りまくろう!
yukiogawa
4
190
出版記念イベントin大阪「書籍紹介&私がよく使うMCPサーバー3選と社内で安全に活用する方法」
kintotechdev
0
140
パワポ作るマンをMCP Apps化してみた
iwamot
PRO
0
290
【AWS】CloudTrail LakeとCloudWatch Logs Insightsの使い分け方針
tsurunosd
0
130
JSTQB Expert Levelシラバス「テストマネジメント」日本語版のご紹介
ymty
0
110
最大のアウトプット術は問題を作ること
ryoaccount
0
270
Babylon.js を使って試した色々な内容 / Various things I tried using Babylon.js / Babylon.js 勉強会 vol.5
you
PRO
0
200
Even G2 クイックスタートガイド(日本語版)
vrshinobi1
0
190
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
330
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
320
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Skip the Path - Find Your Career Trail
mkilby
1
93
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
420
Paper Plane
katiecoart
PRO
1
48k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
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