Multiple adapters per mapper

I have a need for multiple adapters per mapper for my project and wanted to chat about it a bit here. I see it was already mentioned here https://github.com/lotus/model/issues/33 but apparently there are a few issues before work on that can continue.

I have written an auth0.com adapter which I use for a few collections, mainly the user collection. However, I still have collections that I would like to use in pg or mysql. I think the proposed Example 2 in issue #33 would be a nice DSL for this feature.

Any thoughts on revisiting this\what the issues were preventing the implementation?

Thanks!

@taylorfinnell Hello. This was an initial idea that we discarded because it increases a lot the internals of Lotus::Model.

Do you know that you can have multiple instances of Lotus::Model in the same Ruby process? That means your main database connection can be against PG, then the secondary one for auth0. The first should stay under lib/, while the secondary can be used inside the applications eg:

# apps/web/application.rb
module Web
  class Application < Lotus::Application
    configure do
      # ...
      adapter :auth0 # ...

      mapping do
         # ....
      end
    end
  end
end

These two settings aren’t automatically generated in application configuration as of v0.4.0, because they were source of confusion for devs.

If you enable them, you can have a separated, standalone configuration for Lotus::Model.

Please let us to know if this can get your job done. Thank you! :smiley:

2 Likes

@jodosha Seems to me (as a complete lotus noob) that a more reasonable place to define a second data source (e.g. one to postgres, one to auth0.com for instance) would be to have a second subdirectory under lib. so in addition to lib/<the_app_name> you would also have, in the above case, lib/auth0_dot_com (perhaps).

Seems to be the most natural place for that code to live but the caveats are (1) I could have misunderstood the architecture (2) at this moment in time I have no idea how to connect the dots and make it work.

Thoughts ?

@jodosha I have a doubt similar as @baob, but in my case I have two databases (mysql and postgres) with entities/repositories who need to be shared across multiples apps, what is the best place to go?

update: Reading the lotus/model.rb and lotus/repository.rb I found how to setup each repository with different adapter.

If can be helpful to someone else, I made a demo here.