I think too many people use ORMs and rely on them to do everything, then blame the database when things are slow. :(
Then their apps grow complex enough that the ORMs get in the way.
Then the devs get sad.
Well, you're using query parameters, but I think I understand what you mean.
What I would do is write a stored procedure that takes whatever parameters, then I'd write PG SQL to generate bindings to that procedure for whatever language you're using (Golang here). I might write the bindings by hand if it's not a lot of work, but definitely would write a little compiler if it's a tone of work. That way you can get type-safety.
I don't know if Go's SQLite support in turn supports named parameters, but if it does, then that would likely help considerably with readability.
I don't think you are doing anything wrong from a noobies opinion.
- Type-safe DSL generated from your schema that looks like SQL
- (If you can write the SQL, you can write it in jOOQ)
- SQL-injection protection
- Strong multi-dialect and vendor-specific support
- Custom-type mappers
- Composable queries
- Compile-time, schema-aware query safety
- Fine-grained transaction control
- And so much more...
https://jawj.github.io/zapatos/
Using an ORM doesn't mean you have to rely on behaviour that generates slow (e.g. n+1) query issues.
If it doesn't work with an real life implementation e.g. docker test container, then I don't consider it a robust test.