sqlboiler/bdb/table.go
Aaron L fb802ad687 Add to_many relationships as a first class citizen
- to_many relationships are now cached on the table data structure
- to_many relationships now know if any columns involved are nullable
2016-07-11 23:49:42 -07:00

38 lines
752 B
Go

package bdb
import "fmt"
// Table metadata from the database schema.
type Table struct {
Name string
Columns []Column
PKey *PrimaryKey
FKeys []ForeignKey
IsJoinTable bool
ToManyRelationships []ToManyRelationship
}
// 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
}
}
panic(fmt.Sprintf("could not find column name: %s", name))
}