Add strict flag (#2248)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
@@ -102,8 +102,8 @@ func newDefaultOption() Option {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *defaultGenerator) StartFromDDL(filename string, withCache bool, database string) error {
|
||||
modelList, err := g.genFromDDL(filename, withCache, database)
|
||||
func (g *defaultGenerator) StartFromDDL(filename string, withCache, strict bool, database string) error {
|
||||
modelList, err := g.genFromDDL(filename, withCache, strict, database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -111,10 +111,10 @@ func (g *defaultGenerator) StartFromDDL(filename string, withCache bool, databas
|
||||
return g.createFile(modelList)
|
||||
}
|
||||
|
||||
func (g *defaultGenerator) StartFromInformationSchema(tables map[string]*model.Table, withCache bool) error {
|
||||
func (g *defaultGenerator) StartFromInformationSchema(tables map[string]*model.Table, withCache, strict bool) error {
|
||||
m := make(map[string]*codeTuple)
|
||||
for _, each := range tables {
|
||||
table, err := parser.ConvertDataType(each)
|
||||
table, err := parser.ConvertDataType(each, strict)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -201,11 +201,11 @@ func (g *defaultGenerator) createFile(modelList map[string]*codeTuple) error {
|
||||
}
|
||||
|
||||
// ret1: key-table name,value-code
|
||||
func (g *defaultGenerator) genFromDDL(filename string, withCache bool, database string) (
|
||||
func (g *defaultGenerator) genFromDDL(filename string, withCache, strict bool, database string) (
|
||||
map[string]*codeTuple, error,
|
||||
) {
|
||||
m := make(map[string]*codeTuple)
|
||||
tables, err := parser.Parse(filename, database)
|
||||
tables, err := parser.Parse(filename, database, strict)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/config"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/model/sql/builderx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/model/sql/parser"
|
||||
@@ -40,7 +41,7 @@ func TestCacheModel(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = g.StartFromDDL(sqlFile, true, "go_zero")
|
||||
err = g.StartFromDDL(sqlFile, true, false, "go_zero")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, func() bool {
|
||||
_, err := os.Stat(filepath.Join(cacheDir, "TestUserModel.go"))
|
||||
@@ -51,7 +52,7 @@ func TestCacheModel(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = g.StartFromDDL(sqlFile, false, "go_zero")
|
||||
err = g.StartFromDDL(sqlFile, false, false, "go_zero")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, func() bool {
|
||||
_, err := os.Stat(filepath.Join(noCacheDir, "testusermodel.go"))
|
||||
@@ -78,7 +79,7 @@ func TestNamingModel(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = g.StartFromDDL(sqlFile, true, "go_zero")
|
||||
err = g.StartFromDDL(sqlFile, true, false, "go_zero")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, func() bool {
|
||||
_, err := os.Stat(filepath.Join(camelDir, "TestUserModel.go"))
|
||||
@@ -89,7 +90,7 @@ func TestNamingModel(t *testing.T) {
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = g.StartFromDDL(sqlFile, true, "go_zero")
|
||||
err = g.StartFromDDL(sqlFile, true, false, "go_zero")
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, func() bool {
|
||||
_, err := os.Stat(filepath.Join(snakeDir, "test_user_model.go"))
|
||||
@@ -186,7 +187,7 @@ func Test_genPublicModel(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
tables, err := parser.Parse(modelFilename, "")
|
||||
tables, err := parser.Parse(modelFilename, "", false)
|
||||
require.Equal(t, 1, len(tables))
|
||||
|
||||
code, err := g.genModelCustom(*tables[0], false)
|
||||
|
||||
Reference in New Issue
Block a user