Slide 1

Slide 1 text

Olá

Slide 2

Slide 2 text

Building an ORM with ARel Walking up the AS(Tree) @vipulnsward, @_cha1tanya

Slide 3

Slide 3 text

Vipul @vipulnsward && Prathamesh @_cha1tanya

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

RubyIndia.org

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

podcast.rubyindia.org

Slide 10

Slide 10 text

Indian Ruby Conferences RubyConfIndia Garden City Ruby Conf DeccanRubyConf Do visit India!

Slide 11

Slide 11 text

Building an ORM with ARel Walking up the (AS)Tree @vipulnsward, @_cha1tanya

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Build our own ORM - Why?

Slide 15

Slide 15 text

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.

Slide 16

Slide 16 text

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.”

Slide 17

Slide 17 text

Components ● Database connection ● Query Generator ● Attribute Access ● Typecasting

Slide 18

Slide 18 text

SQL torm_development=# select * from posts; id | name | content | author | subject -----+-------------+---------+------------+--------- 332 | RGenGC| Restricted Generation Garbage Collection | GorbyPuff | How does RGenGC work? (1 row)

Slide 19

Slide 19 text

Object Post: id: 332, name: ‘RGenGC’, subject: ‘How does RGenGC work?’ content: ‘Restricted Generation Garbage Collection’ author: ‘GorbyPuff’

Slide 20

Slide 20 text

Object Post: id(int): 332, name(string): ‘RGenGC’, subject(string): ‘How does RGenGC work?’ content(string): ‘Restricted Generation Garbage Collection’ author(string): ‘GorbyPuff’

Slide 21

Slide 21 text

What? post = Post.new subject: 'What is RGenCG?' post.save first_post = Post.find(1) puts first_post.subject #=> 'What is RGenCG?'

Slide 22

Slide 22 text

How? class Post < Torm::Model … end

Slide 23

Slide 23 text

Role of ARel

Slide 24

Slide 24 text

ARel ● Relational Algebra for Ruby ● ARel is a SQL AST manager for Ruby ● Can generate complex SQL queries ● Adapts to multiple databases

Slide 25

Slide 25 text

ARel Components ● AST ● Visitors ● Managers

Slide 26

Slide 26 text

ORM Database ARel

Slide 27

Slide 27 text

Engine ● Provide information to ARel/ Attributes Access ● Column / Table structure ● Database Adapter ● Data Type Mappings

Slide 28

Slide 28 text

Engine Skeleton

Slide 29

Slide 29 text

Database Connection

Slide 30

Slide 30 text

Columns

Slide 31

Slide 31 text

Schema Cache

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Tests

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Attributes ● Data Types ● Casting from / to database types ● Attribute Maps for table ● Accessors for a model

Slide 36

Slide 36 text

Types ● Types ● TypeMap ● Attribute ● AttributeSet

Slide 37

Slide 37 text

Attribute Accessors ● Readers ● Writes ● Initializer

Slide 38

Slide 38 text

Database Statements ● create ● update ● save ● destroy

Slide 39

Slide 39 text

Querying ● find ● count ● where ● delete_all ● ...

Slide 40

Slide 40 text

Summary ● Database Connection ● Creating columns/ Schema cache ● Attribute Types/ Type casting ● Attributes and accessors ● Database statements ● Querying

Slide 41

Slide 41 text

Other ● Associations ● Migrations ● Callbacks ● Validations ● ...

Slide 42

Slide 42 text

Obrigado! gh: prathamesh-sonpatki/torm @vipulnsward @_cha1tanya