view

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebTagSmallCamelCase = "smallCamelCase"
	WebTagCamelCase      = "camelCase"
	WebTagSnakeCase      = "snakeCase"
	WebTagKebab          = "kebab"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name            string       // column name
	OrdinalPosition int          // column ordinal position
	DataType        string       // column data type(string,int...)
	ColumnType      string       // column type(varchar(256)...)
	IsNullable      bool         // column is null or not
	IsAutoIncrement bool         // column auto increment or not
	Default         *string      // default value
	Comment         string       // column comment
	Index           []Index      // index list
	ForeignKeys     []ForeignKey // Foreign key list
}

Column column information

type ColumnKeyType

type ColumnKeyType int

ColumnKeyType column key type

const (
	ColumnKeyNone            ColumnKeyType = iota // default
	ColumnKeyTypePrimary                          // primary key
	ColumnKeyTypeNormalIndex                      // normal index key
	ColumnKeyTypeUniqueKey                        // unique key
	ColumnKeyTypeUnique                           // unique
)

type ColumnSlice

type ColumnSlice []*Column

func (ColumnSlice) Len

func (t ColumnSlice) Len() int

func (ColumnSlice) Less

func (t ColumnSlice) Less(i, j int) bool

func (ColumnSlice) Swap

func (t ColumnSlice) Swap(i, j int)

type Config

type Config struct {
	DbTag            string   `yaml:"dbTag" json:"dbTag"`                       // db标签, 默认gorm
	WebTags          []WebTag `yaml:"webTags" json:"webTags"`                   // web tags 标签列表
	EnableLint       bool     `yaml:"enableLint" json:"enableLint"`             // 使能lint, id -> ID
	DisableNull      bool     `yaml:"disableNull" json:"disableNull"`           // 不输出字段为null指针或sql.Nullxxx类型
	EnableInt        bool     `yaml:"enableInt" json:"enableInt"`               // 使能int8,uint8,int16,uint16,int32,uint32输出为int, uint
	EnableIntegerInt bool     `yaml:"enableIntegerInt" json:"enableIntegerInt"` // 使能int32,uint32输出为int, uint
	EnableBoolInt    bool     `yaml:"enableBoolInt" json:"enableBoolInt"`       // 使能bool输出int
	IsNullToPoint    bool     `yaml:"isNullToPoint" json:"isNullToPoint"`       // 是否字段为null时输出指针类型
	IsOutSQL         bool     `yaml:"isOutSQL" json:"isOutSQL"`                 // 是否输出创建表的SQL
	IsOutColumnName  bool     `yaml:"isOutColumnName" json:"isOutColumnName"`   // 是否输出表的列名, 默认不输出
	IsForeignKey     bool     `yaml:"isForeignKey" json:"isForeignKey"`         // 输出外键
	IsCommentTag     bool     `yaml:"isCommentTag" json:"isCommentTag"`         // 注释同时放入tag标签中
	Protobuf         Protobuf `yaml:"protobuf" json:"protobuf" binding:"omitempty"`
}

type DBModel

type DBModel interface {
	GetDatabase() (*Database, error)
	GetTableAttributes() ([]TableAttribute, error)
	GetTables(tb TableAttribute) (*Table, error)
	GetCreateTableSQL(tbName string) (string, error)
}

DBModel Implement the interface to acquire database information.

type Database

type Database struct {
	Name   string   // database name, 数据库名
	Tables []*Table // table information, 表信息
}

Database database information

type ForeignKey

type ForeignKey struct {
	TableName  string // Affected tables .
	ColumnName string // Which column of the affected table
}

ForeignKey Foreign key

type Index

type Index struct {
	KeyType    ColumnKeyType // key type
	KeyName    string        // index key name, 索引名称
	IsMulti    bool          // Multiple key, 是否为复合索引
	SeqInIndex int           // union index sequence in index, 复合索引中的序列
	IndexType  string        // index type, 索引类型(比如: BTREE, HASH, FULLTEXT)
}

Index database index/unique_index list

type Protobuf

type Protobuf struct {
	Enabled bool              `yaml:"enabled" json:"enabled"`
	Merge   bool              `yaml:"merge" json:"merge"`
	Dir     string            `yaml:"dir" json:"dir" binding:"required_if=Enabled true"`
	Package string            `yaml:"package" json:"package" binding:"required_if=Enabled true"`
	Options map[string]string `yaml:"options" json:"options" binding:"required_if=Enabled true"`
}

Protobuf config

type Table

type Table struct {
	TableAttribute
	Columns []*Column // column information
}

Table database table information

type TableAttribute

type TableAttribute struct {
	Name           string // table name, 表名
	Comment        string // table comment, 表注释
	CreateTableSQL string // Create SQL statements, 创建表的sql语句
}

TableAttribute database table name, comment and create table sql

type TableSlice

type TableSlice []*Table

func (TableSlice) Len

func (t TableSlice) Len() int

func (TableSlice) Less

func (t TableSlice) Less(i, j int) bool

func (TableSlice) Swap

func (t TableSlice) Swap(i, j int)

type View

type View struct {
	Config
	DBModel
}

View information

func New

func New(m DBModel, c Config) *View

New view instance

func (*View) GetDBCreateTableSQLContent

func (sf *View) GetDBCreateTableSQLContent() ([]byte, error)

GetDBCreateTableSQLContent get all table's create table sql content

func (*View) GetDbFile

func (sf *View) GetDbFile(pkgName string) ([]*ast.File, error)

GetDbFile ast file

type WebTag

type WebTag struct {
	Kind    string `yaml:"kind" json:"kind"` // support smallCamelCase, camelCase, snakeCase, kebab
	Tag     string `yaml:"tag" json:"tag"`
	HasOmit bool   `yaml:"hasOmit" json:"hasOmit"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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