-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifierpg.go
35 lines (29 loc) · 955 Bytes
/
verifierpg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Package verifierpg is a PostgreSQL-based implementaion of the Verifier interface.
package verifierpg
import (
"database/sql"
"github.com/gnames/gnames/config"
"github.com/gnames/gnames/ent/verifier"
"github.com/gnames/gnames/io/internal/dbshare"
vlib "github.com/gnames/gnlib/ent/verifier"
log "github.com/sirupsen/logrus"
// postgres driver
_ "github.com/jinzhu/gorm/dialects/postgres"
)
type verifierpg struct {
db *sql.DB
dataSourcesMap map[int]*vlib.DataSource
}
// New creates a new instance of sqlx.DB using configuration data.
func New(cnf config.Config) verifier.Verifier {
db, err := sql.Open("postgres", dbshare.DBURL(cnf))
if err != nil {
log.Fatalf("Cannot create PostgreSQL connection: %s.", err)
}
vf := verifierpg{db: db}
vf.dataSourcesMap = dbshare.DataSourcesMap(db)
return vf
}
func (vf verifierpg) DataSources(ids ...int) ([]*vlib.DataSource, error) {
return dbshare.DataSources(vf.db, ids...)
}