1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-20 09:09:22 +02:00

сделал ReadAll()

This commit is contained in:
Nikitin Aleksandr 2024-09-09 13:55:42 +03:00
parent f4f5d67759
commit 7314abb580
9 changed files with 109 additions and 6 deletions

View File

@ -289,3 +289,8 @@ message ResponseEmpty {
message ResponseMass {
repeated string MassModelString = 1; //массив объект-модель в формате json
}
message Request_Empty {
uint32 VersionModel = 1; //версия структуры модели
}

View File

@ -63,3 +63,5 @@ const SERVER_GRPC_TABLE_CACHE_TEST_FILENAME = "server_grpc_table_cache_test.go_"
const TEXT_OTVET_ID_ALIAS = "Otvet.ID = AliasFromInt(ID)" //"Otvet.ID = ID"
const TEXT_CACHE_SIZE_1000 = "CACHE_SIZE"
const TEXT_READALL = "ReadAll"

View File

@ -147,6 +147,13 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
Underline = "_"
Plus = "+"
}
//кроме помеченных на удаление
if create_files.Has_Column_IsDeleted_Bool(Table1) == true {
TextWhere = TextWhere + "\t" + `tx = tx.Where("is_deleted = ?", false)` + "\n"
}
//
Otvet = strings.ReplaceAll(Otvet, TextFind, TextWhere)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma)

View File

@ -152,6 +152,14 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
Plus = "+"
Comma = ", "
}
//
if len(MassColumns1) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
}
//
Otvet = strings.ReplaceAll(Otvet, TextFind, TextWhere)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma)
@ -283,7 +291,7 @@ func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction s
//
TextAssignFind := "\t" + `Otvet.FieldName = 0` + "\n"
TextAssign := ""
TextFieldName_TEST := ""
TextFieldsDefaultValue := ""
Underline := ""
Comma := ""
@ -296,15 +304,28 @@ func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction s
TextAssign = TextAssign + "\t" + `Otvet.` + Column1.NameGo + ` = ` + DefaultValue + "\n"
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
FieldNamesWithComma = FieldNamesWithComma + Comma + Column1.NameGo
TextFieldName_TEST = TextFieldName_TEST + Comma + DefaultValue
TextFieldsDefaultValue = TextFieldsDefaultValue + Comma + DefaultValue
Underline = "_"
Comma = ", "
}
//
if len(MassColumns1) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
}
//
if TextFieldsDefaultValue == "" {
TextFieldsDefaultValue = `""`
}
//
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesDefault", TextFieldName_TEST)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesDefault", TextFieldsDefaultValue)
return Otvet
}

View File

@ -152,6 +152,14 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
Plus = "+"
Comma = ", "
}
//функция ReadAll()
if len(MassColumns1) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
}
//
Otvet = strings.ReplaceAll(Otvet, TextFind, TextWhere)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPlus", FieldNamesWithComma)
@ -298,6 +306,14 @@ func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction s
Underline = "_"
Comma = ", "
}
//функция ReadAll()
if len(MassColumns1) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
}
//
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
@ -330,7 +346,15 @@ func AddInterfacesFindMassBy(TextModel string, Table1 *types.Table) string {
FieldNamesWithUnderline = FieldNamesWithUnderline + Underline + Column1.NameGo
Underline = "_"
}
TextFunc1 := "\n\tFindMassBy_" + FieldNamesWithUnderline + "(*" + Table1.NameGo + ") ([]" + Table1.NameGo + ", error)"
FuncName := "FindMassBy_" + FieldNamesWithUnderline
//функция ReadAll()
if len(TableColumns1.MassColumnNames) == 0 {
FuncName = constants.TEXT_READALL
}
//
TextFunc1 := "\n\t" + FuncName + "(*" + Table1.NameGo + ") ([]" + Table1.NameGo + ", error)"
TextFunc = TextFunc + TextFunc1
}

View File

@ -171,6 +171,14 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
Plus = "+"
}
//функция ReadAll()
if len(MassColumnsString) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
Otvet = strings.ReplaceAll(Otvet, ".RequestName", ".Request_Empty")
}
//
Otvet = strings.ReplaceAll(Otvet, "RequestName", RequestName)
Otvet = strings.ReplaceAll(Otvet, TextFind, TextAssign)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
@ -331,6 +339,15 @@ func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction s
Underline = "_"
Comma = ", "
}
//функция ReadAll()
if len(MassColumnsString) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
Otvet = strings.ReplaceAll(Otvet, ".RequestName", ".Request_Empty")
}
//
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)

View File

@ -1,6 +1,7 @@
package protobuf
import (
"github.com/ManyakRus/crud_generator/internal/constants"
"github.com/ManyakRus/crud_generator/internal/create_files"
"github.com/ManyakRus/crud_generator/internal/types"
"strings"
@ -53,7 +54,15 @@ func FindText_FindMassBy1(TableColumns1 types.TableColumns) string {
Underline = "_"
}
Otvet = Otvet + TableColumns1.Table.NameGo + "_FindMassBy_" + TextFields + "(" + TextRequest + ") returns (ResponseMass) {}\n"
FuncName := "FindMassBy_" + TextFields
//функция ReadAll()
if len(TableColumns1.Columns) == 0 {
FuncName = constants.TEXT_READALL
TextRequest = "Request_Empty"
}
//
Otvet = Otvet + TableColumns1.Table.NameGo + "_" + FuncName + "(" + TextRequest + ") returns (ResponseMass) {}\n"
return Otvet
}

View File

@ -164,6 +164,14 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
Plus = "+"
}
//функция ReadAll()
if len(MassColumnsString) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
Otvet = strings.ReplaceAll(Otvet, ".RequestName", ".Request_Empty")
}
//
Otvet = strings.ReplaceAll(Otvet, "RequestName", RequestName)
Otvet = strings.ReplaceAll(Otvet, TextFind, TextAssign)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)
@ -326,6 +334,15 @@ func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction s
Underline = "_"
Comma = ", "
}
//функция ReadAll()
if len(MassColumnsString) == 0 {
FuncName := constants.TEXT_READALL
Otvet = strings.ReplaceAll(Otvet, "FindMassBy_FieldNamesWithUnderline", FuncName)
Otvet = strings.ReplaceAll(Otvet, ".RequestName", ".Request_Empty")
}
//
Otvet = strings.ReplaceAll(Otvet, TextAssignFind, TextAssign)
Otvet = strings.ReplaceAll(Otvet, "RequestName", RequestName)
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithUnderline", FieldNamesWithUnderline)

View File

@ -13,7 +13,8 @@
отдельная функция для каждой колонки каждой таблицы.
- UpdateManyFields() - изменение нескольких колонок, перечисленных в массиве
- FindBy_ColumnName() - поиск записи по одной или нескольким колонкам (если заполнить файл findby_functions.json)
- FindMassBy_ColumnName() - поиск несколько записей по одной или нескольким колонкам (если заполнить файл findmassby_functions.json)
- FindMassBy_ColumnName() - поиск несколько записей по одной или нескольким колонкам (если заполнить файл findmassby_functions.json),
если не заполнить колонки - вернёт все записи, будет функция ReadAll()
генерируются файлы:
1. tables - структура struct со всеми полями из БД, и аннотациями gorm + json