Improve database to golang name mapping.

This commit is contained in:
go-jet 2019-07-03 16:27:14 +02:00
parent 3e7277015d
commit 950663dadb
19 changed files with 538 additions and 122 deletions

View file

@ -3,7 +3,7 @@ package postgres_metadata
import (
"database/sql"
"fmt"
"github.com/serenize/snaker"
"github.com/go-jet/jet/internal/util"
"strings"
)
@ -44,7 +44,7 @@ func (c ColumnInfo) SqlBuilderColumnType() string {
func (c ColumnInfo) GoBaseType() string {
switch c.DataType {
case "USER-DEFINED":
return snaker.SnakeToCamel(c.EnumName)
return util.ToGoIdentifier(c.EnumName)
case "boolean":
return "bool"
case "smallint":

View file

@ -2,7 +2,7 @@ package postgres_metadata
import (
"database/sql"
"github.com/serenize/snaker"
"github.com/go-jet/jet/internal/util"
)
type TableInfo struct {
@ -58,7 +58,7 @@ func (t TableInfo) GetImports() []string {
}
func (t TableInfo) GoStructName() string {
return snaker.SnakeToCamel(t.name) + "Table"
return util.ToGoIdentifier(t.name) + "Table"
}
func GetTableInfo(db *sql.DB, dbName, schemaName, tableName string) (tableInfo TableInfo, err error) {

View file

@ -2,11 +2,10 @@ package utils
import (
"bytes"
"github.com/serenize/snaker"
"github.com/go-jet/jet/internal/util"
"go/format"
"os"
"path/filepath"
"strings"
"text/template"
"time"
)
@ -51,9 +50,7 @@ func EnsureDirPath(dirPath string) error {
func GenerateTemplate(templateText string, templateData interface{}) ([]byte, error) {
t, err := template.New("sqlBuilderTableTemplate").Funcs(template.FuncMap{
"camelize": func(txt string) string {
return snaker.SnakeToCamel(strings.Replace(txt, "-", "_", -1))
},
"ToGoIdentifier": util.ToGoIdentifier,
"now": func() string {
return time.Now().Format(time.RFC850)
},