sqlboiler/bdb/column.go
2016-08-14 00:20:34 -07:00

49 lines
1 KiB
Go

package bdb
import "github.com/vattle/sqlboiler/strmangle"
// Column holds information about a database column.
// Types are Go types, converted by TranslateColumnType.
type Column struct {
Name string
Type string
DBType string
Default string
Nullable bool
Unique bool
Validated bool
}
// ColumnNames of the columns.
func ColumnNames(cols []Column) []string {
names := make([]string, len(cols))
for i, c := range cols {
names[i] = c.Name
}
return names
}
// ColumnDBTypes of the columns.
func ColumnDBTypes(cols []Column) map[string]string {
types := map[string]string{}
for _, c := range cols {
types[strmangle.TitleCase(c.Name)] = c.DBType
}
return types
}
// FilterColumnsByDefault generates the list of columns that have default values
func FilterColumnsByDefault(defaults bool, columns []Column) []Column {
var cols []Column
for _, c := range columns {
if (defaults && len(c.Default) != 0) || (!defaults && len(c.Default) == 0) {
cols = append(cols, c)
}
}
return cols
}