mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-27 08:40:53 +02:00
сделал PrimaryKeyColumnsCount
This commit is contained in:
parent
038878ad31
commit
709d8a9d7b
@ -287,7 +287,7 @@ func IsGoodTable(Table1 *types.Table) error {
|
||||
// err = errors.New(TextError)
|
||||
//}
|
||||
|
||||
err = IsGoodTablePrefix(Table1)
|
||||
err = IsGoodTableNamePrefix(Table1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -312,8 +312,8 @@ func IsGoodPrimaryKeyColumnsCount(Table1 *types.Table) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// IsGoodTablePrefix - возвращает ошибку если префикс таблицы = "DELETED_"
|
||||
func IsGoodTablePrefix(Table1 *types.Table) error {
|
||||
// IsGoodTableNamePrefix - возвращает ошибку если префикс таблицы = "DELETED_"
|
||||
func IsGoodTableNamePrefix(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
TableName := Table1.Name
|
||||
@ -1778,16 +1778,18 @@ func Replace_Postgres_ID_Test(Text string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
TextFind := "const Postgres_ID_Test = 0"
|
||||
ColumnPrimary := FindPrimaryKeyColumn(Table1)
|
||||
if ColumnPrimary == nil {
|
||||
PrimaryKeyColumn := FindPrimaryKeyColumn(Table1)
|
||||
if PrimaryKeyColumn == nil {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
IDMinimum := Table1.IDMinimum
|
||||
if IDMinimum == "" {
|
||||
IDMinimum = FindTextDefaultValue(PrimaryKeyColumn.TypeGo)
|
||||
}
|
||||
|
||||
if ColumnPrimary.TypeGo == "uuid.UUID" {
|
||||
if PrimaryKeyColumn.TypeGo == "uuid.UUID" {
|
||||
if Table1.IDMinimum == "" {
|
||||
IDMinimum = FindTextDefaultValue(ColumnPrimary.TypeGo)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test = `+IDMinimum+``)
|
||||
} else {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`)
|
||||
@ -1812,15 +1814,18 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string {
|
||||
}
|
||||
|
||||
IDMinimum := Table1.IDMinimum
|
||||
if IDMinimum == "" {
|
||||
IDMinimum = FindTextDefaultValue(PrimaryKeyColumn.TypeGo)
|
||||
}
|
||||
|
||||
if PrimaryKeyColumn.TypeGo == "uuid.UUID" {
|
||||
if Table1.IDMinimum == "" {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = ""`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum+``)
|
||||
} else {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = "`+IDMinimum+`"`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`)
|
||||
}
|
||||
} else {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = `+IDMinimum)
|
||||
}
|
||||
|
||||
return Otvet
|
||||
|
@ -19,17 +19,25 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
//для каждой таблицы
|
||||
for _, table1 := range MapAll {
|
||||
err = CreateFiles(table1)
|
||||
for _, Table1 := range MapAll {
|
||||
//проверка имени таблицы "DELETED_"
|
||||
err1 := create_files.IsGoodTableNamePrefix(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err)
|
||||
continue
|
||||
}
|
||||
|
||||
//создание файлов
|
||||
err = CreateFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", table1.Name, " error: ", err)
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if config.Settings.NEED_CREATE_UPDATE_EVERY_COLUMN == true {
|
||||
err = CreateFilesUpdateEveryColumn(table1)
|
||||
err = CreateFilesUpdateEveryColumn(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", table1.Name, " error: ", err)
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -18,10 +18,18 @@ import (
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, table1 := range MapAll {
|
||||
err = CreateFiles(table1)
|
||||
for _, Table1 := range MapAll {
|
||||
//проверка имени таблицы "DELETED_"
|
||||
err1 := create_files.IsGoodTableNamePrefix(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err)
|
||||
continue
|
||||
}
|
||||
|
||||
//
|
||||
err = CreateFiles(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", table1.Name, " error: ", err)
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -278,6 +278,7 @@ order by
|
||||
OrderNumberTable++
|
||||
}
|
||||
|
||||
//новая таблица
|
||||
//найдём имя модели golang
|
||||
TableName := v.TableName
|
||||
ModelName := create_files.FindSingularName(TableName)
|
||||
@ -287,6 +288,7 @@ order by
|
||||
TableComment := v.TableComment
|
||||
TableComment = strings.ReplaceAll(TableComment, "\n", "")
|
||||
TableComment = strings.ReplaceAll(TableComment, "\r", "")
|
||||
|
||||
Table1 = CreateTable()
|
||||
Table1.Name = TableName
|
||||
Table1.OrderNumber = OrderNumberTable
|
||||
@ -333,9 +335,10 @@ order by
|
||||
TableName0 = v.TableName
|
||||
}
|
||||
|
||||
//
|
||||
//последнюю таблицу заполним тут
|
||||
if Table1.Name != "" {
|
||||
Table1.MapColumns = MapColumns
|
||||
Table1.PrimaryKeyColumnsCount = PrimaryKeyColumnsCount
|
||||
MapTable[TableName0] = Table1
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user