diff --git a/bin/templates/Makefile_ b/bin/templates/Makefile_ index c16a531..b0c2fe4 100644 --- a/bin/templates/Makefile_ +++ b/bin/templates/Makefile_ @@ -17,7 +17,7 @@ run: mod: clear go get -u ./... - go mod tidy -compat=1.18 + go mod tidy -compat=1.22 go mod vendor go fmt ./... build: diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index ef9ece9..e9457d4 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -301,6 +301,8 @@ func ReplacePrimaryKeyOtvetID_ManyPK1(Text string, Table1 *types.Table, Variable TextRequestIDmID := "" TextRequestIDInt64ID := "" TextOtvetIDmID := "" + TextMID0 := "" + TextOR := "" for _, key1 := range keys { Column1, _ := Table1.MapColumns[key1] if Column1.IsPrimaryKey != true { @@ -314,12 +316,17 @@ func ReplacePrimaryKeyOtvetID_ManyPK1(Text string, Table1 *types.Table, Variable TextInt64ID := FindTextConvertGolangTypeToProtobufType(Table1, Column1, "") TextRequestIDInt64ID = TextRequestIDInt64ID + "\t" + VariableName + "." + RequestColumnName + " = " + TextInt64ID + "\n" TextOtvetIDmID = TextOtvetIDmID + "\t" + "Otvet." + Column1.NameGo + " = " + VariableName + "." + Column1.NameGo + "\n" + + DefaultValue := FindTextDefaultValue(Column1.TypeGo) + TextMID0 = TextMID0 + TextOR + " (" + VariableName + "." + Column1.NameGo + " == " + DefaultValue + ")" + TextOR = " || " } Otvet = strings.ReplaceAll(Otvet, "\t"+VariableName+".ID = AliasFromInt(ID)", TextOtvetIDID) Otvet = strings.ReplaceAll(Otvet, "\t"+VariableName+".ID = IntFromAlias(m.ID)", TextRequestIDmID) Otvet = strings.ReplaceAll(Otvet, "\t"+VariableName+".ID = int64(ID)", TextRequestIDInt64ID) Otvet = strings.ReplaceAll(Otvet, "\tOtvet.ID = "+VariableName+".ID\n", TextOtvetIDmID) + Otvet = strings.ReplaceAll(Otvet, " IntFromAlias("+VariableName+".ID) == 0", TextMID0) //заменим ID := Request.ID Otvet = strings.ReplaceAll(Otvet, "\tID := Request.ID\n", TextIDRequestID) @@ -438,13 +445,6 @@ func AddSkipNow(Text string, Table1 *types.Table) string { func IsGoodTable(Table1 *types.Table) error { var err error - //TableName := Table1.Name - //ColumnName, _ := FindPrimaryKeyNameTypeGo(Table1) - //if ColumnName == "" { - // TextError := fmt.Sprint("Wrong table: ", Table1.Name, " error: not found Primary key") - // err = errors.New(TextError) - //} - err = IsGoodTableNamePrefix(Table1) if err != nil { return err @@ -462,7 +462,7 @@ func IsGoodTable(Table1 *types.Table) error { func IsGoodPrimaryKeyColumnsCount(Table1 *types.Table) error { var err error - if Table1.PrimaryKeyColumnsCount <= 0 || Table1.PrimaryKeyColumnsCount >= 2 { + if Table1.PrimaryKeyColumnsCount <= 0 { TextError := fmt.Sprint("Wrong table: ", Table1.Name, " error: can not use many Primary key columns count: ", Table1.PrimaryKeyColumnsCount) err = errors.New(TextError) } @@ -2119,7 +2119,7 @@ func FindTextIDMinimum(Column1 *types.Column) string { switch Column1.TypeGo { case "uuid.UUID": { - if IDMinimum == "" { + if Column1.IDMinimum == "" { Otvet = "uuid.Nil" } else { Otvet = `uuid.Parse("` + IDMinimum + `")` diff --git a/internal/create_files/crud_starter/crud_starter.go b/internal/create_files/crud_starter/crud_starter.go index c229bf6..fb59164 100644 --- a/internal/create_files/crud_starter/crud_starter.go +++ b/internal/create_files/crud_starter/crud_starter.go @@ -118,17 +118,10 @@ import (` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } @@ -215,17 +208,10 @@ func InitCrudTransport_DB() {` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } @@ -270,17 +256,10 @@ func InitCrudTransport_GRPC() {` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } @@ -324,17 +303,10 @@ func InitCrudTransport_NRPC() {` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } @@ -436,17 +408,10 @@ func initCrudTransport_manual_DB() {` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } @@ -490,17 +455,10 @@ func initCrudTransport_manual_GRPC() {` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } @@ -543,17 +501,10 @@ func initCrudTransport_manual_NRPC() {` log.Panic("MapAll[key1] not found, key: ", key1) } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } diff --git a/internal/create_files/crud_starter_tables/crud_starter_tables.go b/internal/create_files/crud_starter_tables/crud_starter_tables.go index 6b664c5..4120ccd 100644 --- a/internal/create_files/crud_starter_tables/crud_starter_tables.go +++ b/internal/create_files/crud_starter_tables/crud_starter_tables.go @@ -17,17 +17,10 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { var err error for _, Table1 := range MapAll { - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } diff --git a/internal/create_files/crud_tables/crud_tables.go b/internal/create_files/crud_tables/crud_tables.go index 351d86c..218eb4b 100644 --- a/internal/create_files/crud_tables/crud_tables.go +++ b/internal/create_files/crud_tables/crud_tables.go @@ -19,17 +19,10 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { var err error for _, Table1 := range MapAll { - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables.go b/internal/create_files/grpc_client_tables/grpc_client_tables.go index d4283c7..38a9426 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -18,17 +18,10 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { var err error for _, Table1 := range MapAll { - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } diff --git a/internal/create_files/protobuf/protobuf.go b/internal/create_files/protobuf/protobuf.go index 69cb212..298bc4b 100644 --- a/internal/create_files/protobuf/protobuf.go +++ b/internal/create_files/protobuf/protobuf.go @@ -77,17 +77,10 @@ func CreateFileProto(MapAll map[string]*types.Table) error { log.Panic("MapAll[key1] not found") } - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } diff --git a/internal/create_files/server_grpc_tables/server_grpc_tables.go b/internal/create_files/server_grpc_tables/server_grpc_tables.go index 954cda6..ba3c38d 100644 --- a/internal/create_files/server_grpc_tables/server_grpc_tables.go +++ b/internal/create_files/server_grpc_tables/server_grpc_tables.go @@ -18,17 +18,10 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { var err error for _, Table1 := range MapAll { - ////проверка что таблица нормальная - //err1 := create_files.IsGoodTable(Table1) - //if err1 != nil { - // log.Warn(err1) - // continue - //} - //проверка что таблица нормальная - err2 := create_files.IsGoodTableNamePrefix(Table1) - if err2 != nil { - log.Warn(err2) + err1 := create_files.IsGoodTable(Table1) + if err1 != nil { + log.Warn(err1) continue } diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go index ee748f9..eac398f 100644 --- a/internal/postgres/postgres.go +++ b/internal/postgres/postgres.go @@ -446,7 +446,8 @@ func FillIDMinimum_ManyPK(MapTable map[string]*types.Table) error { TextSQL = TextSQL + ` FROM "` + Schema + `"."` + TableName + `" - WHERE 1=1` + WHERE 1=1 +` for _, Column1 := range ColumnsPK { DefaultValueSQL := create_files.FindTextDefaultValueSQL(Column1.TypeGo) @@ -464,7 +465,8 @@ func FillIDMinimum_ManyPK(MapTable map[string]*types.Table) error { TextSQL = TextSQL + ` FROM "` + Schema + `"."` + TableName + `" - WHERE 1=1` + WHERE 1=1 +` for _, Column1 := range ColumnsPK { TextSQL += `and ` + Column1.Name + ` is not null ` @@ -499,8 +501,9 @@ func FillIDMinimum_ManyPK(MapTable map[string]*types.Table) error { log.Panic("Rows() Wrong SQL query: ", TextSQL, " error: ", err) } has_next := rows.Next() - if has_next == false { - log.Panic("Next() Wrong SQL query: ", TextSQL, " error: ", err) + if has_next == false { //нет строк + //log.Panic("Next() Wrong SQL query: ", TextSQL, " error: ", err) + continue } ColumnsGorm, err := rows.Columns()