1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-11-24 08:22:42 +02:00

сделал find_by_functions.json

This commit is contained in:
Nikitin Aleksandr 2024-08-16 12:44:58 +03:00
parent bb57446e60
commit 7d80f3ddfb
11 changed files with 217 additions and 34 deletions

View File

@ -2992,6 +2992,25 @@ func FindMassColumns_from_MassColumnsString(Table1 *types.Table, MassColumnsStri
return Otvet
}
// FindMassTableColumns - преобразует TableColumns_String в TableColumns
func FindMassTableColumns(MapAll map[string]*types.Table, MassTableColumns_String []types.TableColumns_String) []types.TableColumns {
Otvet := make([]types.TableColumns, len(MassTableColumns_String))
for _, TableColumns_string1 := range MassTableColumns_String {
Table1, ok := MapAll[TableColumns_string1.TableName]
if ok == false {
log.Panic(" Error: not found table: ", TableColumns_string1.TableName)
}
Columns1 := FindMassColumns_from_MassColumnsString(Table1, TableColumns_string1.MassColumnNames)
TableColumns1 := types.TableColumns{}
TableColumns1.Table = Table1
TableColumns1.Columns = Columns1
Otvet = append(Otvet, TableColumns1)
}
return Otvet
}
// ConvertProtobufVariableToGolangVariable_with_MassColumns - возвращает имя переменной + имя колонки, преобразованное в тип golang из protobuf
func ConvertProtobufVariableToGolangVariable_with_MassColumns(Column *types.Column, MassColumns []*types.Column, VariableName string) (VariableField string, GolangCode string) {
RequestFieldName := FindRequestFieldName_FromMass(Column, MassColumns)
@ -3017,3 +3036,20 @@ func ConvertProtobufVariableToGolangVariable_with_MassColumns(Column *types.Colu
return VariableField, GolangCode
}
// FindRequestFieldNames_FromMass - возвращает строку с именами колонок для Protobuf
func FindRequestFieldNames_FromMass(MassColumns []*types.Column) string {
Otvet := ""
TextFields := ""
TextRequest := ""
Underline := ""
for _, Column1 := range MassColumns {
TextFields = TextFields + Underline + Column1.NameGo
TextRequest1 := FindRequestFieldName_FromMass(Column1, MassColumns)
TextRequest = TextRequest + Underline + TextRequest1
Underline = "_"
}
return Otvet
}

View File

@ -15,7 +15,7 @@ import (
func CreateFilesFindBy(Table1 *types.Table) error {
var err error
if len(types.MassFindBy) == 0 {
if len(types.MassFindBy_String) == 0 {
return err
}
@ -108,7 +108,7 @@ func CreateFilesFindBy(Table1 *types.Table) error {
func CreateFilesFindByTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
for _, TableColumns1 := range types.MassFindBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -154,7 +154,7 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
func CreateFilesFindByTest(Table1 *types.Table) error {
var err error
if len(types.MassFindBy) == 0 {
if len(types.MassFindBy_String) == 0 {
return err
}
@ -244,7 +244,7 @@ func CreateFilesFindByTest(Table1 *types.Table) error {
func CreateFilesFindByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
for _, TableColumns1 := range types.MassFindBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}

View File

@ -15,7 +15,7 @@ import (
func CreateFilesFindMassBy(Table1 *types.Table) error {
var err error
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return err
}
@ -108,7 +108,7 @@ func CreateFilesFindMassBy(Table1 *types.Table) error {
func CreateFilesFindMassByTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -160,7 +160,7 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
func CreateFilesFindMassByTest(Table1 *types.Table) error {
var err error
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return err
}
@ -250,7 +250,7 @@ func CreateFilesFindMassByTest(Table1 *types.Table) error {
func CreateFilesFindMassByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}

View File

@ -15,7 +15,7 @@ import (
func CreateFilesFindBy(Table1 *types.Table) error {
var err error
if len(types.MassFindBy) == 0 {
if len(types.MassFindBy_String) == 0 {
return err
}
@ -108,7 +108,7 @@ func CreateFilesFindBy(Table1 *types.Table) error {
func CreateFilesFindByTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
for _, TableColumns1 := range types.MassFindBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -154,12 +154,12 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
func AddInterfacesFindBy(TextModel string, Table1 *types.Table) string {
Otvet := TextModel
if len(types.MassFindBy) == 0 {
if len(types.MassFindBy_String) == 0 {
return Otvet
}
TextFunc := ""
for _, TableColumns1 := range types.MassFindBy {
for _, TableColumns1 := range types.MassFindBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}

View File

@ -15,7 +15,7 @@ import (
func CreateFilesFindMassBy(Table1 *types.Table) error {
var err error
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return err
}
@ -108,7 +108,7 @@ func CreateFilesFindMassBy(Table1 *types.Table) error {
func CreateFilesFindMassByTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -160,7 +160,7 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
func CreateFilesFindMassByTest(Table1 *types.Table) error {
var err error
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return err
}
@ -250,7 +250,7 @@ func CreateFilesFindMassByTest(Table1 *types.Table) error {
func CreateFilesFindMassByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -302,12 +302,12 @@ func CreateFilesFindMassByTestTable1(Table1 *types.Table, TextTemplateFunction s
func AddInterfacesFindMassBy(TextModel string, Table1 *types.Table) string {
Otvet := TextModel
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return Otvet
}
TextFunc := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}

View File

@ -88,6 +88,12 @@ func CreateFileProto(MapAll map[string]*types.Table) error {
TextProtoNew = TextProtoNew + FindTextProtoTable1_UpdateManyFields(TextProto, Table1)
TextProtoNew = TextProtoNew + FindTextProtoTable1_UpdateEveryColumn(TextProto, Table1)
//добавим текст FindBy
TextProtoNew = TextProtoNew + FindText_FindBy(TextProto, Table1)
//добавим текст FindMassBy
TextProtoNew = TextProtoNew + FindText_FindMassBy(TextProto, Table1)
if config.Settings.NEED_CREATE_CACHE_API == true {
TextProtoNew = TextProtoNew + FindTextProtoTable1_Cache(TextProto, Table1)
}
@ -692,6 +698,38 @@ message ` + TextRequest + ` {
return Otvet
}
// AddTextMessageRequestID_Columns - в текст .proto добавляет message из присланных колонок
func AddTextMessageRequestID_Columns(Text string, Columns []*types.Column) string {
Otvet := Text
TextRequest := "Request_" + create_files.FindRequestFieldNames_FromMass(Columns)
//найдём уже есть message
TextFind := "message " + TextRequest + " {"
pos1 := strings.Index(Otvet, TextFind)
if pos1 >= 0 {
return Otvet
}
TextMessage := `
// ` + TextRequest + ` - параметры запроса на сервер
message ` + TextRequest + ` {
uint32 VersionModel= 1; //версия структуры модели`
////
//for _, Column1 := range Columns {
// ProtoType := create_files.ConvertGolangTypeNameToProtobufTypeName(Column1.Type)
// ProtoName := create_files.FindRequestFieldName_FromMass(Column1, Columns)
// TextMessage = TextMessage + ``
//}
TextMessage = TextMessage + `
}`
Otvet = Otvet + "\n" + TextMessage
return Otvet
}
// AddTextMessageRequestID - возвращает текст в .proto для таблицы
func AddTextMessageRequestID(TextProto string, Table1 *types.Table) string {
Otvet := TextProto //"\n\t//\n"
@ -717,3 +755,89 @@ func AddTextMessageRequestID(TextProto string, Table1 *types.Table) string {
return Otvet
}
// FindText_FindBy - добавляет текст FindBy
func FindText_FindBy(TextProto string, Table1 *types.Table) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
if TableColumns1.Table.Name != Table1.Name {
continue
}
Text1 := FindText_FindBy1(TableColumns1)
//проверим такой текст уже есть
pos1 := strings.Index(TextProto, Text1)
if pos1 >= 0 {
continue
}
//
Otvet = Otvet + Text1
}
return Otvet
}
// FindText_FindBy1 - находит текст FindBy
func FindText_FindBy1(TableColumns1 types.TableColumns) string {
Otvet := "\n\t rpc "
TextFields := ""
TextRequest := ""
Underline := ""
for _, Column1 := range TableColumns1.Columns {
TextFields = TextFields + Underline + Column1.NameGo
TextRequest1 := create_files.FindRequestFieldName_FromMass(Column1, TableColumns1.Columns)
TextRequest = TextRequest + Underline + TextRequest1
Underline = "_"
}
Otvet = Otvet + TableColumns1.Table.NameGo + "_FindBy_" + TextFields + "(" + TextRequest + ") returns (Response)\n"
return Otvet
}
// FindText_FindMassBy - добавляет текст FindBy
func FindText_FindMassBy(TextProto string, Table1 *types.Table) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
if TableColumns1.Table.Name != Table1.Name {
continue
}
Text1 := FindText_FindMassBy1(TableColumns1)
//проверим такой текст уже есть
pos1 := strings.Index(TextProto, Text1)
if pos1 >= 0 {
continue
}
//
Otvet = Otvet + Text1
}
return Otvet
}
// FindText_FindMassBy1 - находит текст FindBy
func FindText_FindMassBy1(TableColumns1 types.TableColumns) string {
Otvet := "\n\t rpc "
TextFields := ""
TextRequest := ""
Underline := ""
for _, Column1 := range TableColumns1.Columns {
TextFields = TextFields + Underline + Column1.NameGo
TextRequest1 := create_files.FindRequestFieldName_FromMass(Column1, TableColumns1.Columns)
TextRequest = TextRequest + Underline + TextRequest1
Underline = "_"
}
Otvet = Otvet + TableColumns1.Table.NameGo + "_FindMassBy_" + TextFields + "(" + TextRequest + ") returns (ResponseMass)\n"
return Otvet
}

View File

@ -15,7 +15,7 @@ import (
func CreateFilesFindBy(Table1 *types.Table) error {
var err error
if len(types.MassFindBy) == 0 {
if len(types.MassFindBy_String) == 0 {
return err
}
@ -111,7 +111,7 @@ func CreateFilesFindBy(Table1 *types.Table) error {
func CreateFilesFindByTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
for _, TableColumns1 := range types.MassFindBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -172,7 +172,7 @@ func CreateFilesFindByTable1(Table1 *types.Table, TextTemplateFunction string, M
func CreateFilesFindByTest(Table1 *types.Table) error {
var err error
if len(types.MassFindBy) == 0 {
if len(types.MassFindBy_String) == 0 {
return err
}
@ -268,7 +268,7 @@ func CreateFilesFindByTest(Table1 *types.Table) error {
func CreateFilesFindByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindBy {
for _, TableColumns1 := range types.MassFindBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}

View File

@ -15,7 +15,7 @@ import (
func CreateFilesFindMassBy(Table1 *types.Table) error {
var err error
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return err
}
@ -111,7 +111,7 @@ func CreateFilesFindMassBy(Table1 *types.Table) error {
func CreateFilesFindMassByTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}
@ -172,7 +172,7 @@ func CreateFilesFindMassByTable1(Table1 *types.Table, TextTemplateFunction strin
func CreateFilesFindMassByTest(Table1 *types.Table) error {
var err error
if len(types.MassFindMassBy) == 0 {
if len(types.MassFindMassBy_String) == 0 {
return err
}
@ -268,7 +268,7 @@ func CreateFilesFindMassByTest(Table1 *types.Table) error {
func CreateFilesFindMassByTestTable(Table1 *types.Table, TextTemplateFunction string) string {
Otvet := ""
for _, TableColumns1 := range types.MassFindMassBy {
for _, TableColumns1 := range types.MassFindMassBy_String {
if TableColumns1.TableName != Table1.Name {
continue
}

View File

@ -220,14 +220,14 @@ func LoadFindBy() {
log.Panic(TextError)
}
//MassFindBy1 := types.TableNameColumnNames{}
//MassFindBy1 := types.TableColumns_String{}
//MassFindBy1.TableName = "TableName"
//MassFindBy1.MassColumnNames = []string{"ColumnName"}
//types.MassFindBy = append(types.MassFindBy, MassFindBy1)
//bytes, _ = json.Marshal(types.MassFindBy) //удалить
//types.MassFindBy_String = append(types.MassFindBy_String, MassFindBy1)
//bytes, _ = json.Marshal(types.MassFindBy_String) //удалить
//json в map
err = json.Unmarshal(bytes, &types.MassFindBy)
err = json.Unmarshal(bytes, &types.MassFindBy_String)
if err != nil {
log.Panic("Unmarshal() error: ", err)
}
@ -249,7 +249,7 @@ func LoadFindMassBy() {
}
//json в map
err = json.Unmarshal(bytes, &types.MassFindMassBy)
err = json.Unmarshal(bytes, &types.MassFindMassBy_String)
if err != nil {
log.Panic("Unmarshal() error: ", err)
}

View File

@ -2,6 +2,7 @@ package logic
import (
"github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/crud_generator/internal/create_files"
"github.com/ManyakRus/crud_generator/internal/create_files/alias"
"github.com/ManyakRus/crud_generator/internal/create_files/constants_file"
"github.com/ManyakRus/crud_generator/internal/create_files/crud_starter"
@ -25,6 +26,7 @@ import (
"github.com/ManyakRus/crud_generator/internal/create_files/tables_tables"
"github.com/ManyakRus/crud_generator/internal/folders"
"github.com/ManyakRus/crud_generator/internal/postgres"
"github.com/ManyakRus/crud_generator/internal/types"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/micro"
)
@ -46,6 +48,14 @@ func StartFillAll() error {
return err
}
//
Mass1 := create_files.FindMassTableColumns(MapAll, types.MassFindBy_String)
types.MassFindBy = Mass1
//
Mass1 = create_files.FindMassTableColumns(MapAll, types.MassFindMassBy_String)
types.MassFindMassBy = Mass1
//копируем все файлы
dir := micro.ProgramDir_bin()
err = folders.CopyAllFiles_Exclude_(dir+config.Settings.TEMPLATE_FOLDERNAME, dir+config.Settings.READY_FOLDERNAME)

View File

@ -52,13 +52,26 @@ var MapModelCrudDeleteFunctions = make(map[string]string, 0)
// MapRenameFunctions - карта функций которые будут переименованый в файлах crud
var MapRenameFunctions = make(map[string][]ReplaceStruct, 0)
type TableNameColumnNames struct {
// TableColumns_String - структура строк для загрузки из JSON
type TableColumns_String struct {
TableName string `json:"Table"`
MassColumnNames []string `json:"Columns"`
}
// MassFindBy_String - карта функций которые будут созданы для поиска 1 строки в таблице
var MassFindBy_String = make([]TableColumns_String, 0)
// MassFindMassBy_String - карта функций которые будут созданы для поиска много строк в таблице
var MassFindMassBy_String = make([]TableColumns_String, 0)
// TableColumns - структура таблица + колонки
type TableColumns struct {
Table *Table
Columns []*Column
}
// MassFindBy - карта функций которые будут созданы для поиска 1 строки в таблице
var MassFindBy = make([]TableNameColumnNames, 0)
var MassFindBy = make([]TableColumns, 0)
// MassFindMassBy - карта функций которые будут созданы для поиска много строк в таблице
var MassFindMassBy = make([]TableNameColumnNames, 0)
var MassFindMassBy = make([]TableColumns, 0)