ROM 

@ilavriv

What is ROM?

 

Ruby object mapper, toolkit for data manipulation

 
  1. Powerful
  2. Small
  3. Easy
  4. No magic
  5. Usable
  6. Fast
 

Benefits to using ROM

 
  1. Repositories
  2. Relations
  3. Commands
  4. Mappers
  5. Adapters
 

ROM elements

 

ROM Design

 

Using: Setup

 
ROM.setup(
  default: [:sql, 'sqlite::memory'],
  other: [:csv, '/path/to/files', { 
    encoding: 'utf-8', 
    col_sep: ';' 
  }]
)

Using: Relations

 
class BooksRelation < ROM::Relation[:sql]
  include ROM::SQL::Plugin::Pagination
  dataset :books

  per_page 30

  def ordered
    order(:id)
  end
end

Using: Commands

 
class CreateBook < ROM::Commands::Create[:sql]
  relation :users
  register_as :create
end

Using: Mappers

 

 
class UserAsEntity < ROM::Mapper
  register_as :entity 
  relation :users     
  model User       
end

Using: Repositories

 

 
class BookRepository < ROM::Repository::Base
  relations :book

  def new_books(timestamp)
    users.listing.added_after(timestamp)
  end
end

Adapters

 
  • rom-sql
  • rom-mongo
  • rom-csv 
  • ...
3

links

 

Any questions?

 

Rom rb

By Ivan Lavriv

Rom rb

  • 609