Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: database/sql: add query builder #69497

Open
bksamsung opened this issue Sep 17, 2024 · 3 comments
Open

proposal: database/sql: add query builder #69497

bksamsung opened this issue Sep 17, 2024 · 3 comments
Labels
Milestone

Comments

@bksamsung
Copy link

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:

  1. using a query builder (https://github.com/huandu/go-sqlbuilder, https://doug-martin.github.io/goqu/)
  2. joining strings dynamically
  3. 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:

@gopherbot gopherbot added this to the Proposal milestone Sep 17, 2024
@seankhliao
Copy link
Member

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

@ianlancetaylor
Copy link
Contributor

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.

@fontseca
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

5 participants