aflatter / rom

Persistence and mapping toolkit for Ruby

Home Page:http://rom-rb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ruby Object Mapper

Gem Version Build Status Dependency Status Code Climate Test Coverage Inline docs

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:

Adapters

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.

Synopsis

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>]

ROADMAP

ROM is on its way towards 1.0.0. Please refer to issues for details.

Community

Credits

This project has a long history and wouldn't exist without following people:

License

See LICENSE file.

About

Persistence and mapping toolkit for Ruby

http://rom-rb.org

License:MIT License


Languages

Language:Ruby 100.0%