PKGBUILD/pkg/storage/db/db.go

35 lines
567 B
Go
Raw Normal View History

package db
import (
"database/sql"
"fmt"
"net/url"
_ "github.com/lib/pq"
2019-09-29 18:08:54 +00:00
"github.com/volker-raschek/go-logger/pkg/logger"
)
var (
flogger = logger.NewSilentLogger()
2019-09-29 18:08:54 +00:00
)
func New(storageEndpoint *url.URL) (Database, error) {
newDBO, err := sql.Open(storageEndpoint.Scheme, storageEndpoint.String())
if err != nil {
return nil, err
}
switch storageEndpoint.Scheme {
case "postgres":
return &Postgres{
dbo: newDBO,
}, nil
default:
return nil, fmt.Errorf("Unknown Database Type")
}
}
func SetLogger(logger logger.Logger) {
flogger = logger
}