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 28, 2014
Technology
58
0
Share
Building an ORM with Arel
This talk was presented at RubyConf Brasil 2014 with @vipulnsward
Prathamesh Sonpatki
August 28, 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
76
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
98
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
120
Pune_User_Group.pdf
prathamesh
0
110
Other Decks in Technology
See All in Technology
Good Enough Types: Heuristic Type Inference for Ruby
riseshia
1
340
AI와 협업하는 조직으로의 여정
arawn
0
540
AI バイブコーティングでキーボード不要?!
samakada
0
650
Pure Intonation on Browser: Building a Sequencer with Ruby
nagachika
0
260
Choose your own adventure in agentic design patterns
glaforge
0
160
AgentCore Managed Harness を使ってみよう
yakumo
2
250
ハーネスエンジニアリングの概要と設計思想
sergicalsix
9
6.1k
Keeping Ruby Running on Cygwin
fd0
0
180
ネットワーク運用を楽にするAWS DevOps Agent活用法!! / 20260421 Masaki Okuda
shift_evolve
PRO
2
240
AI時代のガードレールとしてのAPIガバナンス
nagix
0
320
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
280
はじめての MagicPod生成AI機能 機能紹介から活用方法まで
magicpod
0
120
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Designing for Timeless Needs
cassininazir
0
210
Between Models and Reality
mayunak
3
270
New Earth Scene 8
popppiees
3
2.1k
We Are The Robots
honzajavorek
0
220
Documentation Writing (for coders)
carmenintech
77
5.3k
Speed Design
sergeychernyshev
33
1.6k
Leo the Paperboy
mayatellez
7
1.7k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
380
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1k
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