From 26975dc3a10a0e68bc8b911a63aaae49c8678349 Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Fri, 8 Jul 2022 22:09:53 +0200 Subject: [PATCH] implemented new constructors for DB --- db.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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) {