datastore

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB added in v0.14.0

func NewDB(n DSName) (*sql.DB, func(), error)

NewDB returns an open database handle of 0 or more underlying PostgreSQL connections

func NewMockDB added in v0.13.0

func NewMockDB(n DSName) *sql.DB

NewMockDB returns nil

Types

type DS

type DS struct {
	DB *sql.DB
	Tx *sql.Tx
}

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.

type DSName

type DSName int

DSName defines the name for the Datastore

const (
	// LocalDatastore represents the local PostgreSQL db
	LocalDatastore DSName = iota
	// GCPCPDatastore represents a local connection to a GCP Cloud
	// SQL db through the Google Cloud Proxy
	GCPCPDatastore
	// GCPDatastore represents a true GCP connection to a GCP
	// Cloud SQL db
	GCPDatastore
	// MockDatastore represents a Mocked Database
	MockDatastore
)

func (DSName) String added in v0.13.0

func (n DSName) String() string

type Datastore

type Datastore interface {
	BeginTx(context.Context) error
	RollbackTx(error) error
	CommitTx() error
}

Datastore is an interface for working with the Database

func NewDatastore added in v0.13.0

func NewDatastore(n DSName, db *sql.DB) (Datastore, error)

NewDatastore 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