You've already forked crud_generator
mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-07-16 02:54:19 +02:00
сделал db
This commit is contained in:
@ -358,6 +358,7 @@ func DeleteFuncTestFind_byExtID(TextDB string, Table1 *types.Table) string {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// AddTextOmit - добавляет код для записи null в колонки Nullable
|
||||
func AddTextOmit(TextDB string, Table1 *types.Table) string {
|
||||
Otvet := TextDB
|
||||
|
||||
@ -370,26 +371,56 @@ func AddTextOmit(TextDB string, Table1 *types.Table) string {
|
||||
TextOmit := ""
|
||||
for _, Column1 := range Table1.MapColumns {
|
||||
TypeGo := Column1.TypeGo
|
||||
if TypeGo != "time.Time" {
|
||||
if Column1.IsNullable == false {
|
||||
continue
|
||||
}
|
||||
|
||||
ColumnNameGo := Column1.NameGo
|
||||
TextFind := `if m.` + ColumnNameGo + `.IsZero() == true {`
|
||||
pos1 := strings.Index(TextDB, TextFind)
|
||||
if pos1 >= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
TextOmit = TextOmit + "\t" + `ColumnName = "` + ColumnNameGo + `"
|
||||
if TypeGo == "time.Time" {
|
||||
TextFind := `if m.` + ColumnNameGo + `.IsZero() == true {`
|
||||
pos1 := strings.Index(TextDB, TextFind)
|
||||
if pos1 >= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
TextOmit = TextOmit + "\t" + `ColumnName = "` + ColumnNameGo + `"
|
||||
if m.` + ColumnNameGo + `.IsZero() == true {
|
||||
MassOmit = append(MassOmit, ColumnName)
|
||||
}
|
||||
|
||||
`
|
||||
} 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:]
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func FindTextColumn(Column1 *types.Column) string {
|
||||
Type_go := SQLMapping1.GoType
|
||||
Column1.TypeGo = Type_go
|
||||
TextDefaultValue := FindTextDefaultValue(Type_go)
|
||||
TextPrimaryKey := FindTextPrimaryKey(Column1.Is_identity)
|
||||
TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity)
|
||||
Description := Column1.Description
|
||||
Description = strconv.Quote(Description) //экранирование символов
|
||||
|
||||
|
@ -19,6 +19,7 @@ type TableColumn struct {
|
||||
ColumnName string `json:"column_name" gorm:"column:column_name;default:''"`
|
||||
ColumnType string `json:"type_name" gorm:"column:type_name;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:''"`
|
||||
ColumnTableKey string `json:"table_key" gorm:"column:table_key;default:''"`
|
||||
ColumnColumnKey string `json:"column_key" gorm:"column:column_key;default:''"`
|
||||
@ -62,6 +63,7 @@ SELECT
|
||||
c.column_name,
|
||||
c.udt_name as type_name,
|
||||
c.is_identity as is_identity,
|
||||
c.is_nullable as is_nullable,
|
||||
COALESCE(pgd.description, '') as description,
|
||||
COALESCE(keys.table_to, '') as table_key,
|
||||
COALESCE(keys.column_to, '') as column_key
|
||||
@ -200,7 +202,10 @@ order by
|
||||
Column1.Name = v.ColumnName
|
||||
Column1.Type = v.ColumnType
|
||||
if v.ColumnIsIdentity == "YES" {
|
||||
Column1.Is_identity = true
|
||||
Column1.IsIdentity = true
|
||||
}
|
||||
if v.ColumnIsNullable == "YES" {
|
||||
Column1.IsNullable = true
|
||||
}
|
||||
Column1.Description = v.ColumnDescription
|
||||
Column1.OrderNumber = OrderNumberColumn
|
||||
|
@ -3,7 +3,8 @@ package types
|
||||
type Column struct {
|
||||
Name string `json:"name" gorm:"column: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:''"`
|
||||
OrderNumber int
|
||||
TableKey string `json:"table_key" gorm:"column:table_key;default:''"`
|
||||
|
Reference in New Issue
Block a user