mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-24 08:22:42 +02:00
сделал Replace_Postgres_ID_Test_ManyPK()
This commit is contained in:
parent
f68324aa06
commit
5e5f74be0d
@ -109,6 +109,12 @@ TEMPLATE_EXTERNAL_PROTO_FILENAME=/home/user/GolandProjects/!sanek/sync_service/a
|
||||
|
||||
#---------------------Create files settings---------------------
|
||||
|
||||
#NEED_CREATE_MODEL_STRUCT - fill "true" if you want create model files with golang struct with all database fields
|
||||
NEED_CREATE_MODEL_STRUCT=true
|
||||
|
||||
#NEED_CREATE_MANUAL_FILES - fill "true" if you want create "_manual.go" files, intended for user manual changes
|
||||
NEED_CREATE_MANUAL_FILES=true
|
||||
|
||||
#NEED_CREATE_CRUD - fill "true" if you want create crud operations files
|
||||
NEED_CREATE_CRUD=true
|
||||
|
||||
@ -118,9 +124,6 @@ NEED_CREATE_GRPC=true
|
||||
#NEED_CREATE_NRPC - fill "true" if you want create nrpc operations files (need NATS message query server)
|
||||
NEED_CREATE_NRPC=true
|
||||
|
||||
#NEED_CREATE_MODEL_STRUCT - fill "true" if you want create model files with golang struct with all database fields
|
||||
NEED_CREATE_MODEL_STRUCT=true
|
||||
|
||||
#NEED_CREATE_MODEL_CRUD - fill "true" if you want create crud operations in model files
|
||||
NEED_CREATE_MODEL_CRUD=true
|
||||
|
||||
@ -145,9 +148,6 @@ NEED_CREATE_NRPC_SERVER_TEST=true
|
||||
#NEED_CREATE_NRPC_CLIENT_TEST - fill "true" if you want create NRPC client _test.go files
|
||||
NEED_CREATE_NRPC_CLIENT_TEST=true
|
||||
|
||||
#NEED_CREATE_MANUAL_FILES - fill "true" if you want create "_manual.go" files, intended for user manual changes
|
||||
NEED_CREATE_MANUAL_FILES=true
|
||||
|
||||
#PREFIX_SERVER_GRPC - filename prefix for grpc server files
|
||||
PREFIX_SERVER_GRPC="server_grpc_"
|
||||
|
||||
|
@ -16,12 +16,14 @@ func TestReadFromCache(t *testing.T) {
|
||||
defer postgres_gorm.CloseConnection()
|
||||
|
||||
//читаем из БД
|
||||
m1, err := Crud_DB{}.ReadFromCache(Postgres_ID_Test)
|
||||
m1 := lawsuit_status_types.LawsuitStatusType{}
|
||||
m1.ID = Postgres_ID_Test
|
||||
err = Crud_DB{}.Read(&m1)
|
||||
if err != nil {
|
||||
t.Errorf("TestReadFromCache() error:t %v", err)
|
||||
}
|
||||
|
||||
//читаем из БД
|
||||
//читаем из Кеша
|
||||
m2, err := Crud_DB{}.ReadFromCache(Postgres_ID_Test)
|
||||
if err != nil {
|
||||
t.Errorf("TestReadFromCache() error:t %v", err)
|
||||
|
@ -53,7 +53,6 @@ func TestSave(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("TestSave() error: ", err)
|
||||
}
|
||||
t.Log(TableName+"_test.TestSave() Otvet: ", Otvet.ID)
|
||||
|
||||
}
|
||||
|
||||
|
@ -1947,7 +1947,8 @@ func Replace_Postgres_ID_Test(Text string, Table1 *types.Table) string {
|
||||
Otvet = Replace_Postgres_ID_Test1(Otvet, Table1, PrimaryKeyColumn)
|
||||
TextFind := "Postgres_ID_Test"
|
||||
PrimaryKeyName := strings.ToUpper(PrimaryKeyColumn.NameGo)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `Postgres_`+PrimaryKeyName+`_Test`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, PrimaryKeyName+`_Test`)
|
||||
//Otvet = strings.ReplaceAll(Otvet, TextFind, `Postgres_`+PrimaryKeyName+`_Test`)
|
||||
} else {
|
||||
Otvet = Replace_Postgres_ID_Test_ManyPK(Otvet, Table1)
|
||||
}
|
||||
@ -1959,15 +1960,98 @@ func Replace_Postgres_ID_Test(Text string, Table1 *types.Table) string {
|
||||
func Replace_Postgres_ID_Test_ManyPK(Text string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
TextFind := "const Postgres_ID_Test = 0\n"
|
||||
|
||||
TextNew := ""
|
||||
MassPK := FindPrimaryKeyColumns(Table1)
|
||||
for _, PrimaryKeyColumn := range MassPK {
|
||||
TextNew = TextNew + Replace_Postgres_ID_Test1(TextFind, Table1, PrimaryKeyColumn)
|
||||
if len(MassPK) == 0 {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
//заменим const Postgres_ID_Test = 0
|
||||
TextFind := "const Postgres_ID_Test = 0\n"
|
||||
TextNew := ""
|
||||
for _, PrimaryKey1 := range MassPK {
|
||||
TextNew = TextNew + Replace_Postgres_ID_Test1(TextFind, Table1, PrimaryKey1)
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, TextNew)
|
||||
|
||||
//заменим Otvet.ID = Postgres_ID_Test
|
||||
TextFind = "\tOtvet.ID = Postgres_ID_Test\n"
|
||||
TextNew = ""
|
||||
for _, PrimaryKey1 := range MassPK {
|
||||
Text1 := FindTextIDMinimumVariable(PrimaryKey1, "Otvet."+PrimaryKey1.NameGo)
|
||||
TextNew = TextNew + "\t" + Text1 + "\n"
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, TextNew)
|
||||
|
||||
//заменим m.ID = Postgres_ID_Test
|
||||
TextFind = "\tm.ID = Postgres_ID_Test\n"
|
||||
TextNew = ""
|
||||
for _, PrimaryKey1 := range MassPK {
|
||||
Text1 := FindTextIDMinimumVariable(PrimaryKey1, "m."+PrimaryKey1.NameGo)
|
||||
TextNew = TextNew + "\t" + Text1 + "\n"
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, TextNew)
|
||||
|
||||
//заменим m1.ID = Postgres_ID_Test
|
||||
TextFind = "\tm1.ID = Postgres_ID_Test\n"
|
||||
TextNew = ""
|
||||
for _, PrimaryKey1 := range MassPK {
|
||||
Text1 := FindTextIDMinimumVariable(PrimaryKey1, "m1."+PrimaryKey1.NameGo)
|
||||
TextNew = TextNew + "\t" + Text1 + "\n"
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, TextNew)
|
||||
|
||||
//заменим ReadFromCache(Postgres_ID_Test)
|
||||
TextFind = "ReadFromCache(Postgres_ID_Test)"
|
||||
TextNew = "ReadFromCache("
|
||||
Comma := ""
|
||||
for _, PrimaryKey1 := range MassPK {
|
||||
Name := FindNameGoTest(PrimaryKey1)
|
||||
TextNew = TextNew + Comma + Name
|
||||
Comma = ", "
|
||||
}
|
||||
TextNew = TextNew + ")"
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, TextNew)
|
||||
|
||||
// //удалим лишний код
|
||||
// TextDelete := ` 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)
|
||||
// }
|
||||
//`
|
||||
// Otvet = strings.ReplaceAll(Otvet, TextDelete, "")
|
||||
|
||||
//заменим ненужные Otvet.ID на Otvet.Name
|
||||
PrimaryKey1 := MassPK[0]
|
||||
Otvet = strings.ReplaceAll(Otvet, " Otvet.ID ", " Otvet."+PrimaryKey1.NameGo+" ")
|
||||
Otvet = strings.ReplaceAll(Otvet, " Otvet.ID)", " Otvet."+PrimaryKey1.NameGo+")")
|
||||
Name := FindNameGoTest(PrimaryKey1)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Postgres_ID_Test", Name)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindNameGoTest - находит имя переменной для тестов
|
||||
func FindNameGoTest(Column1 *types.Column) string {
|
||||
Otvet := ""
|
||||
Otvet = strings.ToUpper(Column1.NameGo) + "_Test"
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextNameTest_ManyPK - находит текст "ID, ID" для тестов
|
||||
func FindTextNameTest_ManyPK(Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
MassPK := FindPrimaryKeyColumns(Table1)
|
||||
if len(MassPK) == 0 {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
for _, PrimaryKey1 := range MassPK {
|
||||
Otvet = Otvet + FindNameGoTest(PrimaryKey1) + ", "
|
||||
}
|
||||
Otvet = strings.TrimSuffix(Otvet, ", ")
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
@ -1981,24 +2065,72 @@ func Replace_Postgres_ID_Test1(Text string, Table1 *types.Table, PrimaryKeyColum
|
||||
IDMinimum = FindTextDefaultValue(PrimaryKeyColumn.TypeGo)
|
||||
}
|
||||
|
||||
PrimaryKeyName := strings.ToUpper(PrimaryKeyColumn.NameGo)
|
||||
|
||||
Name := FindNameGoTest(PrimaryKeyColumn)
|
||||
sIDMinimum := FindTextIDMinimum(PrimaryKeyColumn)
|
||||
switch PrimaryKeyColumn.TypeGo {
|
||||
case "uuid.UUID":
|
||||
{
|
||||
if PrimaryKeyColumn.IDMinimum == "" {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_`+PrimaryKeyName+`_Test = `+IDMinimum+``)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+Name+` = `+sIDMinimum)
|
||||
} else {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_`+PrimaryKeyName+`_Test, _ = uuid.Parse("`+IDMinimum+`")`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+Name+`, _ = `+sIDMinimum)
|
||||
}
|
||||
}
|
||||
case "string":
|
||||
{
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const Postgres_`+PrimaryKeyName+`_Test = "`+IDMinimum+`"`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+Name+` = `+sIDMinimum+``)
|
||||
}
|
||||
default:
|
||||
{
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const Postgres_`+PrimaryKeyName+`_Test = `+IDMinimum)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+Name+` = `+sIDMinimum)
|
||||
}
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextIDMinimumVariable - возвращает текст для присваивания переменной IDMinimum
|
||||
func FindTextIDMinimumVariable(Column1 *types.Column, VariableName string) string {
|
||||
Otvet := ""
|
||||
|
||||
TextValue := FindTextIDMinimum(Column1)
|
||||
|
||||
IDMinimum := Column1.IDMinimum
|
||||
switch Column1.TypeGo {
|
||||
case "uuid.UUID":
|
||||
{
|
||||
if IDMinimum == "" {
|
||||
Otvet = VariableName + " = " + "uuid.Nil"
|
||||
} else {
|
||||
Otvet = VariableName + ", _ = " + `uuid.Parse("` + IDMinimum + `")`
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
Otvet = VariableName + " = " + TextValue
|
||||
}
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextIDMinimum - возвращает текст для IDMinimum, в зависимости от типа
|
||||
func FindTextIDMinimum(Column1 *types.Column) string {
|
||||
Otvet := Column1.IDMinimum
|
||||
|
||||
IDMinimum := Column1.IDMinimum
|
||||
switch Column1.TypeGo {
|
||||
case "uuid.UUID":
|
||||
{
|
||||
if IDMinimum == "" {
|
||||
Otvet = "uuid.Nil"
|
||||
} else {
|
||||
Otvet = `uuid.Parse("` + IDMinimum + `")`
|
||||
}
|
||||
}
|
||||
case "string":
|
||||
{
|
||||
Otvet = `"` + IDMinimum + `"`
|
||||
}
|
||||
}
|
||||
|
||||
@ -2010,7 +2142,7 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
TEXT_TEMPLATE_MODEL := config.Settings.TEXT_TEMPLATE_MODEL
|
||||
ModelName := Table1.NameGo
|
||||
//ModelName := Table1.NameGo
|
||||
TextFind := "const " + TEXT_TEMPLATE_MODEL + "_ID_Test = 0"
|
||||
PrimaryKeyColumn := FindPrimaryKeyColumn(Table1)
|
||||
if PrimaryKeyColumn == nil {
|
||||
@ -2023,23 +2155,24 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string {
|
||||
}
|
||||
DefaultModelName := config.Settings.TEXT_TEMPLATE_MODEL
|
||||
|
||||
Name := FindNameGoTest(PrimaryKeyColumn)
|
||||
switch PrimaryKeyColumn.TypeGo {
|
||||
case "uuid.UUID":
|
||||
{
|
||||
if PrimaryKeyColumn.IDMinimum == "" {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum+``)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+Name+` = `+IDMinimum+``)
|
||||
} else {
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+Name+`, _ = uuid.Parse("`+IDMinimum+`")`)
|
||||
}
|
||||
Otvet = strings.ReplaceAll(Otvet, ``+DefaultModelName+`_ID_Test`, ``+ModelName+`_ID_Test.String()`)
|
||||
Otvet = strings.ReplaceAll(Otvet, ``+DefaultModelName+`_ID_Test`, ``+Name+`.String()`)
|
||||
}
|
||||
case "string":
|
||||
{
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = "`+IDMinimum+`"`)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+Name+` = "`+IDMinimum+`"`)
|
||||
}
|
||||
default:
|
||||
{
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = `+IDMinimum)
|
||||
Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+Name+` = `+IDMinimum)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,12 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.IsGoodTable(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn(err1)
|
||||
continue
|
||||
}
|
||||
////проверка что таблица нормальная
|
||||
//err1 := create_files.IsGoodTable(Table1)
|
||||
//if err1 != nil {
|
||||
// log.Warn(err1)
|
||||
// continue
|
||||
//}
|
||||
|
||||
//проверка что таблица нормальная
|
||||
err2 := create_files.IsGoodTableNamePrefix(Table1)
|
||||
@ -737,6 +737,9 @@ func CreateFilesUpdateEveryColumnTest(Table1 *types.Table) error {
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
//Postgres_ID_Test = ID Minimum
|
||||
TextCrud = create_files.Replace_Postgres_ID_Test(TextCrud, Table1)
|
||||
|
||||
TextCrud = create_files.ReplacePrimaryKeyM_ID(TextCrud, Table1)
|
||||
TextCrud = create_files.ReplacePrimaryKeyOtvetID(TextCrud, Table1)
|
||||
//TextCrud = create_files.ConvertRequestIdToAlias(TextCrud, Table1)
|
||||
@ -813,6 +816,9 @@ func FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc string, Table1 *types.Tab
|
||||
TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1)
|
||||
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||
|
||||
//Postgres_ID_Test = ID Minimum
|
||||
Otvet = create_files.Replace_Postgres_ID_Test(Otvet, Table1)
|
||||
|
||||
Otvet = create_files.ReplacePrimaryKeyM_ID(Otvet, Table1)
|
||||
Otvet = create_files.ReplacePrimaryKeyOtvetID(Otvet, Table1)
|
||||
|
||||
@ -902,8 +908,6 @@ func CreateFilesCache(Table1 *types.Table) error {
|
||||
TextIDMany = create_files.ReplaceIDtoID_Many(TextIDMany, Table1)
|
||||
TextCache = strings.ReplaceAll(TextCache, "(ID)", "("+Table1.Name+".StringIdentifier"+TextIDMany+")")
|
||||
TextCache = create_files.ReplaceIDtoID_Many(TextCache, Table1)
|
||||
//TextCache = strings.ReplaceAll(TextCache, "(ID,", "("+Table1.Name+".StringIdentifier"+TextIDMany+",")
|
||||
//TextCache = strings.ReplaceAll(TextCache, "ID int64", "ID "+ColumnTypeGo)
|
||||
}
|
||||
|
||||
//uuid
|
||||
@ -968,6 +972,20 @@ func CreateFilesCacheTest(Table1 *types.Table) error {
|
||||
//замена "postgres_gorm.Connect_WithApplicationName("
|
||||
TextCache = create_files.ReplaceConnect_WithApplicationName(TextCache)
|
||||
|
||||
//тип ID кэша
|
||||
if Table1.PrimaryKeyColumnsCount == 1 {
|
||||
} else {
|
||||
TextIDMany := "(ID)"
|
||||
TextIDMany = create_files.ReplaceIDtoID_Many(TextIDMany, Table1)
|
||||
//TextCache = strings.ReplaceAll(TextCache, "(ID)", "("+Table1.Name+".StringIdentifier"+TextIDMany+")")
|
||||
//TextCache = create_files.ReplaceIDtoID_Many(TextCache, Table1)
|
||||
//TextIDMany := create_files.FindTextNameTest_ManyPK(Table1)
|
||||
//TextCache = strings.ReplaceAll(TextCache, "ReadFromCache(Postgres_ID_Test)", "ReadFromCache("+TextIDMany+")")
|
||||
//TextCache = create_files.Replace_Postgres_ID_Test(TextCache, Table1)
|
||||
//EntityURL := create_files.FindModelTableURL(Table1.Name)
|
||||
//TextCache = create_files.CheckAndAddImport(TextCache, EntityURL)
|
||||
TextCache = create_files.Replace_Postgres_ID_Test_ManyPK(TextCache, Table1)
|
||||
}
|
||||
}
|
||||
|
||||
//замена слов
|
||||
|
Loading…
Reference in New Issue
Block a user