table

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenAstFile

func OpenAstFile(path string) (*ast.File, string)

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

func TraversalAstDir(typeName, path, traversalFile string) string

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

func TraversalFile(path, objName string) []*ast.Field

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 (列别/索引名称/映射字段域名称)

func (AstIndexDef) Index

func (s AstIndexDef) Index() *IndexDef

Index switch to IndexDef

func (AstIndexDef) String

func (s AstIndexDef) String() string

just @def and remove @def

type CheckType added in v0.0.5

type CheckType = string

CheckType sql field check description type

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

type DocPlaceHolderDef struct {
	PlaceHolderKey    string
	PlaceHolderValues []string
}

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

func PickFieldDef

func PickFieldDef(fields ...*ast.Field) []*FieldDef

PickFieldDef table filed

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

func PickIndexDef

func PickIndexDef(doc *ast.CommentGroup) []*IndexDef

PickIndexDef table index

type IndexMapFields added in v0.0.5

type IndexMapFields = string

IndexMapFields Index map all fields type

type IndexName added in v0.0.5

type IndexName = string

IndexName sql index name 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 (t *SqlSchema) AlterColumn() string

func (*SqlSchema) AnalysisTable added in v0.0.5

func (t *SqlSchema) AnalysisTable() *Analysis

func (*SqlSchema) CreateTable added in v0.0.5

func (t *SqlSchema) CreateTable() string

func (*SqlSchema) Fields added in v0.0.5

func (t *SqlSchema) Fields() string

func (*SqlSchema) Index added in v0.0.5

func (t *SqlSchema) Index() string

func (*SqlSchema) Name added in v0.0.5

func (t *SqlSchema) Name() string

func (*SqlSchema) PrimaryKey added in v0.0.5

func (t *SqlSchema) PrimaryKey() string

func (*SqlSchema) PrimaryKeyValues added in v0.0.5

func (t *SqlSchema) PrimaryKeyValues() []string

type TagAttachment added in v0.0.5

type TagAttachment map[string]string

TagAttachment Field Check 字段约束

Jump to

Keyboard shortcuts

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