mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-22 00:36:41 +02:00
сделал TEMPLATES_CRUD_TABLE_UPDATE_FILENAME
This commit is contained in:
parent
1fdb9c8453
commit
95a94e1bfd
@ -194,4 +194,11 @@ TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME="model_crud_delete_functions.json
|
||||
TEMPLATES_NAME_REPLACE_FILENAME="name_replace.json"
|
||||
|
||||
#TEMPLATES_NULLABLE_FILENAME - short filename of "nullable.json" file
|
||||
TEMPLATES_NULLABLE_FILENAME="nullable.json"
|
||||
TEMPLATES_NULLABLE_FILENAME="nullable.json"
|
||||
|
||||
#TEMPLATES_CRUD_TABLE_UPDATE_FILENAME - short filename of "crud_table_update.go_" file
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_FILENAME="crud_table_update.go_"
|
||||
|
||||
#TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME - short filename of "crud_table_update_test.go_" file
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME="crud_table_update_test.go_"
|
||||
|
||||
|
14
bin/templates/pkg/db/crud/crud_table_update.go_
Normal file
14
bin/templates/pkg/db/crud/crud_table_update.go_
Normal file
@ -0,0 +1,14 @@
|
||||
package crud_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
// Read - изменяет 1 поле Name в базе данных
|
||||
// Read - изменяет 1 поле ColumnName в базе данных
|
||||
func (crud Crud_DB) Read(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
@ -10,7 +10,7 @@ func (crud Crud_DB) Read(m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read_ctx - изменяет 1 поле Name в базе данных
|
||||
// Read_ctx - изменяет 1 поле ColumnName в базе данных
|
||||
func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
|
||||
var err error
|
||||
|
||||
|
8
bin/templates/pkg/db/crud/crud_table_update_test.go_
Normal file
8
bin/templates/pkg/db/crud/crud_table_update_test.go_
Normal file
@ -0,0 +1,8 @@
|
||||
package crud_lawsuit_status_types
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||
"testing"
|
||||
)
|
@ -46,6 +46,8 @@ type SettingsINI struct {
|
||||
TEMPLATES_MODEL_CRUD_DELETE_FUNCTIONS_FILENAME string
|
||||
TEMPLATES_NAME_REPLACE_FILENAME string
|
||||
TEMPLATES_NULLABLE_FILENAME string
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_FILENAME string
|
||||
TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME string
|
||||
NEED_CREATE_MODEL_STRUCT bool
|
||||
NEED_CREATE_MODEL_CRUD bool
|
||||
NEED_CREATE_DB bool
|
||||
@ -413,6 +415,17 @@ func FillSettings() {
|
||||
Name = "TEMPLATES_NULLABLE_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATES_NULLABLE_FILENAME = s
|
||||
|
||||
//
|
||||
Name = "TEMPLATES_CRUD_TABLE_UPDATE_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATES_CRUD_TABLE_UPDATE_FILENAME = s
|
||||
|
||||
//
|
||||
Name = "TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
Settings.TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME = s
|
||||
|
||||
}
|
||||
|
||||
// CurrentDirectory - возвращает текущую директорию ОС
|
||||
|
@ -474,32 +474,45 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
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
|
||||
FilenameTemplateCrudFunc := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_UPDATE_FUNC_FILENAME
|
||||
DirReadyTable := DirReadyCrud
|
||||
FilenameReadyCrudUpdate := DirReadyTable + config.Settings.PREFIX_CRUD + TableName + "_update.go"
|
||||
FilenameReadyCrudUpdateFunc := DirReadyTable + config.Settings.PREFIX_CRUD + TableName + "_update.go"
|
||||
|
||||
//создадим папку готовых файлов
|
||||
folders.CreateFolder(DirReadyTable)
|
||||
|
||||
bytes, err := os.ReadFile(FilenameTemplateCrud)
|
||||
//читаем шаблон файла, только функции
|
||||
bytes, err := os.ReadFile(FilenameTemplateCrudFunc)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrudFunc, " error: ", err)
|
||||
}
|
||||
TextCrudUpdateFunc := string(bytes)
|
||||
|
||||
TextCrud := "package " + config.Settings.PREFIX_CRUD + TableName + "\n\n"
|
||||
TextCrud = TextCrud + `import (
|
||||
"errors"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"gorm.io/gorm"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
)
|
||||
//читаем шаблон файла, без функций
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_UPDATE_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateCrud)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
}
|
||||
TextCrud := string(bytes)
|
||||
TextCrud = TextCrud + "\n"
|
||||
|
||||
`
|
||||
//заменим имя пакета на новое
|
||||
TextCrud = create_files.ReplacePackageName(TextCrud, DirReadyTable)
|
||||
|
||||
// TextCrud := "package " + config.Settings.PREFIX_CRUD + TableName + "\n\n"
|
||||
// TextCrud = TextCrud + `import (
|
||||
// "errors"
|
||||
// "context"
|
||||
// "fmt"
|
||||
// "time"
|
||||
// "gorm.io/gorm"
|
||||
// "github.com/ManyakRus/starter/contextmain"
|
||||
// "github.com/ManyakRus/starter/micro"
|
||||
// "github.com/ManyakRus/starter/postgres_gorm"
|
||||
//)
|
||||
//
|
||||
//`
|
||||
|
||||
//заменим импорты
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
@ -533,7 +546,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
TextCrud = create_files.DeleteEmptyLines(TextCrud)
|
||||
|
||||
//запись файла
|
||||
err = os.WriteFile(FilenameReadyCrudUpdate, []byte(TextCrud), constants.FILE_PERMISSIONS)
|
||||
err = os.WriteFile(FilenameReadyCrudUpdateFunc, []byte(TextCrud), constants.FILE_PERMISSIONS)
|
||||
|
||||
return err
|
||||
}
|
||||
@ -618,27 +631,40 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
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
|
||||
FilenameTemplateCrudFunc := 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)
|
||||
//читаем шаблон файла, только функции
|
||||
bytes, err := os.ReadFile(FilenameTemplateCrudFunc)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrudFunc, " error: ", err)
|
||||
}
|
||||
TextCrudUpdateFunc := string(bytes)
|
||||
|
||||
TextCrud := "package " + config.Settings.PREFIX_CRUD + TableName + "\n\n"
|
||||
TextCrud = TextCrud + `import (
|
||||
"testing"
|
||||
"github.com/ManyakRus/starter/config_main"
|
||||
"github.com/ManyakRus/starter/postgres_gorm"
|
||||
)
|
||||
//читаем шаблон файла, без функций
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_UPDATE_TEST_FILENAME
|
||||
bytes, err = os.ReadFile(FilenameTemplateCrud)
|
||||
if err != nil {
|
||||
log.Panic("ReadFile() ", FilenameTemplateCrud, " error: ", err)
|
||||
}
|
||||
TextCrud := string(bytes)
|
||||
TextCrud = TextCrud + "\n"
|
||||
|
||||
`
|
||||
//заменим имя пакета на новое
|
||||
TextCrud = create_files.ReplacePackageName(TextCrud, DirReadyTable)
|
||||
|
||||
// TextCrud := "package " + config.Settings.PREFIX_CRUD + TableName + "\n\n"
|
||||
// TextCrud = TextCrud + `import (
|
||||
// "testing"
|
||||
// "github.com/ManyakRus/starter/config_main"
|
||||
// "github.com/ManyakRus/starter/postgres_gorm"
|
||||
//)
|
||||
//
|
||||
//`
|
||||
|
||||
//заменим импорты
|
||||
//if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
|
Loading…
Reference in New Issue
Block a user