Documentation
¶
Index ¶
- Variables
- func ColsNeedTimeImport(cols []ColumnMeta) bool
- func EntityJSONTag(c ColumnMeta, goType string) string
- func FieldTags(c ColumnMeta, mode string) string
- func ListMySQLTables(dsn, database string) ([]string, error)
- func ListPostgresTables(dsn, schema string) ([]string, error)
- func ModuleNameFromPhysical(physical, prefix string) string
- func MySQLDatabaseFromDSN(dsn string) string
- func ProtoType(c ColumnMeta) string
- func ShouldExcludeTable(table string, userExclude []string) bool
- type ClassifiedTable
- type CodegenRules
- type ColumnMeta
- type GoField
- type TableMeta
Constants ¶
This section is empty.
Variables ¶
var AlwaysExcludeTables = []string{"_sqlx_migrations"}
内置扫表排除(不可关闭)。
Functions ¶
func ColsNeedTimeImport ¶
func ColsNeedTimeImport(cols []ColumnMeta) bool
ColsNeedTimeImport 判断列集合生成的 Go 类型是否需要 import "time"。
func EntityJSONTag ¶
func EntityJSONTag(c ColumnMeta, goType string) string
EntityJSONTag 领域实体 json 标签(列名与数据库一致,可空字段带 omitempty)。
func FieldTags ¶
func FieldTags(c ColumnMeta, mode string) string
FieldTags 生成 json + validate 结构体标签(用于 Command 等写模型)。 mode: "create" | "update"
func ListMySQLTables ¶
ListMySQLTables 列出 database 下所有基表。
func ListPostgresTables ¶
ListPostgresTables 列出 schema 下所有基表。
func ModuleNameFromPhysical ¶
ModuleNameFromPhysical 从物理表名解析模块名(去掉 table_prefix)。
func MySQLDatabaseFromDSN ¶
MySQLDatabaseFromDSN 从 DSN 解析库名(user:pass@tcp(host:3306)/dbname?...)。
func ShouldExcludeTable ¶
ShouldExcludeTable 判断是否排除该表(内置 + 用户 exclude)。
Types ¶
type ClassifiedTable ¶
type ClassifiedTable struct {
TableMeta
ModuleName string // 逻辑模块名(不含 table_prefix)
PhysicalName string // 实际表名
PKColumn string
SoftDeleteCol string
CreateOmit []string
UpdateOmit []string
BusinessCols []ColumnMeta
CreateCols []ColumnMeta
UpdateCols []ColumnMeta
ReadCols []ColumnMeta
}
ClassifiedTable 带列角色的表(用于代码生成)。
func Classify ¶
func Classify(t TableMeta, moduleName, physicalName string, rules CodegenRules) ClassifiedTable
Classify 根据规则标注列并拆分 Create/Update 业务列。
type CodegenRules ¶
type CodegenRules struct {
CreateOmit []string
UpdateOmit []string
SoftDeleteColumn string
TouchCreatedAtOnInsert bool
TouchUpdatedAtOnUpdate bool
}
CodegenRules 列分类与写请求裁剪规则。
func DefaultCodegenRules ¶
func DefaultCodegenRules() CodegenRules
type ColumnMeta ¶
type ColumnMeta struct {
Name string
DBType string
Nullable bool
IsPrimaryKey bool
Ordinal int
Comment string // 列备注(PG col_description / MySQL COLUMN_COMMENT)
}
ColumnMeta 列元数据。
func UniqueColumnsByName ¶
func UniqueColumnsByName(groups ...[]ColumnMeta) []ColumnMeta
UniqueColumnsByName 按列名去重合并多组列(保留首次出现顺序)。
type GoField ¶
GoField 生成 Go 结构体字段信息。
func GoFieldFromColumn ¶
func GoFieldFromColumn(c ColumnMeta) GoField
type TableMeta ¶
type TableMeta struct {
Schema string
Name string
TableComment string // 表备注(PG/MySQL)
Columns []ColumnMeta
}
TableMeta 数据库表元数据。
func LoadMySQLTable ¶
LoadMySQLTable 读取 MySQL 单表结构(schema 参数为 database 名)。
func LoadPostgresTable ¶
LoadPostgresTable 读取单表结构。