1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал CreateFilesUpdateEveryColumn()

This commit is contained in:
Nikitin Aleksandr 2024-02-15 15:15:16 +03:00
parent e4e84ce1f7
commit b37b6bac7c
9 changed files with 62 additions and 29 deletions

View File

@ -10,7 +10,7 @@ import (
)
// LawsuitStatusType_ID_Test - ID таблицы для тестирования
const LawsuitStatusType_ID_Test = 1
const LawsuitStatusType_ID_Test = 0
func Test_server_LawsuitStatusType_Read(t *testing.T) {
config_main.LoadEnv()

View File

@ -7,7 +7,7 @@ import (
"testing"
)
const Postgres_ID_Test = 1
const Postgres_ID_Test = 0
func TestRead(t *testing.T) {
config_main.LoadEnv()
@ -23,8 +23,8 @@ func TestRead(t *testing.T) {
t.Error("TestRead() error: ", err)
}
if Otvet.ID == 0 {
t.Error(TableName + "_test.TestRead() error ID=0 ")
if Otvet.ID != Postgres_ID_Test {
t.Error(TableName + "_test.TestRead() error ID != ", Postgres_ID_Test)
} else {
t.Log(TableName+"_test.TestRead() Otvet: ", Otvet.ID)
}
@ -44,8 +44,8 @@ func TestSave(t *testing.T) {
t.Error("TestSave() error: ", err)
}
if Otvet.ID == 0 {
t.Error(TableName + "_test.TestSave() error ID=0 ")
if Otvet.ID != Postgres_ID_Test {
t.Error(TableName + "_test.TestSave() error ID != ", Postgres_ID_Test)
}
err = crud.Save(&Otvet)
@ -117,7 +117,7 @@ func TestFind_ByExtID(t *testing.T) {
t.Error("TestFind_ByExtID() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestFind_ByExtID() error: ID =0")
if Otvet.ID != Postgres_ID_Test {
t.Error("TestFind_ByExtID() error: ID != ", Postgres_ID_Test)
}
}

View File

@ -7,7 +7,7 @@ import (
"testing"
)
const Postgres_ID_Test = 1
const Postgres_ID_Test = 0
func TestRead(t *testing.T) {
config_main.LoadEnv()
@ -23,8 +23,8 @@ func TestRead(t *testing.T) {
t.Error("TestRead() error: ", err)
}
if Otvet.ID == 0 {
t.Error(TableName + "_test.TestRead() error ID=0 ")
if Otvet.ID != Postgres_ID_Test {
t.Error(TableName + "_test.TestRead() error ID != ", Postgres_ID_Test)
} else {
t.Log(TableName+"_test.TestRead() Otvet: ", Otvet.ID)
}
@ -44,8 +44,8 @@ func TestSave(t *testing.T) {
t.Error("TestSave() error: ", err)
}
if Otvet.ID == 0 {
t.Error(TableName + "_test.TestSave() error ID=0 ")
if Otvet.ID != Postgres_ID_Test {
t.Error(TableName + "_test.TestSave() error ID != ", Postgres_ID_Test)
}
err = crud.Save(&Otvet)
@ -94,8 +94,8 @@ func TestFind_ByExtID(t *testing.T) {
t.Error("TestFind_ByExtID() error: ", err)
}
if Otvet.ID == 0 {
t.Error("TestFind_ByExtID() error: ID =0")
if Otvet.ID != Postgres_ID_Test {
t.Error("TestFind_ByExtID() error: ID != ", Postgres_ID_Test)
}
}

View File

@ -8,7 +8,7 @@ import (
)
// Postgres_ID_Test - ID таблицы для тестирования
const Postgres_ID_Test = 1
const Postgres_ID_Test = 0
func TestGetVersionModel(t *testing.T) {

View File

@ -1224,11 +1224,36 @@ func FindTextEqualEmpty(Column1 *types.Column, VariableName string) string {
Otvet := ""
DefaultValue := FindTextDefaultValue(Column1.TypeGo)
Otvet = VariableName + "." + Column1.NameGo + " == " + DefaultValue
Otvet = VariableName + " == " + DefaultValue
if DefaultValue == "time.Time{}" {
Otvet = VariableName + "." + Column1.NameGo + ".IsZero() == true"
Otvet = VariableName + ".IsZero() == true"
}
return Otvet
}
//// AddSkipNowEveryFunc - добавляет функцию SkipNow() для каждой тестовой функции
//func AddSkipNowEveryFunc(Text string) string {
// Otvet := ""
//
// sFind := "\nfunc "
// Mass := make([]string, 0)
// Mass = strings.Split(Text, sFind)
// for _, v := range Mass {
// pos1 := strings.Index(v, sFind)
// if pos1 < 0 {
// continue
// }
//
// s2 := Text[pos1:]
// pos2 := strings.Index(s2, "\n")
// if pos2 < 0 {
// continue
// }
// v = v[:pos1+pos2] + "\n\tt.SkipNow() //нет строк в БД \n" + v[pos1+pos2:]
// Otvet = Otvet + v
// }
//
// return Otvet
//}

View File

@ -4,6 +4,7 @@ import (
"github.com/ManyakRus/crud_generator/internal/types"
"github.com/ManyakRus/crud_generator/pkg/dbmeta"
"github.com/ManyakRus/starter/log"
"strings"
)
// Has_Column_ExtID_ConnectionID - возвращает true если есть поля ExtId и ConnectionID
@ -316,11 +317,15 @@ func Is_Common_Сolumn(Column1 *types.Column) bool {
return Otvet
}
// Is_NotNeedUpdate_Сolumn - возвращает true если это общая колонка: table_name_id, table_row_id, is_group, parent_id, ext_id, created_at, modified_at, deleted_at, id
// Is_NotNeedUpdate_Сolumn - возвращает true если не нужна функция UpdateColumnNAme(), например если это общая колонка: table_name_id, table_row_id, is_group, parent_id, ext_id, created_at, modified_at, deleted_at, id
func Is_NotNeedUpdate_Сolumn(Column1 *types.Column) bool {
Otvet := false
Otvet = Is_Column_CommonStruct(Column1) || Is_Column_GroupsStruct(Column1) || Is_Column_ExtLinksStruct(Column1)
if strings.HasPrefix(Column1.Name, "DELETED_") == true {
Otvet = true
}
return Otvet
}

View File

@ -208,13 +208,13 @@ func CreateTestFiles(Table1 *types.Table) error {
//Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" {
TextFind := "const Postgres_ID_Test = "
TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum)
TextDB = strings.ReplaceAll(TextDB, TextFind+"0", TextFind+Table1.IDMinimum)
}
//SkipNow()
//SkipNow() если нет строк в БД
TextDB = create_files.AddSkipNow(TextDB, Table1)
// замена ID на PrimaryKey
//замена ID на PrimaryKey
TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1)
//замена импортов на новые URL
@ -588,10 +588,10 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table,
//Otvet = strings.ReplaceAll(Otvet, "m.ID", "m."+ColumnName)
//внешние ключи заменяем 0 на null
if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time{}") {
Otvet = strings.ReplaceAll(Otvet, "0==1", "1==1")
TextEqualEmpty := create_files.FindTextEqualEmpty(Column1, "Value")
Otvet = strings.ReplaceAll(Otvet, "Value == 0", TextEqualEmpty)
TextEqualEmpty := create_files.FindTextEqualEmpty(Column1, "Value")
Otvet = strings.ReplaceAll(Otvet, "Value == 0", TextEqualEmpty)
if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") {
Otvet = strings.ReplaceAll(Otvet, "0==1 && ", "")
}
return Otvet
@ -637,7 +637,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
ModelTableURL := create_files.FindModelTableURL(TableName)
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
//TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
//}
//создание текста
@ -653,6 +653,9 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud
//SkipNow() если нет строк в БД
TextCrud = create_files.AddSkipNow(TextCrud, Table1)
//удаление пустого импорта
TextCrud = create_files.DeleteEmptyImport(TextCrud)
TextCrud = create_files.DeleteEmptyLines(TextCrud)

View File

@ -216,7 +216,7 @@ func CreateTestFiles(Table1 *types.Table) error {
//Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" {
TextFind := "const Postgres_ID_Test = "
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"1", TextFind+Table1.IDMinimum)
TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"0", TextFind+Table1.IDMinimum)
}
// замена ID на PrimaryKey

View File

@ -195,7 +195,7 @@ func CreateTestFiles(Table1 *types.Table) error {
//Postgres_ID_Test = ID Minimum
if Table1.IDMinimum != "" {
TextFind := "const " + ModelName + "_ID_Test = "
TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"1", TextFind+Table1.IDMinimum)
TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"0", TextFind+Table1.IDMinimum)
}
// замена ID на PrimaryKey