must

package
v0.0.0-...-cc996d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2020 License: Zlib Imports: 1 Imported by: 0

Documentation

Overview

package must wraps the rdb database interface with one that returns errors with a panic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config(config *rdb.Config, err error) *rdb.Config

ConfigMust takes the output of the ParseConfig and panics if an error is present.

func Run

func Run(f func(r Roller) error) (err error)

A method to take many panicing members and return a normal error. The Roller function will rollback to an existing savepoint if it has not already been commited. An empty savepoint parameter to Roller will roll the transaction back entirely.

func ExampleRun() error {
	return rdb.Run(func(r rdb.Roller) error {
		db := rdb.OpenMust(config)
		t := db.Begin()
		r(t, "")

		t.Query(cmd1)

		t.SavePoint("Foo")
		r(t, "Foo")

		t.Query(cmd2)

		t.Commit()
		return nil
	})
}

Types

type ConnPool

type ConnPool struct {
	// contains filtered or unexported fields
}

func NewConnPool

func NewConnPool(cp *rdb.ConnPool) ConnPool

Get the panic'ing version that doesn't return errors.

func Open

func Open(c *rdb.Config) ConnPool

Same as Open() but all errors are returned as a panic(MustError{}).

func (ConnPool) Begin

func (must ConnPool) Begin() Transaction

Same as Query but will panic on an error.

func (ConnPool) BeginLevel

func (must ConnPool) BeginLevel(level rdb.IsolationLevel) Transaction

Same as Query but will panic on an error.

func (ConnPool) Close

func (must ConnPool) Close()

func (ConnPool) ConnectionInfo

func (must ConnPool) ConnectionInfo() *rdb.ConnectionInfo

func (ConnPool) Normal

func (must ConnPool) Normal() *rdb.ConnPool

Get the non-panic'ing version of Database.

func (ConnPool) Ping

func (must ConnPool) Ping()

func (ConnPool) PoolAvailable

func (must ConnPool) PoolAvailable() (capacity, available int)

func (ConnPool) Query

func (must ConnPool) Query(cmd *rdb.Command, params ...rdb.Param) Result

Input parameter values can either be specified in the paremeter definition or on each query. If the value is not put in the parameter definition then the command instance may be reused for every query.

type Error

type Error struct {
	Err error
}

Type panic'ed with after calling a Must method.

func (Error) Error

func (err Error) Error() string

type Result

type Result struct {
	// contains filtered or unexported fields
}

func NewResult

func NewResult(r *rdb.Result) Result

Get the panic'ing version that doesn't return errors.

func (Result) Close

func (must Result) Close()

Make sure the result is closed.

func (Result) Get

func (must Result) Get(name string) interface{}

Use after Scan(). Can only pull fields which have not already been sent into a prepared value.

func (Result) GetN

func (must Result) GetN(name string) rdb.Nullable

Use after Scan(). Can only pull fields which have not already been sent into a prepared value.

func (Result) GetRowN

func (must Result) GetRowN() []rdb.Nullable

Use after Scan(). Can only pull fields which have not already been sent into a prepared value. Not all fields will be populated if some have been prepared.

func (Result) Getx

func (must Result) Getx(index int) interface{}

Use after Scan(). Can only pull fields which have not already been sent into a prepared value.

func (Result) GetxN

func (must Result) GetxN(index int) rdb.Nullable

Use after Scan(). Can only pull fields which have not already been sent into a prepared value.

func (Result) Info

func (must Result) Info() []*rdb.Message

Informational messages. Do not call concurrently with Scan() or Done().

func (Result) Next

func (must Result) Next() (more bool)

func (Result) NextResult

func (must Result) NextResult() (more bool)

func (Result) Normal

func (must Result) Normal() *rdb.Result

Get the non-panic'ing version of Result.

func (Result) Prep

func (must Result) Prep(name string, value interface{}) Result

Prepare pointers to values to be populated by name using Prep. After preparing call Scan().

func (Result) Prepx

func (must Result) Prepx(index int, value interface{}) Result

Prepare pointers to values to be populated by index using Prep. After preparing call Scan().

func (*Result) RowsAffected

func (r *Result) RowsAffected() uint64

func (Result) Scan

func (must Result) Scan(values ...interface{}) Result

For each needed field, call Prep() or PrepAll() to prepare value pointers for scanning. To scan prepared fields call Scan(). Call Scan() before using Get() or Getx(). Returns false if no more rows.

func (Result) Schema

func (must Result) Schema() []*rdb.Column

Fetch the table schema.

type Roller

type Roller func(t Transaction, savepoint string)

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(tran *rdb.Transaction) Transaction

Get the panic'ing version that doesn't return errors.

func (Transaction) Active

func (must Transaction) Active() bool

func (Transaction) Commit

func (must Transaction) Commit()

func (Transaction) Normal

func (must Transaction) Normal() *rdb.Transaction

Get the non-panic'ing version of Transaction.

func (Transaction) Query

func (must Transaction) Query(cmd *rdb.Command, params ...rdb.Param) Result

Input parameter values can either be specified in the paremeter definition or on each query. If the value is not put in the parameter definition then the command instance may be reused for every query.

func (Transaction) Rollback

func (must Transaction) Rollback()

func (Transaction) RollbackTo

func (must Transaction) RollbackTo(savepoint string)

func (Transaction) SavePoint

func (must Transaction) SavePoint(name string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL