mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-25 00:46:20 +02:00
сделал table.comment
This commit is contained in:
parent
1b4b7ecfe2
commit
a6335de223
@ -7,5 +7,9 @@
|
|||||||
"nsi_flat": "NSIFlat",
|
"nsi_flat": "NSIFlat",
|
||||||
"nsi_flat_id": "NSIFlatID",
|
"nsi_flat_id": "NSIFlatID",
|
||||||
"nsi_id": "NSIID",
|
"nsi_id": "NSIID",
|
||||||
"www": "WWW"
|
"www": "WWW",
|
||||||
|
"bik": "BIK",
|
||||||
|
"city_name": "City",
|
||||||
|
"edms_link": "EDMSLink",
|
||||||
|
"code_nsi": "CodeNSI"
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ var versionLawsuitStatusType uint32
|
|||||||
// crud_LawsuitStatusType - объект контроллер crud операций
|
// crud_LawsuitStatusType - объект контроллер crud операций
|
||||||
var crud_LawsuitStatusType ICrud_LawsuitStatusType
|
var crud_LawsuitStatusType ICrud_LawsuitStatusType
|
||||||
|
|
||||||
// LawsuitStatusType Статусы дел (справочник).
|
// LawsuitStatusType
|
||||||
type LawsuitStatusType struct {
|
type LawsuitStatusType struct {
|
||||||
entities.CommonStruct
|
entities.CommonStruct
|
||||||
entities.NameStruct
|
entities.NameStruct
|
||||||
@ -28,6 +28,7 @@ type ICrud_LawsuitStatusType interface {
|
|||||||
Create(*LawsuitStatusType) error
|
Create(*LawsuitStatusType) error
|
||||||
Delete(*LawsuitStatusType) error
|
Delete(*LawsuitStatusType) error
|
||||||
Restore(*LawsuitStatusType) error
|
Restore(*LawsuitStatusType) error
|
||||||
|
Find_ByExtID(*LawsuitStatusType) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName - возвращает имя таблицы в БД, нужен для gorm
|
// TableName - возвращает имя таблицы в БД, нужен для gorm
|
||||||
|
@ -277,3 +277,23 @@ func FindModelURL() string {
|
|||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FindTextDefaultValue(Type_go string) string {
|
||||||
|
var Otvet string
|
||||||
|
|
||||||
|
sValue := ""
|
||||||
|
switch Type_go {
|
||||||
|
case "string":
|
||||||
|
sValue = "\\\"\\\""
|
||||||
|
case "int", "int32", "int64", "float32", "float64", "uint", "uint32", "uint64":
|
||||||
|
sValue = "0"
|
||||||
|
case "time.Time":
|
||||||
|
sValue = "null"
|
||||||
|
}
|
||||||
|
|
||||||
|
if sValue != "" {
|
||||||
|
Otvet = ";default:" + sValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return Otvet
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ package crud_starter
|
|||||||
import (
|
import (
|
||||||
"github.com/ManyakRus/crud_generator/internal/config"
|
"github.com/ManyakRus/crud_generator/internal/config"
|
||||||
"github.com/ManyakRus/crud_generator/internal/constants"
|
"github.com/ManyakRus/crud_generator/internal/constants"
|
||||||
|
"github.com/ManyakRus/crud_generator/internal/create_files"
|
||||||
"github.com/ManyakRus/crud_generator/internal/types"
|
"github.com/ManyakRus/crud_generator/internal/types"
|
||||||
"github.com/ManyakRus/starter/log"
|
"github.com/ManyakRus/starter/log"
|
||||||
"github.com/ManyakRus/starter/micro"
|
"github.com/ManyakRus/starter/micro"
|
||||||
@ -94,6 +95,7 @@ import (
|
|||||||
}
|
}
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
//все таблицы
|
||||||
TextModel := ""
|
TextModel := ""
|
||||||
TextDB := ""
|
TextDB := ""
|
||||||
TextGRPC := ""
|
TextGRPC := ""
|
||||||
@ -103,6 +105,14 @@ import (
|
|||||||
if ok == false {
|
if ok == false {
|
||||||
log.Panic("MapAll[key1] not found, key: ", key1)
|
log.Panic("MapAll[key1] not found, key: ", key1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//проверка что таблица нормальная
|
||||||
|
err1 := create_files.CheckGoodTable(Table1)
|
||||||
|
if err1 != nil {
|
||||||
|
log.Warn(err1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
TextModel = TextModel + FindTextImportModel1(Table1)
|
TextModel = TextModel + FindTextImportModel1(Table1)
|
||||||
TextDB = TextDB + FindTextImportDB1(Table1)
|
TextDB = TextDB + FindTextImportDB1(Table1)
|
||||||
TextGRPC = TextGRPC + FindTextImportGRPC1(Table1)
|
TextGRPC = TextGRPC + FindTextImportGRPC1(Table1)
|
||||||
|
@ -61,6 +61,14 @@ func CreateFileProto(MapAll map[string]*types.Table) error {
|
|||||||
if ok == false {
|
if ok == false {
|
||||||
log.Panic("MapAll[key1] not found")
|
log.Panic("MapAll[key1] not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//проверка что таблица нормальная
|
||||||
|
err1 := create_files.CheckGoodTable(Table1)
|
||||||
|
if err1 != nil {
|
||||||
|
log.Warn(err1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
TextProtoNew = TextProtoNew + FindTextProtoTable1(TextProto, Table1)
|
TextProtoNew = TextProtoNew + FindTextProtoTable1(TextProto, Table1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,16 +61,6 @@ func CreateFiles(Table1 *types.Table) error {
|
|||||||
TextModelStruct, ModelName, err := FindTextModelStruct(Table1)
|
TextModelStruct, ModelName, err := FindTextModelStruct(Table1)
|
||||||
TextModel = ReplaceModelStruct(TextModel, TextModelStruct)
|
TextModel = ReplaceModelStruct(TextModel, TextModelStruct)
|
||||||
|
|
||||||
////(l LawsuitStatusType) = (b Branch)
|
|
||||||
//TextTemplateVarModel := "(" + strings.ToLower(config.Settings.TEXT_TEMPLATE_MODEL[:1]) + " " + config.Settings.TEXT_TEMPLATE_MODEL
|
|
||||||
//TextVarModel := "(" + strings.ToLower(ModelName[:1]) + " " + ModelName
|
|
||||||
//TextModel = strings.ReplaceAll(TextModel, TextTemplateVarModel, TextVarModel)
|
|
||||||
//
|
|
||||||
////(l *LawsuitStatusType) = (b *Branch)
|
|
||||||
//TextTemplateVarModel = "(" + strings.ToLower(config.Settings.TEXT_TEMPLATE_MODEL[:1]) + " *" + config.Settings.TEXT_TEMPLATE_MODEL
|
|
||||||
//TextVarModel = "(" + strings.ToLower(ModelName[:1]) + " *" + ModelName
|
|
||||||
//TextModel = strings.ReplaceAll(TextModel, TextTemplateVarModel, TextVarModel)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_MODEL, ModelName)
|
||||||
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
TextModel = strings.ReplaceAll(TextModel, config.Settings.TEXT_TEMPLATE_TABLENAME, Table1.Name)
|
||||||
@ -101,7 +91,7 @@ func FindTextModelStruct(Table1 *types.Table) (string, string, error) {
|
|||||||
ModelName = create_files.FormatName(ModelName)
|
ModelName = create_files.FormatName(ModelName)
|
||||||
Table1.NameGo = ModelName
|
Table1.NameGo = ModelName
|
||||||
|
|
||||||
Otvet = `// ` + ModelName + ` - model from table ` + TableName + `
|
Otvet = `// ` + ModelName + ` - model from table ` + TableName + `: ` + Table1.Comment + `
|
||||||
type ` + ModelName + ` struct {
|
type ` + ModelName + ` struct {
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -138,41 +128,21 @@ func FindTextColumn(Column1 *types.Column) string {
|
|||||||
//Type_go := SQLMapping1.GoType
|
//Type_go := SQLMapping1.GoType
|
||||||
Type_go := Column1.TypeGo
|
Type_go := Column1.TypeGo
|
||||||
Column1.TypeGo = Type_go
|
Column1.TypeGo = Type_go
|
||||||
TextDefaultValue := FindTextDefaultValue(Type_go)
|
TextDefaultValue := create_files.FindTextDefaultValue(Type_go)
|
||||||
TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity)
|
TextPrimaryKey := FindTextPrimaryKey(Column1.IsIdentity)
|
||||||
Description := Column1.Description
|
Description := Column1.Description
|
||||||
Description = create_files.PrintableString(Description) //экранирование символов
|
Description = create_files.PrintableString(Description) //экранирование символов
|
||||||
|
|
||||||
Otvet = Otvet + "\t" + ColumnModelName + " " + Type_go + "\t"
|
Otvet = Otvet + "\t" + ColumnModelName + " " + Type_go + "\t"
|
||||||
Otvet = Otvet + "`json:\"" + ColumnName + "\""
|
Otvet = Otvet + "`json:\"" + ColumnName + "\""
|
||||||
Otvet = Otvet + "\tgorm:\"column:" + ColumnName + TextPrimaryKey + TextDefaultValue + "\""
|
Otvet = Otvet + " gorm:\"column:" + ColumnName + TextPrimaryKey + TextDefaultValue + "\""
|
||||||
Otvet = Otvet + "\tdb:\"" + ColumnName + "\""
|
Otvet = Otvet + " db:\"" + ColumnName + "\""
|
||||||
Otvet = Otvet + "`"
|
Otvet = Otvet + "`"
|
||||||
Otvet = Otvet + "\t//" + Description
|
Otvet = Otvet + "\t//" + Description
|
||||||
|
|
||||||
return Otvet
|
return Otvet
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindTextDefaultValue(Type_go string) string {
|
|
||||||
var Otvet string
|
|
||||||
|
|
||||||
sValue := ""
|
|
||||||
switch Type_go {
|
|
||||||
case "string":
|
|
||||||
sValue = "\\\"\\\""
|
|
||||||
case "int", "int32", "int64", "float32", "float64", "uint", "uint32", "uint64":
|
|
||||||
sValue = "0"
|
|
||||||
case "time.Time":
|
|
||||||
sValue = "null"
|
|
||||||
}
|
|
||||||
|
|
||||||
if sValue != "" {
|
|
||||||
Otvet = ";default:" + sValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return Otvet
|
|
||||||
}
|
|
||||||
|
|
||||||
func FindTextPrimaryKey(Is_identity bool) string {
|
func FindTextPrimaryKey(Is_identity bool) string {
|
||||||
Otvet := ""
|
Otvet := ""
|
||||||
|
|
||||||
@ -322,9 +292,6 @@ func DeleteFuncFind_byExtID(TextModel, Modelname string, Table1 *types.Table) st
|
|||||||
|
|
||||||
//
|
//
|
||||||
_, ok1 := Table1.MapColumns["ext_id"]
|
_, ok1 := Table1.MapColumns["ext_id"]
|
||||||
//if ok == false {
|
|
||||||
// return Otvet
|
|
||||||
//}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
_, ok2 := Table1.MapColumns["connection_id"]
|
_, ok2 := Table1.MapColumns["connection_id"]
|
||||||
|
@ -26,6 +26,7 @@ type TableColumn struct {
|
|||||||
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:''"`
|
||||||
|
TableComment string `json:"table_comment" gorm:"column:table_comment;default:''"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FillMapTable - возвращает массив MassTable данными из БД
|
// FillMapTable - возвращает массив MassTable данными из БД
|
||||||
@ -35,7 +36,6 @@ func FillMapTable() (map[string]*types.Table, error) {
|
|||||||
MapTable := make(map[string]*types.Table, 0)
|
MapTable := make(map[string]*types.Table, 0)
|
||||||
|
|
||||||
TextSQL := `
|
TextSQL := `
|
||||||
|
|
||||||
drop table if exists temp_keys;
|
drop table if exists temp_keys;
|
||||||
CREATE TEMPORARY TABLE temp_keys (table_from text, column_from text, table_to text, column_to text);
|
CREATE TEMPORARY TABLE temp_keys (table_from text, column_from text, table_to text, column_to text);
|
||||||
|
|
||||||
@ -46,6 +46,7 @@ SELECT
|
|||||||
UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as column_from,
|
UNNEST((select array_agg(attname) from pg_attribute where attrelid = c.conrelid and array[attnum] <@ c.conkey)) as column_from,
|
||||||
(select r.relname from pg_class r where r.oid = c.confrelid) as table_to,
|
(select r.relname from pg_class r where r.oid = c.confrelid) as table_to,
|
||||||
a.attname as column_to
|
a.attname as column_to
|
||||||
|
|
||||||
FROM
|
FROM
|
||||||
pg_constraint c
|
pg_constraint c
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ on
|
|||||||
c.confrelid=a.attrelid and a.attnum = ANY(confkey)
|
c.confrelid=a.attrelid and a.attnum = ANY(confkey)
|
||||||
|
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
--and c.confrelid = (select oid from pg_class where relname = 'debt_types')
|
--and c.confrelid = (select oid from pg_class where relname = 'lawsuit_invoices')
|
||||||
--AND c.confrelid!=c.conrelid
|
--AND c.confrelid!=c.conrelid
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -69,23 +70,25 @@ SELECT
|
|||||||
c.is_nullable as is_nullable,
|
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,
|
||||||
|
(SELECT obj_description(oid) FROM pg_class as r WHERE relkind = 'r' and r.oid = st.relid) as table_comment
|
||||||
|
|
||||||
FROM
|
FROM
|
||||||
pg_catalog.pg_statio_all_tables as st
|
pg_catalog.pg_statio_all_tables as st
|
||||||
|
|
||||||
inner join
|
|
||||||
pg_catalog.pg_description pgd
|
|
||||||
on
|
|
||||||
pgd.objoid = st.relid
|
|
||||||
|
|
||||||
right join
|
right join
|
||||||
information_schema.columns c
|
information_schema.columns c
|
||||||
on
|
on
|
||||||
pgd.objsubid = c.ordinal_position
|
|
||||||
and c.table_schema = st.schemaname
|
c.table_schema = st.schemaname
|
||||||
and c.table_name = st.relname
|
and c.table_name = st.relname
|
||||||
|
|
||||||
|
left join
|
||||||
|
pg_catalog.pg_description pgd
|
||||||
|
on
|
||||||
|
pgd.objoid = st.relid
|
||||||
|
and pgd.objsubid = c.ordinal_position
|
||||||
|
|
||||||
|
|
||||||
LEFT JOIN --внешние ключи
|
LEFT JOIN --внешние ключи
|
||||||
temp_keys as keys
|
temp_keys as keys
|
||||||
@ -106,11 +109,15 @@ where 1=1
|
|||||||
and v.table_name is null
|
and v.table_name is null
|
||||||
--INCLUDE_TABLES
|
--INCLUDE_TABLES
|
||||||
--EXCLUDE_TABLES
|
--EXCLUDE_TABLES
|
||||||
|
--and c.table_name = 'lawsuit_invoices'
|
||||||
|
|
||||||
order by
|
order by
|
||||||
table_name,
|
table_name,
|
||||||
is_identity desc,
|
is_identity desc,
|
||||||
column_name
|
column_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
SCHEMA := strings.Trim(postgres_gorm.Settings.DB_SCHEMA, " ")
|
SCHEMA := strings.Trim(postgres_gorm.Settings.DB_SCHEMA, " ")
|
||||||
@ -199,6 +206,7 @@ order by
|
|||||||
Table1 = CreateTable()
|
Table1 = CreateTable()
|
||||||
Table1.Name = v.TableName
|
Table1.Name = v.TableName
|
||||||
Table1.OrderNumber = OrderNumberTable
|
Table1.OrderNumber = OrderNumberTable
|
||||||
|
Table1.Comment = v.TableComment
|
||||||
}
|
}
|
||||||
|
|
||||||
Column1 := types.Column{}
|
Column1 := types.Column{}
|
||||||
|
@ -21,6 +21,7 @@ type Table struct {
|
|||||||
OrderNumber int
|
OrderNumber int
|
||||||
NameGo string
|
NameGo string
|
||||||
IDMinimum string
|
IDMinimum string
|
||||||
|
Comment string `json:"table_comment" gorm:"column:table_comment;default:''"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var MapReplaceName = make(map[string]string, 0)
|
var MapReplaceName = make(map[string]string, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user