<commit_before>package pg

import (
	"database/sql"
	_ "github.com/lib/pq"
)

type DB struct {
	*sql.DB
}

type ConnSpec struct {
	User, Password string
	Database       string
}

func (c ConnSpec) SpecForDB(db string) ConnSpec {
	copy := c
	copy.Database = db
	return copy
}

func (c ConnSpec) ConnectionString() string {
	res := "sslmode=disable"
	if c.Database != "" {
		res += " dbname=" + c.Database
	}
	if c.User != "" {
		res += " user=" + c.User
	}
	if c.Password != "" {
		res += " password=" + c.Password
	}
	return res
}

func (c ConnSpec) Open() (DB, error) {
	dbh, err := sql.Open("postgres", c.ConnectionString())
	if err != nil {
		return DB{}, err
	}
	return DB{dbh}, nil
}

func OpenDBUser(db, user, password string) (DB, error) {
	return ConnSpec{Database: db, User: user, Password: password}.Open()
}

type PgError struct {
	Context string
	Cause   error
}

func (p PgError) Error() string {
	return p.Context + ": " + p.Cause.Error()
}

func ctx(context string, err error) error {
	return PgError{Context: context, Cause: err}
}
<commit_msg>When connection fails, say which DB.<commit_after>package pg

import (
	"database/sql"

	"github.com/greensnark/go-sequell/ectx"
	_ "github.com/lib/pq"
)

type DB struct {
	*sql.DB
}

type ConnSpec struct {
	User, Password string
	Database       string
}

func (c ConnSpec) SpecForDB(db string) ConnSpec {
	copy := c
	copy.Database = db
	return copy
}

func (c ConnSpec) ConnectionString() string {
	res := "sslmode=disable"
	if c.Database != "" {
		res += " dbname=" + c.Database
	}
	if c.User != "" {
		res += " user=" + c.User
	}
	if c.Password != "" {
		res += " password=" + c.Password
	}
	return res
}

func (c ConnSpec) Open() (DB, error) {
	dbh, err := sql.Open("postgres", c.ConnectionString())
	if err != nil {
		return DB{}, ectx.Err("connect db="+c.Database, err)
	}
	return DB{dbh}, nil
}

func OpenDBUser(db, user, password string) (DB, error) {
	return ConnSpec{Database: db, User: user, Password: password}.Open()
}

type PgError struct {
	Context string
	Cause   error
}

func (p PgError) Error() string {
	return p.Context + ": " + p.Cause.Error()
}

func ctx(context string, err error) error {
	return PgError{Context: context, Cause: err}
}

{'fraction_non_alphanumeric': 0.15308419630796938, 'fraction_numerical': 0.0, 'mean_word_length': 3.5626283367556466, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2901842', 'n_tokens_mistral': 851, 'n_tokens_neox': 818, 'n_words': 232}