setup a small application that can talk to a database using the dry-system
and dry-auto_inject
gems
along with rom and rom-sql
config/boot.rb
- Requires boot-level pieces of our application - such asBundler
anddotenv
config/application.rb
- Defines aContainer
for our application's configuration. Serves as the main entry point for our applicationsystem/boot/db.rb
- Specifies how our application connects to a databaselib/projects/repos/user_repo.rb
- A class that contains methods for interacting with our relation allowing us to create + retrieve data from the databaselib/projects/relations/user.rb
- Defines a class that can contain query logic for ourusers
table
entities
Classes that represent specific data types. These are used by therepository
to represent data from the database, but the main thin here is that they can be used in complete isolationrelations
Classes that can contain custom methods for querying the database. When we write complicated queries to get data from our db, this is now where the code will gorepos
Classes that provide a place for defining a public API betweenrelations
and our application code. Provides a clean API between the relations and the entitites, Uses relations to fetch data from a database and use entities to represent that data
ROM
and Dry
separate our application into small, clearly defined pieces with individual responsabilites
While this setup cost feels large now. it's a cost that we're only going to be paying once.
Setups cost is one-time maintenance cost is forever