mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
replace db driver package and driver name for postgres
This commit is contained in:
parent
ab24b84d15
commit
4dc2d67bd2
13
apiapp.go
13
apiapp.go
@ -89,11 +89,11 @@ import (
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
{{.DriverPkg}}
|
||||
)
|
||||
|
||||
func init() {
|
||||
orm.RegisterDataBase("default", "mysql", "{{.conn}}")
|
||||
orm.RegisterDataBase("default", "{{.DriverName}}", "{{.conn}}")
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -574,9 +574,16 @@ func createapi(cmd *Command, args []string) int {
|
||||
|
||||
if conn != "" {
|
||||
fmt.Println("create main.go:", path.Join(apppath, "main.go"))
|
||||
maingoContent := strings.Replace(apiMainconngo, "{{.Appname}}", packpath, -1)
|
||||
maingoContent = strings.Replace(maingoContent, "{{.DriverName}}", string(driver), -1)
|
||||
if driver == "mysql" {
|
||||
maingoContent = strings.Replace(maingoContent, "{{.DriverPkg}}", `_ "github.com/go-sql-driver/mysql"`, -1)
|
||||
} else if driver == "postgres" {
|
||||
maingoContent = strings.Replace(maingoContent, "{{.DriverPkg}}", `_ "github.com/lib/pq"`, -1)
|
||||
}
|
||||
writetofile(path.Join(apppath, "main.go"),
|
||||
strings.Replace(
|
||||
strings.Replace(apiMainconngo, "{{.Appname}}", packpath, -1),
|
||||
maingoContent,
|
||||
"{{.conn}}",
|
||||
conn.String(),
|
||||
-1,
|
||||
|
Loading…
Reference in New Issue
Block a user