Custom logic for dynamic routes

As mentioned in this post, I’m looking to migrate a rails app to Ghost. I currently have a membership base that I would move to a Ghost membership, but also have courses and purchases tables` that will need to be in a separate DB.

I can add a new column to the purchase table that matches the Ghost member ID, but from what I can see there is no way to access Members via the API, which would mean the pages showing the Courses would need to be part of the Ghost app as custom pages/routes in order to access this.

My question then is there any way to add logic to a custom page/route that would be able to pull the relevant courses data from a separate DB? Or is there a better way to match a Ghost member with an external DB so that these pages could be s a separate application/micro-service?