Documentation
¶
Overview ¶
Package dbschema 连接数据库,内省表结构,并将其转换为 parser.ParseResult, 供 generator 直接生成完整的 RESTful 微服务代码。
支持驱动:mysql / postgres / sqlite / sqlserver
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SnakeToCamel ¶
SnakeToCamel 将 snake_case 转换为 CamelCase(首字母大写,导出供外部使用)
func ToParseResult ¶
func ToParseResult(schemas []*TableSchema, serviceName, pkgName string) *parser.ParseResult
ToParseResult 将数据库表 schema 转换为 parser.ParseResult, 每张表生成一个 Model 和对应的 CRUD Service。
Types ¶
type ColumnInfo ¶
type ColumnInfo struct {
Name string // 列名
DBType string // 数据库原始类型(varchar(64)、int、bigint unsigned …)
IsNullable bool // 是否允许 NULL
IsPrimary bool // 是否主键
IsAutoIncr bool // 是否自增
IsUnique bool // 是否唯一索引
Comment string // 列注释(MySQL/Postgres 支持)
Default string // 默认值(可为空)
}
ColumnInfo 单列元数据
type Introspector ¶
type Introspector interface {
// Tables 返回数据库中所有(或指定)表的 schema
Tables(db *sql.DB, dbName string, tables []string) ([]*TableSchema, error)
}
Introspector 数据库内省器接口
func NewIntrospector ¶
func NewIntrospector(driver string) (Introspector, error)
NewIntrospector 根据驱动名返回对应的内省器
type TableSchema ¶
type TableSchema struct {
TableName string
Columns []ColumnInfo
}
TableSchema 单张表的列信息
func ModelToSchema ¶
func ModelToSchema(m *parser.Model) *TableSchema
ModelToSchema converts a parser.Model (read from an existing idl.go) back into a TableSchema so it can be passed through WriteIDL again during incremental generation. Column metadata is reconstructed from the model fields' gorm tags.
Click to show internal directories.
Click to hide internal directories.