zesty

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 6 Imported by: 0

README

zesty is based on gorp, and abstracts DB transaction specifics.

It abstracts DB and Tx objects through a unified interface: DBProvider, which in turn lets your function
remain ignorant of the current transaction state they get passed.

It also manages nested transactions, with mid-Tx savepoints making partial rollbacks very easy.

You can create a zesty.DB by calling NewDB().
You can then register this DB by calling RegisterDB().

This lets you instantiate DBProviders for this DB with NewDBProvider(), which is the main
object that you manipulate.

A DBProvider contains a DB instance, and provides Tx functionalities.

You access the DB by calling provider.DB()

By calling provider.Tx(), you create a new transaction.
Future calls to provider.DB() will provide the Tx instead of the main DB object,
allowing caller code to be completely ignorant of transaction context.

Transactions can be nested infinitely, and each nesting level can be rolled back independantly.
Only the final commit will end the transaction and commit the changes to the DB.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDB

func RegisterDB(db DB, name string) error

func UnregisterDB

func UnregisterDB(name string) error

Types

type DB

type DB interface {
	gorp.SqlExecutor
	Begin() (Tx, error)
	Close() error
	Ping() error
	PingContext(context.Context) error
	Stats() sql.DBStats
}

func NewDB

func NewDB(dbmap *gorp.DbMap) DB

type DBProvider

type DBProvider interface {
	DB() gorp.SqlExecutor
	Tx() error
	TxSavepoint() (SavePoint, error)
	Commit() error
	Rollback() error
	RollbackTo(SavePoint) error
	Close() error
	Ping() error
	PingContext(context.Context) error
	Stats() sql.DBStats
}

func NewDBProvider

func NewDBProvider(name string) (DBProvider, error)

func NewTempDBProvider

func NewTempDBProvider(db DB) DBProvider

type SavePoint

type SavePoint uint

type Tx

type Tx interface {
	gorp.SqlExecutor
	Commit() error
	Rollback() error
	Savepoint(string) error
	RollbackToSavepoint(string) error
}

Directories

Path Synopsis
utils

Jump to

Keyboard shortcuts

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