Coder Social home page Coder Social logo

rom's Introduction

Ruby Object Mapper

ROM is an experimental ruby ORM.

Status

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

Project is being rebuilt from scratch. Watch this space.

Synopsis

require 'rom'
require 'rom/adapter/sequel'

rom = ROM.setup(sqlite: "sqlite::memory")

rom.sqlite.connection.run(
  <<-SQL
  CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name STRING,
    age INTEGER
  )
  SQL
)

rom.relations do
  register(:users) do

    def by_name(name)
      where(name: name)
    end

    def adults
      where { age >= 18 }
    end

  end
end

rom.mappers do
  define(:users) do
    model(name: 'User')
  end
end

# accessing registered relations
users = rom.relations.users

users.insert(name: "Joe", age: 17)
users.insert(name: "Jane", age: 18)

puts users.by_name("Jane").adults.to_a.inspect
# => [{:id=>2, :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

Here's a top-level TODO:

  • Add redis adapter (just to prove that stuff works with different adapters)
  • Add a couple of RA operations (there's just Join now)
  • Release 0.3.0.alpha \o/

Please refer to issues for details

Community

License

See LICENSE file.

rom's People

Contributors

adz avatar antoinelyset avatar billdueber avatar chastell avatar cored avatar dkubb avatar dreoliv avatar indrekj avatar jeremyf avatar jgeiger avatar lasseebert avatar locks avatar mbj avatar myabc avatar olefine avatar ovargas27 avatar plexus avatar rolfb avatar rrrene avatar senny avatar snusnu avatar solnic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.