Skip to content

Commit d4a4dc3

Browse files
committed
docs: Improve OpenDBWithDriver comments
1 parent 8712ba6 commit d4a4dc3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

db.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@ import (
55
"fmt"
66
)
77

8-
// OpenDBWithDriver creates a connection to a database, and modifies goose
9-
// internals to be compatible with the supplied driver by calling SetDialect.
8+
// OpenDBWithDriver creates a connection to a database, and modifies goose internals to be
9+
// compatible with the supplied driver by calling SetDialect.
1010
func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
1111
if err := SetDialect(driver); err != nil {
1212
return nil, err
1313
}
1414

15-
// To avoid breaking existing consumers. An implementation detail
16-
// that consumers should not care which underlying driver is used.
15+
// The Go ecosystem has added more and more drivers over the years. As a result, there's no
16+
// longer a one-to-one match between the driver name and the dialect name. For instance, there's
17+
// no "redshift" driver, but that's the internal dialect name within goose. Hence, we need to
18+
// convert the dialect name to a supported driver name. This conversion is a best-effort
19+
// attempt, as we can't support both lib/pq and pgx, which some users might have.
20+
//
21+
// We recommend users to create a [NewProvider] with the desired dialect, open a connection
22+
// using their preferred driver, and provide the *sql.DB to goose. This approach removes the
23+
// need for mapping dialects to drivers, rendering this function unnecessary.
24+
1725
switch driver {
1826
case "mssql":
1927
driver = "sqlserver"
@@ -22,7 +30,6 @@ func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
2230
case "turso":
2331
driver = "libsql"
2432
case "sqlite3":
25-
// Internally uses the CGo-free port of SQLite: modernc.org/sqlite
2633
driver = "sqlite"
2734
case "postgres", "redshift":
2835
driver = "pgx"

0 commit comments

Comments
 (0)