1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2024-12-22 00:36:41 +02:00

сделал CreateFilesUpdateEveryColumn()

This commit is contained in:
Nikitin Aleksandr 2024-02-14 18:03:08 +03:00
parent b1df27bd89
commit e4e84ce1f7
3 changed files with 30 additions and 1 deletions

View File

@ -30,7 +30,14 @@ func (crud Crud_DB) Read_ctx(ctx context.Context, m *lawsuit_status_types.Lawsui
db.WithContext(ctx) db.WithContext(ctx)
// //
tx := db.Model(&m).Update("ColumnName", m.ColumnName) var tx *gorm.DB
Value := m.ColumnName
if 0==1 && Value == 0 {
tx = db.Model(&m).Update("ColumnName", gorm.Expr("NULL"))
} else {
tx = db.Model(&m).Update("ColumnName", Value)
}
err = tx.Error err = tx.Error
if err != nil { if err != nil {
err = fmt.Errorf("Read() id: %v, error: %v", m.ID, err) err = fmt.Errorf("Read() id: %v, error: %v", m.ID, err)

View File

@ -1218,3 +1218,17 @@ func FindTextConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types
return Otvet return Otvet
} }
// FindTextEqualEmpty - находит текст сравнение с пустым значением
func FindTextEqualEmpty(Column1 *types.Column, VariableName string) string {
Otvet := ""
DefaultValue := FindTextDefaultValue(Column1.TypeGo)
Otvet = VariableName + "." + Column1.NameGo + " == " + DefaultValue
if DefaultValue == "time.Time{}" {
Otvet = VariableName + "." + Column1.NameGo + ".IsZero() == true"
}
return Otvet
}

View File

@ -487,6 +487,7 @@ func CreateFilesUpdateEveryColumn(Table1 *types.Table) error {
"context" "context"
"fmt" "fmt"
"time" "time"
"gorm.io/gorm"
"github.com/ManyakRus/starter/contextmain" "github.com/ManyakRus/starter/contextmain"
"github.com/ManyakRus/starter/micro" "github.com/ManyakRus/starter/micro"
"github.com/ManyakRus/starter/postgres_gorm" "github.com/ManyakRus/starter/postgres_gorm"
@ -586,6 +587,13 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table,
//Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName) //Otvet = strings.ReplaceAll(Otvet, "ColumnName", ColumnName)
//Otvet = strings.ReplaceAll(Otvet, "m.ID", "m."+ColumnName) //Otvet = strings.ReplaceAll(Otvet, "m.ID", "m."+ColumnName)
//внешние ключи заменяем 0 на null
if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time{}") {
Otvet = strings.ReplaceAll(Otvet, "0==1", "1==1")
TextEqualEmpty := create_files.FindTextEqualEmpty(Column1, "Value")
Otvet = strings.ReplaceAll(Otvet, "Value == 0", TextEqualEmpty)
}
return Otvet return Otvet
} }