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
rom 4.0 is coming
Search
Piotr Solnica
July 09, 2017
Programming
3
830
rom 4.0 is coming
Piotr Solnica
July 09, 2017
Tweet
Share
More Decks by Piotr Solnica
See All by Piotr Solnica
[KRUG] Architecture. The reclaimed years.
solnic
2
480
rom-rb 4.0 - Moscow, RailsClub 2017
solnic
3
1.3k
Blending Functional and OO programming in Ruby
solnic
22
2.4k
Deep Dive Into ROM
solnic
7
1.1k
Clean Code Cowboy
solnic
4
960
Convenience vs Simplicity
solnic
4
1.7k
Micro Libraries FTW
solnic
2
530
DataMapper 2 - an object mapping toolkit
solnic
6
1k
Beyond the ORM - RuLu Conf 2012
solnic
1
1.3k
Other Decks in Programming
See All in Programming
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
290
Macとオーディオ再生 2024/11/02
yusukeito
0
290
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
380
C++でシェーダを書く
fadis
6
3.6k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
210
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
290
Piniaの現状と今後
waka292
5
1.6k
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
230
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
190
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
120
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
180
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
550
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Why Our Code Smells
bkeepers
PRO
334
57k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
340
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Practical Orchestrator
shlominoach
186
10k
For a Future-Friendly Web
brad_frost
175
9.4k
Transcript
ROM-RB 4.0 IS COMING PIOTR SOLNICA >> BRIGHTON RUBY 2017
1
PIOTR SOLNICA > ! Cracow, Poland > github.com/solnic > @_solnic_
> solnic.eu 2
TECH LEAD AT ICELAB 3
WHAT'S ROM-RB? 4
an open-source persistence and mapping toolkit for Ruby built for
speed and simplicity 5
DATABASE-AGNOSTIC, FLEXIBLE, EXTENDIBLE, FAST, SIMPLE 6
FOR REAL ! 7
SOUNDS LIKE SOME CRAZY OBJECT RELATIONAL MAPPER, EH? 8
ROM IS NOT AN ORM 9
WHY DOES IT EVEN EXIST? 10
A TRUE ALTERNATIVE TO ACTIVE RECORD 11
ROM-RB PROVIDES A WAY TO SEPARATE PERSISTENCE CONCERNS FROM APPLICATION
DOMAIN 12
WHAT'S THE DEAL WITH 4.0? 13
RUBYISTS LOVE MAGIC ˾(✿˙ᗜ˙)੭ʓ̤ꚍ.*ꙓꙏꚍ 14
MAGIC AKA: IMPLICIT CODE AKA: EASY TO USE ABSTRACTIONS 15
ACTIVERECORD POSSIBLY THE MOST MAGICAL GEM IN THE UNIVERSE 16
NO BOILERPLATE class User < ActiveRecord::Base end 17
PERSISTENCE, SO SIMPLE user = User.create(name: "Jane") 18
QUERIES, SO SIMPLE User.where(name: "Jane").first 19
MAKING CHANGES, SO SIMPLE User.where(name: "Jane").update_all(name: "Jane Doe") 20
EASE OF USE > Little code to write to get
started > A lot of functionality OOTB > No boilerplate 21
THIS IS A REAL CHALLENGE FOR ROM-RB! 22
> Dynamic query interface > Explicit representation of data structures
> Mapping to struct objects decoupled from the database > No concept of lazy-loadable associations 23
THIS IS FINE 24
WE MADE IT (⊃ꙏ•́‿•̀ꙏ)⊃━☆ꚍ.*ꙓꙏꚍ 25
RELATIONS AND STRUCTS 26
class Users < ROM::Relation[:sql] schema(infer: true) end 27
✅ NO BOILERPLATE 28
users.changeset(:create, name: "Jane").commit # => #<ROM::Struct::User id=1 name="Jane"> 29
✅ PERSISTENCE, SO SIMPLE 30
users.where(name: "Jane").first # => #<ROM::Struct::User id=1 name="Jane"> 31
✅ QUERIES, SO SIMPLE 32
users.where(name: "Jane").changeset(:update, name: "Jane Doe").commit # => #<ROM::Struct::User id=1 name="Jane
Doe"> 33
✅ MAKING CHANGES, SO SIMPLE 34
BUT... 35
users.first # => #<ROM::Struct::User id=1 name="Jane"> users.select(:name).first # => #<ROM::Struct::User
name="Jane"> 36
PEOPLE WANT THEIR OWN METHODS, OBVIOUSLY 37
class User < ActiveRecord::Base def first_name name.split(' ').first end def
last_name name.split(' ').last end end 38
ROM-RB: CUSTOM STRUCT NAMESPACE 39
class Users < ROM::Relation[:sql] struct_namespace Entities schema(infer: true) end 40
class Users < ROM::Relation[:sql] struct_namespace Entities schema(infer: true) end 41
module Entities class User < ROM::Struct def first_name name.split(' ').first
end def last_name name.split(' ').last end end end 42
module Entities class User < ROM::Struct def first_name name.split(' ').first
end def last_name name.split(' ').last end end end 43
user = users.first => #<Entities::User id=1 name="Jane Doe"> user.first_name #
"Jane" user.last_name # "Doe" 44
user = users.select(:name).first => #<Entities::User name="Jane Doe"> user.first_name # "Jane"
user.last_name # "Doe" 45
WHAT DOES THIS MEAN, REALLY? ! 46
THE TRUTH ABOUT MAGIC 47
EXCITEMENT ABOUT MAGIC (AKA HAPPINESS) 48
ROM-RB DOESN'T ENFORCE MAGIC! 49
AT ANY POINT IN TIME YOU CAN DEFINE STRUCTS WITH
EXPLICIT ATTRIBUTES AND ASK ROM-RB TO LOAD THEM 50
require "entities/address" module Entities class UserProfile < ROM::Struct attribute :email,
Types::Strict::String attribute :name, Types::Strict::String attribute :age, Types::Strict::Integer attribute :address, Address end end 51
users.combine(:address).as(:user_profile).first 52
HOWEVER...THIS REQUIRES TIME, AND GOOD UNDERSTANDING OF THE APPLICATION DOMAIN!
53
IT'S A PROCESS, AND ROM-RB FULLY SUPPORTS IT 54
4.0.0.BETA WAS RELEASED A COUPLE WEEKS AGO ! (JUST SAYING!)
55
THANK YOU ! ! GITHUB.COM/ROM-RB/ROM 56