diff --git a/db.go b/db.go index da1e5fa..85795c2 100644 --- a/db.go +++ b/db.go @@ -12,16 +12,19 @@ type Database struct { closefuncs []func() error } -func NewDatabase(host string, port uint16, user, pass, db string) (*Database, error) { +func NewDatabase(conn *sql.DB) *Database { + return &Database{ + db: conn, + closefuncs: make([]func() error, 0), + } +} + +func NewMysqlDatabase(host string, port uint16, user, pass, db string) (*Database, error) { conn, err := sql.Open("mysql", connString(host, port, user, pass, db)) if err != nil { return nil, adverr.Wrap("could not connect to database", err) } - - return &Database{ - db: conn, - closefuncs: make([]func() error, 0), - }, nil + return NewDatabase(conn), nil } func (db *Database) prepare(query string) (*sql.Stmt, error) {