proposal: database/sql: add query builder
Proposal Details
I propose to add a query builder that would help us to write more dynamic SQL queries.
The problem
When writing webapps, it's common to have dynamic queries that are useful, for example, sorting or filtering. Writing
To achieve that we have a few options like:
- using a query builder (https://github.com/huandu/go-sqlbuilder, https://doug-martin.github.io/goqu/)
- joining strings dynamically
- using an ORM
The second option is the most error probe and may be good source for bugs. The option with an ORM doesn't seem like a good option because many developers don't wan to use any ORM at all. A query builder looks like a sweet spot between the flexibility, safety of syntax of the query and the speed of development and building final queries.
Related issues:
- https://github.com/golang/go/issues/18478
see https://go.dev/doc/faq#x_in_std
given the existence of third party libraries that already do this, and the numerous SQL dialects that SQL builders need to support, I don't think this would be an appropriate fit for the standard library
This proposal should define a new API that you suggest that we implement in the standard library.
To be clear, I don't know whether we should do this. But we can't decide without seeing what exactly is being proposed. Thanks.
Shouldn't strings.Builder be enough? I don't think trying to add support for every SQL dialect to build a query concerns the std. As @ianlancetaylor mentioned, maybe showing an API would make things clearer.
Timed out in state WaitingForInfo. Closing.
(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)