⚠️ This post links to an external website. ⚠️
“Your context module has 30 query functions. It needs five.” That line stuck. I recognized the pattern immediately: a growing list of narrowly scoped functions like
get_active_users,get_active_users_with_posts,get_active_users_with_posts_and_comments. I’ve done this myself, and it scales poorly. The differences are usually just filters, joins, or preload options, yet each variation becomes its own function.The better approach is to collapse this into a few composable query entry points. I pass options for filters, sorting, pagination, and associations instead of hardcoding combinations. It keeps the API small and predictable. It also makes changes easier, since I update one place instead of ten. This feels very similar to how tools like Ecto queries or even LLM APIs work: fewer primitives, more composition.
continue reading onbobbie-barker.medium.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.