Top Related Projects
The advanced business logic framework for Ruby.
The web, with simplicity.
Quick Overview
ROM (Ruby Object Mapper) is a data mapping and persistence toolkit for Ruby. It provides a flexible and powerful way to work with databases, offering a clean separation between the domain logic and persistence layer. ROM supports various data sources and promotes a functional programming approach to data manipulation.
Pros
- Flexible architecture that supports multiple adapters for different data sources
- Encourages clean separation of concerns and domain-driven design
- Provides powerful query interface and composable relations
- Offers excellent performance due to minimal overhead
Cons
- Steeper learning curve compared to traditional ORMs like ActiveRecord
- Less "magic" and convention-over-configuration, requiring more explicit setup
- Smaller community and ecosystem compared to more popular ORMs
- May require more boilerplate code for simple use cases
Code Examples
Creating a relation:
class Users < ROM::Relation[:sql]
schema(infer: true)
def by_name(name)
where(name: name)
end
end
Defining a command:
class CreateUser < ROM::Commands::Create[:sql]
relation :users
result :one
end
Querying data:
users.by_name('John').to_a
# => [{ id: 1, name: 'John', email: 'john@example.com' }]
Getting Started
- Add ROM to your Gemfile:
gem 'rom'
gem 'rom-sql'
- Set up the ROM configuration:
require 'rom'
ROM::Configuration.new(:sql, 'sqlite::memory') do |config|
config.register_relation(Users)
end
container = ROM.container(config)
- Use the container to access relations and execute queries:
users = container.relations[:users]
user = users.by_name('John').one
Competitor Comparisons
The advanced business logic framework for Ruby.
Pros of Trailblazer
- Provides a complete architecture for Ruby applications, including business logic, view, and persistence layers
- Offers a more structured approach to application design, which can be beneficial for large, complex projects
- Includes built-in concepts like Operations, Cells, and Representers for better code organization
Cons of Trailblazer
- Steeper learning curve due to its comprehensive nature and unique concepts
- May be considered "overkill" for smaller, simpler applications
- Less flexible than ROM for custom data persistence solutions
Code Comparison
Trailblazer (Operation example):
class Create < Trailblazer::Operation
step Model(User, :new)
step Contract::Build(constant: UserContract)
step Contract::Validate()
step Contract::Persist()
end
ROM (Repository example):
class UserRepo < ROM::Repository[:users]
commands :create, update: :by_pk
def find(id)
users.by_pk(id).one!
end
end
Both libraries aim to improve Ruby application architecture, but they take different approaches. Trailblazer provides a full-stack solution with predefined patterns, while ROM focuses on flexible data persistence and mapping. The choice between them depends on project requirements, team preferences, and the desired level of structure and flexibility.
The web, with simplicity.
Pros of Hanami
- Full-stack web framework with integrated components
- Emphasis on clean architecture and modularity
- Built-in security features and performance optimizations
Cons of Hanami
- Steeper learning curve for developers new to the framework
- Smaller community and ecosystem compared to ROM
Code Comparison
Hanami (Entity definition):
class Book < Hanami::Entity
attributes do
attribute :id, Types::Int
attribute :title, Types::String
attribute :author, Types::String
end
end
ROM (Relation definition):
class Books < ROM::Relation[:sql]
schema do
attribute :id, Types::Integer
attribute :title, Types::String
attribute :author, Types::String
end
end
Summary
Hanami is a full-stack web framework that provides a complete solution for building Ruby applications, while ROM focuses on providing a flexible data mapping and persistence layer. Hanami offers a more opinionated structure and integrated components, which can lead to faster development for those familiar with the framework. However, ROM's flexibility allows for easier integration with existing projects and provides more granular control over data persistence.
Both projects have their strengths, and the choice between them depends on the specific needs of your project and your preferred development approach.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
rom
Ruby Object Mapper (rom-rb) is a data mapping and persistence toolkit for Ruby with the goal to provide powerful object mapping capabilities without limiting the full power of your database.
Main rom gem provides following components:
- core - Core and Adapter APIs
- changeset - Changeset objects integrated with rom-core
- repository - Additional repository abstraction integrated with rom-core
Learn more:
Backers
Support us with a monthly donation and help us continue our activities. [Become a backer]
Sponsors
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]
Ecosystem
There are other gems within the rom ecosystem that you will find useful:
- rom-factory struct generator with support for persistence
- (WIP) rom-migrator common APIs for database migrations
Adapters
- rom-sql
- rom-yesql
- rom-elasticsearch
- rom-http
- rom-couchdb
- rom-csv
- rom-yaml
- rom-cassandra
- rom-event_store
- rom-git
- rom-influxdb
- rom-json
- rom-kafka
- rom-mongo
- rom-neo4j
- rom-rethinkdb
Framework integrations
Community
Credits
This project has a long history and wouldn't exist without following people:
License
See LICENSE
file.
Top Related Projects
The advanced business logic framework for Ruby.
The web, with simplicity.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot