The db package utilities are messy to use, modify, and extend.
Methods in the db package (like FindOne and FindAll) are difficult to change because the options are passed in as one long parameter list. If you want to change one spot to pass in a new option, you have to change every single usage of FindOne and FindAll in the code base to support the new option.
This also makes it difficult for options to be truly optional. For example, most of the time, a projection is probably unnecessary, but if you call FindOne or FindAll, you have to pass the NoProjection option explicitly.
Some potential improvements:
- Use an options builder pattern to pass in an optional parameter list to the FindOne and FindAll methods. Alternatively, remove the ability to use FindOne and FindAll directly - instead, require the usage of the FindOneQ and FindAllQ variants to ensure all queries pass through db.Q.
- db.Q is basically just a passthrough wrapper around anser's query-building capabilities that exposes a subset of the available options. Maybe it would be better to remove db.Q entirely and just use anser's query-builder directly instead of the middleman db.Q, which has to update when anser supports new options.