Multiple configurations in a container

Say I had two rom configurations:

http_configuration = ROM::Configuration.new(:http, {
  uri: 'http://jsonplaceholder.typicode.com',
  headers: {
    Accept: 'application/json'
  },
  handlers: :json
})

sql_configuration = config = ROM::Configuration.new(:sql, 'postgres://localhost:5432/mydbname', opts)


How could I create a container that would be have access to the relations in both configs?

ROM.container(sql: sql_configuration, http: http_configuration) # this doesn't work, just pseudo-code

@ianks did you try what’s described under Connect to multiple databases section of the docs?

I’m trying to solve the same problem outlined in this question. The framework setup docs in 5.2 only show setting up a Configuration object and creating a Container with it. Is it possible to setup a Container with multiple Configuration objects? Syntactically that’s not exactly the same as the “Connect to multiple databases” link you suggested before. A more specific example could be very useful :slight_smile:

No, it’s not. I’m not sure why that’s needed?

@solnic what would be the correct approach to read from one Configuration and write to another in the same process? Particularly in the case where, e.g. one is using HTTP and another SQL?

@pmackay wdym by “write to another”?

@solnic I mean read from one data source and write to another data source, which could be different types of storage (HTTP, db).

@pmackay wait, it is possible to configure multiple gateways in a single container. Sorry but I feel like I’m missing something here. What’s the actual problem? You can pass in multiple configuration options to establish a multi-gateway container via ROM::Configuration.new - configuration is not per gateway, it’s per container. A single configuration object can set up more than one gateway. Maybe that’s the part you’ve missed?

1 Like