diff --git a/core.go b/core.go index 3b27651..6eb3fc3 100644 --- a/core.go +++ b/core.go @@ -23,6 +23,7 @@ type Namespace struct{} type generateOption struct { goFileName string defaultStructName string + sqlxPkgName string } type option interface { @@ -197,3 +198,9 @@ func GoFileNameOpt(name string) OptionFunc { opt.goFileName = name } } + +func SqlxPkgName(name string) OptionFunc { + return func(opt *generateOption) { + opt.sqlxPkgName = name + } +} diff --git a/generator.go b/generator.go index b1dc205..99aaf9a 100644 --- a/generator.go +++ b/generator.go @@ -12,12 +12,17 @@ import ( "github.com/jmoiron/sqlx" ) +const ( + _defaultSqlxPkgName = "github.com/jmoiron/sqlx" +) + var ( _ Generator = (*sqlGenerator)(nil) ) type tmplCtx struct { PkgName string + SqlxPkgName string DefaultStructName string AllQuery []*Query DefaultQueryMap QueryMap @@ -77,12 +82,14 @@ func (s *sqlGenerator) Generate(dstPath string, pkgName string, query SQLQuery, opt := &generateOption{ goFileName: "yesql.go", defaultStructName: "Yesql", + sqlxPkgName: _defaultSqlxPkgName, } for _, arg := range opts { arg.apply(opt) } data := &tmplCtx{ PkgName: pkgName, + SqlxPkgName: opt.sqlxPkgName, DefaultStructName: naming.Naming(opt.defaultStructName), AllQuery: query.AllQuery(), ScopeQuery: query.ListScope(), diff --git a/template/sqlx.tmpl b/template/sqlx.tmpl index 38930e9..7bea0b6 100644 --- a/template/sqlx.tmpl +++ b/template/sqlx.tmpl @@ -8,7 +8,7 @@ import ( "context" "github.com/alimy/yesql" - "github.com/jmoiron/sqlx" + "{{ .SqlxPkgName }}" ) const ( diff --git a/version.go b/version.go index 3b46fc2..4f2824d 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package yesql -var Version = "v1.5.0" +var Version = "v1.6.0"