db

package
v0.0.0-...-66f7f76 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conf Config) *Client

func (*Client) ConnectDB

func (c *Client) ConnectDB() (db *gorm.DB, err error)

func (*Client) GetTableColumnInfo

func (c *Client) GetTableColumnInfo(dbName, tableName string) ([]*define.TableColumn, error)

GetTableColumnInfo 查询 information_schema.COLUMNS 表,获取指定表的列信息

func (*Client) GetTableDDL

func (c *Client) GetTableDDL(tableName string) ([]*define.TableDDL, error)

GetTableDDL 获取表结构

func (*Client) GetTables

func (c *Client) GetTables() ([]*define.Table, error)

GetTables 查询存在的所有表

type Config

type Config struct {
	DBType          string `toml:"DBType" yaml:"db_type"`     // 数据库驱动类型
	Host            string `toml:"Host" yaml:"host"`          // 主机地址
	Port            int    `toml:"Port" yaml:"port"`          // 端口号
	DBName          string `toml:"DBName" yaml:"db_name"`     // 数据库名
	UserName        string `toml:"UserName" yaml:"user_name"` // 用户名
	PassWord        string `toml:"PassWord" yaml:"pass_word"` // 密码
	CharSet         string `toml:"CharSet" yaml:"char_set"`   // 字符集
	MaxIdleConns    int    `toml:"MaxIdleConns" yaml:"max_idle_conns"`
	MaxOpenConns    int    `toml:"MaxOpenConns" yaml:"max_open_conns"`
	ConnMaxLifetime int    `toml:"ConnMaxLifetime" yaml:"conn_max_lifetime"`
	LogMode         bool   `toml:"LogMode" yaml:"log_mode"`
}

Config 数据库配置

type StructColumn

type StructColumn struct {
	Name    string
	Type    string
	Tag     string
	Comment string
}

StructColumn 存储转换后的 Go 结构体中的所有字段信息

type StructTemplate

type StructTemplate struct {
	FilePath string // 输出文件路径
	// contains filtered or unexported fields
}

func NewStructTemplate

func NewStructTemplate() *StructTemplate

func (*StructTemplate) AssemblyColumns

func (t *StructTemplate) AssemblyColumns(tbColumns []*define.TableColumn) []*StructColumn

AssemblyColumns 对通过查询 COLUMNS 表所组装得到的 tbColumns 进行进一步的分解和转换

func (*StructTemplate) Generate

func (t *StructTemplate) Generate(tableName string, tmpColumns []*StructColumn) error

Generate 用转换之后的结构体去渲染模版 template.Must 方法判断返回的 *Template 是否有错误,引发panic,导致程序崩溃(如果模版解析错误,则直接让程序挂掉)

type StructTemplateDB

type StructTemplateDB struct {
	TableName string
	Columns   []*StructColumn
}

StructTemplateDB 存储最终用于渲染的模版对象信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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