mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-11-21 05:05:52 +02:00
сделал objects
This commit is contained in:
parent
ffc3504081
commit
292e17d711
@ -44,7 +44,7 @@ func ReadObject_ctx(ctx context.Context, db *gorm.DB, m *object_lawsuit_status_t
|
||||
Model := m.LawsuitStatusType
|
||||
err = crud_lawsuit_status_types.Read_ctx(ctx, db, &Model)
|
||||
if err != nil {
|
||||
err = fmt.Errorf(m.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithComma, err)
|
||||
err = fmt.Errorf(m.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithCommaM, err)
|
||||
}
|
||||
m.LawsuitStatusType = Model
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
//заполним FieldNameForeign
|
||||
FieldNameForeign := TableNameForeign.FieldNameForeign{}
|
||||
FieldNameForeign.PrimaryKeyNameF = m.FieldNameForeign
|
||||
err = crud_TableNameForeign.Read_ctx(ctx, db, &FieldNameForeign)
|
||||
//ObjectFieldNameTable
|
||||
ObjectFieldNameTable := TableNameForeign.ModelNameForeign{}
|
||||
ObjectFieldNameTable.PrimaryKeyNameF = m.FieldNameTable
|
||||
err = crud_TableNameForeign.Read_ctx(ctx, db, &ObjectFieldNameTable)
|
||||
if err != nil {
|
||||
err = fmt.Errorf(FieldNameForeign.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithComma, err)
|
||||
err = fmt.Errorf(ObjectFieldNameTable.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithCommaM, err)
|
||||
}
|
||||
m.Color = Color
|
||||
m.ObjectFieldNameTable = ObjectFieldNameTable
|
||||
|
||||
|
3
go.mod
3
go.mod
@ -5,7 +5,7 @@ go 1.22.0
|
||||
toolchain go1.22.1
|
||||
|
||||
require (
|
||||
github.com/ManyakRus/starter v1.0.58
|
||||
github.com/ManyakRus/starter v1.0.66
|
||||
github.com/alexsergivan/transliterator v1.0.1
|
||||
github.com/bxcodec/faker/v3 v3.8.1
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
@ -31,6 +31,7 @@ require (
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
golang.org/x/crypto v0.28.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.26.0 // indirect
|
||||
|
8
go.sum
8
go.sum
@ -3,8 +3,10 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJc
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8=
|
||||
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792 h1:bxwxD0H3kSUAH3uNk/b74gkImcUiP7dyibmMoVwk338=
|
||||
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792/go.mod h1:OUyxCVbPW/2lC1e6cM7Am941SJiC88BhNnb24x2R3a8=
|
||||
github.com/ManyakRus/starter v1.0.58 h1:/Sm97vILgqj8cmuqIPxcnM4EiROKG1eXLHf5isgkHHk=
|
||||
github.com/ManyakRus/starter v1.0.58/go.mod h1:U9WyHWnavyxu4+J5D6VpF3G2yZ4KagfSNM2Soo9O+7c=
|
||||
github.com/ManyakRus/starter v1.0.65 h1:3TvYfrO2N55qUziPFxuLCVZI3nGKmKupTb4v7zMbNqo=
|
||||
github.com/ManyakRus/starter v1.0.65/go.mod h1:U9WyHWnavyxu4+J5D6VpF3G2yZ4KagfSNM2Soo9O+7c=
|
||||
github.com/ManyakRus/starter v1.0.66 h1:wwX2Z6l35wzGs9bNCVAgBatK57ElYqzompBRBaXiWU4=
|
||||
github.com/ManyakRus/starter v1.0.66/go.mod h1:U9WyHWnavyxu4+J5D6VpF3G2yZ4KagfSNM2Soo9O+7c=
|
||||
github.com/alexsergivan/transliterator v1.0.1 h1:vON2ilWCHjq+S5Y4obhLGhHK4Y1VIhsHEtQlij5d9pI=
|
||||
github.com/alexsergivan/transliterator v1.0.1/go.mod h1:0IrumukulURJ4PD0z6UcdJKP2job1DYDhnHAP5y+5pE=
|
||||
github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM=
|
||||
@ -148,6 +150,8 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw
|
||||
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
|
||||
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
|
||||
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
|
@ -515,6 +515,25 @@ func AddSkipNow(Text string, Table1 *types.Table) string {
|
||||
func IsGood_Table(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
//есть Primary Key
|
||||
err = IsGood_PrimaryKeyColumnsCount(Table1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//название УДАЛИТЬ
|
||||
err = IsGood_TableName(Table1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// IsGood_TableName - возвращает ошибку если таблица неправильная
|
||||
func IsGood_TableName(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
err = IsGood_TableNamePrefix(Table1)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -525,11 +544,6 @@ func IsGood_Table(Table1 *types.Table) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = IsGood_PrimaryKeyColumnsCount(Table1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -538,7 +552,7 @@ func IsGood_PrimaryKeyColumnsCount(Table1 *types.Table) error {
|
||||
var err error
|
||||
|
||||
if Table1.PrimaryKeyColumnsCount <= 0 {
|
||||
TextError := fmt.Sprint("Wrong table: ", Table1.Name, " error: can not use many Primary key columns count: ", Table1.PrimaryKeyColumnsCount)
|
||||
TextError := fmt.Sprint("Wrong table: ", Table1.Name, ", error: can not use many Primary key columns count: ", Table1.PrimaryKeyColumnsCount)
|
||||
err = errors.New(TextError)
|
||||
}
|
||||
|
||||
@ -553,7 +567,7 @@ func IsGood_TableNamePrefix(Table1 *types.Table) error {
|
||||
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_")
|
||||
TextError := fmt.Sprint("Wrong table: ", Table1.Name, ", warning: name = DELETED_")
|
||||
err = errors.New(TextError)
|
||||
}
|
||||
|
||||
@ -568,7 +582,7 @@ func IsGood_TableCommentPrefix(Table1 *types.Table) error {
|
||||
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)
|
||||
TextError := fmt.Sprint("Wrong table: ", Table1.Name, ", warning: comment= ", TableComment)
|
||||
err = errors.New(TextError)
|
||||
}
|
||||
|
||||
@ -719,7 +733,7 @@ func Find_ModelTableURL(TableName string) string {
|
||||
func Find_ObjectTableURL(TableName string) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATES_READOBJECT_FOLDERNAME + "/" + TableName
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATES_READOBJECT_FOLDERNAME + "/object_" + TableName
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -728,7 +742,7 @@ func Find_ObjectTableURL(TableName string) string {
|
||||
func Find_CrudObjectTableURL(TableName string) string {
|
||||
Otvet := ""
|
||||
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATES_CRUD_READOBJECT_FOLDERNAME + "/" + TableName
|
||||
Otvet = config.Settings.SERVICE_REPOSITORY_URL + "/" + config.Settings.TEMPLATES_CRUD_READOBJECT_FOLDERNAME + "/" + config.Settings.PREFIX_CRUD_READOBJECT + TableName
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -2898,6 +2912,23 @@ func Find_FieldNamesWithComma_from_Mass(MassColumns []*types.Column) string {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// Find_FieldNamesWithComma_from_Mass_VariableName - возвращает строку в формате "Имя1: %v, Имя2: %v"
|
||||
func Find_FieldNamesWithComma_from_Mass_VariableName(MassColumns []*types.Column, VariableName string) string {
|
||||
Otvet := ""
|
||||
Comma := ""
|
||||
|
||||
if VariableName != "" && strings.HasSuffix(VariableName, ".") == false {
|
||||
VariableName = VariableName + "."
|
||||
}
|
||||
|
||||
for _, ColumnPK1 := range MassColumns {
|
||||
Otvet = Otvet + Comma + VariableName + ColumnPK1.NameGo
|
||||
Comma = ", "
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// Find_FieldNamesWithPercent_from_Table - возвращает строку в формате "Имя1: %v, Имя2: %v"
|
||||
func Find_FieldNamesWithPercent_from_Table(Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
@ -2917,3 +2948,13 @@ func Find_FieldNamesWithComma_from_Table(Table1 *types.Table) string {
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// Find_FieldNamesWithComma_from_Table_VariableName - возвращает строку в формате "VariableName.Имя1, VariableName.Имя2"
|
||||
func Find_FieldNamesWithComma_from_Table_VariableName(Table1 *types.Table, VariableName string) string {
|
||||
Otvet := ""
|
||||
|
||||
MassPK := Find_PrimaryKeyColumns(Table1)
|
||||
Otvet = Find_FieldNamesWithComma_from_Mass_VariableName(MassPK, VariableName)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
@ -4,13 +4,15 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// CreateAllFiles - создаёт все файлы в папке objects
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.IsGood_Table(Table1)
|
||||
if err1 != nil {
|
||||
|
@ -24,7 +24,7 @@ func CreateFiles_ReadObject(MapAll map[string]*types.Table, Table1 *types.Table)
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_READOBJECT_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyCrud + config.Settings.PREFIX_CRUD_READOBJECT + TableName
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD_READOBJECT + TableName
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD_READOBJECT + TableName + ".go"
|
||||
|
||||
//создадим каталог
|
||||
create_files.CreateDirectory(DirReadyTable)
|
||||
@ -52,9 +52,13 @@ func CreateFiles_ReadObject(MapAll map[string]*types.Table, Table1 *types.Table)
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextCrud = create_files.Delete_TemplateRepositoryImports(TextCrud)
|
||||
|
||||
//
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
////
|
||||
//ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
//TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
//crud foreign
|
||||
CrudTableURL := create_files.Find_CrudTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, CrudTableURL)
|
||||
|
||||
//
|
||||
ObjectTableURL := create_files.Find_ObjectTableURL(TableName)
|
||||
@ -71,16 +75,17 @@ func CreateFiles_ReadObject(MapAll map[string]*types.Table, Table1 *types.Table)
|
||||
FieldNamesWithPercent := create_files.Find_FieldNamesWithPercent_from_Table(Table1)
|
||||
TextCrud = strings.ReplaceAll(TextCrud, "FieldNamesWithPercent", FieldNamesWithPercent)
|
||||
|
||||
//FieldNamesWithComma
|
||||
FieldNamesWithComma := create_files.Find_FieldNamesWithComma_from_Table(Table1)
|
||||
TextCrud = strings.ReplaceAll(TextCrud, "FieldNamesWithComma", FieldNamesWithComma)
|
||||
//FieldNamesWithCommaM
|
||||
FieldNamesWithCommaM := create_files.Find_FieldNamesWithComma_from_Table_VariableName(Table1, "m")
|
||||
TextCrud = strings.ReplaceAll(TextCrud, "FieldNamesWithCommaM", FieldNamesWithCommaM)
|
||||
|
||||
//создание функций
|
||||
TextCrudFunc := CreateFiles_ReadObjectTable(MapAll, Table1, TextTemplatedFunction)
|
||||
if TextCrudFunc == "" {
|
||||
return err
|
||||
}
|
||||
TextCrud = TextCrud + TextCrudFunc
|
||||
TextCrud, TextCrudFunc := CreateFiles_ReadObjectTable(MapAll, Table1, TextCrud, TextTemplatedFunction)
|
||||
//if TextCrudFunc == "" {
|
||||
// return err
|
||||
//}
|
||||
//TextCrud = TextCrud + TextCrudFunc
|
||||
TextCrud = strings.ReplaceAll(TextCrud, "\t//TextFillManyFields", TextCrudFunc)
|
||||
|
||||
//создание текста
|
||||
TextCrud = create_files.Replace_TemplateModel_to_Model(TextCrud, Table1.NameGo)
|
||||
@ -113,19 +118,44 @@ func CreateFiles_ReadObject(MapAll map[string]*types.Table, Table1 *types.Table)
|
||||
}
|
||||
|
||||
// CreateFiles_ReadObjectTable - создаёт текст всех функций
|
||||
func CreateFiles_ReadObjectTable(MapAll map[string]*types.Table, Table1 *types.Table, TextTemplateFunction string) string {
|
||||
Otvet := ""
|
||||
func CreateFiles_ReadObjectTable(MapAll map[string]*types.Table, Table1 *types.Table, TextCrud0, TextTemplateFunction0 string) (TextCrud, TextTemplateFunction string) {
|
||||
TextCrud = TextCrud0
|
||||
TextTemplateFunction = ""
|
||||
|
||||
//
|
||||
MassImports := make([]string, 0)
|
||||
|
||||
//
|
||||
for _, Column1 := range Table1.MapColumns {
|
||||
IsForeignColumn := create_files.IsForeignColumn(MapAll, Column1)
|
||||
if IsForeignColumn == false {
|
||||
continue
|
||||
}
|
||||
Otvet1 := CreateFiles_ReadObject_Table1(MapAll, Table1, Column1, TextTemplateFunction)
|
||||
Otvet = Otvet + Otvet1
|
||||
|
||||
TableF, _ := create_files.Find_TableF_ColumnF(MapAll, Column1)
|
||||
TableNameF := TableF.Name
|
||||
|
||||
//шаблон функции
|
||||
TextTemplateFunction1 := CreateFiles_ReadObject_Table1(MapAll, Table1, Column1, TextTemplateFunction0)
|
||||
TextTemplateFunction = TextTemplateFunction + TextTemplateFunction1
|
||||
|
||||
//добавим импорты
|
||||
//Model
|
||||
ModelFTableURL := create_files.Find_ModelTableURL(TableNameF)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelFTableURL)
|
||||
|
||||
//crud foreign
|
||||
MassImports = append(MassImports, TableNameF)
|
||||
}
|
||||
|
||||
return Otvet
|
||||
//заполним импорты отсортированно
|
||||
for _, Import1 := range MassImports {
|
||||
CrudFTableURL := create_files.Find_CrudTableURL(Import1)
|
||||
TextCrud = create_files.AddImport(TextCrud, CrudFTableURL)
|
||||
|
||||
}
|
||||
|
||||
return TextCrud, TextTemplateFunction
|
||||
}
|
||||
|
||||
// CreateFiles_ReadObject_Table1 - создаёт текст всех функций
|
||||
@ -140,7 +170,7 @@ func CreateFiles_ReadObject_Table1(MapAll map[string]*types.Table, Table1 *types
|
||||
Otvet = strings.ReplaceAll(Otvet, "PrimaryKeyNameF", PrimaryKeyNameF)
|
||||
|
||||
//FieldNameForeign
|
||||
FieldNameForeign := ColumnF.Name
|
||||
FieldNameForeign := ColumnF.NameGo
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNameForeign", FieldNameForeign)
|
||||
|
||||
//TableNameForeign
|
||||
@ -151,10 +181,25 @@ func CreateFiles_ReadObject_Table1(MapAll map[string]*types.Table, Table1 *types
|
||||
FieldNamesWithPercent := create_files.Find_FieldNamesWithPercent_from_Table(Table1)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithPercent", FieldNamesWithPercent)
|
||||
|
||||
//FieldNamesWithCommaM
|
||||
FieldNamesWithCommaM := create_files.Find_FieldNamesWithComma_from_Table_VariableName(Table1, "m")
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithCommaM", FieldNamesWithCommaM)
|
||||
|
||||
//FieldNamesWithComma
|
||||
FieldNamesWithComma := create_files.Find_FieldNamesWithComma_from_Table(Table1)
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
|
||||
|
||||
//ModelNameForeign
|
||||
ModelNameForeign := TableF.NameGo
|
||||
Otvet = strings.ReplaceAll(Otvet, "ModelNameForeign", ModelNameForeign)
|
||||
|
||||
//FieldName
|
||||
FieldNameTable := Column1.NameGo
|
||||
Otvet = strings.ReplaceAll(Otvet, "FieldNameTable", FieldNameTable)
|
||||
|
||||
//crud_
|
||||
Otvet = strings.ReplaceAll(Otvet, " crud_", " "+config.Settings.PREFIX_CRUD)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
@ -172,7 +217,7 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
||||
FilenameTemplateCrud := DirTemplatesCrud + config.Settings.TEMPLATES_CRUD_TABLE_READOBJECT_TEST_FILENAME
|
||||
TableName := strings.ToLower(Table1.Name)
|
||||
DirReadyTable := DirReadyCrud + config.Settings.PREFIX_CRUD_READOBJECT + TableName + micro.SeparatorFile() + config.Settings.TESTS_FOLDERNAME
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD_READOBJECT + TableName
|
||||
FilenameReady := DirReadyTable + micro.SeparatorFile() + config.Settings.PREFIX_CRUD_READOBJECT + TableName + "_test.go"
|
||||
|
||||
//создадим каталог
|
||||
create_files.CreateDirectory(DirReadyTable)
|
||||
@ -200,9 +245,9 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
||||
if config.Settings.USE_DEFAULT_TEMPLATE == true {
|
||||
TextCrud = create_files.Delete_TemplateRepositoryImports(TextCrud)
|
||||
|
||||
//
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
////
|
||||
//ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
//TextCrud = create_files.AddImport(TextCrud, ModelTableURL)
|
||||
|
||||
//
|
||||
ObjectTableURL := create_files.Find_ObjectTableURL(TableName)
|
||||
@ -220,9 +265,9 @@ func CreateFiles_ReadObject_Test(MapAll map[string]*types.Table, Table1 *types.T
|
||||
CrudStarterURL := create_files.Find_CrudStarterURL()
|
||||
TextCrud = create_files.AddImport(TextCrud, CrudStarterURL)
|
||||
|
||||
////
|
||||
//CrudFuncURL := create_files.Find_CrudFuncURL(TableName)
|
||||
//TextCrud = create_files.AddImport(TextCrud, CrudFuncURL)
|
||||
//
|
||||
CrudFuncURL := create_files.Find_CrudFuncURL(TableName)
|
||||
TextCrud = create_files.AddImport(TextCrud, CrudFuncURL)
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@ import (
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.IsGood_Table(Table1)
|
||||
if err1 != nil {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -12,7 +13,8 @@ import (
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.IsGood_Table(Table1)
|
||||
if err1 != nil {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// CreateAllFiles - создаёт все файлы в папке model
|
||||
@ -12,9 +13,10 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
//для каждой таблицы
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка имени таблицы "DELETED_"
|
||||
err1 := create_files.IsGood_TableNamePrefix(Table1)
|
||||
err1 := create_files.IsGood_TableName(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err)
|
||||
continue
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@ -13,7 +14,8 @@ import (
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.IsGood_Table(Table1)
|
||||
if err1 != nil {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// CreateAllFiles - создаёт все файлы в папке model
|
||||
@ -11,18 +12,19 @@ func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
//для каждой таблицы
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка имени таблицы "DELETED_"
|
||||
err1 := create_files.IsGood_TableNamePrefix(Table1)
|
||||
err1 := create_files.IsGood_TableName(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err)
|
||||
log.Warn("CreateFiles() table: ", Table1.Name, ", warning: ", err1)
|
||||
continue
|
||||
}
|
||||
|
||||
//создание файлов
|
||||
err = CreateFiles(MapAll, Table1)
|
||||
if err != nil {
|
||||
log.Error("CreateFiles() table: ", Table1.Name, " error: ", err)
|
||||
log.Error("CreateFiles() table: ", Table1.Name, ", error: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ func CreateFiles(MapAll map[string]*types.Table, Table1 *types.Table) error {
|
||||
|
||||
TextGo = CreateFiles1(MapAll, Table1, TextGo)
|
||||
|
||||
//ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
//TextGo = create_files.AddImport(TextGo, ModelTableURL)
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableName)
|
||||
TextGo = create_files.AddImport(TextGo, ModelTableURL)
|
||||
|
||||
}
|
||||
|
||||
@ -97,6 +97,7 @@ func CreateFiles1(MapAll map[string]*types.Table, Table1 *types.Table, TextGo st
|
||||
err = create_files.IsGood_Column(Column1)
|
||||
if err != nil {
|
||||
log.Warn("CreateFiles1() table: ", Table1.Name, " column: ", Column1.Name, " warning: ", err)
|
||||
continue
|
||||
}
|
||||
|
||||
//проверка есть внешний ключ
|
||||
@ -123,10 +124,10 @@ func CreateFiles1(MapAll map[string]*types.Table, Table1 *types.Table, TextGo st
|
||||
|
||||
//добавим import
|
||||
ModelTableURL := create_files.Find_ModelTableURL(TableNameFK)
|
||||
TextGo = create_files.AddImport(TextGo, ModelTableURL)
|
||||
Otvet = create_files.AddImport(Otvet, ModelTableURL)
|
||||
|
||||
//добавим поле
|
||||
TextField1 := "\t" + Column1.NameGo + " " + TableFK.Name + "." + TableFK.NameGo + "\n"
|
||||
TextField1 := "\tObject" + Column1.NameGo + " " + TableFK.Name + "." + TableFK.NameGo + "\n"
|
||||
TextField = TextField + TextField1
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"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"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -12,7 +13,8 @@ import (
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка что таблица нормальная
|
||||
err1 := create_files.IsGood_Table(Table1)
|
||||
if err1 != nil {
|
||||
|
@ -17,9 +17,10 @@ import (
|
||||
func CreateAllFiles(MapAll map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
for _, Table1 := range MapAll {
|
||||
MassAll := micro.MassFrom_Map(MapAll)
|
||||
for _, Table1 := range MassAll {
|
||||
//проверка имени таблицы "DELETED_"
|
||||
err1 := create_files.IsGood_TableNamePrefix(Table1)
|
||||
err1 := create_files.IsGood_TableName(Table1)
|
||||
if err1 != nil {
|
||||
log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err)
|
||||
continue
|
||||
|
202
vendor/github.com/ManyakRus/starter/micro/microfunctions.go
generated
vendored
202
vendor/github.com/ManyakRus/starter/micro/microfunctions.go
generated
vendored
@ -9,7 +9,9 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/exp/constraints"
|
||||
"hash/fnv"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sort"
|
||||
@ -1004,3 +1006,203 @@ func Int32FromString(s string) (int32, error) {
|
||||
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
// ExecuteShellCommand - выполняет команду в shell, и возвращает строку результата
|
||||
func ExecuteShellCommand(TextCommand string, args ...string) (string, error) {
|
||||
Otvet := ""
|
||||
var err error
|
||||
|
||||
MassByte, err := exec.Command(TextCommand, args...).CombinedOutput()
|
||||
Otvet = string(MassByte)
|
||||
if err != nil {
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
// DeleteEndEndline - убирает в конце "\n"
|
||||
func DeleteEndEndline(Text string) string {
|
||||
Otvet := Text
|
||||
|
||||
if Otvet == "" {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
LastSymbol := Otvet[len(Otvet)-1:]
|
||||
if LastSymbol == "\n" {
|
||||
Otvet = Otvet[0 : len(Otvet)-1]
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// Find_Directory_ModifiedTime - возвращает дату последнего изменения в папке internal
|
||||
func Find_Directory_ModifiedTime(FolderName string) (time.Time, error) {
|
||||
var Otvet time.Time
|
||||
var err error
|
||||
|
||||
dir := ProgramDir()
|
||||
dir = dir + FolderName
|
||||
|
||||
ok, err := FileExists(dir)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Find_Directory_ModifiedTime() FileExists() error: %w", err)
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
if ok == false {
|
||||
err = fmt.Errorf("Find_Directory_ModifiedTime() FileExists() error: file not exists: %s", dir)
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
//найдём дату папки
|
||||
f, err := os.Open(dir)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Find_Directory_ModifiedTime() os.Open() error: %w", err)
|
||||
return Otvet, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
stat, err := f.Stat()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Find_Directory_ModifiedTime() f.Stat() error: %w", err)
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
Otvet = stat.ModTime()
|
||||
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
// Show_Repository_Code_ModifiedTime - выводит дату последнего изменения в папках cmd, internal, pkg, vendor
|
||||
func Show_Repository_Code_ModifiedTime() {
|
||||
Date, err := Find_Repository_Code_ModifiedTime()
|
||||
if err != nil {
|
||||
println("Find_Repository_Code_ModifiedTime() error: ", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if Date.IsZero() {
|
||||
println("Last repository code modified time: not found")
|
||||
return
|
||||
}
|
||||
|
||||
println("Last repository code modified time: ", Date.String())
|
||||
|
||||
}
|
||||
|
||||
// Find_Repository_Code_ModifiedTime - возвращает дату последнего изменения в папках cmd, internal, pkg, vendor
|
||||
func Find_Repository_Code_ModifiedTime() (time.Time, error) {
|
||||
var Otvet time.Time
|
||||
var err error
|
||||
|
||||
//cmd
|
||||
Time_cmd, err := Find_Directory_ModifiedTime("cmd")
|
||||
if err != nil {
|
||||
//return Otvet, err
|
||||
}
|
||||
|
||||
//internal
|
||||
Time_internal, err := Find_Directory_ModifiedTime("internal")
|
||||
if err != nil {
|
||||
//return Otvet, err
|
||||
}
|
||||
|
||||
//pkg
|
||||
Time_pkg, err := Find_Directory_ModifiedTime("pkg")
|
||||
if err != nil {
|
||||
//return Otvet, err
|
||||
}
|
||||
|
||||
//vendor
|
||||
Time_vendor, err := Find_Directory_ModifiedTime("vendor")
|
||||
if err != nil {
|
||||
//return Otvet, err
|
||||
}
|
||||
|
||||
//выбираем максимальную дату
|
||||
Otvet = TimeMax(Time_cmd, Time_internal, Time_pkg, Time_vendor)
|
||||
|
||||
return Otvet, err
|
||||
}
|
||||
|
||||
// TimeMax - возвращает максимальную дату
|
||||
func TimeMax(x time.Time, y ...time.Time) time.Time {
|
||||
maxTime := x
|
||||
for _, val := range y {
|
||||
if val.After(maxTime) {
|
||||
maxTime = val
|
||||
}
|
||||
}
|
||||
return maxTime
|
||||
}
|
||||
|
||||
// TimeMin - возвращает минимальную дату
|
||||
func TimeMin(x time.Time, y ...time.Time) time.Time {
|
||||
minTime := x
|
||||
for _, val := range y {
|
||||
if val.Before(minTime) {
|
||||
minTime = val
|
||||
}
|
||||
}
|
||||
return minTime
|
||||
}
|
||||
|
||||
// Show_Version - выводит версию сервиса на экран
|
||||
func Show_Version(Version string) {
|
||||
println("Service version: ", Version)
|
||||
}
|
||||
|
||||
// MassFrom_MapString - сортирует map по названию колонок и возвращает слайс
|
||||
func MassFrom_MapString[V any](Map map[string]V) []V {
|
||||
Otvet := make([]V, 0)
|
||||
|
||||
//сортировка по названию колонок
|
||||
keys := make([]string, 0, len(Map))
|
||||
for k := range Map {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
//
|
||||
for _, key1 := range keys {
|
||||
Value, ok := Map[key1]
|
||||
if ok == false {
|
||||
fmt.Printf("Map[%s] not found\n", key1)
|
||||
}
|
||||
Otvet = append(Otvet, Value)
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// SortMass - сортирует слайс
|
||||
func SortMass[T constraints.Ordered](s []T) {
|
||||
sort.Slice(s, func(i, j int) bool {
|
||||
return s[i] < s[j]
|
||||
})
|
||||
}
|
||||
|
||||
// MassFrom_Map - сортирует map по названию колонок и возвращает слайс
|
||||
func MassFrom_Map[C constraints.Ordered, V any](Map map[C]V) []V {
|
||||
Otvet := make([]V, 0)
|
||||
|
||||
//сортировка по названию колонок
|
||||
keys := make([]C, 0, len(Map))
|
||||
for k := range Map {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
SortMass(keys)
|
||||
|
||||
//
|
||||
for _, key1 := range keys {
|
||||
Value, ok := Map[key1]
|
||||
if ok == false {
|
||||
fmt.Printf("Map[%v] not found\n", key1)
|
||||
}
|
||||
Otvet = append(Otvet, Value)
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
27
vendor/golang.org/x/exp/LICENSE
generated
vendored
Normal file
27
vendor/golang.org/x/exp/LICENSE
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright 2009 The Go Authors.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
22
vendor/golang.org/x/exp/PATENTS
generated
vendored
Normal file
22
vendor/golang.org/x/exp/PATENTS
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Additional IP Rights Grant (Patents)
|
||||
|
||||
"This implementation" means the copyrightable works distributed by
|
||||
Google as part of the Go project.
|
||||
|
||||
Google hereby grants to You a perpetual, worldwide, non-exclusive,
|
||||
no-charge, royalty-free, irrevocable (except as stated in this section)
|
||||
patent license to make, have made, use, offer to sell, sell, import,
|
||||
transfer and otherwise run, modify and propagate the contents of this
|
||||
implementation of Go, where such license applies only to those patent
|
||||
claims, both currently owned or controlled by Google and acquired in
|
||||
the future, licensable by Google that are necessarily infringed by this
|
||||
implementation of Go. This grant does not include claims that would be
|
||||
infringed only as a consequence of further modification of this
|
||||
implementation. If you or your agent or exclusive licensee institute or
|
||||
order or agree to the institution of patent litigation against any
|
||||
entity (including a cross-claim or counterclaim in a lawsuit) alleging
|
||||
that this implementation of Go or any code incorporated within this
|
||||
implementation of Go constitutes direct or contributory patent
|
||||
infringement, or inducement of patent infringement, then any patent
|
||||
rights granted to you under this License for this implementation of Go
|
||||
shall terminate as of the date such litigation is filed.
|
50
vendor/golang.org/x/exp/constraints/constraints.go
generated
vendored
Normal file
50
vendor/golang.org/x/exp/constraints/constraints.go
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2021 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package constraints defines a set of useful constraints to be used
|
||||
// with type parameters.
|
||||
package constraints
|
||||
|
||||
// Signed is a constraint that permits any signed integer type.
|
||||
// If future releases of Go add new predeclared signed integer types,
|
||||
// this constraint will be modified to include them.
|
||||
type Signed interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64
|
||||
}
|
||||
|
||||
// Unsigned is a constraint that permits any unsigned integer type.
|
||||
// If future releases of Go add new predeclared unsigned integer types,
|
||||
// this constraint will be modified to include them.
|
||||
type Unsigned interface {
|
||||
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
||||
}
|
||||
|
||||
// Integer is a constraint that permits any integer type.
|
||||
// If future releases of Go add new predeclared integer types,
|
||||
// this constraint will be modified to include them.
|
||||
type Integer interface {
|
||||
Signed | Unsigned
|
||||
}
|
||||
|
||||
// Float is a constraint that permits any floating-point type.
|
||||
// If future releases of Go add new predeclared floating-point types,
|
||||
// this constraint will be modified to include them.
|
||||
type Float interface {
|
||||
~float32 | ~float64
|
||||
}
|
||||
|
||||
// Complex is a constraint that permits any complex numeric type.
|
||||
// If future releases of Go add new predeclared complex numeric types,
|
||||
// this constraint will be modified to include them.
|
||||
type Complex interface {
|
||||
~complex64 | ~complex128
|
||||
}
|
||||
|
||||
// Ordered is a constraint that permits any ordered type: any type
|
||||
// that supports the operators < <= >= >.
|
||||
// If future releases of Go add new ordered types,
|
||||
// this constraint will be modified to include them.
|
||||
type Ordered interface {
|
||||
Integer | Float | ~string
|
||||
}
|
5
vendor/modules.txt
vendored
5
vendor/modules.txt
vendored
@ -1,7 +1,7 @@
|
||||
# github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792
|
||||
## explicit; go 1.13
|
||||
github.com/ManyakRus/logrus
|
||||
# github.com/ManyakRus/starter v1.0.58
|
||||
# github.com/ManyakRus/starter v1.0.66
|
||||
## explicit; go 1.22.0
|
||||
github.com/ManyakRus/starter/config_main
|
||||
github.com/ManyakRus/starter/constants
|
||||
@ -84,6 +84,9 @@ github.com/serenize/snaker
|
||||
# golang.org/x/crypto v0.28.0
|
||||
## explicit; go 1.20
|
||||
golang.org/x/crypto/pbkdf2
|
||||
# golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
|
||||
## explicit; go 1.22.0
|
||||
golang.org/x/exp/constraints
|
||||
# golang.org/x/mod v0.21.0
|
||||
## explicit; go 1.22.0
|
||||
golang.org/x/mod/internal/lazyregexp
|
||||
|
Loading…
Reference in New Issue
Block a user