add columntype method for table

This commit is contained in:
Lunny Xiao 2015-02-23 00:00:10 +08:00
parent 833d5b7beb
commit 6759548865
1 changed files with 8 additions and 3 deletions

View File

@ -65,13 +65,18 @@ func (table *Table) GetColumnIdx(name string, idx int) *Column {
// if has primary key, return column
func (table *Table) PKColumns() []*Column {
columns := make([]*Column, 0)
for _, name := range table.PrimaryKeys {
columns = append(columns, table.GetColumn(name))
columns := make([]*Column, len(table.PrimaryKeys))
for i, name := range table.PrimaryKeys {
columns[i] = table.GetColumn(name)
}
return columns
}
func (table *Table) ColumnType(name string) reflect.Type {
t, _ := table.Type.FieldByName(name)
return t.Type
}
func (table *Table) AutoIncrColumn() *Column {
return table.GetColumn(table.AutoIncrement)
}