Re:Simplify Your Code: Functional Core, Imperative Shell
by soulofmischief on Tuesday October 28, 2025 @10:12AM
(#45733158)
This is a better story because it has consistent semantics and a specific query structure. The db.getUsers() approach is not part of a well-thought-out query structure.
The query shape would be:
That gives you an expression object which only encodes an intent. Then you have the option to make basic templates you can build from: ...where `exclude` is any set-valued expression.Then at execution time, the objects representing query expressions are rendered into queries and sent to the database:
With SQLAlchemy, I'll usually make simple dataclasses for the query shapes because "get_something" or "select_something" names are confusing when they're not really for actions.