Ruby Object Mapper (ROM) is an experimental Ruby library with the goal to provide powerful object mapping capabilities without limiting the full power of your datastore.
Learn more:
See issues for a list of adapters that are planned to be added soon.
ROM can be used with Rails next to ActiveRecord via rom-rails railtie. Integration with other frameworks is planned.
require 'rom-sql'
setup = ROM.setup(sqlite: "sqlite::memory")
setup.sqlite.connection.create_table :users do
primary_key :id
String :name
Integer :age
end
# set up relations
setup.relation(:users) do
def by_name(name)
where(name: name)
end
def adults
where { age >= 18 }
end
end
# set up commands
setup.commands(:users) do
define(:create)
end
# set up mappers
setup.mappers do
define(:users) do
model(name: 'User')
end
end
rom = setup.finalize
# accessing defined commands
rom.command(:users).try { create(name: "Joe", age: 17) }
rom.command(:users).try { create(name: "Jane", age: 18) }
# reading relations using defined mappers
puts rom.read(:users).by_name("Jane").adults.to_a.inspect
# => [#<User:0x007fdba161cc48 @id=2, @name="Jane", @age=18>]
ROM is on its way towards 1.0.0. Please refer to issues for details.
- Official Blog
- Ruby Object Mapper mailing list
This project has a long history and wouldn't exist without following people:
See LICENSE
file.