database

package
v0.0.0-...-fa2bc5f Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the connection to the database

func Connect

func Connect(cfg *config.CommonConfigFlags) error

Connect connects to the database mentioned in the config variable.

func DBInstance

func DBInstance() (*pg.DB, error)

DBInstance returns a reference to the database connection

func Migrate

func Migrate(cfg *config.CommonConfigFlags) error

Migrate database to the latest version.

Types

type Context

type Context interface {
	DB() (DB, error)
}

Context is an interface type representing the context in which queries run, currently relating to the existence or non-existence of a database transaction Call `.NoTx()` or `.NewTx()` to acquire a Context

func NoTx

func NoTx() Context

NoTx creates and returns an instance of dbaccess.Context without an attached database transaction

type DB

type DB interface {
	Model(model ...interface{}) *orm.Query
	Select(model interface{}) error
	Insert(model ...interface{}) error
	Update(model interface{}) error
	Delete(model interface{}) error
	QueryOne(model, query interface{}, params ...interface{}) (orm.Result, error)
}

DB is an interface type implemented both by pg.DB and pg.Tx. We use DB to execute db operations with or without transaction context.

type TxContext

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

TxContext represents a database context with an attached database transaction

func NewTx

func NewTx() (*TxContext, error)

NewTx returns an instance of TxContext with a new database transaction

func (*TxContext) Commit

func (ctx *TxContext) Commit() error

Commit commits the transaction attached to this TxContext

func (*TxContext) DB

func (ctx *TxContext) DB() (DB, error)

DB returns a db instance

func (*TxContext) Rollback

func (ctx *TxContext) Rollback() error

Rollback rolls-back the transaction attached to this TxContext.

func (*TxContext) RollbackUnlessCommitted

func (ctx *TxContext) RollbackUnlessCommitted() error

RollbackUnlessCommitted rolls-back the transaction attached to this TxContext if the transaction was not committed.

Jump to

Keyboard shortcuts

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