A golang library for updating your database schema
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
574 B

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 ``
}