1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-10-31 16:00:05 -04:00

Take unexported database methods 'private'

This commit is contained in:
Aaron Lindsay 2017-12-09 06:06:20 -05:00
parent e89198fe2e
commit c4d2fe27e6
3 changed files with 15 additions and 13 deletions

View File

@ -258,10 +258,7 @@ func RunTests(m *testing.M) int {
} }
defer db.Close() defer db.Close()
err = db.DbMap.TruncateTables() db.Empty() // clear the DB tables
if err != nil {
log.Fatal(err)
}
server = httptest.NewTLSServer(&handlers.APIHandler{Store: db}) server = httptest.NewTLSServer(&handlers.APIHandler{Store: db})
defer server.Close() defer server.Close()

View File

@ -19,7 +19,7 @@ import (
// implementation's string type specified by the same. // implementation's string type specified by the same.
const luaMaxLengthBuffer int = 4096 const luaMaxLengthBuffer int = 4096
func GetDbMap(db *sql.DB, dbtype config.DbType) (*gorp.DbMap, error) { func getDbMap(db *sql.DB, dbtype config.DbType) (*gorp.DbMap, error) {
var dialect gorp.Dialect var dialect gorp.Dialect
if dbtype == config.SQLite { if dbtype == config.SQLite {
dialect = gorp.SqliteDialect{} dialect = gorp.SqliteDialect{}
@ -55,7 +55,7 @@ func GetDbMap(db *sql.DB, dbtype config.DbType) (*gorp.DbMap, error) {
return dbmap, nil return dbmap, nil
} }
func GetDSN(dbtype config.DbType, dsn string) string { func getDSN(dbtype config.DbType, dsn string) string {
if dbtype == config.MySQL && !strings.Contains(dsn, "parseTime=true") { if dbtype == config.MySQL && !strings.Contains(dsn, "parseTime=true") {
log.Fatalf("The DSN for MySQL MUST contain 'parseTime=True' but does not!") log.Fatalf("The DSN for MySQL MUST contain 'parseTime=True' but does not!")
} }
@ -63,25 +63,29 @@ func GetDSN(dbtype config.DbType, dsn string) string {
} }
type DbStore struct { type DbStore struct {
DbMap *gorp.DbMap dbMap *gorp.DbMap
}
func (db *DbStore) Empty() error {
return db.dbMap.TruncateTables()
} }
func (db *DbStore) Begin() (store.Tx, error) { func (db *DbStore) Begin() (store.Tx, error) {
tx, err := db.DbMap.Begin() tx, err := db.dbMap.Begin()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Tx{db.DbMap.Dialect, tx}, nil return &Tx{db.dbMap.Dialect, tx}, nil
} }
func (db *DbStore) Close() error { func (db *DbStore) Close() error {
err := db.DbMap.Db.Close() err := db.dbMap.Db.Close()
db.DbMap = nil db.dbMap = nil
return err return err
} }
func GetStore(dbtype config.DbType, dsn string) (store *DbStore, err error) { func GetStore(dbtype config.DbType, dsn string) (store *DbStore, err error) {
dsn = GetDSN(dbtype, dsn) dsn = getDSN(dbtype, dsn)
database, err := sql.Open(dbtype.String(), dsn) database, err := sql.Open(dbtype.String(), dsn)
if err != nil { if err != nil {
return nil, err return nil, err
@ -92,7 +96,7 @@ func GetStore(dbtype config.DbType, dsn string) (store *DbStore, err error) {
} }
}() }()
dbmap, err := GetDbMap(database, dbtype) dbmap, err := getDbMap(database, dbtype)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -117,6 +117,7 @@ type Tx interface {
} }
type Store interface { type Store interface {
Empty() error
Begin() (Tx, error) Begin() (Tx, error)
Close() error Close() error
} }