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: Go 2: database/sql: Prepare and QueryRow to return Statement and Row interface #22626

Closed
andizzle opened this issue Nov 8, 2017 · 8 comments
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Milestone

Comments

@andizzle
Copy link

andizzle commented Nov 8, 2017

Have a Stmt interface gives developer more controls when writing database related tools. It would be nice to to be able to create a custom stmt struct that has the same method signatures as sql.Stmt but with some custom instructions inside each method. For example, when writing a DB wrapper for handling database read replicas, the statement may need to be prepared in multiple db pools, to provide a seamless feel for the end users, I woulld like the users to call the Prepare() or PrepareContext() as if they are using database/sql.DB.

example usecase

In some rare cases we would like to include some custom errors when using QueryRow. Take read replica situation as an example again, if the tool wants to provide the custom QueryRow function but need to capture certain errors, it would be nice to return a Row interface instead of panicing.

example usecase

@gopherbot gopherbot added this to the Proposal milestone Nov 8, 2017
@andizzle
Copy link
Author

andizzle commented Nov 8, 2017

@pjebs

@kshvakov
Copy link

kshvakov commented Nov 8, 2017

I think will better returns interfaces from all methods

@ianlancetaylor ianlancetaylor changed the title Proposal: database/sql Prepare and QueryRow to return Statement and Row interface proposal: database/sql: Prepare and QueryRow to return Statement and Row interface Nov 8, 2017
@ianlancetaylor
Copy link
Contributor

CC @kardianos

@ianlancetaylor
Copy link
Contributor

We can't change the signature of (*DB).PrepareContext to return Stmt rather than *Stmt. That would break the Go 1 compatibility guarantee (https://golang.org/doc/go1compat).

@andizzle
Copy link
Author

andizzle commented Nov 8, 2017

Of course. How'bout in Go2?

@ianlancetaylor
Copy link
Contributor

In Go 2 we could make such a change, but it should ideally be part of an overhaul of the database/sql package in general.

@ianlancetaylor ianlancetaylor added the v2 A language change or incompatible library change label Nov 8, 2017
@ianlancetaylor ianlancetaylor changed the title proposal: database/sql: Prepare and QueryRow to return Statement and Row interface proposal: Go 2: database/sql: Prepare and QueryRow to return Statement and Row interface Nov 8, 2017
@kardianos
Copy link
Contributor

@andizzle Please read my comment here:
#22697 (comment)

In essence, for Go2 I would like to separate out preparing a statement on a given connection from the Stmt connection pool. Then the user can handle these situations themselves. They can call conn.Prepare, and the returned stmt is specific to that connection.

@ianlancetaylor
Copy link
Contributor

Closing this specific issue in favor of the more general #22697.

@golang golang locked and limited conversation to collaborators Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants