Hi everyone, just getting started with Pedestal here 👋
I’ve read through this guide: http://pedestal.io/guides/your-first-api and have a question on how you would go about plugging in a real DB to the example code.
In the example an atom is used as an in-memory DB, and the first :enter
interceptor in the chain on each route derefs it and attaches the whole DB value to the context so that subsequent interceptors can query it to pull out individual records.
If I were to use a real DB instead, I obviously don’t want to dump the entire contents of said DB on the context. What is the recommended pattern here? Is it okay for the DB interceptor to perform queries based on the params in the request to only return records relevant to that request, and attach these to the context? Or should I create multiple, specific DB interceptors that query the correct data and attach these to the relevant routes?
the ions sample app has examples on how to add a connection and db to the request, and some of the routes inject the single domain instance (a pet in this case) for endpoints that affect one instance: https://github.com/pedestal/pedestal-ions-sample/blob/master/src/ion_sample/service.clj#L157
for other databases you'd probably put in a connection instance instead of the db