table

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 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 ToVarchar

func ToVarchar(size int64) string

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     []string
	FieldKey            []string
	UniqueIndexFieldKey []map[string]string
	IndexFieldKey       []map[string]string
}

type AstConstraintDef

type AstConstraintDef string

AstConstraintDef example: // @def primary ID

func (AstConstraintDef) Constraint

func (astP AstConstraintDef) Constraint() *ConstraintDef

func (AstConstraintDef) String

func (astP AstConstraintDef) String() string

type AstFieldDef

type AstFieldDef string

AstFieldDef example `db:"name,size=10,default='0'"`

func (AstFieldDef) Field

func (s AstFieldDef) Field() *TableFieldDef

func (AstFieldDef) String

func (s AstFieldDef) String() string

just `db` and remove `db`、`"`

type AstIndexDef

type AstIndexDef string

AstIndexDef example // @def index i_name name (列别/索引名称/映射字段域名称)

func (AstIndexDef) Index

func (s AstIndexDef) Index() *TableIndexDef

Index switch to TableIndexDef

func (AstIndexDef) String

func (s AstIndexDef) String() string

just @def and remove @def

type Constraint

type Constraint map[string]string

Constraint FieldConstraint 字段约束

func (Constraint) HasSizeConstraint

func (f Constraint) HasSizeConstraint() string

func (Constraint) IncludeSequence

func (f Constraint) IncludeSequence() bool

func (Constraint) String

func (f Constraint) String() string

type ConstraintDef

type ConstraintDef struct {
	ConstraintKey    string
	ConstraintValues []string
}

func PickConstraintDef

func PickConstraintDef(doc *ast.CommentGroup) []*ConstraintDef

PickConstraintDef table constraint from doc

type DBTableDef

type DBTableDef struct {
	// file name of picked
	Name string
	// all valid field define
	FieldDef []*TableFieldDef
	// all valid table index define
	IndexDef []*TableIndexDef
	// all valid doc constraint define
	ConstraintDef []*ConstraintDef
}

DBTableDef database table define

func Def

func Def(path string) *DBTableDef

Def /** parser table description file with return *DBTableDef

type Field

type Field struct {
	Define string
	SqlSequenceDef
}

type FieldCursor

type FieldCursor uint8
const (
	FieldCursorName       FieldCursor = iota // 字段名称
	FieldCursorType                          // 字段类型
	FieldCursorConstraint                    // 字段约束
)

type FieldType

type FieldType uint8

FieldType FieldType 字段类型

const (
	PIndent FieldType
	Pint8
	Puint8
	Pint16
	Puint16
	Pint32
	Puint32
	Pint64
	Puint64
	Pint
	Pfloat32
	Pfloat64
	Pbyte
	Pstring
)

func Lookup

func Lookup(ty string) FieldType

func (FieldType) String

func (tok FieldType) String() string

type IndexCursor

type IndexCursor uint8
const (
	IndexCursorClass  IndexCursor = iota // 索引类别
	IndexCursorName                      // 索引字段
	IndexCursorFields                    // 索引映射字段
)

type PGType

type PGType struct {
}

func (*PGType) ToType

func (pg *PGType) ToType(ty FieldType) string

type PrimaryDef

type PrimaryDef []string

func (PrimaryDef) Primary

func (p PrimaryDef) Primary() string

func (PrimaryDef) String

func (p PrimaryDef) String() string

type SqlSequenceDef

type SqlSequenceDef struct {
	RelativeField string
	SequenceName  string
}

type SqlTableFieldDef

type SqlTableFieldDef struct {
	TableName string
	*TableFieldDef
}

func (*SqlTableFieldDef) HasSequence

func (s *SqlTableFieldDef) HasSequence() bool

func (*SqlTableFieldDef) SequenceName

func (f *SqlTableFieldDef) SequenceName() string

func (SqlTableFieldDef) String

func (s SqlTableFieldDef) String() string

type SqlTableIndexDef

type SqlTableIndexDef TableIndexDef

func (SqlTableIndexDef) Index

func (in SqlTableIndexDef) Index() [3]string

func (SqlTableIndexDef) IsUnique

func (in SqlTableIndexDef) IsUnique(class string) bool

func (SqlTableIndexDef) String

func (in SqlTableIndexDef) String() string

type TableFieldDef

type TableFieldDef struct {
	// 字段类型
	DefType string
	// 字段名称
	DefName string
	// 字段描述
	DefDesc map[string]string
}

TableFieldDef table field define

func PickFieldDef

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

PickFieldDef table filed

type TableIndexDef

type TableIndexDef struct {
	// 索引名称
	DefName string
	// 索引类别
	DefClass string
	// 索引关联字段名称
	DefRelativeName []string
}

TableIndexDef table index define

func PickIndexDef

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

PickIndexDef table index

type TableSql

type TableSql struct {
	DBName string

	Def *DBTableDef
	// contains filtered or unexported fields
}

func NewTableSql

func NewTableSql(dbName, tableName string, dbdef *DBTableDef) *TableSql

func (*TableSql) AlterColumn

func (t *TableSql) AlterColumn() string

func (*TableSql) AlterIndex

func (t *TableSql) AlterIndex() string

AlterIndex /** ALTER INDEX [ IF EXISTS ] name RENAME TO new_name ALTER INDEX [ IF EXISTS ] name SET TABLESPACE tablespace_name ALTER INDEX name ATTACH PARTITION index_name ALTER INDEX name DEPENDS ON EXTENSION extension_name ALTER INDEX [ IF EXISTS ] name SET ( storage_parameter [= value] [, ... ] ) ALTER INDEX [ IF EXISTS ] name RESET ( storage_parameter [, ... ] ) ALTER INDEX [ IF EXISTS ] name ALTER [ COLUMN ] column_number

SET STATISTICS integer

ALTER INDEX ALL IN TABLESPACE name [ OWNED BY role_name [, ... ] ]

SET TABLESPACE new_tablespace [ NOWAIT ]

Description

func (*TableSql) AnalysisTable

func (t *TableSql) AnalysisTable() *Analysis

func (*TableSql) CreateTable

func (t *TableSql) CreateTable() string

func (*TableSql) Fields

func (t *TableSql) Fields(seq func(string, string)) string

func (*TableSql) Index

func (t *TableSql) Index() string

func (*TableSql) Name

func (t *TableSql) Name() string

func (*TableSql) PrimaryKeyConstraint

func (t *TableSql) PrimaryKeyConstraint() string

func (*TableSql) PrimaryKeys

func (t *TableSql) PrimaryKeys() []string

func (*TableSql) Sequence

func (t *TableSql) Sequence(fieldName, seqName string) string

type TableSqlBuild

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

func NewTableSqlBuild

func NewTableSqlBuild(dbName, tableName, filePath string) *TableSqlBuild

func (*TableSqlBuild) Build

func (t *TableSqlBuild) Build() *TableSql

type TypeConvert

type TypeConvert interface {
	ToType(ty FieldType) string
}

TypeConvert define to adapter different db

Jump to

Keyboard shortcuts

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