ROM-RB 4.0 IS COMINGPIOTR SOLNICA >> BRIGHTON RUBY 20171
View Slide
PIOTR SOLNICA> ! Cracow, Poland> github.com/solnic> @_solnic_> solnic.eu2
TECH LEAD AT ICELAB3
WHAT'S ROM-RB?4
an open-source persistence andmapping toolkit for Ruby built forspeed and simplicity5
DATABASE-AGNOSTIC, FLEXIBLE,EXTENDIBLE, FAST, SIMPLE6
FOR REAL !7
SOUNDS LIKE SOMECRAZYOBJECT RELATIONALMAPPER, EH?8
ROMIS NOTAN ORM9
WHY DOES IT EVEN EXIST?10
A TRUE ALTERNATIVE TO ACTIVE RECORD11
ROM-RB PROVIDES A WAY TOSEPARATE PERSISTENCE CONCERNSFROM APPLICATION DOMAIN12
WHAT'S THEDEAL WITH 4.0?13
RUBYISTS LOVE MAGIC˾(✿˙ᗜ˙)੭ʓ̤ꚍ.*ꙓꙏꚍ14
MAGICAKA: IMPLICIT CODEAKA: EASY TO USE ABSTRACTIONS15
ACTIVERECORDPOSSIBLY THE MOST MAGICAL GEM IN THE UNIVERSE16
NO BOILERPLATEclass User < ActiveRecord::Baseend17
PERSISTENCE, SO SIMPLEuser = User.create(name: "Jane")18
QUERIES, SO SIMPLEUser.where(name: "Jane").first19
MAKING CHANGES, SO SIMPLEUser.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 boilerplate21
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 associations23
THIS IS FINE24
WE MADE IT(⊃ꙏ•́‿•̀ꙏ)⊃━☆ꚍ.*ꙓꙏꚍ25
RELATIONS AND STRUCTS26
class Users < ROM::Relation[:sql]schema(infer: true)end27
✅ NO BOILERPLATE28
users.changeset(:create, name: "Jane").commit# => #29
✅ PERSISTENCE, SO SIMPLE30
users.where(name: "Jane").first# => #31
✅ QUERIES, SO SIMPLE32
users.where(name: "Jane").changeset(:update, name: "Jane Doe").commit# => #33
✅ MAKING CHANGES, SO SIMPLE34
BUT...35
users.first# => #users.select(:name).first# => #36
PEOPLE WANT THEIR OWN METHODS, OBVIOUSLY37
class User < ActiveRecord::Basedef first_namename.split(' ').firstenddef last_namename.split(' ').lastendend38
ROM-RB: CUSTOM STRUCT NAMESPACE39
class Users < ROM::Relation[:sql]struct_namespace Entitiesschema(infer: true)end40
class Users < ROM::Relation[:sql]struct_namespace Entitiesschema(infer: true)end41
module Entitiesclass User < ROM::Structdef first_namename.split(' ').firstenddef last_namename.split(' ').lastendendend42
module Entitiesclass User < ROM::Structdef first_namename.split(' ').firstenddef last_namename.split(' ').lastendendend43
user = users.first=> #user.first_name# "Jane"user.last_name# "Doe"44
user = users.select(:name).first=> #user.first_name# "Jane"user.last_name# "Doe"45
WHAT DOES THIS MEAN, REALLY? !46
THE TRUTHABOUT MAGIC47
EXCITEMENT ABOUT MAGIC (AKA HAPPINESS)48
ROM-RB DOESN'T ENFORCE MAGIC!49
AT ANY POINT IN TIMEYOU CAN DEFINE STRUCTSWITH EXPLICIT ATTRIBUTESAND ASK ROM-RB TO LOAD THEM50
require "entities/address"module Entitiesclass UserProfile < ROM::Structattribute :email, Types::Strict::Stringattribute :name, Types::Strict::Stringattribute :age, Types::Strict::Integerattribute :address, Addressendend51
users.combine(:address).as(:user_profile).first52
HOWEVER...THIS REQUIRES TIME,AND GOOD UNDERSTANDING OF THE APPLICATION DOMAIN!53
IT'S A PROCESS, AND ROM-RB FULLY SUPPORTS IT54
4.0.0.BETAWAS RELEASED A COUPLEWEEKS AGO !(JUST SAYING!)55
THANK YOU !! GITHUB.COM/ROM-RB/ROM56