package subscriptions

import (
	"database/sql"
)

// NewPostgres returns a usable Postgres instance, if and only
// if error is nil. If error is not nil, the returned Postgres
// instance should not be used.
func NewPostgres(conn string) (Postgres, error) {
	db, err := sql.Open("postgres", conn)
	if err != nil {
		return Postgres{}, err
	}
	return Postgres{db}, nil
}

// Postgres represents a thin wrapper around *sql.DB, so we can
// inherit its methods but also define our own (so we can fulfill
// our subscriptionStore interface on Postgres). Note that the
// value of a Postgres variable contains a _pointer_ to an sql.DB
// pool of connections, so it's not necessary to use the address of
// the Postgres variable itself (though there shouldn't be any harm
// in doing so).
type Postgres struct {
	*sql.DB
}
