Giter VIP home page Giter VIP logo

rom-mongo's Introduction

MongoDB adapter for Ruby Object Mapper

Maintainability Test Coverage CircleCI Gem Version Downloads GitHub Contributor Covenant

rom-mongodb - MongoDB adapter for ROM. What is ROM? It's a fast ruby persistence library with the goal of providing powerful object mapping capabilities without limiting the full power of the underlying datastore.

Table of Contents

Requirements

Ruby MRI 2.5.0+

Installation

Add this line to your application's Gemfile:

gem 'rom-mongodb'

And then execute:

bundle

Or install it yourself as:

gem install rom-mongodb

Usage

# Define your container with mongo adapter

require 'mongo'
require 'rom'
require 'rom/mongo'

connection = Mongo::Client.new('mongodb://127.0.0.1:27017/your_db_name')
container = ROM.container(:mongo, connection) do |config|
  config.relation(:users) do
    schema(:users) do
      attribute :_id, ROM::Types.Nominal(BSON::ObjectId)
      attribute :email, ROM::Types::String
      attribute :rating, ROM::Types::Integer
      attribute :status, ROM::Types::Bool
      attribute :orders?, ROM::Types::Array # optional attribute, if field does not exists will return nil
    end
  end
end

# Define your repository

require 'rom/repository'

UserRepository = ::Class.new(ROM::Repository[:users]) do
  commands(:create, :delete, update: :by_pk)

  def all
    users.to_a
  end

  def find(**options)
    users.find(options)
  end
end

user_repository = UserRepository.new(container)

# Now you can do some manipulations with your repository

user_repository.create({ email: '[email protected]', rating: 42, status: true })
user_repository.all
user_repository.find(email: '[email protected]')

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/rom-mongo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. Please check the open tickets. Be sure to follow Contributor Code of Conduct below and our Contributing Guidelines.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the rom-mongodb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Credits

Versioning

rom-mongodb uses Semantic Versioning 2.0.0

rom-mongo's People

Contributors

bestwebua avatar

Watchers

 avatar  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.