PKGBUILD/pkg/storage/db/db.go
Markus Pesch dbef4f8241
fix(pkg/config): use storage endpoints
changes:
- Only one storage endpoint can be defined. This consists of a URL which
  can be used to specify whether the data is to be stored in a file or
  in a database.
2019-12-08 12:49:21 +01:00

35 lines
567 B
Go

package db
import (
"database/sql"
"fmt"
"net/url"
_ "github.com/lib/pq"
"github.com/volker-raschek/go-logger/pkg/logger"
)
var (
flogger = logger.NewSilentLogger()
)
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
}