1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-13 21:42:33 +02:00

сделал CreateFiles_FindMassBy

This commit is contained in:
Nikitin Aleksandr 2024-12-11 10:32:44 +03:00
parent 86622e99ee
commit 40b0e32bb9
11 changed files with 29 additions and 12 deletions

View File

@ -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"]}
]

View File

@ -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

View File

@ -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{}

View File

@ -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

View File

@ -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{}

View File

@ -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"
)

View File

@ -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{}

View File

@ -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{}

View File

@ -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 = "_"

View File

@ -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)
}
//создание функций

View File

@ -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)
}
//создание функций