1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-07-16 02:54:19 +02:00

сделал db

This commit is contained in:
Nikitin Aleksandr
2023-10-26 10:33:18 +03:00
parent 3fff82129c
commit 9bfbf269f5
4 changed files with 47 additions and 10 deletions

View File

@ -358,6 +358,7 @@ func DeleteFuncTestFind_byExtID(TextDB string, Table1 *types.Table) string {
return Otvet return Otvet
} }
// AddTextOmit - добавляет код для записи null в колонки Nullable
func AddTextOmit(TextDB string, Table1 *types.Table) string { func AddTextOmit(TextDB string, Table1 *types.Table) string {
Otvet := TextDB Otvet := TextDB
@ -370,11 +371,13 @@ func AddTextOmit(TextDB string, Table1 *types.Table) string {
TextOmit := "" TextOmit := ""
for _, Column1 := range Table1.MapColumns { for _, Column1 := range Table1.MapColumns {
TypeGo := Column1.TypeGo TypeGo := Column1.TypeGo
if TypeGo != "time.Time" { if Column1.IsNullable == false {
continue continue
} }
ColumnNameGo := Column1.NameGo ColumnNameGo := Column1.NameGo
if TypeGo == "time.Time" {
TextFind := `if m.` + ColumnNameGo + `.IsZero() == true {` TextFind := `if m.` + ColumnNameGo + `.IsZero() == true {`
pos1 := strings.Index(TextDB, TextFind) pos1 := strings.Index(TextDB, TextFind)
if pos1 >= 0 { if pos1 >= 0 {
@ -387,9 +390,37 @@ func AddTextOmit(TextDB string, Table1 *types.Table) string {
} }
` `
} else if IsNumberType(TypeGo) == true && Column1.TableKey != "" {
TextFind := `if m.` + ColumnNameGo + ` == 0 {`
pos1 := strings.Index(TextDB, TextFind)
if pos1 >= 0 {
continue
}
TextOmit = TextOmit + "\t" + `ColumnName = "` + ColumnNameGo + `"
if m.` + ColumnNameGo + ` == 0 {
MassOmit = append(MassOmit, ColumnName)
}
`
}
} }
Otvet = Otvet[:pos1] + TextOmit + Otvet[pos1:] Otvet = Otvet[:pos1] + TextOmit + Otvet[pos1:]
return Otvet return Otvet
} }
func IsNumberType(TypeGo string) bool {
Otvet := false
switch TypeGo {
case "int", "int8", "int16", "int32", "int64", "float32", "float64", "uint", "uint8", "uint16", "uint32", "uint64", "byte":
{
Otvet = true
}
}
return Otvet
}

View File

@ -127,7 +127,7 @@ func FindTextColumn(Column1 *types.Column) string {
Type_go := SQLMapping1.GoType Type_go := SQLMapping1.GoType
Column1.TypeGo = Type_go Column1.TypeGo = Type_go
TextDefaultValue := FindTextDefaultValue(Type_go) TextDefaultValue := FindTextDefaultValue(Type_go)
TextPrimaryKey := FindTextPrimaryKey(Column1.Is_identity) TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity)
Description := Column1.Description Description := Column1.Description
Description = strconv.Quote(Description) //экранирование символов Description = strconv.Quote(Description) //экранирование символов

View File

@ -19,6 +19,7 @@ type TableColumn struct {
ColumnName string `json:"column_name" gorm:"column:column_name;default:''"` ColumnName string `json:"column_name" gorm:"column:column_name;default:''"`
ColumnType string `json:"type_name" gorm:"column:type_name;default:''"` ColumnType string `json:"type_name" gorm:"column:type_name;default:''"`
ColumnIsIdentity string `json:"is_identity" gorm:"column:is_identity;default:''"` ColumnIsIdentity string `json:"is_identity" gorm:"column:is_identity;default:''"`
ColumnIsNullable string `json:"is_nullable" gorm:"column:is_nullable;default:''"`
ColumnDescription string `json:"description" gorm:"column:description;default:''"` ColumnDescription string `json:"description" gorm:"column:description;default:''"`
ColumnTableKey string `json:"table_key" gorm:"column:table_key;default:''"` ColumnTableKey string `json:"table_key" gorm:"column:table_key;default:''"`
ColumnColumnKey string `json:"column_key" gorm:"column:column_key;default:''"` ColumnColumnKey string `json:"column_key" gorm:"column:column_key;default:''"`
@ -62,6 +63,7 @@ SELECT
c.column_name, c.column_name,
c.udt_name as type_name, c.udt_name as type_name,
c.is_identity as is_identity, c.is_identity as is_identity,
c.is_nullable as is_nullable,
COALESCE(pgd.description, '') as description, COALESCE(pgd.description, '') as description,
COALESCE(keys.table_to, '') as table_key, COALESCE(keys.table_to, '') as table_key,
COALESCE(keys.column_to, '') as column_key COALESCE(keys.column_to, '') as column_key
@ -200,7 +202,10 @@ order by
Column1.Name = v.ColumnName Column1.Name = v.ColumnName
Column1.Type = v.ColumnType Column1.Type = v.ColumnType
if v.ColumnIsIdentity == "YES" { if v.ColumnIsIdentity == "YES" {
Column1.Is_identity = true Column1.IsIdentity = true
}
if v.ColumnIsNullable == "YES" {
Column1.IsNullable = true
} }
Column1.Description = v.ColumnDescription Column1.Description = v.ColumnDescription
Column1.OrderNumber = OrderNumberColumn Column1.OrderNumber = OrderNumberColumn

View File

@ -3,7 +3,8 @@ package types
type Column struct { type Column struct {
Name string `json:"name" gorm:"column:name;default:''"` Name string `json:"name" gorm:"column:name;default:''"`
Type string `json:"type_name" gorm:"column:type_name;default:''"` Type string `json:"type_name" gorm:"column:type_name;default:''"`
Is_identity bool `json:"is_identity" gorm:"column:is_identity;default:false"` IsIdentity bool `json:"is_identity" gorm:"column:is_identity;default:false"`
IsNullable bool `json:"is_nullable" gorm:"column:is_nullable;default:''"`
Description string `json:"description" gorm:"column:description;default:''"` Description string `json:"description" gorm:"column:description;default:''"`
OrderNumber int OrderNumber int
TableKey string `json:"table_key" gorm:"column:table_key;default:''"` TableKey string `json:"table_key" gorm:"column:table_key;default:''"`