🎨 精简完善系统
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/config"
|
||||
"github.com/gookit/color"
|
||||
@@ -19,6 +20,10 @@ import (
|
||||
|
||||
type PgsqlInitHandler struct{}
|
||||
|
||||
func quotePgIdentifier(name string) string {
|
||||
return `"` + strings.ReplaceAll(name, `"`, `""`) + `"`
|
||||
}
|
||||
|
||||
func NewPgsqlInitHandler() *PgsqlInitHandler {
|
||||
return &PgsqlInitHandler{}
|
||||
}
|
||||
@@ -55,9 +60,13 @@ func (h PgsqlInitHandler) EnsureDB(ctx context.Context, conf *request.InitDB) (n
|
||||
dsn := conf.PgsqlEmptyDsn()
|
||||
var createSql string
|
||||
if conf.Template != "" {
|
||||
createSql = fmt.Sprintf("CREATE DATABASE %s WITH TEMPLATE %s;", c.Dbname, conf.Template)
|
||||
createSql = fmt.Sprintf(
|
||||
"CREATE DATABASE %s WITH TEMPLATE %s;",
|
||||
quotePgIdentifier(c.Dbname),
|
||||
quotePgIdentifier(conf.Template),
|
||||
)
|
||||
} else {
|
||||
createSql = fmt.Sprintf("CREATE DATABASE %s;", c.Dbname)
|
||||
createSql = fmt.Sprintf("CREATE DATABASE %s;", quotePgIdentifier(c.Dbname))
|
||||
}
|
||||
if err = createDatabase(dsn, "pgx", createSql); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user