25 lines
483 B
Go
25 lines
483 B
Go
package repository
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
_ "github.com/lib/pq"
|
|
)
|
|
|
|
const driver = "postgres"
|
|
|
|
// DatabaseConnector holds a connection to the database
|
|
type DatabaseConnector struct {
|
|
*sql.DB
|
|
}
|
|
|
|
// NewDatabaseConnector opens a new database connection with the given uri
|
|
func NewDatabaseConnector(uri string) (*DatabaseConnector, error) {
|
|
connection, err := sql.Open(driver, uri)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &DatabaseConnector{connection}, connection.Ping()
|
|
}
|