~netlandish/gobwebs

d1367ff8f27e80411e854add1496c2991441052b — Peter Sanchez 1 year, 9 months ago c231306
Unexporting DBI types to avoid accidental usage
1 files changed, 12 insertions(+), 12 deletions(-)

R database/{db.go => dbi.go}
R database/db.go => database/dbi.go +12 -12
@@ 9,7 9,7 @@ import (
)

// DBI is an interface to provide database access
type DBI interface {
type dbi interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	CommitTx() error
	RollbackTx() error


@@ 19,8 19,8 @@ type DBI interface {
	GetDB() *sql.DB
}

// DB database wrapper that meets DBI interface signature
type DB struct {
// db database wrapper that meets DBI interface signature
type db struct {
	db     *sql.DB
	tx     *sql.Tx
	commit bool


@@ 35,7 35,7 @@ func roTransaction(opts *sql.TxOptions) bool {
}

// BeginTx begins a db transaction
func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) {
func (d *db) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) {
	if d.db == nil {
		return nil, errors.New("You must first set the *sql.DB value")
	}


@@ 61,7 61,7 @@ func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error) 
}

// CommitTx commits active transaction
func (d *DB) CommitTx() error {
func (d *db) CommitTx() error {
	if d.tx == nil {
		// No errors here
		return nil


@@ 75,7 75,7 @@ func (d *DB) CommitTx() error {
}

// RollbackTx rollsback active transaction
func (d *DB) RollbackTx() error {
func (d *db) RollbackTx() error {
	if d.tx == nil {
		// No errors here
		return nil


@@ 86,28 86,28 @@ func (d *DB) RollbackTx() error {
}

// WillCommit will return the value of commit
func (d *DB) WillCommit() bool {
func (d *db) WillCommit() bool {
	return d.commit
}

// EnableCommit enables the commit flag
func (d *DB) EnableCommit() bool {
func (d *db) EnableCommit() bool {
	d.commit = true
	return d.commit
}

// DisableCommit enables the commit flag
func (d *DB) DisableCommit() bool {
func (d *db) DisableCommit() bool {
	d.commit = false
	return d.commit
}

// GetDB returns the *sql.DB instance
func (d *DB) GetDB() *sql.DB {
func (d *db) GetDB() *sql.DB {
	return d.db
}

// NewDB returns a new DB struct
func NewDB(sdb *sql.DB) *DB {
	return &DB{db: sdb}
func newDB(sdb *sql.DB) *db {
	return &db{db: sdb}
}