magicwallet/db/db.go

31 lines
385 B
Go
Raw Normal View History

package db
import (
"database/sql"
_ "github.com/lib/pq"
)
type DB struct {
*sql.DB
}
func New(dbUrl string) (*DB, error) {
// open connection
db_, err := sql.Open("postgres", dbUrl)
if err != nil {
return nil, err
}
// test connection
_, err = db_.Exec("SELECT 1")
if err != nil {
return nil, err
}
// TODO: run migrations
db := &DB{DB: db_}
return db, nil
}