mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-22 00:36:41 +02:00
сделал CreateFilesUpdateEveryColumn()
This commit is contained in:
parent
119710afec
commit
33b784ca4f
@ -173,4 +173,10 @@ TEMPLATES_CRUD_FILENAME="crud_tables_rapira.go_"
|
||||
TEMPLATES_CRUD_TEST_FILENAME="crud_tables_rapira_test.go_"
|
||||
|
||||
#NEED_CREATE_UPDATE_EVERY_COLUMN - fill true if you want create Update_ColumnName() function for every column
|
||||
NEED_CREATE_UPDATE_EVERY_COLUMN=true
|
||||
NEED_CREATE_UPDATE_EVERY_COLUMN=true
|
||||
|
||||
#TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME - short filename of "crud_table_update_func.go_" file
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME="crud_table_update_func.go_"
|
||||
|
||||
#TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME - short filename of "crud_table_update_func_test.go_" file
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME="crud_table_update_func_test.go_"
|
40
bin/templates/pkg/db/crud/crud_table_update_func.go_
Normal file
40
bin/templates/pkg/db/crud/crud_table_update_func.go_
Normal file
@ -0,0 +1,40 @@
|
||||
// Read - изменяет 1 поле Name в базе данных
|
||||
func (crud Crud_DB) Read(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
ctxMain := contextmain.GetContext()
|
||||
ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
|
||||
defer ctxCancelFunc()
|
||||
|
||||
err = crud.Read_ctx(ctx, m)
|
||||
return err
|
||||
}
|
||||
|
||||
// Read_ctx - изменяет 1 поле Name в базе данных
|
||||
func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
if micro.ContextDone(ctx) == true {
|
||||
err = context.Canceled
|
||||
return err
|
||||
}
|
||||
|
||||
//ID не должен быть =0
|
||||
if m.ID == 0 {
|
||||
err = errors.New("Read() error: ID=0")
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
db := postgres_gorm.GetConnection()
|
||||
db.WithContext(ctx)
|
||||
|
||||
//
|
||||
tx := db.Model(&m).Update("Name", m.ID)
|
||||
err = tx.Error
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Read() id: %v, error: %v", m.ID, err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
16
bin/templates/pkg/db/crud/crud_table_update_func_test.go_
Normal file
16
bin/templates/pkg/db/crud/crud_table_update_func_test.go_
Normal file
@ -0,0 +1,16 @@
|
||||
func TestRead(t *testing.T) {
|
||||
config_main.LoadEnv()
|
||||
|
||||
postgres_gorm.Connect()
|
||||
defer postgres_gorm.CloseConnection()
|
||||
|
||||
crud := Crud_DB{}
|
||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||
Otvet.ID = Postgres_ID_Test
|
||||
Otvet.ColumnName = DefaultValue
|
||||
err := crud.Read(&Otvet)
|
||||
if err != nil {
|
||||
t.Error("TestRead() error: ", err)
|
||||
}
|
||||
|
||||
}
|
@ -14,62 +14,64 @@ var Settings SettingsINI
|
||||
|
||||
// SettingsINI - структура для хранения всех нужных переменных окружения
|
||||
type SettingsINI struct {
|
||||
INCLUDE_TABLES string
|
||||
EXCLUDE_TABLES string
|
||||
TEMPLATE_FOLDERNAME string
|
||||
TEMPLATE_FOLDERNAME_MODEL string
|
||||
TEMPLATE_FOLDERNAME_DB string
|
||||
TEMPLATE_FOLDERNAME_CRUD string
|
||||
TEMPLATE_FOLDERNAME_TABLES string
|
||||
TEMPLATE_FOLDERNAME_GRPC string
|
||||
TEMPLATE_FOLDERNAME_GRPC_PROTO string
|
||||
TEMPLATE_FOLDERNAME_GRPC_SERVER string
|
||||
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
|
||||
TEMPLATE_FOLDERNAME_NRPC string
|
||||
TEMPLATE_FOLDERNAME_NRPC_SERVER string
|
||||
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
|
||||
TEMPLATE_FOLDERNAME_GRPC_NRPC string
|
||||
TEMPLATE_SERVICE_NAME string
|
||||
TEMPLATE_FOLDERNAME_CRUD_STARTER string
|
||||
TEMPLATE_FOLDERNAME_ALIAS string
|
||||
TEMPLATE_FOLDER_CRUD_FUNCTIONS string
|
||||
TEMPLATE_FOLDERNAME_MAIN string
|
||||
TEMPLATE_REPOSITORY_URL string
|
||||
TEMPLATE_EXTERNAL_PROTO_FILENAME string
|
||||
TEMPLATES_CRUD_FILENAME string
|
||||
TEMPLATES_CRUD_TEST_FILENAME string
|
||||
TEMPLATES_ALIAS_FILENAME string
|
||||
NEED_CREATE_MODEL_STRUCT bool
|
||||
NEED_CREATE_MODEL_CRUD bool
|
||||
NEED_CREATE_DB bool
|
||||
NEED_CREATE_DB_TEST bool
|
||||
NEED_CREATE_DB_TABLES bool
|
||||
NEED_CREATE_GRPC bool
|
||||
NEED_CREATE_GRPC_SERVER_TEST bool
|
||||
NEED_CREATE_GRPC_CLIENT_TEST bool
|
||||
NEED_CREATE_NRPC bool
|
||||
NEED_CREATE_NRPC_SERVER_TEST bool
|
||||
NEED_CREATE_NRPC_CLIENT_TEST bool
|
||||
NEED_CREATE_MANUAL_FILES bool
|
||||
SERVICE_NAME string
|
||||
SERVICE_REPOSITORY_URL string
|
||||
TEXT_TEMPLATE_MODEL string
|
||||
TEXT_TEMPLATE_TABLENAME string
|
||||
HAS_IS_DELETED bool
|
||||
READY_FOLDERNAME string
|
||||
TEXT_DB_MODIFIED_AT string
|
||||
TEXT_DB_CREATED_AT string
|
||||
TEXT_DB_IS_DELETED string
|
||||
USE_DEFAULT_TEMPLATE bool
|
||||
PREFIX_SERVER_GRPC string
|
||||
PREFIX_CLIENT_GRPC string
|
||||
PREFIX_CRUD string
|
||||
PREFIX_MODEL string
|
||||
PREFIX_TABLE string
|
||||
COMMENT_MODEL_STRUCT string
|
||||
TEXT_MODULE_GENERATED string
|
||||
READY_ALIAS_FILENAME string
|
||||
NEED_CREATE_UPDATE_EVERY_COLUMN bool
|
||||
INCLUDE_TABLES string
|
||||
EXCLUDE_TABLES string
|
||||
TEMPLATE_FOLDERNAME string
|
||||
TEMPLATE_FOLDERNAME_MODEL string
|
||||
TEMPLATE_FOLDERNAME_DB string
|
||||
TEMPLATE_FOLDERNAME_CRUD string
|
||||
TEMPLATE_FOLDERNAME_TABLES string
|
||||
TEMPLATE_FOLDERNAME_GRPC string
|
||||
TEMPLATE_FOLDERNAME_GRPC_PROTO string
|
||||
TEMPLATE_FOLDERNAME_GRPC_SERVER string
|
||||
TEMPLATE_FOLDERNAME_GRPC_CLIENT string
|
||||
TEMPLATE_FOLDERNAME_NRPC string
|
||||
TEMPLATE_FOLDERNAME_NRPC_SERVER string
|
||||
TEMPLATE_FOLDERNAME_NRPC_CLIENT string
|
||||
TEMPLATE_FOLDERNAME_GRPC_NRPC string
|
||||
TEMPLATE_SERVICE_NAME string
|
||||
TEMPLATE_FOLDERNAME_CRUD_STARTER string
|
||||
TEMPLATE_FOLDERNAME_ALIAS string
|
||||
TEMPLATE_FOLDER_CRUD_FUNCTIONS string
|
||||
TEMPLATE_FOLDERNAME_MAIN string
|
||||
TEMPLATE_REPOSITORY_URL string
|
||||
TEMPLATE_EXTERNAL_PROTO_FILENAME string
|
||||
TEMPLATES_CRUD_FILENAME string
|
||||
TEMPLATES_CRUD_TEST_FILENAME string
|
||||
TEMPLATES_ALIAS_FILENAME string
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME string
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME string
|
||||
NEED_CREATE_MODEL_STRUCT bool
|
||||
NEED_CREATE_MODEL_CRUD bool
|
||||
NEED_CREATE_DB bool
|
||||
NEED_CREATE_DB_TEST bool
|
||||
NEED_CREATE_DB_TABLES bool
|
||||
NEED_CREATE_GRPC bool
|
||||
NEED_CREATE_GRPC_SERVER_TEST bool
|
||||
NEED_CREATE_GRPC_CLIENT_TEST bool
|
||||
NEED_CREATE_NRPC bool
|
||||
NEED_CREATE_NRPC_SERVER_TEST bool
|
||||
NEED_CREATE_NRPC_CLIENT_TEST bool
|
||||
NEED_CREATE_MANUAL_FILES bool
|
||||
SERVICE_NAME string
|
||||
SERVICE_REPOSITORY_URL string
|
||||
TEXT_TEMPLATE_MODEL string
|
||||
TEXT_TEMPLATE_TABLENAME string
|
||||
HAS_IS_DELETED bool
|
||||
READY_FOLDERNAME string
|
||||
TEXT_DB_MODIFIED_AT string
|
||||
TEXT_DB_CREATED_AT string
|
||||
TEXT_DB_IS_DELETED string
|
||||
USE_DEFAULT_TEMPLATE bool
|
||||
PREFIX_SERVER_GRPC string
|
||||
PREFIX_CLIENT_GRPC string
|
||||
PREFIX_CRUD string
|
||||
PREFIX_MODEL string
|
||||
PREFIX_TABLE string
|
||||
COMMENT_MODEL_STRUCT string
|
||||
TEXT_MODULE_GENERATED string
|
||||
READY_ALIAS_FILENAME string
|
||||
NEED_CREATE_UPDATE_EVERY_COLUMN bool
|
||||
}
|
||||
|
||||
// FillSettings загружает переменные окружения в структуру из переменных окружения
|
||||
@ -181,6 +183,8 @@ func FillSettings() {
|
||||
Settings.READY_ALIAS_FILENAME = os.Getenv("READY_ALIAS_FILENAME")
|
||||
Settings.NEED_CREATE_UPDATE_EVERY_COLUMN = BoolFromString(os.Getenv("NEED_CREATE_UPDATE_EVERY_COLUMN"))
|
||||
Settings.PREFIX_CLIENT_GRPC = os.Getenv("PREFIX_CLIENT_GRPC")
|
||||
Settings.TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME = os.Getenv("TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME")
|
||||
Settings.TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME = os.Getenv("TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME")
|
||||
|
||||
}
|
||||
|
||||
|
@ -456,6 +456,8 @@ func FindTextDefaultValue(Type_go string) string {
|
||||
Otvet = "0"
|
||||
case "time.Time":
|
||||
Otvet = "time.Time{}"
|
||||
case "bool":
|
||||
Otvet = "false"
|
||||
}
|
||||
|
||||
return Otvet
|
||||
@ -841,7 +843,7 @@ func DeleteEmptyLines(Text string) string {
|
||||
Otvet = strings.ReplaceAll(Otvet, "\n\t//\n\n", "\n\n")
|
||||
//Otvet = strings.ReplaceAll(Otvet, "\r\r", "\r")
|
||||
//Otvet = strings.ReplaceAll(Otvet, "\r\n", "\n")
|
||||
Otvet = strings.ReplaceAll(Otvet, "}\n\n", "}\n")
|
||||
//Otvet = strings.ReplaceAll(Otvet, "}\n\n", "}\n")
|
||||
pos1 := strings.Index(Otvet, "\n\n\n")
|
||||
if pos1 >= 0 {
|
||||
Otvet = DeleteEmptyLines(Otvet)
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -33,6 +34,7 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//тестовые файлы db
|
||||
if config.Settings.NEED_CREATE_DB_TEST == true {
|
||||
err = CreateTestFiles(Table1)
|
||||
@ -41,6 +43,22 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if config.Settings.NEED_CREATE_UPDATE_EVERY_COLUMN == true {
|
||||
//файлы db update
|
||||
err = CreateFilesUpdateEveryColumn(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
//тестовые файлы db update
|
||||
err = CreateTestFilesUpdateEveryColumn(Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateTestFiles() table: ", Table1.Name, " error: ", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
@ -436,3 +454,259 @@ func RenameFunctions(TextDB string, Table1 *types.Table) string {
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_client
|
||||
func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesCrud := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
DirReadyCrud := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME
|
||||
DirReadyTable := DirReadyCrud
|
||||
FilenameReadyCrudUpdate := DirReadyTable + config.Settings.PREFIX_CRUD + TableName + "_update.go"
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyTable)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateCrud)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
}
|
||||
TextCrudUpdateFunc := string(bytes)
|
||||
|
||||
TextCrud := "package " + config.Settings.PREFIX_CRUD + TableName + "\n\n"
|
||||
TextCrud = TextCrud + `import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
)
|
||||
|
||||
`
|
||||
|
||||
//заменим импорты
|
||||
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
DBConstantsURL := create_files.FindDBConstantsURL()
|
||||
TextCrud = create_files.AddImport(TextCrud, DBConstantsURL)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
|
||||
//}
|
||||
|
||||
//создание текста
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextCrudUpdateFunc, Table1)
|
||||
// пустой файл не нужен
|
||||
if TextUpdateEveryColumn == "" {
|
||||
return err
|
||||
}
|
||||
|
||||
//ModelName := Table1.NameGo
|
||||
//TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
//TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextCrud = TextCrud + TextUpdateEveryColumn
|
||||
|
||||
TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud
|
||||
|
||||
//удаление пустого импорта
|
||||
TextCrud = create_files.DeleteEmptyImport(TextCrud)
|
||||
TextCrud = create_files.DeleteEmptyLines(TextCrud)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyCrudUpdate, []byte(TextCrud), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumn - возвращает текст для всех таблиц
|
||||
func FindTextUpdateEveryColumn(TextCrudUpdateFunc string, Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
//сортировка по названию таблиц
|
||||
keys := make([]string, 0, len(Table1.MapColumns))
|
||||
for k := range Table1.MapColumns {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
//найдём новый текст для каждой таблицы
|
||||
for _, key1 := range keys {
|
||||
Column1, ok := Table1.MapColumns[key1]
|
||||
if ok == false {
|
||||
log.Panic("FindTextUpdateEveryColumn() Table1.MapColumns[key1] = false")
|
||||
}
|
||||
if create_files.Is_Common_Сolumn(Column1) == true {
|
||||
continue
|
||||
}
|
||||
|
||||
TextColumn1 := FindTextUpdateEveryColumn1(TextCrudUpdateFunc, Table1, Column1)
|
||||
Otvet = Otvet + TextColumn1 + "\n\n"
|
||||
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumn1 - возвращает текст для одной таблицы
|
||||
func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
|
||||
Otvet := TextCrudUpdateFunc
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
FuncName := "Update_" + ColumnName
|
||||
TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo)
|
||||
|
||||
//заменяем Read_ctx()
|
||||
Otvet = strings.ReplaceAll(Otvet, " Read_ctx ", " "+FuncName+"_ctx ")
|
||||
Otvet = strings.ReplaceAll(Otvet, " Read_ctx(", " "+FuncName+"_ctx(")
|
||||
Otvet = strings.ReplaceAll(Otvet, ".Read_ctx(", "."+FuncName+"_ctx(")
|
||||
|
||||
//заменяем Read()
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL+"_Read", ModelName+"_"+FuncName)
|
||||
Otvet = strings.ReplaceAll(Otvet, " Read ", " "+FuncName+" ")
|
||||
Otvet = strings.ReplaceAll(Otvet, " Read(", " "+FuncName+"(")
|
||||
Otvet = strings.ReplaceAll(Otvet, `"Read()`, `"`+FuncName+"()")
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest)
|
||||
Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Model.ID", "Model."+ColumnName)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextRequestFieldName)
|
||||
Otvet = strings.ReplaceAll(Otvet, " Name ", " "+ColumnName+" ")
|
||||
Otvet = strings.ReplaceAll(Otvet, `"Name"`, `"`+ColumnName+`"`)
|
||||
//Otvet = strings.ReplaceAll(Otvet, "m.ID", "m."+ColumnName)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_client
|
||||
func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
|
||||
//чтение файлов
|
||||
DirBin := micro.ProgramDir_bin()
|
||||
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
|
||||
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
|
||||
DirTemplatesCrud := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile()
|
||||
DirReadyCrud := DirReady + config.Settings.TEMPLATE_FOLDERNAME_CRUD + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + micro.SeparatorFile()
|
||||
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_UPDATE_FUNC_TEST_FILENAME
|
||||
DirReadyTable := DirReadyCrud
|
||||
FilenameReadyCrudUpdate := DirReadyTable + config.Settings.PREFIX_CRUD + TableName + "_update_test.go"
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyTable)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateCrud)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
}
|
||||
TextCrudUpdateFunc := string(bytes)
|
||||
|
||||
TextCrud := "package " + config.Settings.PREFIX_CRUD + TableName + "\n\n"
|
||||
TextCrud = TextCrud + `import (
|
||||
"testing"
|
||||
"errors"
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
)
|
||||
|
||||
`
|
||||
|
||||
//заменим импорты
|
||||
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1)
|
||||
//}
|
||||
|
||||
//создание текста
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextCrudUpdateFunc, Table1)
|
||||
// пустой файл не нужен
|
||||
if TextUpdateEveryColumn == "" {
|
||||
return err
|
||||
}
|
||||
//ModelName := Table1.NameGo
|
||||
//TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
//TextCrud = strings.ReplaceAll(TextCrud, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextCrud = TextCrud + TextUpdateEveryColumn
|
||||
|
||||
TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud
|
||||
|
||||
//удаление пустого импорта
|
||||
TextCrud = create_files.DeleteEmptyImport(TextCrud)
|
||||
TextCrud = create_files.DeleteEmptyLines(TextCrud)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyCrudUpdate, []byte(TextCrud), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumnTest - возвращает текст для всех таблиц
|
||||
func FindTextUpdateEveryColumnTest(TextCrudUpdateFunc string, Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
//сортировка по названию таблиц
|
||||
keys := make([]string, 0, len(Table1.MapColumns))
|
||||
for k := range Table1.MapColumns {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
//найдём новый текст для каждой таблицы
|
||||
for _, key1 := range keys {
|
||||
Column1, ok := Table1.MapColumns[key1]
|
||||
if ok == false {
|
||||
log.Panic("FindTextUpdateEveryColumnTest() Table1.MapColumns[key1] = false")
|
||||
}
|
||||
if create_files.Is_Common_Сolumn(Column1) == true {
|
||||
continue
|
||||
}
|
||||
|
||||
TextColumn1 := FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc, Table1, Column1)
|
||||
Otvet = Otvet + TextColumn1 + "\n\n"
|
||||
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumnTest1 - возвращает текст для одной таблицы
|
||||
func FindTextUpdateEveryColumnTest1(TextCrudUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
|
||||
Otvet := TextCrudUpdateFunc
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
FuncName := "Update_" + ColumnName
|
||||
TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Column1.TypeGo)
|
||||
DefaultValue := create_files.FindTextDefaultValue(Column1.TypeGo)
|
||||
|
||||
Otvet = strings.ReplaceAll(Otvet, " TestCrud_GRPC_Read(", " TestCrud_GRPC_"+FuncName+"(")
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
Otvet = strings.ReplaceAll(Otvet, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
Otvet = strings.ReplaceAll(Otvet, "grpc_proto.RequestId", "grpc_proto."+TextRequest)
|
||||
Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Model.ID", "Model."+ColumnName)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextRequestFieldName)
|
||||
Otvet = strings.ReplaceAll(Otvet, "Otvet.Name", "Otvet."+ColumnName)
|
||||
//Otvet = strings.ReplaceAll(Otvet, "Postgres_ID_Test", DefaultValue)
|
||||
Otvet = strings.ReplaceAll(Otvet, "TestRead(", "Test"+FuncName+"(")
|
||||
Otvet = strings.ReplaceAll(Otvet, ".Read(", "."+FuncName+"(")
|
||||
Otvet = strings.ReplaceAll(Otvet, " DefaultValue", " "+DefaultValue)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
//TextGRPCServer = create_files.ReplaceServiceURLImports(TextGRPCServer)
|
||||
//TextGRPCClient = create_files.ReplaceServiceURLImports(TextGRPCClient)
|
||||
TextGRPCClient = create_files.DeleteTemplateRepositoryImports(TextGRPCClient)
|
||||
|
||||
//proto
|
||||
@ -353,7 +353,7 @@ func DeleteFuncTestFind_byExtID(Text, ModelName string, Table1 *types.Table) str
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_server
|
||||
// CreateFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_client
|
||||
func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
@ -377,9 +377,9 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err)
|
||||
}
|
||||
TextGRPCServerUpdateFunc := string(bytes)
|
||||
TextGRPC_ClientUpdateFunc := string(bytes)
|
||||
|
||||
TextGRPC_Client := "package " + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "\n\n"
|
||||
TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n"
|
||||
TextGRPC_Client = TextGRPC_Client + `import (
|
||||
"context"
|
||||
"time"
|
||||
@ -412,7 +412,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
//}
|
||||
|
||||
//создание текста
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc, Table1)
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumn(TextGRPC_ClientUpdateFunc, Table1)
|
||||
// пустой файл не нужен
|
||||
if TextUpdateEveryColumn == "" {
|
||||
return err
|
||||
@ -436,7 +436,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumn - возвращает текст для всех таблиц
|
||||
func FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc string, Table1 *types.Table) string {
|
||||
func FindTextUpdateEveryColumn(TextGRPC_ClientUpdateFunc string, Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
//сортировка по названию таблиц
|
||||
@ -456,7 +456,7 @@ func FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc string, Table1 *types.Ta
|
||||
continue
|
||||
}
|
||||
|
||||
TextColumn1 := FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc, Table1, Column1)
|
||||
TextColumn1 := FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc, Table1, Column1)
|
||||
Otvet = Otvet + TextColumn1 + "\n\n"
|
||||
|
||||
}
|
||||
@ -465,8 +465,8 @@ func FindTextUpdateEveryColumn(TextGRPCServerUpdateFunc string, Table1 *types.Ta
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumn1 - возвращает текст для одной таблицы
|
||||
func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
|
||||
Otvet := TextGRPCServerUpdateFunc
|
||||
func FindTextUpdateEveryColumn1(TextGRPC_ClientUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
|
||||
Otvet := TextGRPC_ClientUpdateFunc
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
@ -488,7 +488,7 @@ func FindTextUpdateEveryColumn1(TextGRPCServerUpdateFunc string, Table1 *types.T
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_server
|
||||
// CreateTestFilesUpdateEveryColumn - создаёт 1 файл в папке grpc_client
|
||||
func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
@ -512,10 +512,10 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateGRPC_Client, " error: ", err)
|
||||
}
|
||||
TextGRPCServerUpdateFunc := string(bytes)
|
||||
TextGRPC_ClientUpdateFunc := string(bytes)
|
||||
|
||||
TextGRPCClient := "package " + config.Settings.TEMPLATE_FOLDERNAME_GRPC + "\n\n"
|
||||
TextGRPCClient = TextGRPCClient + `import (
|
||||
TextGRPC_Client := "package " + config.Settings.PREFIX_CLIENT_GRPC + TableName + "\n\n"
|
||||
TextGRPC_Client = TextGRPC_Client + `import (
|
||||
"testing"
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
)
|
||||
@ -525,39 +525,39 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
//заменим импорты
|
||||
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
GRPCClientURL := create_files.FindGRPClientURL()
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, GRPCClientURL)
|
||||
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, GRPCClientURL)
|
||||
|
||||
ModelTableURL := create_files.FindModelTableURL(TableName)
|
||||
TextGRPCClient = create_files.AddImport(TextGRPCClient, ModelTableURL)
|
||||
TextGRPC_Client = create_files.AddImport(TextGRPC_Client, ModelTableURL)
|
||||
|
||||
TextGRPCClient = create_files.ConvertIdToAlias(TextGRPCClient, Table1)
|
||||
TextGRPC_Client = create_files.ConvertIdToAlias(TextGRPC_Client, Table1)
|
||||
//}
|
||||
|
||||
//создание текста
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc, Table1)
|
||||
TextUpdateEveryColumn := FindTextUpdateEveryColumnTest(TextGRPC_ClientUpdateFunc, Table1)
|
||||
// пустой файл не нужен
|
||||
if TextUpdateEveryColumn == "" {
|
||||
return err
|
||||
}
|
||||
//ModelName := Table1.NameGo
|
||||
//TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
//TextGRPCClient = strings.ReplaceAll(TextGRPCClient, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextGRPCClient = TextGRPCClient + TextUpdateEveryColumn
|
||||
//TextGRPC_Client = strings.ReplaceAll(TextGRPC_Client, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||
//TextGRPC_Client = strings.ReplaceAll(TextGRPC_Client, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||
TextGRPC_Client = TextGRPC_Client + TextUpdateEveryColumn
|
||||
|
||||
TextGRPCClient = config.Settings.TEXT_MODULE_GENERATED + TextGRPCClient
|
||||
TextGRPC_Client = config.Settings.TEXT_MODULE_GENERATED + TextGRPC_Client
|
||||
|
||||
//удаление пустого импорта
|
||||
TextGRPCClient = create_files.DeleteEmptyImport(TextGRPCClient)
|
||||
TextGRPCClient = create_files.DeleteEmptyLines(TextGRPCClient)
|
||||
TextGRPC_Client = create_files.DeleteEmptyImport(TextGRPC_Client)
|
||||
TextGRPC_Client = create_files.DeleteEmptyLines(TextGRPC_Client)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyGRPC_ClientUpdate, []byte(TextGRPCClient), constants.FILE_PERMISSIONS)
|
||||
err = os.WriteFile(FilenameReadyGRPC_ClientUpdate, []byte(TextGRPC_Client), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumnTest - возвращает текст для всех таблиц
|
||||
func FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc string, Table1 *types.Table) string {
|
||||
func FindTextUpdateEveryColumnTest(TextGRPC_ClientUpdateFunc string, Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
|
||||
//сортировка по названию таблиц
|
||||
@ -577,7 +577,7 @@ func FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc string, Table1 *type
|
||||
continue
|
||||
}
|
||||
|
||||
TextColumn1 := FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc, Table1, Column1)
|
||||
TextColumn1 := FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc, Table1, Column1)
|
||||
Otvet = Otvet + TextColumn1 + "\n\n"
|
||||
|
||||
}
|
||||
@ -586,8 +586,8 @@ func FindTextUpdateEveryColumnTest(TextGRPCServerUpdateFunc string, Table1 *type
|
||||
}
|
||||
|
||||
// FindTextUpdateEveryColumnTest1 - возвращает текст для одной таблицы
|
||||
func FindTextUpdateEveryColumnTest1(TextGRPCServerUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
|
||||
Otvet := TextGRPCServerUpdateFunc
|
||||
func FindTextUpdateEveryColumnTest1(TextGRPC_ClientUpdateFunc string, Table1 *types.Table, Column1 *types.Column) string {
|
||||
Otvet := TextGRPC_ClientUpdateFunc
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
ColumnName := Column1.NameGo
|
||||
|
Loading…
Reference in New Issue
Block a user