sqlboiler/bdb/table.go

39 lines
752 B
Go
Raw Normal View History

package bdb
2016-07-12 08:48:30 +02:00
import "fmt"
// Table metadata from the database schema.
type Table struct {
Name string
Columns []Column
PKey *PrimaryKey
FKeys []ForeignKey
IsJoinTable bool
ToManyRelationships []ToManyRelationship
}
2016-07-12 08:48:30 +02:00
// GetTable by name. Panics if not found (for use in templates mostly).
func GetTable(tables []Table, name string) (tbl Table) {
for _, t := range tables {
if t.Name == name {
return t
}
}
panic(fmt.Sprintf("could not find table name: %s", name))
}
// GetColumn by name. Panics if not found (for use in templates mostly).
func (t Table) GetColumn(name string) (col Column) {
for _, c := range t.Columns {
if c.Name == name {
return c
}
}
2016-07-12 08:48:30 +02:00
panic(fmt.Sprintf("could not find column name: %s", name))
}