Review fixes

This commit is contained in:
vetcher 2021-09-01 14:38:45 +03:00 committed by go-jet
parent 5b7c34e333
commit b31464e491
2 changed files with 21 additions and 14 deletions

View file

@ -3,6 +3,7 @@ package mysql
import (
"database/sql"
"fmt"
"strings"
"github.com/go-jet/jet/v2/generator/metadata"
"github.com/go-jet/jet/v2/generator/template"
@ -44,6 +45,14 @@ func Generate(destDir string, dbConn DBConnection, generatorTemplate ...template
func GenerateDSN(dsn, destDir string, templates ...template.Template) (err error) {
defer utils.ErrorCatch(&err)
// Special case for go mysql driver. It does not understand schema,
// so we need to trim it before passing to generator
// https://github.com/go-sql-driver/mysql#dsn-data-source-name
idx := strings.Index(dsn, "://")
if idx != -1 {
dsn = dsn[idx+len("://"):]
}
cfg, err := mysqldr.ParseDSN(dsn)
throw.OnError(err)
if cfg.DBName == "" {