https://github.com/bestwebua/rom-mongo
MongoDB adapter for ROM.
https://github.com/bestwebua/rom-mongo
data-access-layer data-mapping hacktoberfest mongo mongodb rom-rb ruby ruby-gem
Last synced: 11 months ago
JSON representation
MongoDB adapter for ROM.
- Host: GitHub
- URL: https://github.com/bestwebua/rom-mongo
- Owner: bestwebua
- License: mit
- Created: 2022-06-22T18:37:43.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T09:09:44.000Z (almost 2 years ago)
- Last Synced: 2025-03-03T18:49:26.793Z (12 months ago)
- Topics: data-access-layer, data-mapping, hacktoberfest, mongo, mongodb, rom-rb, ruby, ruby-gem
- Language: Ruby
- Homepage:
- Size: 78.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# MongoDB adapter for Ruby Object Mapper
[](https://codeclimate.com/github/bestwebua/rom-mongo/maintainability)
[](https://codeclimate.com/github/bestwebua/rom-mongo/test_coverage)
[](https://circleci.com/gh/bestwebua/rom-mongo/tree/master)
[](https://badge.fury.io/rb/rom-mongodb)
[](https://rubygems.org/gems/rom-mongodb)
[](LICENSE.txt)
[](CODE_OF_CONDUCT.md)
`rom-mongodb` - MongoDB adapter for [ROM](https://rom-rb.org). 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](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Code of Conduct](#code-of-conduct)
- [Credits](#credits)
- [Versioning](#versioning)
- [Changelog](CHANGELOG.md)
## Requirements
Ruby MRI 2.5.0+
## Installation
Add this line to your application's `Gemfile`:
```ruby
gem 'rom-mongodb'
```
And then execute:
```bash
bundle
```
Or install it yourself as:
```bash
gem install rom-mongodb
```
## Usage
```ruby
# 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: 'olo@domain.com', rating: 42, status: true })
user_repository.all
user_repository.find(email: 'olo@domain.com')
```
## Contributing
Bug reports and pull requests are welcome on GitHub at . This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. Please check the [open tickets](https://github.com/bestwebua/rom-mongo/issues). Be sure to follow Contributor Code of Conduct below and our [Contributing Guidelines](CONTRIBUTING.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## 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](CODE_OF_CONDUCT.md).
## Credits
- [The Contributors](https://github.com/bestwebua/rom-mongo/graphs/contributors) for code and awesome suggestions
- [The Stargazers](https://github.com/bestwebua/rom-mongo/stargazers) for showing their support
## Versioning
rom-mongodb uses [Semantic Versioning 2.0.0](https://semver.org)