mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-12-24 10:40:55 +08:00
fix: sql or protobuf name cannot use the suffix _test
This commit is contained in:
@@ -203,6 +203,7 @@ func TestGetPostgresqlTableInfo(t *testing.T) {
|
||||
t.Log(err)
|
||||
return
|
||||
}
|
||||
printPGFields(fields)
|
||||
sql, fieldTypes := ConvertToSQLByPgFields("user_example", fields)
|
||||
t.Log(sql, fieldTypes)
|
||||
}
|
||||
@@ -259,6 +260,13 @@ func printCode(code map[string]string) {
|
||||
}
|
||||
}
|
||||
|
||||
func printPGFields(fields []*PGField) {
|
||||
fmt.Printf("%-20v %-20v %-20v %-20v %-20v %-20v\n", "Name", "Type", "Length", "Lengthvar", "Notnull", "Comment")
|
||||
for _, p := range fields {
|
||||
fmt.Printf("%-20v %-20v %-20v %-20v %-20v %-20v\n", p.Name, p.Type, p.Length, p.Lengthvar, p.Notnull, p.Comment)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getMongodbTableFields(t *testing.T) {
|
||||
fields := []*MgoField{
|
||||
{
|
||||
|
||||
@@ -130,10 +130,3 @@ func closeDB(db *gorm.DB) {
|
||||
}
|
||||
_ = sqlDB.Close()
|
||||
}
|
||||
|
||||
func printString(fields []*PGField) {
|
||||
fmt.Printf("%-20v %-20v %-20v %-20v %-20v %-20v\n", "Name", "Type", "Length", "Lengthvar", "Notnull", "Comment")
|
||||
for _, p := range fields {
|
||||
fmt.Printf("%-20v %-20v %-20v %-20v %-20v %-20v\n", p.Name, p.Type, p.Length, p.Lengthvar, p.Notnull, p.Comment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,15 @@ func (a *Args) checkValid() error {
|
||||
if a.SQL == "" && a.DDLFile == "" && (a.DBDsn == "" && a.DBTable == "") {
|
||||
return errors.New("you must specify sql or ddl file")
|
||||
}
|
||||
if a.DBTable != "" {
|
||||
tables := strings.Split(a.DBTable, ",")
|
||||
for _, name := range tables {
|
||||
if strings.HasSuffix(name, "_test") {
|
||||
return fmt.Errorf(`the table name (%s) suffix "_test" is not supported for code generation, please delete suffix "_test" or change it to another name. `, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if a.DBDriver == "" {
|
||||
a.DBDriver = parser.DBDriverMysql
|
||||
} else if a.DBDriver == parser.DBDriverSqlite {
|
||||
|
||||
Reference in New Issue
Block a user