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
44
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
51
The Complete Handbook to OpenTelemetry Metrics
prathamesh
1
25
Breaking down the Pillars of Observability: From data to outcomes
prathamesh
0
20
Monitoring vs. Debugging
prathamesh
0
46
Handling High Cardinality in Observability
prathamesh
1
50
Setting up Monitoring for Kubernetes
prathamesh
0
230
Monitoring vs. Debugging - SRE BLR Meetup
prathamesh
0
53
Monitoring vs. Debugging - IG Meetup 22nd July
prathamesh
2
66
Pune_User_Group.pdf
prathamesh
0
69
Other Decks in Technology
See All in Technology
Cypress or Playwright?
rainerhahnekamp
0
110
【NW X Security JAWS#3】L3-4:AWS環境のIPv6移行に向けて知っておきたいこと
shotashiratori
0
370
家族アルバム みてねにおけるGrafana活用術 / Grafana Meetup Japan Vol.1 LT
isaoshimizu
1
770
Azureの基本的な権限管理の勉強会
yhana
0
600
Delivering Millions of Messages within seconds @ Duolingo
pelelgrino
0
350
競技としてのKaggle、役に立つKaggle
yu4u
3
1.8k
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
130
Building Dashboards as a Hobby
egmc
0
230
DevOpsメトリクスとアウトカムの接続にトライ!開発プロセスを通して計測できるメトリクスの活用方法
ham0215
2
240
開発パフォーマンスを最大化するための開発体制
ham0215
2
440
Google Cloud の AI を支える裏側のインフラを垣間見る!
maroon1st
0
360
web-application-security
matsuihidetoshi
0
170
Featured
See All Featured
Creatively Recalculating Your Daily Design Routine
revolveconf
210
11k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
Clear Off the Table
cherdarchuk
84
310k
Building Applications with DynamoDB
mza
88
5.6k
Code Reviewing Like a Champion
maltzj
514
39k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
Being A Developer After 40
akosma
57
580k
Git: the NoSQL Database
bkeepers
PRO
422
63k
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