Documentation ¶
Index ¶
- func OpenAstFile(path string) (*ast.File, string)
- func SwitchImportFilePath(f *ast.File, expr *ast.SelectorExpr) string
- func TraversalAstDir(typeName, path, traversalFile string) string
- func TraversalFile(path, objName string) []*ast.Field
- type Analysis
- type AstFieldDef
- type AstFieldType
- type AstHolderPlaceDef
- type AstIndexDef
- type CheckType
- type DBTableDef
- type DocPlaceHolderDef
- type FieldCheck
- type FieldCursor
- type FieldDef
- type IndexCursor
- type IndexDef
- type IndexMapFields
- type IndexName
- type PrimaryDef
- type SqlBuilder
- type SqlFieldDef
- type SqlFieldName
- type SqlIndexDef
- type SqlSchema
- func (t *SqlSchema) AlterColumn() string
- func (t *SqlSchema) AnalysisTable() *Analysis
- func (t *SqlSchema) CreateTable() string
- func (t *SqlSchema) Fields() string
- func (t *SqlSchema) Index() string
- func (t *SqlSchema) Name() string
- func (t *SqlSchema) PrimaryKey() string
- func (t *SqlSchema) PrimaryKeyValues() []string
- type TagAttachment
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenAstFile ¶
OpenAstFile /** Open ast.File and its fileName path target file full path
func SwitchImportFilePath ¶
func SwitchImportFilePath(f *ast.File, expr *ast.SelectorExpr) string
SwitchImportFilePath /** Base $GOPATH to switch import path with file path
func TraversalAstDir ¶
TraversalAstDir /** Traversal dir to search struct type which is not has traversal file, typeName struct type Name; path target search dir; traversalFile has traversal file; any error will panic
func TraversalFile ¶
TraversalFile /** Traversal file to collect all table define, path target search file; objName target struct name which can be empty; any error will panic
Types ¶
type Analysis ¶
type Analysis struct { TableName string PrimaryFieldKey []SqlFieldName FieldKey []SqlFieldName UniqueIndexFieldKey []map[IndexName]IndexMapFields IndexFieldKey []map[IndexName]IndexMapFields AutoFieldKey map[SqlFieldName]bool }
type AstFieldDef ¶
type AstFieldDef string
AstFieldDef example `db:"name,size=10,default='0'"`
func (AstFieldDef) Field ¶
func (s AstFieldDef) Field() *FieldDef
func (AstFieldDef) String ¶
func (s AstFieldDef) String() string
type AstFieldType ¶ added in v0.0.5
type AstFieldType uint8
AstFieldType 字段类型
const ( Indent AstFieldType Int8 Uint8 Int16 Uint16 Int32 Uint32 Int64 Uint64 Int Float32 Float64 Byte String )
func Lookup ¶
func Lookup(ty string) AstFieldType
func (AstFieldType) SqlAutoType ¶ added in v0.0.5
func (AstFieldType) SqlAutoType() string
func (AstFieldType) SqlType ¶ added in v0.0.5
func (ft AstFieldType) SqlType() string
func (AstFieldType) String ¶ added in v0.0.5
func (ft AstFieldType) String() string
func (AstFieldType) Varchar ¶ added in v0.0.5
func (ft AstFieldType) Varchar(size int64) string
type AstHolderPlaceDef ¶ added in v0.0.5
type AstHolderPlaceDef string
AstHolderPlaceDef example: // @def primary ID
func (AstHolderPlaceDef) Constraint ¶ added in v0.0.5
func (astP AstHolderPlaceDef) Constraint() *DocPlaceHolderDef
func (AstHolderPlaceDef) String ¶ added in v0.0.5
func (astP AstHolderPlaceDef) String() string
type AstIndexDef ¶
type AstIndexDef string
AstIndexDef example // @def index i_name name (列别/索引名称/映射字段域名称)
type DBTableDef ¶
type DBTableDef struct { // file name of picked Name string // all valid field define FieldDef []*FieldDef // all valid table index define IndexDef []*IndexDef // all valid doc constraint define ConstraintDef []*DocPlaceHolderDef }
DBTableDef database table define
func Def ¶
func Def(path string) *DBTableDef
Def /** parser table description file with return *DBTableDef
type DocPlaceHolderDef ¶ added in v0.0.5
func PickConstraintDef ¶
func PickConstraintDef(doc *ast.CommentGroup) []*DocPlaceHolderDef
PickConstraintDef table constraint from doc
type FieldCheck ¶ added in v0.0.5
type FieldCheck struct { TagAttachment // 字段约束描述 CheckType // 字段约束 IsAuto bool // 是否自动增长 Size int64 // 包含的size 字段值 }
func NewFieldCheck ¶ added in v0.0.5
func NewFieldCheck(c TagAttachment) *FieldCheck
func (*FieldCheck) Handle ¶ added in v0.0.5
func (f *FieldCheck) Handle() *FieldCheck
type FieldCursor ¶
type FieldCursor uint8
const ( FieldCursorName FieldCursor = iota // 字段名称 FieldCursorType // 字段类型 FieldCursorConstraint // 字段约束 )
type FieldDef ¶ added in v0.0.5
type FieldDef struct { // 字段类型 DefType string // 字段名称 DefName string // 字段描述 DefDesc map[string]string }
FieldDef table field define
type IndexCursor ¶
type IndexCursor uint8
const ( IndexCursorClass IndexCursor = iota // 索引类别 IndexCursorName // 索引字段 IndexCursorFields // 索引映射字段 )
type IndexDef ¶ added in v0.0.5
type IndexDef struct { // 索引名称 DefName string // 索引类别 DefClass string // 索引关联字段名称 DefRelativeName []string }
IndexDef table index define
type IndexMapFields ¶ added in v0.0.5
type IndexMapFields = string
IndexMapFields Index map all fields type
type PrimaryDef ¶
type PrimaryDef []string
func (PrimaryDef) Primary ¶
func (p PrimaryDef) Primary() string
func (PrimaryDef) String ¶
func (p PrimaryDef) String() string
type SqlBuilder ¶ added in v0.0.5
type SqlBuilder struct {
// contains filtered or unexported fields
}
func NewSqlBuilder ¶ added in v0.0.5
func NewSqlBuilder(dbName, tableName, filePath string) *SqlBuilder
func (*SqlBuilder) Build ¶ added in v0.0.5
func (t *SqlBuilder) Build() *SqlSchema
type SqlFieldDef ¶ added in v0.0.5
type SqlFieldDef FieldDef
func (SqlFieldDef) IsAuto ¶ added in v0.0.5
func (s SqlFieldDef) IsAuto() bool
func (SqlFieldDef) String ¶ added in v0.0.5
func (s SqlFieldDef) String() string
type SqlFieldName ¶ added in v0.0.5
type SqlFieldName = string
SqlFieldName sql field description type
type SqlIndexDef ¶ added in v0.0.5
type SqlIndexDef IndexDef
func (SqlIndexDef) Index ¶ added in v0.0.5
func (in SqlIndexDef) Index() [3]string
func (SqlIndexDef) IsUnique ¶ added in v0.0.5
func (in SqlIndexDef) IsUnique(class string) bool
func (SqlIndexDef) String ¶ added in v0.0.5
func (in SqlIndexDef) String() string
type SqlSchema ¶ added in v0.0.5
type SqlSchema struct { DBName string Def *DBTableDef // contains filtered or unexported fields }
func NewSqlSchema ¶ added in v0.0.5
func NewSqlSchema(dbName, tableName string, dbdef *DBTableDef) *SqlSchema
func (*SqlSchema) AlterColumn ¶ added in v0.0.5
func (*SqlSchema) AnalysisTable ¶ added in v0.0.5
func (*SqlSchema) CreateTable ¶ added in v0.0.5
func (*SqlSchema) PrimaryKey ¶ added in v0.0.5
func (*SqlSchema) PrimaryKeyValues ¶ added in v0.0.5
type TagAttachment ¶ added in v0.0.5
TagAttachment Field Check 字段约束