Giter Site home page Giter Site logo

rom-mongo's Introduction

rom-mongo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rom-mongo's Issues

Switch to driver for queries exclusively

It turned out origin gem has been merged into mongoid codebase and is now considered a private API. Because of this we need to rely only on the driver. If we want a fancy query DSL, we need to build it ourselves.

Relation with association can not be finalized

Relation can not be finalized if it has at least one defined association.

#!/usr/bin/env ruby

require 'bundler/inline'

gemfile(true) do
  gem 'dry-struct', '~> 0.3.1'
  gem 'rom-mongo', github: 'rom-rb/rom-mongo', branch: :master
  gem 'rspec'
end

require 'rspec'
require 'rspec/autorun'

require 'rom-mongo'

RSpec.configure do |config|
  config.color = true
  config.formatter = :documentation
end

RSpec.describe ROM::Mongo do
  let(:conn) { Mongo::Client.new('mongodb://0.0.0.0:27017/rom_mongo') }
  let(:conf) { ROM::Configuration.new(:mongo, conn) }
  let(:container) { ROM.container(conf) }

  before do
    conn[:users].drop

    conf.relation(:users) do
      schema(:users) do
        attribute :_id,   ROM::Types.Definition(BSON::ObjectId)
        attribute :name,  ROM::Types::String
        attribute :email, ROM::Types::String
      end
    end
  end

  it { expect { container }.not_to raise_error }

  describe 'relation with association' do
    before do
      conf.relation(:tasks) do
        schema(:tasks) do
          attribute :_id,     ROM::Types.Definition(BSON::ObjectId)
          attribute :user_id, ROM::Types::Int

          associations do
            belongs_to :user, foreign_key: :u_id
          end
        end
      end
    end

    it { expect { container }.not_to raise_error }
  end
end
Failures:

  1) ROM::Mongo relation with association should not raise Exception
     Failure/Error: it { expect { container }.not_to raise_error }

       expected no Exception, got #<LocalJumpError: no block given (yield)> with backtrace:
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/schema.rb:380:in `finalize_associations!'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/schema.rb:44:in `block (2 levels) in <class:Schema>'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/registry.rb:61:in `block in each'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/registry.rb:61:in `each'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/registry.rb:61:in `each'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/schema.rb:42:in `block in <class:Schema>'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/support/notifications.rb:141:in `trigger'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/support/notifications.rb:69:in `block in trigger'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/support/notifications.rb:68:in `each'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/support/notifications.rb:68:in `trigger'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/setup/finalize/finalize_relations.rb:59:in `run!'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/setup/finalize.rb:86:in `load_relations'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/setup/finalize.rb:62:in `run!'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/create_container.rb:38:in `finalize'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/create_container.rb:14:in `initialize'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/create_container.rb:59:in `initialize'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/create_container.rb:65:in `new'
         # /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/rom-core-4.1.0/lib/rom/create_container.rb:65:in `container'
         # ./associations_spec.rb:24:in `block (2 levels) in <main>'
         # ./associations_spec.rb:54:in `block (4 levels) in <main>'
         # ./associations_spec.rb:54:in `block (3 levels) in <main>'
     # ./associations_spec.rb:54:in `block (3 levels) in <main>'

It can be fixed by defining self own finalize_associations! method for ROM::Mongo::Schema or inheriting this class from ROM::Memory::Schema.

RomStruct should have dynamic fields schema

I working with ROM-mongo on a mongo DB that have dynamic fields on each collection, I defined a schema for the collection, but ROM struct raises an exception when trying to instantiate a new struct for document with a missing field. I think the mongo schema should be dynamic and accept missing fields.

Get it to work with Rom::Repository

Tried to use this adapter with the guide to repositories on rom-rb-org only to find it does not work. Read up a bit and rom-sql seems to work with repositories but i can't find out how/why. Any pointers?

ROM v5.0.2 support

Hello !

I want to use ROM with MongoDB (legacy choice ๐Ÿ‘Ž)

The problem is that I don't know where to start to update this gem.

Thanks for your help !

update gem rom version

I want to install rom-mongo beside rom-sql on the Gemfile. I had an error on bundle install.

Bundler could not find compatible versions for gem "rom":
  In snapshot (Gemfile.lock):
    rom (= 3.0.1)

  In Gemfile:
    rom

    rom-mongo was resolved to 0.0.1, which depends on
      rom (~> 0.3)

    rom-sql was resolved to 1.0.2, which depends on
      rom (~> 3.0)

    rom-sql was resolved to 1.0.2, which depends on
      rom (~> 3.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

my Gemfile contains

gem 'rom-sql'
gem 'rom-mongo'
gem 'rom-repository'

I solved the problem by using gem 'gem 'rom-mongo', git: 'https://github.com/rom-rb/rom-mongo'
please update the gem version.

Current version of origin gem displays warning

Origin gem displays the warning:

/Users/wafcio/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/origin-2.3.0/lib/origin/aggregable.rb:26: warning: instance variable @aggregating not initialized

It can be hard to fix because origin gem is legacy right now.

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.