rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.07k stars 161 forks source link

Introduce gateway component #645

Closed solnic closed 3 years ago

solnic commented 3 years ago

This replaces immediate loading of gateways during configuration phase with the component-based approach which makes it lazy-loadable.

Backward-compatibility is kept via rom/compat, if you don't use it your gateways will be loaded upon first access within the runtime container.

Here's an example:

# Doing this no longer connects to the db
rom = ROM.container(:sql, "postgres://localhost/my_db")

# The gateway will be initialized and connected once you access it for the first time.
# This means that whenever a relation loads and asks for its dataset, the corresponding
# gateway will be initialized
rom.gateways[:default]