datastore

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DS

type DS struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

DS is a concrete implementation for a database

func (*DS) BeginTx

func (db *DS) BeginTx(ctx context.Context) error

BeginTx is a wrapper for sql.DB.BeginTx in order to expose from the Datastore interface

func (*DS) CommitTx

func (db *DS) CommitTx() error

CommitTx is a wrapper for sql.Tx.Commit in order to expose from the Datastore interface. Proper error handling is also considered.

func (*DS) RollbackTx

func (db *DS) RollbackTx(err error) error

RollbackTx is a wrapper for sql.Tx.Rollback in order to expose from the Datastore interface. Proper error handling is also considered.

func (*DS) Tx

func (db *DS) Tx() (*sql.Tx, error)

Tx exposes the Tx stored in the struct in order to be exposed from the Datastore interface.

type DSName

type DSName int

DSName defines the name for the Datastore

const (
	// AppDatastore represents main application database
	AppDatastore DSName = iota
	// LogDatastore represents http logging database
	LogDatastore
	// MockDatastore represents a Mocked Database
	MockDatastore
)

type Datastore

type Datastore interface {
	BeginTx(context.Context) error
	Tx() (*sql.Tx, error)
	RollbackTx(error) error
	CommitTx() error
}

Datastore is an interface for working with the Database

func ProvideDatastore

func ProvideDatastore(n DSName) (Datastore, error)

ProvideDatastore provides either a DS struct, which has a concrete implementation of a database or a MockDS struct which is a mocked DB implementation

type MockDS

type MockDS struct {
}

MockDS is a mock implementation for a database

func (*MockDS) BeginTx

func (db *MockDS) BeginTx(ctx context.Context) error

BeginTx is a wrapper for sql.DB.BeginTx in order to expose from the Datastore interface

func (*MockDS) CommitTx

func (db *MockDS) CommitTx() error

CommitTx is a wrapper for sql.Tx.Commit in order to expose from the Datastore interface. Proper error handling is also considered.

func (*MockDS) RollbackTx

func (db *MockDS) RollbackTx(err error) error

RollbackTx is a wrapper for sql.Tx.Rollback in order to expose from the Datastore interface. Proper error handling is also considered.

func (*MockDS) Tx

func (db *MockDS) Tx() (*sql.Tx, error)

Tx exposes the Tx stored in the struct in order to be exposed from the Datastore interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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