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: allow driver-specific transaction options #29847

Closed
rittneje opened this issue Jan 20, 2019 · 1 comment
Closed

proposal: database/sql: allow driver-specific transaction options #29847

rittneje opened this issue Jan 20, 2019 · 1 comment

Comments

@rittneje
Copy link

rittneje commented Jan 20, 2019

Problem: In SQLite, there are three transaction behaviors to choose from when starting a transaction - deferred, immediate, or exclusive. However, there is no way to say which one to use via the existing Begin or BeginTx methods in the database/sql package. And since this is a SQLite-only concept, it would seem strange to make "transaction behavior" a field of the sql.TxOptions struct.

I propose adding a new field for driver-specific transaction options to sql.TxOptions (and driver.TxOptions).

type TxOptions struct {
    ...
    DriverOptions interface{}
}

The user could then supply an options struct from their driver package, as in the following hypothetical example:

tx, err := db.BeginTx(ctx, &sql.TxOptions{
    DriverOptions: &sqlite3.TxOptions{
        Behavior: sqlite3.BeginImmediate,
    },
})

From a compatibility standpoint, one potential issue is that existing drivers that already implement driver.ConnBeginTx would not know to evaluate this new DriverOptions field, so they would allow through potentially invalid input. Then, when that driver gets updated to actually evaluate the new field, it would start returning an error, breaking existing programs. However, it would seem silly for someone to use a driver options struct that isn't supported by their driver package, so this may be an unlikely issue in practice. At worst, yet another optional interface could be added to the database/sql/driver package.

@gopherbot gopherbot added this to the Proposal milestone Jan 20, 2019
@kardianos
Copy link
Contributor

Duplicate of #19981

@kardianos kardianos marked this as a duplicate of #19981 Jan 21, 2019
@golang golang locked and limited conversation to collaborators Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants