mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-02-07 23:16:43 +02:00
сделал uuid
This commit is contained in:
parent
47e21aebf3
commit
e9bb4c9712
@ -38,7 +38,7 @@ func UpdateManyFields_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_ty
|
||||
return err
|
||||
}
|
||||
|
||||
if m.ID == 0 {
|
||||
if int64(m.ID) == 0 {
|
||||
err = errors.New(m.TableNameDB() + " UpdateManyFields() error: ID=0")
|
||||
return err
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func Read_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
|
||||
}
|
||||
|
||||
//ID не должен быть =0
|
||||
if m.ID == 0 {
|
||||
if int64(m.ID) == 0 {
|
||||
err = errors.New(m.TableNameDB()+" Read() error: ID=0")
|
||||
return err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func Save_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
|
||||
return err
|
||||
}
|
||||
|
||||
is_create := !micro.BoolFromInt64(int64(m.ID))
|
||||
is_create := !micro.IsEmptyValue(int64(m.ID))
|
||||
err = create_update_ctx(ctx, db, m, is_create, nil)
|
||||
return err
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func Save_ctx(ctx context.Context, db *gorm.DB, m *lawsuit_status_types.LawsuitS
|
||||
return err
|
||||
}
|
||||
|
||||
is_create := !micro.BoolFromInt64(int64(m.ID))
|
||||
is_create := !micro.IsEmptyValue(int64(m.ID))
|
||||
err = create_update_ctx(ctx, db, m, is_create, nil)
|
||||
return err
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ func FillSettings() {
|
||||
|
||||
//
|
||||
Name = "TEMPLATE_EXTERNAL_PROTO_FILENAME"
|
||||
s = Getenv(Name, true)
|
||||
s = Getenv(Name, false)
|
||||
Settings.TEMPLATE_EXTERNAL_PROTO_FILENAME = s
|
||||
|
||||
//
|
||||
|
@ -160,6 +160,19 @@ func FindPrimaryKeyNameType(Table1 *types.Table) (string, string) {
|
||||
return Otvet, Type
|
||||
}
|
||||
|
||||
// FindPrimaryKeyColumn - возвращает Column для колонки PrimaryKey
|
||||
func FindPrimaryKeyColumn(Table1 *types.Table) (Column1 *types.Column) {
|
||||
var Otvet *types.Column
|
||||
|
||||
for _, Column1 := range Table1.MapColumns {
|
||||
if Column1.IsPrimaryKey == true {
|
||||
return Column1
|
||||
}
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
//// FindPrimaryKeyNameTypeGo - возвращает наименование и тип golang колонки PrimaryKey
|
||||
//func FindPrimaryKeyNameTypeGo(Table1 *types.Table) (string, string) {
|
||||
// Otvet := ""
|
||||
|
@ -169,6 +169,9 @@ func CreateFiles(Table1 *types.Table) error {
|
||||
//замена импортов на новые URL
|
||||
TextDB = create_files.ReplaceServiceURLImports(TextDB)
|
||||
|
||||
//uuid
|
||||
TextDB = create_files.CheckAndAddImportUUID_FromText(TextDB)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextDB = create_files.DeleteEmptyImport(TextDB)
|
||||
|
||||
@ -241,7 +244,12 @@ func CreateTestFiles(Table1 *types.Table) error {
|
||||
//Postgres_ID_Test = ID Minimum
|
||||
if Table1.IDMinimum != "" {
|
||||
TextFind := "const Postgres_ID_Test = "
|
||||
TextDB = strings.ReplaceAll(TextDB, TextFind+"0", TextFind+Table1.IDMinimum)
|
||||
ColumnPrimary := create_files.FindPrimaryKeyColumn(Table1)
|
||||
if ColumnPrimary.TypeGo == "uuid.UUID" {
|
||||
TextDB = strings.ReplaceAll(TextDB, TextFind+"0", TextFind+`var Postgres_ID_Test, _ = uuid.Parse("`+TextFind+Table1.IDMinimum+`")`)
|
||||
} else {
|
||||
TextDB = strings.ReplaceAll(TextDB, TextFind+"0", TextFind+Table1.IDMinimum)
|
||||
}
|
||||
}
|
||||
|
||||
//SkipNow() если нет строк в БД
|
||||
@ -566,6 +574,12 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
|
||||
//переименование функций
|
||||
//TextCrud = RenameFunctions(TextCrud, Table1)
|
||||
|
||||
//заменяет "m.ID" на название колонки PrimaryKey
|
||||
TextCrud = create_files.ReplacePrimaryKeyM_ID(TextCrud, Table1)
|
||||
|
||||
//uuid
|
||||
TextCrud = create_files.CheckAndAddImportUUID_FromText(TextCrud)
|
||||
|
||||
//удаление пустого импорта
|
||||
TextCrud = create_files.DeleteEmptyImport(TextCrud)
|
||||
|
||||
@ -835,7 +849,8 @@ func CreateFilesCache(Table1 *types.Table) error {
|
||||
|
||||
//тип ID кэша
|
||||
_, ColumnTypeGo := create_files.FindPrimaryKeyNameTypeGo(Table1)
|
||||
TextCache = strings.ReplaceAll(TextCache, ".LRU[int64", ".LRU["+ColumnTypeGo)
|
||||
TextCache = strings.ReplaceAll(TextCache, "LRU[int64", "LRU["+ColumnTypeGo)
|
||||
TextCache = strings.ReplaceAll(TextCache, "ID int64", "ID "+ColumnTypeGo)
|
||||
|
||||
//uuid
|
||||
TextCache = create_files.CheckAndAddImportUUID_FromText(TextCache)
|
||||
|
@ -317,7 +317,7 @@ func TextFindByExtId(ModelName string) string {
|
||||
|
||||
// FindTextProtoTable1_UpdateEveryColumn - возвращает текст всех функций .proto для таблицы, обновления каждого поля таблицы
|
||||
func FindTextProtoTable1_UpdateEveryColumn(TextProto string, Table1 *types.Table) string {
|
||||
Otvet := "\n" //"\n\t//\n"
|
||||
Otvet := "" //"\n\t//\n"
|
||||
|
||||
//ModelName := Table1.NameGo
|
||||
|
||||
@ -387,18 +387,17 @@ func TextUpdateEveryColumn(Table1 *types.Table, Column1 *types.Column) string {
|
||||
|
||||
// FindTextProtoTable1_Cache - возвращает текст функции ReadFromCache() .proto для таблицы
|
||||
func FindTextProtoTable1_Cache(TextProto string, Table1 *types.Table) string {
|
||||
Otvet := "\n" //"\n\t//\n"
|
||||
Otvet := "" //"\n\t//\n"
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
Otvet = Otvet + FindTextReadFromCache(TextProto, ModelName)
|
||||
Otvet = Otvet + FindTextReadFromCache(TextProto, Table1)
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextReadFromCache - возвращает текст .proto
|
||||
func FindTextReadFromCache(TextProto string, ModelName string) string {
|
||||
func FindTextReadFromCache(TextProto string, Table1 *types.Table) string {
|
||||
Otvet := ""
|
||||
Otvet2 := TextReadFromCache(ModelName)
|
||||
Otvet2 := TextReadFromCache(Table1)
|
||||
|
||||
//проверка такой текст уже есть
|
||||
pos1 := strings.Index(TextProto, Otvet2)
|
||||
@ -412,15 +411,18 @@ func FindTextReadFromCache(TextProto string, ModelName string) string {
|
||||
}
|
||||
|
||||
// TextReadFromCache - возвращает текст .proto
|
||||
func TextReadFromCache(ModelName string) string {
|
||||
Otvet := "rpc " + ModelName + "_ReadFromCache(RequestId) returns (Response) {}"
|
||||
func TextReadFromCache(Table1 *types.Table) string {
|
||||
Column1 := create_files.FindPrimaryKeyColumn(Table1)
|
||||
TextRequestId, _ := create_files.FindTextProtobufRequest(Column1.TypeGo)
|
||||
ModelName := Table1.NameGo
|
||||
Otvet := "rpc " + ModelName + "_ReadFromCache(" + TextRequestId + ") returns (Response) {}"
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// FindTextProtoTable1_UpdateManyFields - возвращает текст функции UpdateManyFields() .proto для таблицы
|
||||
func FindTextProtoTable1_UpdateManyFields(TextProto string, Table1 *types.Table) string {
|
||||
Otvet := "\n" //"\n\t//\n"
|
||||
Otvet := "" //"\n\t//\n"
|
||||
|
||||
ModelName := Table1.NameGo
|
||||
Otvet = Otvet + FindTextUpdateManyFields(TextProto, ModelName)
|
||||
|
@ -37,6 +37,32 @@ type TableRowsStruct struct {
|
||||
|
||||
// FillMapTable - возвращает массив MassTable данными из БД
|
||||
func FillMapTable() (map[string]*types.Table, error) {
|
||||
MapTable := make(map[string]*types.Table, 0)
|
||||
var err error
|
||||
|
||||
MapTable, err = FillMapTable1()
|
||||
if err != nil {
|
||||
log.Error("FillMapTable1() error: ", err)
|
||||
return MapTable, err
|
||||
}
|
||||
|
||||
err = FillIDMinimum(MapTable)
|
||||
if err != nil {
|
||||
log.Error("FillIDMinimum() error: ", err)
|
||||
return MapTable, err
|
||||
}
|
||||
|
||||
err = FillRowsCount(MapTable)
|
||||
if err != nil {
|
||||
log.Error("FillRowsCount() error: ", err)
|
||||
return MapTable, err
|
||||
}
|
||||
|
||||
return MapTable, err
|
||||
}
|
||||
|
||||
// FillMapTable1 - возвращает массив MassTable данными из БД
|
||||
func FillMapTable1() (map[string]*types.Table, error) {
|
||||
var err error
|
||||
//MassTable := make([]types.Table, 0)
|
||||
MapTable := make(map[string]*types.Table, 0)
|
||||
@ -309,9 +335,6 @@ order by
|
||||
|
||||
//FillTypeGo(MapTable)
|
||||
|
||||
FillIDMinimum(MapTable)
|
||||
FillRowsCount(MapTable)
|
||||
|
||||
return MapTable, err
|
||||
}
|
||||
|
||||
@ -323,7 +346,7 @@ func CreateTable() *types.Table {
|
||||
}
|
||||
|
||||
// FillIDMinimum - находим минимальный ID, для тестов с этим ID
|
||||
func FillIDMinimum(MapTable map[string]*types.Table) {
|
||||
func FillIDMinimum(MapTable map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
//соединение
|
||||
@ -349,7 +372,8 @@ func FillIDMinimum(MapTable map[string]*types.Table) {
|
||||
WHERE
|
||||
"` + NameID + `" <> ` + DefaultValueSQL
|
||||
} else {
|
||||
TextSQL = `SELECT "` + NameID + `" as id_minimum FROM "` + Schema + `"."` + TableName + `"
|
||||
TextSQL = `SELECT "` + NameID + `" as id_minimum
|
||||
FROM "` + Schema + `"."` + TableName + `"
|
||||
WHERE "` + NameID + `" is not null
|
||||
ORDER BY ` + NameID + `
|
||||
LIMIT 1`
|
||||
@ -381,10 +405,11 @@ func FillIDMinimum(MapTable map[string]*types.Table) {
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// FillRowsCount - находим количество строк в таблице, для кэша
|
||||
func FillRowsCount(MapTable map[string]*types.Table) {
|
||||
func FillRowsCount(MapTable map[string]*types.Table) error {
|
||||
var err error
|
||||
|
||||
//соединение
|
||||
@ -426,6 +451,7 @@ WHERE
|
||||
Table1.RowsCount = RowsCount.Int64
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// FindNameType_from_PrimaryKey - возвращает наименование и тип БД для колонки PrimaryKey (ID)
|
||||
|
Loading…
x
Reference in New Issue
Block a user