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

сделал objects

This commit is contained in:
Nikitin Aleksandr 2024-11-06 10:53:25 +03:00
parent 292e17d711
commit f09ac2a582
4 changed files with 58 additions and 12 deletions

View File

@ -1,9 +1,9 @@
//ObjectFieldNameTable
ObjectFieldNameTable := TableNameForeign.ModelNameForeign{}
ObjectFieldNameTable.PrimaryKeyNameF = m.FieldNameTable
err = crud_TableNameForeign.Read_ctx(ctx, db, &ObjectFieldNameTable)
ModelNameColumn:= TableNameForeign.ModelNameForeign{}
ModelNameColumn.PrimaryKeyNameF = m.FieldNameTable
err = crud_TableNameForeign.Read_ctx(ctx, db, &ModelNameColumn)
if err != nil {
err = fmt.Errorf(ObjectFieldNameTable.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithCommaM, err)
err = fmt.Errorf(ModelNameColumn.TableNameDB()+" Read() FieldNamesWithPercent, error: %w", FieldNamesWithCommaM, err)
}
m.ObjectFieldNameTable = ObjectFieldNameTable
m.ModelNameColumn = ModelNameColumn

View File

@ -2958,3 +2958,44 @@ func Find_FieldNamesWithComma_from_Table_VariableName(Table1 *types.Table, Varia
return Otvet
}
// Find_ObjectColumnModelName - возвращает имя модели для колонки у Object = "ModelИмяКолонкиБезИД"
func Find_ObjectColumnModelName(ColumnName string) string {
Otvet := ColumnName
//добавим _model если не кончается на ID
Otvet = Otvet + "_model"
//
len1 := len(ColumnName)
if len1 >= 3 && strings.HasSuffix(ColumnName, "ID") == true {
Otvet1 := strings.TrimSuffix(ColumnName, "ID")
len2 := len(Otvet1)
if len2 > 0 {
s2 := Otvet1[len2-1:]
if s2 == strings.ToLower(s2) {
Otvet = Otvet1
}
}
}
return Otvet
}
//// DeleteSuffixID_small_previous - убирает ID суффикс, только если последняя буква маленькая
//func DeleteSuffixID_small_previous(ModelName string) string {
// Otvet := ModelName
//
// //убираем ID суффикс
// //только если последняя буква маленькая
// Otvet1 := strings.TrimSuffix(ModelName, "ID")
// len1 := len(Otvet1)
// if len1 > 0 {
// s2 := Otvet1[len1-2:]
// if s2 == strings.ToLower(s2) {
// Otvet = Otvet1
// }
// }
//
// return Otvet
//}

View File

@ -162,19 +162,19 @@ func CreateFiles_ReadObjectTable(MapAll map[string]*types.Table, Table1 *types.T
func CreateFiles_ReadObject_Table1(MapAll map[string]*types.Table, Table1 *types.Table, Column1 *types.Column, TextTemplateFunction string) string {
Otvet := TextTemplateFunction
TableF, ColumnF := create_files.Find_TableF_ColumnF(MapAll, Column1)
ColumnPKF := create_files.Find_PrimaryKeyColumn(TableF)
TableFK, ColumnFK := create_files.Find_TableF_ColumnF(MapAll, Column1)
ColumnPKF := create_files.Find_PrimaryKeyColumn(TableFK)
//PrimaryKeyNameF
PrimaryKeyNameF := ColumnPKF.NameGo
Otvet = strings.ReplaceAll(Otvet, "PrimaryKeyNameF", PrimaryKeyNameF)
//FieldNameForeign
FieldNameForeign := ColumnF.NameGo
FieldNameForeign := ColumnFK.NameGo
Otvet = strings.ReplaceAll(Otvet, "FieldNameForeign", FieldNameForeign)
//TableNameForeign
TableNameForeign := TableF.Name
TableNameForeign := TableFK.Name
Otvet = strings.ReplaceAll(Otvet, "TableNameForeign", TableNameForeign)
//FieldNamesWithPercent
@ -190,13 +190,17 @@ func CreateFiles_ReadObject_Table1(MapAll map[string]*types.Table, Table1 *types
Otvet = strings.ReplaceAll(Otvet, "FieldNamesWithComma", FieldNamesWithComma)
//ModelNameForeign
ModelNameForeign := TableF.NameGo
ModelNameForeign := TableFK.NameGo
Otvet = strings.ReplaceAll(Otvet, "ModelNameForeign", ModelNameForeign)
//FieldName
//FieldNameTable
FieldNameTable := Column1.NameGo
Otvet = strings.ReplaceAll(Otvet, "FieldNameTable", FieldNameTable)
//ModelNameColumn
ModelNameColumn := create_files.Find_ObjectColumnModelName(Column1.NameGo)
Otvet = strings.ReplaceAll(Otvet, "ModelNameColumn", ModelNameColumn)
//crud_
Otvet = strings.ReplaceAll(Otvet, " crud_", " "+config.Settings.PREFIX_CRUD)

View File

@ -127,7 +127,8 @@ func CreateFiles1(MapAll map[string]*types.Table, Table1 *types.Table, TextGo st
Otvet = create_files.AddImport(Otvet, ModelTableURL)
//добавим поле
TextField1 := "\tObject" + Column1.NameGo + " " + TableFK.Name + "." + TableFK.NameGo + "\n"
ModelNameColumn := create_files.Find_ObjectColumnModelName(Column1.NameGo)
TextField1 := "\t" + ModelNameColumn + " " + TableFK.Name + "." + TableFK.NameGo + "\n"
TextField = TextField + TextField1
}