From 67595488654a06be0fb353cbb68ce54e1f25d01e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 23 Feb 2015 00:00:10 +0800 Subject: [PATCH] add columntype method for table --- table.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/table.go b/table.go index f7c9d464..aba1f96e 100644 --- a/table.go +++ b/table.go @@ -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) }