Back to godoc.org

Package database

v0.0.0-...-1557bcf
Latest Go to latest

The latest major version is .

Published: Aug 13, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Index

func Get

func Get(c context.Context) *sql.DB

Get returns the database pointer embedded in the current context. The database pointer can be embedded in the current context using With.

func With

func With(c context.Context, database *sql.DB) context.Context

With installs a database pointer into the given context. It can be retrieved later using Get.

func WithMiddleware

func WithMiddleware(c *router.Context, next router.Handler)

WithMiddleware is middleware which installs a database pointer into the given context. It can be retrieved later in the middleware chain using Get.

type ExecerContext

type ExecerContext interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

ExecerContext defines an interface which supports ExecContext calls. Implemented by sql.Conn, sql.DB, sql.Stmt, sql.Tx.

type QueryerContext

type QueryerContext interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

QueryerContext defines an interface which supports QueryContext calls. Implemented by sql.Conn, sql.DB, sql.Stmt, sql.Tx.

type RollbackTx

type RollbackTx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

RollbackTx is a sql.Tx which supports automatic rollback. defer a call to MaybeRollback(), then call (*RollbackTx).Commit() instead of (*sql.Tx).Commit() to avoid having the transaction rolled back by the defer.

func Begin

func Begin(c context.Context) (*RollbackTx, error)

Begin begins a transaction using the database pointer embedded in the current context.

func (*RollbackTx) Commit

func (r *RollbackTx) Commit() error

Commit commits the transaction.

func (*RollbackTx) MaybeRollback

func (r *RollbackTx) MaybeRollback(c context.Context) error

MaybeRollback rolls back the transaction if (*RollbackTx).Commit() hasn't been called. Logs the error if the rollback itself fails.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier