From d1367ff8f27e80411e854add1496c2991441052b Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Thu, 16 Feb 2023 11:28:19 -0600 Subject: [PATCH] Unexporting DBI types to avoid accidental usage --- database/{db.go => dbi.go} | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) rename database/{db.go => dbi.go} (80%) diff --git a/database/db.go b/database/dbi.go similarity index 80% rename from database/db.go rename to database/dbi.go index 5875bd9..3da5dc4 100644 --- a/database/db.go +++ b/database/dbi.go @@ -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} } -- 2.45.2