What's the best way to convert the type sqlx.DB (jmoiron/sqlx) to sql.DB (database/sql)?
I'm currently using the package github.com/golang-migrate/migrate and it requires an existing connection to follow sql.DB interface.
func Migrate(db *sqlx.DB) error {
driver, err := postgres.WithInstance(db, &postgres.Config{})
m, err := migrate.NewWithDatabaseInstance(
"file://src/db/migrations",
"postgres", driver)
if err != nil {
return err
}
return m.Up()
}
Update: I mixed the description and added more details. The title was correct.