Help us shape the future of Go! Take the 2026 Go Developer Survey

schema

package
v0.0.0-...-4f2a88f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func ListMySQLTables(dsn, database string) ([]string, error)

ListMySQLTables 列出 database 下所有基表。

func ListPostgresTables

func ListPostgresTables(dsn, schema string) ([]string, error)

ListPostgresTables 列出 schema 下所有基表。

func ModuleNameFromPhysical

func ModuleNameFromPhysical(physical, prefix string) string

ModuleNameFromPhysical 从物理表名解析模块名(去掉 table_prefix)。

func MySQLDatabaseFromDSN

func MySQLDatabaseFromDSN(dsn string) string

MySQLDatabaseFromDSN 从 DSN 解析库名(user:pass@tcp(host:3306)/dbname?...)。

func ProtoType

func ProtoType(c ColumnMeta) string

ProtoType 映射 proto3 类型。

func ShouldExcludeTable

func ShouldExcludeTable(table string, userExclude []string) bool

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

type GoField struct {
	Name   string // Pascal
	DBName string
	GoType string
	Tag    string
}

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

func LoadMySQLTable(dsn, database, table string) (TableMeta, error)

LoadMySQLTable 读取 MySQL 单表结构(schema 参数为 database 名)。

func LoadPostgresTable

func LoadPostgresTable(dsn, schema, table string) (TableMeta, error)

LoadPostgresTable 读取单表结构。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL