Skip to content

database/sql: don't encumber Context with options #18284

@tgulacsi

Description

@tgulacsi

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.8beta1

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

See https://groups.google.com/forum/#!topic/golang-nuts/20NtIGTgBeg

What did you expect to see?

A nice, clean API just as before, and not using context.Context for transferring options.

What did you see instead?

ReadOnlyContext and IsolationContext to passes isolation level and readonly flag in the Context.

I'd modify BeginContext as

func (db *DB) BeginContext(ctx context.Context, options... TxOption) (*Tx, error)

type TxOption func(*txOption)

type txOption struct {
    IsReadOnly bool
    IsolationLevel
}

func WithIsolationLevel(level IsolationLevel) TxOption { return func(o *txOption) { o.IsolationLevel = level } }
func WithReadOnly(readOnly bool) TxOption { return func(o *txOption) { o.IsReadOnly = readOnly } }

This does not block anybody to use the Context as bag-of-values, but at least does not encourage that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions