aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--internal/storage/db.go14
-rw-r--r--internal/storage/db_test.go2
2 files changed, 10 insertions, 6 deletions
diff --git a/internal/storage/db.go b/internal/storage/db.go
index 26d3b3b..02683b4 100644
--- a/internal/storage/db.go
+++ b/internal/storage/db.go
@@ -10,18 +10,22 @@ import (
)
var (
- ErrInvalidConnectionString = errors.New("invalid database connection parameters provided")
- ErrUnableToConnect = errors.New("unable to open connection to database")
+ ErrMalformedConnectionString = errors.New("malformed database connection parameters provided")
+ ErrUnableToConnect = errors.New("unable to open connection to database")
)
// DBConnect establishes a connection to the database using the driver
-// and connection information.
+// and connection information. Only "postgres" is supported as the driver.
//
-// Note that only "postgres" is supported as the driver right now.
+// The following errors may be returned:
+// - ErrMalformedConnectionString: The provided connection parameters are
+// not in a valid format.
+// - ErrUnableToConnect: Unable to make a connection to the database with
+// the provided connection parameters.
func DBConnect(driver string, connectionParams string) (*sql.DB, error) {
db, err := sql.Open(driver, connectionParams)
if err != nil {
- return nil, fmt.Errorf("%w: %v", ErrInvalidConnectionString, err)
+ return nil, fmt.Errorf("%w: %v", ErrMalformedConnectionString, err)
}
// Note: `sql.Open` only validates the connection string we provided is sane.
diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go
index c871c47..e85cc57 100644
--- a/internal/storage/db_test.go
+++ b/internal/storage/db_test.go
@@ -31,7 +31,7 @@ func TestDBConnect_UnsupportedDriver(t *testing.T) {
cfg := bolttest.NewTestConnectionConfig(t, "redis")
_, err := storage.DBConnect(cfg.Driver, storage.DBConnectionString(cfg))
- assert.ErrorIs(t, err, storage.ErrInvalidConnectionString)
+ assert.ErrorIs(t, err, storage.ErrMalformedConnectionString)
assert.ErrorContains(t, err, `unknown driver "redis"`)
}