From 40b0e32bb9dbd6b0e9190988c7a7feebf343cdc5 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Wed, 11 Dec 2024 10:32:44 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20CreateFi?= =?UTF-8?q?les=5FFindMassBy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configs_/findmassby_functions_tink.json | 3 ++- .../pkg/db/crud/crud_tables_findby_function.go_ | 2 +- .../db/crud/crud_tables_findby_function_test.go_ | 2 +- .../pkg/db/crud/crud_tables_findmassby_function.go_ | 4 ++-- .../crud/crud_tables_findmassby_function_test.go_ | 2 +- .../pkg/db/crud/crud_tables_findmassby_test.go_ | 1 + .../crud/crud_tables_findmodelby_function_test.go_ | 2 +- .../db/crud/crud_tables_readall_function_test.go_ | 2 +- .../create_files/crud_tables/crud_tables_findby.go | 7 +++++-- .../crud_tables/crud_tables_findmassby.go | 13 +++++++++++-- .../crud_tables/crud_tables_findmodelby.go | 3 +++ 11 files changed, 29 insertions(+), 12 deletions(-) diff --git a/bin/templates/configs_/findmassby_functions_tink.json b/bin/templates/configs_/findmassby_functions_tink.json index 23d8079..e7e0038 100644 --- a/bin/templates/configs_/findmassby_functions_tink.json +++ b/bin/templates/configs_/findmassby_functions_tink.json @@ -1,5 +1,6 @@ [ {"Table":"tinkoff_instrument","Columns":["instrument_type"]}, {"Table":"tinkoff_instrument","Columns":["instrument_type", "name"]}, -{"Table":"tinkoff_instrument","Columns":["instrument_type", "currency"]} +{"Table":"tinkoff_instrument","Columns":["instrument_type", "currency"]}, +{"Table":"moex_securities_all","Columns":["group", "is_traded"]} ] diff --git a/bin/templates/pkg/db/crud/crud_tables_findby_function.go_ b/bin/templates/pkg/db/crud/crud_tables_findby_function.go_ index 9554972..b4a2ae4 100644 --- a/bin/templates/pkg/db/crud/crud_tables_findby_function.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_findby_function.go_ @@ -19,7 +19,7 @@ func FindBy_FieldNamesWithUnderline_ctx(ctx context.Context, db *gorm.DB, m *law tx := db.WithContext(ctx) - tx = tx.Where("ColumnName = ?", m.FieldName) + tx = tx.Where(`"ColumnName" = ?`, m.FieldName) tx = tx.Take(m) err = tx.Error diff --git a/bin/templates/pkg/db/crud/crud_tables_findby_function_test.go_ b/bin/templates/pkg/db/crud/crud_tables_findby_function_test.go_ index 12580b7..610405f 100644 --- a/bin/templates/pkg/db/crud/crud_tables_findby_function_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_findby_function_test.go_ @@ -1,7 +1,7 @@ func TestFindBy_FieldNamesWithUnderline(t *testing.T) { config_main.LoadEnv() - postgres_gorm.Connect() + postgres_gorm.Connect_WithApplicationName_SingularTableName(constants.SERVICE_NAME + "_test") defer postgres_gorm.CloseConnection() crud := Crud_DB{} diff --git a/bin/templates/pkg/db/crud/crud_tables_findmassby_function.go_ b/bin/templates/pkg/db/crud/crud_tables_findmassby_function.go_ index 43f60c9..7eb9b81 100644 --- a/bin/templates/pkg/db/crud/crud_tables_findmassby_function.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_findmassby_function.go_ @@ -21,8 +21,8 @@ func FindMassBy_FieldNamesWithUnderline_ctx(ctx context.Context, db *gorm.DB, m tx := db.WithContext(ctx) - tx = tx.Where("ColumnName = ?", m.FieldName) - tx = tx.Order("ColumnNamesWithComma") + tx = tx.Where(`"ColumnName" = ?`, m.FieldName) + tx = tx.Order(`ColumnNamesWithCommaQuotes`) tx = tx.Find(&Otvet) err = tx.Error diff --git a/bin/templates/pkg/db/crud/crud_tables_findmassby_function_test.go_ b/bin/templates/pkg/db/crud/crud_tables_findmassby_function_test.go_ index fc15db3..3c523b8 100644 --- a/bin/templates/pkg/db/crud/crud_tables_findmassby_function_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_findmassby_function_test.go_ @@ -1,7 +1,7 @@ func TestFindMassBy_FieldNamesWithUnderline(t *testing.T) { config_main.LoadEnv() - postgres_gorm.Connect() + postgres_gorm.Connect_WithApplicationName_SingularTableName(constants.SERVICE_NAME + "_test") defer postgres_gorm.CloseConnection() crud := Crud_DB{} diff --git a/bin/templates/pkg/db/crud/crud_tables_findmassby_test.go_ b/bin/templates/pkg/db/crud/crud_tables_findmassby_test.go_ index 682bbd9..a219c94 100644 --- a/bin/templates/pkg/db/crud/crud_tables_findmassby_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_findmassby_test.go_ @@ -5,6 +5,7 @@ import ( "github.com/ManyakRus/starter/postgres_gorm" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/crud_func" + "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/constants" "testing" ) diff --git a/bin/templates/pkg/db/crud/crud_tables_findmodelby_function_test.go_ b/bin/templates/pkg/db/crud/crud_tables_findmodelby_function_test.go_ index 371c901..9e64357 100644 --- a/bin/templates/pkg/db/crud/crud_tables_findmodelby_function_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_findmodelby_function_test.go_ @@ -1,7 +1,7 @@ func TestFindModelBy_FieldNamesWithUnderline(t *testing.T) { config_main.LoadEnv() - postgres_gorm.Connect() + postgres_gorm.Connect_WithApplicationName_SingularTableName(constants.SERVICE_NAME + "_test") defer postgres_gorm.CloseConnection() crud := Crud_DB{} diff --git a/bin/templates/pkg/db/crud/crud_tables_readall_function_test.go_ b/bin/templates/pkg/db/crud/crud_tables_readall_function_test.go_ index 5dd821f..b31ad5e 100644 --- a/bin/templates/pkg/db/crud/crud_tables_readall_function_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_readall_function_test.go_ @@ -1,7 +1,7 @@ func TestReadAll(t *testing.T) { config_main.LoadEnv() - postgres_gorm.Connect() + postgres_gorm.Connect_WithApplicationName_SingularTableName(constants.SERVICE_NAME + "_test") defer postgres_gorm.CloseConnection() crud := Crud_DB{} diff --git a/internal/create_files/crud_tables/crud_tables_findby.go b/internal/create_files/crud_tables/crud_tables_findby.go index 136bdf1..c16d1c3 100644 --- a/internal/create_files/crud_tables/crud_tables_findby.go +++ b/internal/create_files/crud_tables/crud_tables_findby.go @@ -62,6 +62,9 @@ func CreateFiles_FindBy(Table1 *types.Table) error { ConstantsURL := create_files.Find_DBConstantsURL() TextCrud = create_files.AddImport(TextCrud, ConstantsURL) + //замена "postgres_gorm.Connect_WithApplicationName(" + TextCrud = create_files.Replace_Connect_WithApplicationName(TextCrud) + } //создание функций @@ -126,7 +129,7 @@ func CreateFiles_FindBy_Table1(Table1 *types.Table, TextTemplateFunction string, TextWhere := "" // - TextFind := "\t" + `tx = tx.Where("ColumnName = ?", m.FieldName)` + "\n" + TextFind := "\t" + `tx = tx.Where(` + "`" + `"ColumnName" = ?` + "`" + `, m.FieldName)` + "\n" Underline := "" Plus := "" for _, ColumnName1 := range MassColumns1 { @@ -134,7 +137,7 @@ func CreateFiles_FindBy_Table1(Table1 *types.Table, TextTemplateFunction string, if ok == false { log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false") } - TextWhere = TextWhere + "\t" + `tx = tx.Where("` + ColumnName1 + ` = ?", m.` + Column1.NameGo + `)` + "\n" + TextWhere = TextWhere + "\t" + `tx = tx.Where(` + "`" + `"` + ColumnName1 + `" = ?` + "`" + `, m.` + Column1.NameGo + `)` + "\n" FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo Underline = "_" diff --git a/internal/create_files/crud_tables/crud_tables_findmassby.go b/internal/create_files/crud_tables/crud_tables_findmassby.go index dff058e..06eb247 100644 --- a/internal/create_files/crud_tables/crud_tables_findmassby.go +++ b/internal/create_files/crud_tables/crud_tables_findmassby.go @@ -124,9 +124,10 @@ func CreateFiles_FindMassBy_Table1(Table1 *types.Table, TextTemplateFunction str FieldNamesWithUnderline := "" FieldNamesWithComma := "" ColumnNamesWithComma := "" + ColumnNamesWithCommaQuotes := "" // - TextFind := "\t" + `tx = tx.Where("ColumnName = ?", m.FieldName)` + "\n" + TextFind := "\t" + `tx = tx.Where(` + "`" + `"ColumnName" = ?` + "`" + `, m.FieldName)` + "\n" TextWhere := "" Underline := "" Plus := "" @@ -136,10 +137,11 @@ func CreateFiles_FindMassBy_Table1(Table1 *types.Table, TextTemplateFunction str if ok == false { log.Panic(Table1.Name + " .MapColumns[" + ColumnName1 + "] = false") } - TextWhere = TextWhere + "\t" + `tx = tx.Where("` + ColumnName1 + ` = ?", m.` + Column1.NameGo + `)` + "\n" + TextWhere = TextWhere + "\t" + `tx = tx.Where(` + "`" + `"` + ColumnName1 + `"` + ` = ?` + "`" + `, m.` + Column1.NameGo + `)` + "\n" FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo FieldNamesWithComma = FieldNamesWithComma + Plus + Column1.NameGo ColumnNamesWithComma = ColumnNamesWithComma + Comma + Column1.Name + ColumnNamesWithCommaQuotes = ColumnNamesWithCommaQuotes + Comma + `"` + Column1.Name + `"` Underline = "_" Plus = "+" @@ -166,6 +168,7 @@ func CreateFiles_FindMassBy_Table1(Table1 *types.Table, TextTemplateFunction str Otvet = strings.ReplaceAll(Otvet, TextFind, TextWhere) Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline) Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma) + Otvet = strings.ReplaceAll(Otvet, "ColumnNamesWithCommaQuotes", ColumnNamesWithCommaQuotes) Otvet = strings.ReplaceAll(Otvet, "ColumnNamesWithComma", ColumnNamesWithComma) return Otvet @@ -223,6 +226,12 @@ func CreateFiles_FindMassBy_Test(Table1 *types.Table) error { CrudFuncURL := create_files.Find_CrudFuncURL() TextCrud = create_files.AddImport(TextCrud, CrudFuncURL) + ConstantsURL := create_files.Find_ConstantsURL() + TextCrud = create_files.AddImport(TextCrud, ConstantsURL) + + //замена "postgres_gorm.Connect_WithApplicationName(" + TextCrud = create_files.Replace_Connect_WithApplicationName(TextCrud) + } //создание функций diff --git a/internal/create_files/crud_tables/crud_tables_findmodelby.go b/internal/create_files/crud_tables/crud_tables_findmodelby.go index d744f77..4b4908a 100644 --- a/internal/create_files/crud_tables/crud_tables_findmodelby.go +++ b/internal/create_files/crud_tables/crud_tables_findmodelby.go @@ -62,6 +62,9 @@ func CreateFiles_FindModelBy(MapAll map[string]*types.Table, Table1 *types.Table ConstantsURL := create_files.Find_DBConstantsURL() TextCrud = create_files.AddImport(TextCrud, ConstantsURL) + //замена "postgres_gorm.Connect_WithApplicationName(" + TextCrud = create_files.Replace_Connect_WithApplicationName(TextCrud) + } //создание функций