Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dim_table_field.go 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package model
  2. import (
  3. "time"
  4. "git.x2erp.com/qdy/go-db/sqldef"
  5. )
  6. func init() {
  7. sqldef.AddRegistration(func(r *sqldef.Registry) {
  8. tb := sqldef.NewTable("dim_table_field", "表字段字典").
  9. ID("id", 64).Comment("主键ID").End().
  10. String("project_id", 8).NotNull().Comment("项目编号").End().
  11. String("table_name", 64).NotNull().Comment("表名").End().
  12. String("field_name", 64).NotNull().Comment("字段名称(英文)").End().
  13. String("field_name_cn", 128).NotNull().Comment("字段中文名称").End().
  14. String("description", 128).Comment("字段描述").End().
  15. String("field_type", 64).NotNull().Comment("字段类型(如:varchar, int, datetime等)").End().
  16. Int("field_length").Comment("字段长度/精度").End().
  17. Bool("is_primary_key").Default("0").NotNull().Comment("是否为主键(0:否, 1:是)").End().
  18. Bool("is_nullable").Default("1").NotNull().Comment("是否允许为空(0:否, 1:是)").End().
  19. Int("decimal_places").Comment("小数位数(对于decimal类型)").End().
  20. String("creator", 32).NotNull().Comment("创建人").End().
  21. DateTime("created_at").NotNull().Default("CURRENT_TIMESTAMP").Comment("创建时间").End().
  22. DateTime("updated_at").NotNull().Default("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP").Comment("更新时间").End()
  23. // 添加唯一索引:同一项目下同一表的字段名不能重复
  24. //tb.AddUniqueIndex("uk_project_table_field", "project_id", "table_name", "field_name")
  25. // 添加普通索引,方便查询
  26. tb.AddIndex("idx_project_id", "project_id")
  27. tb.AddIndex("idx_table_name", "table_name")
  28. tb.AddIndex("idx_field_name", "field_name")
  29. tb.AddIndex("idx_field_name_cn", "field_name_cn")
  30. tb.AddIndex("idx_description", "description")
  31. r.RegisterTable(tb.Build())
  32. })
  33. }
  34. // DimTableField 表字段字典结构体
  35. type DimTableField struct {
  36. ID string `gorm:"column:id;type:varchar(64);primaryKey;comment:主键ID"`
  37. ProjectID string `gorm:"column:project_id;type:varchar(8);not null;index:idx_project_id;comment:项目编号"`
  38. TableName string `gorm:"column:table_name;type:varchar(64);not null;index:idx_table_name;comment:表名"`
  39. FieldName string `gorm:"column:field_name;type:varchar(64);not null;comment:字段名称(英文)"`
  40. FieldNameCN string `gorm:"column:field_name_cn;type:varchar(128);not null;comment:字段中文名称"`
  41. Description string `gorm:"column:description;type:text;comment:字段描述"`
  42. FieldType string `gorm:"column:field_type;type:varchar(64);not null;comment:字段类型(如:varchar, int, datetime等)"`
  43. FieldLength *int `gorm:"column:field_length;type:int;comment:字段长度/精度"`
  44. IsPrimaryKey bool `gorm:"column:is_primary_key;type:tinyint(1);not null;default:0;comment:是否为主键(0:否, 1:是)"`
  45. IsNullable bool `gorm:"column:is_nullable;type:tinyint(1);not null;default:1;comment:是否允许为空(0:否, 1:是)"`
  46. DecimalPlaces *int `gorm:"column:decimal_places;type:int;comment:小数位数(对于decimal类型)"`
  47. Creator string `gorm:"column:creator;type:varchar(32);not null;comment:创建人"`
  48. CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
  49. UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:更新时间"`
  50. }
  51. func (DimTableField) DimTableField() string {
  52. return "dim_table_field"
  53. }