PKGBUILD/pkg/storage/db/db.go

36 lines
650 B
Go
Raw Normal View History

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