30 lines
574 B
Go
30 lines
574 B
Go
package migrate
|
|
|
|
import (
|
|
"database/sql"
|
|
"reflect"
|
|
"strings"
|
|
)
|
|
|
|
func getPkgName(db *sql.DB) string {
|
|
t := reflect.TypeOf(db.Driver())
|
|
if t.Kind() == reflect.Ptr {
|
|
t = t.Elem()
|
|
}
|
|
path := t.PkgPath()
|
|
parts := strings.Split(path, `/vendor/`)
|
|
return parts[len(parts)-1]
|
|
}
|
|
|
|
func getDbType(db *sql.DB) string {
|
|
switch getPkgName(db) {
|
|
case `github.com/lib/pq`, `github.com/jackc/pgx/stdlib`:
|
|
return `pq`
|
|
case `github.com/go-sql-driver/mysql`, `github.com/ziutek/mymysql/godrv`:
|
|
return `my`
|
|
case `github.com/denisenkom/go-mssqldb`:
|
|
return `ms`
|
|
}
|
|
return ``
|
|
}
|