luci: go.chromium.org/luci/machine-db/appengine/database Index | Files

package database

import "go.chromium.org/luci/machine-db/appengine/database"

Index

Package Files

database.go interfaces.go tx.go

func Get Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

func (*RollbackTx) Commit Uses

func (r *RollbackTx) Commit() error

Commit commits the transaction.

func (*RollbackTx) MaybeRollback Uses

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 database imports 10 packages (graph) and is imported by 3 packages. Updated 2018-12-14. Refresh now. Tools for package owners.