table

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddColumn

func AddColumn(db *sqlx.DB, col Column) error

func ChangeColumn

func ChangeColumn(db *sqlx.DB, col Column) error

func CheckAutoSet

func CheckAutoSet(defaultVal *string) bool

func CheckAutoincrement

func CheckAutoincrement(extra string) bool

func CheckNull

func CheckNull(null nullenum.Null) bool

func CheckPk

func CheckPk(key keyenum.Key) bool

func CheckUnsigned

func CheckUnsigned(dbColType string) bool

func CreateTable

func CreateTable(db *sqlx.DB, t Table) error

func NewFieldFromColumn

func NewFieldFromColumn(col Column) astutils.FieldMeta

Types

type Column

type Column struct {
	Table         string
	Name          string
	Type          columnenum.ColumnType
	Default       interface{}
	Pk            bool
	Nullable      bool
	Unsigned      bool
	Autoincrement bool
	Extra         extraenum.Extra
	Meta          astutils.FieldMeta
	AutoSet       bool
	Indexes       []IndexItem
}

func (*Column) AddColumnSql

func (c *Column) AddColumnSql() (string, error)

func (*Column) ChangeColumnSql

func (c *Column) ChangeColumnSql() (string, error)

type DbColumn

type DbColumn struct {
	Field   string        `db:"Field"`
	Type    string        `db:"Type"`
	Null    nullenum.Null `db:"Null"`
	Key     keyenum.Key   `db:"Key"`
	Default *string       `db:"Default"`
	Extra   string        `db:"Extra"`
	Comment string        `db:"Comment"`
}

type DbIndex

type DbIndex struct {
	Table        string `db:"Table"`        // The name of the table
	Non_unique   bool   `db:"Non_unique"`   // 1 if the index can contain duplicates, 0 if it cannot.
	Key_name     string `db:"Key_name"`     // The name of the index. The primary key index always has the name of PRIMARY.
	Seq_in_index int    `db:"Seq_in_index"` // The column sequence number in the index. The first column sequence number starts from 1.
	Column_name  string `db:"Column_name"`  // The column name
	Collation    string `db:"Collation"`    // Collation represents how the column is sorted in the index. A means ascending, B means descending, or NULL means not sorted.
}

https://www.mysqltutorial.org/mysql-index/mysql-show-indexes/

type Index

type Index struct {
	Unique bool
	Name   string
	Items  []IndexItem
}

type IndexItem

type IndexItem struct {
	Unique bool
	Name   string
	Column string
	Order  int
	Sort   sortenum.Sort
}

type IndexItems

type IndexItems []IndexItem

func (IndexItems) Len

func (it IndexItems) Len() int

func (IndexItems) Less

func (it IndexItems) Less(i, j int) bool

func (IndexItems) Swap

func (it IndexItems) Swap(i, j int)

type Table

type Table struct {
	Name    string
	Columns []Column
	Pk      string
	Indexes []Index
	Meta    astutils.StructMeta
}

func NewTableFromStruct

func NewTableFromStruct(structMeta astutils.StructMeta, prefix ...string) Table
Example
var files []string
var err error
err = filepath.Walk(testDir, astutils.Visit(&files))
if err != nil {
	panic(err)
}
var sc astutils.StructCollector
for _, file := range files {
	fset := token.NewFileSet()
	root, err := parser.ParseFile(fset, file, nil, parser.ParseComments)
	if err != nil {
		panic(err)
	}
	ast.Walk(&sc, root)
}
flattened := sc.FlatEmbed()

for _, sm := range flattened {
	table := NewTableFromStruct(sm)
	fmt.Println(table)
}
Output:

func (*Table) CreateSql

func (t *Table) CreateSql() (string, error)

Jump to

Keyboard shortcuts

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