mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-03 01:22:21 +02:00
сделал StringIdentifier()
This commit is contained in:
parent
118503e1ae
commit
35e94c42a6
@ -11,6 +11,7 @@ import (
|
||||
"github.com/ManyakRus/starter/micro"
|
||||
"github.com/iancoleman/strcase"
|
||||
"github.com/jinzhu/inflection"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -177,7 +178,15 @@ func FindPrimaryKeyColumn(Table1 *types.Table) (Column1 *types.Column) {
|
||||
func FindPrimaryKeyColumns(Table1 *types.Table) []*types.Column {
|
||||
Otvet := make([]*types.Column, 0)
|
||||
|
||||
for _, Column1 := range Table1.MapColumns {
|
||||
//сортировка по названию таблиц
|
||||
keys := make([]string, 0, len(Table1.MapColumns))
|
||||
for k := range Table1.MapColumns {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, key1 := range keys {
|
||||
Column1, _ := Table1.MapColumns[key1]
|
||||
if Column1.IsPrimaryKey == true {
|
||||
Otvet = append(Otvet, Column1)
|
||||
}
|
||||
@ -268,14 +277,22 @@ func ReplacePrimaryKeyOtvetID1(Text string, Table1 *types.Table) string {
|
||||
func ReplacePrimaryKeyOtvetID_Many(Text string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
//сортировка по названию таблиц
|
||||
keys := make([]string, 0, len(Table1.MapColumns))
|
||||
for k := range Table1.MapColumns {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
TextOtvetIDID := ""
|
||||
for _, Column1 := range Table1.MapColumns {
|
||||
if Column1.IsPrimaryKey == false {
|
||||
for _, key1 := range keys {
|
||||
Column1, _ := Table1.MapColumns[key1]
|
||||
if Column1.IsPrimaryKey != true {
|
||||
continue
|
||||
}
|
||||
|
||||
TextOtvetIDID = TextOtvetIDID + "\tOtvet." + Column1.NameGo + " = " + Column1.NameGo + "\n"
|
||||
}
|
||||
|
||||
Otvet = strings.ReplaceAll(Otvet, "\tOtvet.ID = AliasFromInt(ID)", TextOtvetIDID)
|
||||
|
||||
//TextNames, TextNamesTypes, TextProtoNames := FindTextIDMany(Table1)
|
||||
@ -817,7 +834,7 @@ func CheckAndAddImportStrconv(Text string) string {
|
||||
Otvet := Text
|
||||
|
||||
RepositoryURL := `strconv`
|
||||
Otvet = AddImport(Text, RepositoryURL)
|
||||
Otvet = CheckAndAddImport(Text, RepositoryURL)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -827,7 +844,7 @@ func CheckAndAddImportFmt(Text string) string {
|
||||
Otvet := Text
|
||||
|
||||
RepositoryURL := `fmt`
|
||||
Otvet = AddImport(Text, RepositoryURL)
|
||||
Otvet = CheckAndAddImport(Text, RepositoryURL)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
@ -2085,6 +2102,36 @@ func FindTextIDMany(Table1 *types.Table) (TextNames, TextNamesTypes, TextProtoNa
|
||||
//TextNamesTypes := ""
|
||||
//TextNames := ""
|
||||
|
||||
TextNames, TextNamesTypes, TextProtoNames = FindTextID_VariableName_Many(Table1, "")
|
||||
|
||||
//Comma := ""
|
||||
//MassPrimaryKey := FindPrimaryKeyColumns(Table1)
|
||||
//for _, PrimaryKey1 := range MassPrimaryKey {
|
||||
// OtvetColumnName := FindTextConvertGolangTypeToProtobufType(Table1, PrimaryKey1, "")
|
||||
// if OtvetColumnName == "" {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// TextProtoNames = TextProtoNames + Comma + OtvetColumnName
|
||||
// TextNamesTypes = TextNamesTypes + Comma + PrimaryKey1.NameGo + " " + PrimaryKey1.TypeGo
|
||||
// TextNames = TextNames + Comma + PrimaryKey1.NameGo
|
||||
//
|
||||
// Comma = ", "
|
||||
//}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FindTextID_VariableName_Many - находит все PrimaryKey строкой
|
||||
func FindTextID_VariableName_Many(Table1 *types.Table, VariableName string) (TextNames, TextNamesTypes, TextProtoNames string) {
|
||||
//TextProtoNames := ""
|
||||
//TextNamesTypes := ""
|
||||
//TextNames := ""
|
||||
|
||||
Dot := ""
|
||||
if VariableName != "" {
|
||||
Dot = "."
|
||||
}
|
||||
Comma := ""
|
||||
MassPrimaryKey := FindPrimaryKeyColumns(Table1)
|
||||
for _, PrimaryKey1 := range MassPrimaryKey {
|
||||
@ -2095,7 +2142,7 @@ func FindTextIDMany(Table1 *types.Table) (TextNames, TextNamesTypes, TextProtoNa
|
||||
|
||||
TextProtoNames = TextProtoNames + Comma + OtvetColumnName
|
||||
TextNamesTypes = TextNamesTypes + Comma + PrimaryKey1.NameGo + " " + PrimaryKey1.TypeGo
|
||||
TextNames = TextNames + Comma + PrimaryKey1.NameGo
|
||||
TextNames = TextNames + Comma + VariableName + Dot + PrimaryKey1.NameGo
|
||||
|
||||
Comma = ", "
|
||||
}
|
||||
@ -2212,3 +2259,17 @@ func FindTextConvertToString(Column1 *types.Column, VariableName string) string
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// ReplaceCacheRemove_ManyPK - заменяет cache.Remove(IntFromAlias(m.ID)) на cache.Remove(m.StringIdentifier())
|
||||
func ReplaceCacheRemove_ManyPK(Text string, Table1 *types.Table) string {
|
||||
Otvet := Text
|
||||
|
||||
if Table1.PrimaryKeyColumnsCount > 1 {
|
||||
TextOld := "cache.Remove(IntFromAlias(m.ID))"
|
||||
TextNames, _, _ := FindTextID_VariableName_Many(Table1, "m")
|
||||
TextNew := "cache.Remove(" + Table1.Name + ".StringIdentifier(" + TextNames + "))"
|
||||
Otvet = strings.ReplaceAll(Otvet, TextOld, TextNew)
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
@ -171,6 +171,9 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
TextDB = ReplaceText_created_at(TextDB, Table1)
|
||||
TextDB = ReplaceText_is_deleted_deleted_at(TextDB, Table1)
|
||||
TextDB = create_files.DeleteImportModel(TextDB)
|
||||
|
||||
TextDB = create_files.ReplaceCacheRemove_ManyPK(TextDB, Table1)
|
||||
|
||||
TextDB = create_files.ReplacePrimaryKeyM_ID(TextDB, Table1)
|
||||
|
||||
//замена импортов на новые URL
|
||||
@ -643,6 +646,8 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table,
|
||||
FuncName := "Update_" + ColumnName
|
||||
TextRequest, TextRequestFieldName := create_files.FindTextProtobufRequest(Table1)
|
||||
|
||||
Otvet = create_files.ReplaceCacheRemove_ManyPK(Otvet, Table1)
|
||||
|
||||
//запись null в nullable колонки
|
||||
if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") {
|
||||
} else {
|
||||
|
@ -738,7 +738,15 @@ func StringIdentifier(` + TextNamesTypes + `) string {
|
||||
Otvet := ""
|
||||
`
|
||||
|
||||
for _, Column1 := range Table1.MapColumns {
|
||||
//сортировка по названию таблиц
|
||||
keys := make([]string, 0, len(Table1.MapColumns))
|
||||
for k := range Table1.MapColumns {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, key1 := range keys {
|
||||
Column1, _ := Table1.MapColumns[key1]
|
||||
if Column1.IsPrimaryKey == false {
|
||||
continue
|
||||
}
|
||||
|
2
vendor/github.com/ManyakRus/starter/micro/microfunctions.go
generated
vendored
2
vendor/github.com/ManyakRus/starter/micro/microfunctions.go
generated
vendored
@ -179,7 +179,7 @@ func LastWord(StringFrom string) string {
|
||||
}
|
||||
|
||||
r := []rune(StringFrom)
|
||||
for f := len(r); f >= 0; f-- {
|
||||
for f := len(r); f > 0; f-- {
|
||||
r1 := r[f-1]
|
||||
if r1 == '_' {
|
||||
} else if unicode.IsLetter(r1) == false && unicode.IsDigit(r1) == false {
|
||||
|
Loading…
Reference in New Issue
Block a user