mirror of
https://github.com/pressly/goose.git
synced 2025-05-31 11:42:04 +00:00
docs: Improve OpenDBWithDriver comments
This commit is contained in:
parent
8712ba69e6
commit
d4a4dc3aa1
17
db.go
17
db.go
@ -5,15 +5,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OpenDBWithDriver creates a connection to a database, and modifies goose
|
// OpenDBWithDriver creates a connection to a database, and modifies goose internals to be
|
||||||
// internals to be compatible with the supplied driver by calling SetDialect.
|
// compatible with the supplied driver by calling SetDialect.
|
||||||
func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
|
func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
|
||||||
if err := SetDialect(driver); err != nil {
|
if err := SetDialect(driver); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// To avoid breaking existing consumers. An implementation detail
|
// The Go ecosystem has added more and more drivers over the years. As a result, there's no
|
||||||
// that consumers should not care which underlying driver is used.
|
// longer a one-to-one match between the driver name and the dialect name. For instance, there's
|
||||||
|
// no "redshift" driver, but that's the internal dialect name within goose. Hence, we need to
|
||||||
|
// convert the dialect name to a supported driver name. This conversion is a best-effort
|
||||||
|
// attempt, as we can't support both lib/pq and pgx, which some users might have.
|
||||||
|
//
|
||||||
|
// We recommend users to create a [NewProvider] with the desired dialect, open a connection
|
||||||
|
// using their preferred driver, and provide the *sql.DB to goose. This approach removes the
|
||||||
|
// need for mapping dialects to drivers, rendering this function unnecessary.
|
||||||
|
|
||||||
switch driver {
|
switch driver {
|
||||||
case "mssql":
|
case "mssql":
|
||||||
driver = "sqlserver"
|
driver = "sqlserver"
|
||||||
@ -22,7 +30,6 @@ func OpenDBWithDriver(driver string, dbstring string) (*sql.DB, error) {
|
|||||||
case "turso":
|
case "turso":
|
||||||
driver = "libsql"
|
driver = "libsql"
|
||||||
case "sqlite3":
|
case "sqlite3":
|
||||||
// Internally uses the CGo-free port of SQLite: modernc.org/sqlite
|
|
||||||
driver = "sqlite"
|
driver = "sqlite"
|
||||||
case "postgres", "redshift":
|
case "postgres", "redshift":
|
||||||
driver = "pgx"
|
driver = "pgx"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user