1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-11-21 05:05:52 +02:00

сделал CreateFiles_FindModelBy()

This commit is contained in:
Nikitin Aleksandr 2024-11-02 11:53:38 +03:00
parent c3702173c3
commit decc46e081
24 changed files with 334 additions and 233 deletions

View File

@ -0,0 +1,11 @@
package object_lawsuit_status_types
import (
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
)
// ObjectLawsuitStatusType - объект для таблицы lawsuit_status_types: Статусы дел (справочник).
type ObjectLawsuitStatusType struct {
lawsuit_status_types.LawsuitStatusType
//TextNewFields
}

View File

@ -218,6 +218,17 @@ type SettingsINI struct {
TEXT_READALL string
NEED_USE_DB_VIEWS bool
//Objects
PREFIX_OBJECT string
TEMPLATE_FOLDERNAME_OBJECTS string
TEMPLATES_OBJECTS_FILENAME string
//Text DELETED
TEXT_DELETED_TABLE string
TEXT_DELETED_TABLE_RUS string
TEXT_DELETED_COLUMN string
TEXT_DELETED_COLUMN_RUS string
}
// Getenv - возвращает переменную окружения
@ -1141,6 +1152,41 @@ func FillSettings() {
s = Getenv(Name, true)
Settings.TEMPLATES_NAME_PRIMARYKEYS_FILENAME = s
//
Name = "TEMPLATE_FOLDERNAME_OBJECTS"
s = Getenv(Name, true)
Settings.TEMPLATE_FOLDERNAME_OBJECTS = s
//
Name = "TEMPLATES_OBJECTS_FILENAME"
s = Getenv(Name, true)
Settings.TEMPLATES_OBJECTS_FILENAME = s
//
Name = "PREFIX_OBJECT"
s = Getenv(Name, true)
Settings.PREFIX_OBJECT = s
//
Name = "TEXT_DELETED_TABLE"
s = Getenv(Name, true)
Settings.TEXT_DELETED_TABLE = s
//
Name = "TEXT_DELETED_TABLE_RUS"
s = Getenv(Name, true)
Settings.TEXT_DELETED_TABLE_RUS = s
//
Name = "TEXT_DELETED_COLUMN"
s = Getenv(Name, true)
Settings.TEXT_DELETED_COLUMN = s
//
Name = "TEXT_DELETED_COLUMN_RUS"
s = Getenv(Name, true)
Settings.TEXT_DELETED_COLUMN_RUS = s
}
// CurrentDirectory - возвращает текущую директорию ОС

View File

@ -10,6 +10,7 @@ import (
"github.com/ManyakRus/starter/micro"
"github.com/gobeam/stringy"
"github.com/jinzhu/inflection"
"os"
"slices"
"sort"
"strconv"
@ -549,7 +550,9 @@ func IsGood_TableNamePrefix(Table1 *types.Table) error {
var err error
TableName := Table1.Name
if strings.HasPrefix(TableName, "DELETED_") == true {
HasPrefix := strings.HasPrefix(TableName, config.Settings.TEXT_DELETED_TABLE)
HasPrefixRus := strings.HasPrefix(TableName, config.Settings.TEXT_DELETED_TABLE_RUS)
if HasPrefix == true || HasPrefixRus == true {
TextError := fmt.Sprint("Wrong table: ", Table1.Name, " error: name = DELETED_")
err = errors.New(TextError)
}
@ -562,7 +565,9 @@ func IsGood_TableCommentPrefix(Table1 *types.Table) error {
var err error
TableComment := Table1.Comment
if strings.HasPrefix(TableComment, "DELETED") == true || strings.HasPrefix(TableComment, "УДАЛИТЬ") == true {
HasPrefix := strings.HasPrefix(TableComment, config.Settings.TEXT_DELETED_TABLE)
HasPrefixRus := strings.HasPrefix(TableComment, config.Settings.TEXT_DELETED_TABLE_RUS)
if HasPrefix == true || HasPrefixRus == true {
TextError := fmt.Sprint("Wrong table: ", Table1.Name, " error: comment: ", TableComment)
err = errors.New(TextError)
}
@ -2749,3 +2754,64 @@ func ColumnNamesGo_WithQuotes(ColumnsPK []*types.Column) string {
return Otvet
}
// IsGood_Column - возвращает ошибку если колонка неправильная
func IsGood_Column(Column1 *types.Column) error {
var err error
err = IsGood_ColumnNamePrefix(Column1)
if err != nil {
return err
}
err = IsGood_ColumnCommentPrefix(Column1)
if err != nil {
return err
}
return err
}
// IsGood_ColumnNamePrefix - возвращает ошибку если префикс таблицы = "DELETED_"
func IsGood_ColumnNamePrefix(Column1 *types.Column) error {
var err error
ColumnName := Column1.Name
HasPrefix := strings.HasPrefix(ColumnName, config.Settings.TEXT_DELETED_COLUMN)
HasPrefixRus := strings.HasPrefix(ColumnName, config.Settings.TEXT_DELETED_COLUMN_RUS)
if HasPrefix == true || HasPrefixRus == true {
TextError := fmt.Sprint("Wrong column: ", ColumnName, " error: name = DELETED_")
err = errors.New(TextError)
}
return err
}
// IsGood_ColumnCommentPrefix - возвращает ошибку если префикс комментария колонки = "DELETED_"
func IsGood_ColumnCommentPrefix(Column1 *types.Column) error {
var err error
ColumnComment := Column1.Description
HasPrefix := strings.HasPrefix(ColumnComment, config.Settings.TEXT_DELETED_COLUMN)
HasPrefixRus := strings.HasPrefix(ColumnComment, config.Settings.TEXT_DELETED_COLUMN_RUS)
if HasPrefix == true || HasPrefixRus == true {
TextError := fmt.Sprint("Wrong table: ", ColumnComment, " error: comment: ", ColumnComment)
err = errors.New(TextError)
}
return err
}
// CreateDirectory - создает каталог на диске, если его нет
func CreateDirectory(DirectoryName string) {
var err error
//создадим каталог
ok, err := micro.FileExists(DirectoryName)
if ok == false {
err = os.MkdirAll(DirectoryName, 0777)
if err != nil {
log.Panic("Mkdir() ", DirectoryName, " error: ", err)
}
}
}

View File

@ -77,13 +77,7 @@ func CreateFiles(Table1 *types.Table) error {
FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + config.Settings.STARTER_TABLES_PREFIX + TableName + ".go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
bytes, err := os.ReadFile(FilenameTemplateDB)
if err != nil {
@ -202,14 +196,9 @@ func CreateFiles_manual(Table1 *types.Table) error {
FilenameReadyManual := DirReadyTable + micro.SeparatorFile() + config.Settings.STARTER_TABLES_PREFIX + TableName + "_manual.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//
bytes, err := os.ReadFile(FilenameTemplateDB)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateDB, " error: ", err)
@ -266,14 +255,9 @@ func CreateFiles_manual_test(Table1 *types.Table) error {
FilenameReadyManual := DirReadyTable + micro.SeparatorFile() + config.Settings.STARTER_TABLES_PREFIX + TableName + "_manual_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//
bytes, err := os.ReadFile(FilenameTemplateDB)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateDB, " error: ", err)

View File

@ -30,13 +30,7 @@ func CreateFiles(Table1 *types.Table) error {
FilenameReadyDB := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + ".go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateDB)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)
@ -181,13 +175,7 @@ func CreateFiles_FindBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindMassBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findmassby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)
@ -198,13 +192,7 @@ func CreateFiles_FindMassBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findmassby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindModelBy(MapAll map[string]*types.Table, Table1 *types.Table
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findmodelby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)
@ -221,13 +215,7 @@ func CreateFiles_FindModelBy_Test(MapAll map[string]*types.Table, Table1 *types.
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findmodelby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)

View File

@ -31,13 +31,7 @@ func CreateFiles_ReadAll(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_readall.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)
@ -160,13 +154,7 @@ func CreateFiles_ReadAll_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_readall_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)

View File

@ -32,13 +32,7 @@ func CreateFiles_FindBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_MODEL + TableName + "_findby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateModel)

View File

@ -32,13 +32,7 @@ func CreateFiles_FindMassBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_MODEL + TableName + "_findmassby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateModel)
@ -190,13 +184,7 @@ func CreateFiles_FindMassBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD + TableName + "_findmassby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateCrud)

View File

@ -32,13 +32,7 @@ func CreateFiles_FindModelBy(MapAll map[string]*types.Table, Table1 *types.Table
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_MODEL + TableName + "_findmodelby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateModel)

View File

@ -32,13 +32,7 @@ func CreateFiles_ReadAll(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_MODEL + TableName + "_readall.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateModel)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
@ -201,13 +195,7 @@ func CreateFiles_FindBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindMassBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findmassby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
@ -210,13 +204,7 @@ func CreateFiles_FindMassBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findmassby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindModelBy(MapAll map[string]*types.Table, Table1 *types.Table
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findmodelby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
@ -229,13 +223,7 @@ func CreateFiles_FindModelBy_Test(MapAll map[string]*types.Table, Table1 *types.
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_findmodelby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)

View File

@ -31,13 +31,7 @@ func CreateFiles_ReadAll(Table1 *types.Table) error {
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_readall.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)
@ -166,13 +160,7 @@ func CreateFiles_ReadAll_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + config.Settings.PREFIX_CLIENT_GRPC + TableName + "_readall_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCClient)

View File

@ -0,0 +1,32 @@
package object_tables
import (
"github.com/ManyakRus/crud_generator/internal/create_files"
"github.com/ManyakRus/crud_generator/internal/types"
"github.com/ManyakRus/starter/log"
)
// CreateAllFiles - создаёт все файлы в папке model
func CreateAllFiles(MapAll map[string]*types.Table) error {
var err error
//для каждой таблицы
for _, Table1 := range MapAll {
//проверка имени таблицы "DELETED_"
err1 := create_files.IsGood_TableNamePrefix(Table1)
if err1 != nil {
log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err)
continue
}
//создание файлов
err = CreateFiles(MapAll, Table1)
if err != nil {
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
return err
}
}
return err
}

View File

@ -0,0 +1,134 @@
package object_tables
import (
"github.com/ManyakRus/crud_generator/internal/config"
"github.com/ManyakRus/crud_generator/internal/create_files"
"github.com/ManyakRus/crud_generator/internal/types"
"github.com/ManyakRus/starter/log"
"github.com/ManyakRus/starter/micro"
"os"
"strings"
)
// CreateFiles - создаёт 1 файл в папке db
func CreateFiles(MapAll map[string]*types.Table, Table1 *types.Table) error {
var err error
//чтение файлов
DirBin := micro.ProgramDir_bin()
DirTemplates := DirBin + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile()
DirReady := DirBin + config.Settings.READY_FOLDERNAME + micro.SeparatorFile()
DirTemplatesObjects := DirTemplates + config.Settings.TEMPLATE_FOLDERNAME_OBJECTS + micro.SeparatorFile()
DirReadyDB := DirReady + config.Settings.TEMPLATE_FOLDERNAME_OBJECTS + micro.SeparatorFile()
FilenameTemplateObject := DirTemplatesObjects + config.Settings.TEMPLATES_OBJECTS_FILENAME
TableName := strings.ToLower(Table1.Name)
DirReadyTable := DirReadyDB + config.Settings.PREFIX_OBJECT + TableName
FilenameReadyObjects := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_OBJECT + TableName + ".go"
//создадим каталог
create_files.CreateDirectory(DirReadyTable)
//ok, err := micro.FileExists(DirReadyTable)
//if ok == false {
// err = os.MkdirAll(DirReadyTable, 0777)
// if err != nil {
// log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
// }
//}
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateObject)
if err != nil {
log.Panic("ReadFile() ", FilenameTemplateObject, " error: ", err)
}
TextGo := string(bytes)
//заменим имя пакета на новое
TextGo = create_files.Replace_PackageName(TextGo, DirReadyTable)
//ModelName := Table1.NameGo
//заменим импорты
if config.Settings.USE_DEFAULT_TEMPLATE == true {
TextGo = create_files.Delete_TemplateRepositoryImports(TextGo)
TextGo = CreateFiles1(MapAll, Table1, TextGo)
//ModelTableURL := create_files.Find_ModelTableURL(TableName)
//TextGo = create_files.AddImport(TextGo, ModelTableURL)
}
////замена импортов на новые URL
//TextGo = create_files.Replace_RepositoryImportsURL(TextGo)
//uuid
TextGo = create_files.CheckAndAdd_ImportUUID_FromText(TextGo)
//alias
TextGo = create_files.CheckAndAdd_ImportAlias(TextGo)
//удаление пустого импорта
TextGo = create_files.Delete_EmptyImport(TextGo)
//импорт "fmt"
TextGo = create_files.CheckAndAdd_ImportFmt(TextGo)
//удаление пустых строк
TextGo = create_files.Delete_EmptyLines(TextGo)
//запись файла
err = os.WriteFile(FilenameReadyObjects, []byte(TextGo), config.Settings.FILE_PERMISSIONS)
return err
}
// CreateFiles1 - возвращает текст заполненный
func CreateFiles1(MapAll map[string]*types.Table, Table1 *types.Table, TextGo string) string {
Otvet := TextGo
var err error
//
TextField := ""
for _, Column1 := range Table1.MapColumns {
//проверка имени колонки "DELETED_"
err1 := create_files.IsGood_Column(Column1)
if err1 != nil {
log.Warn("CreateFiles1() table: ", Table1.Name, " column: ", Column1.Name, " warning: ", err)
}
//проверка есть внешний ключ
TableNameFK := Column1.TableKey
if TableNameFK == "" {
continue
}
//ColumnNameFK := Column1.ColumnKey
//if ColumnNameFK == "" {
// continue
//}
//
TableFK, ok := MapAll[TableNameFK]
if ok == false {
continue
}
//ColumnFK := TableFK.MapColumns[ColumnNameFK]
//if ColumnFK == nil {
// continue
//}
//добавим import
ModelTableURL := create_files.Find_ModelTableURL(TableNameFK)
TextGo = create_files.AddImport(TextGo, ModelTableURL)
//добавим поле
TextField1 := "\t" + Column1.NameGo + " " + TableFK.Name + "." + TableFK.NameGo + "\n"
TextField = TextField + TextField1
}
Otvet = strings.ReplaceAll(Otvet, "//TextNewFields\n", TextField)
return Otvet
}

View File

@ -31,13 +31,7 @@ func CreateFiles_FindBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_findby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
@ -192,13 +186,7 @@ func CreateFiles_FindBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_findby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindMassBy(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_findmassby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
@ -200,13 +194,7 @@ func CreateFiles_FindMassBy_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_findmassby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)

View File

@ -31,13 +31,7 @@ func CreateFiles_FindModelBy(MapAll map[string]*types.Table, Table1 *types.Table
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_findmodelby.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
@ -220,13 +214,7 @@ func CreateFiles_FindModelBy_Test(MapAll map[string]*types.Table, Table1 *types.
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_findmodelby_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)

View File

@ -31,13 +31,7 @@ func CreateFiles_ReadAll(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_readall.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)
@ -153,13 +147,7 @@ func CreateFiles_ReadAll_Test(Table1 *types.Table) error {
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_SERVER_GRPC + TableName + "_readall_test.go"
//создадим каталог
ok, err := micro.FileExists(DirReadyTable)
if ok == false {
err = os.MkdirAll(DirReadyTable, 0777)
if err != nil {
log.Panic("Mkdir() ", DirReadyTable, " error: ", err)
}
}
create_files.CreateDirectory(DirReadyTable)
//загрузим шаблон файла
bytes, err := os.ReadFile(FilenameTemplateGRPCServer)

View File

@ -18,6 +18,7 @@ import (
"github.com/ManyakRus/crud_generator/internal/create_files/main_file"
"github.com/ManyakRus/crud_generator/internal/create_files/makefile"
"github.com/ManyakRus/crud_generator/internal/create_files/nrpc_client"
"github.com/ManyakRus/crud_generator/internal/create_files/object_tables"
"github.com/ManyakRus/crud_generator/internal/create_files/protobuf"
"github.com/ManyakRus/crud_generator/internal/create_files/readme_file"
"github.com/ManyakRus/crud_generator/internal/create_files/server_grpc_func"
@ -231,6 +232,13 @@ func StartFillAll() error {
return err
}
//objects
err = object_tables.CreateAllFiles(MapAll)
if err != nil {
//log.Error("env_file.CreateAllFiles() error: ", err)
return err
}
return err
}