AddTableDynamic registers the given interface type with gorp. The table name will be dynamically determined at runtime by using the GetTableName method on DynamicTable interface
(inp DynamicTable, schema string)
| 252 | // The table name will be dynamically determined at runtime by |
| 253 | // using the GetTableName method on DynamicTable interface |
| 254 | func (m *DbMap) AddTableDynamic(inp DynamicTable, schema string) *TableMap { |
| 255 | |
| 256 | val := reflect.ValueOf(inp) |
| 257 | elm := val.Elem() |
| 258 | t := elm.Type() |
| 259 | name := inp.TableName() |
| 260 | if name == "" { |
| 261 | panic("Missing table name in DynamicTable instance") |
| 262 | } |
| 263 | |
| 264 | // Check if there is another dynamic table with the same name |
| 265 | if _, found := m.dynamicTableFind(name); found { |
| 266 | panic(fmt.Sprintf("A table with the same name %v already exists", name)) |
| 267 | } |
| 268 | |
| 269 | tmap := &TableMap{gotype: t, TableName: name, SchemaName: schema, dbmap: m} |
| 270 | var primaryKey []*ColumnMap |
| 271 | tmap.Columns, primaryKey = m.readStructColumns(t) |
| 272 | if len(primaryKey) > 0 { |
| 273 | tmap.keys = append(tmap.keys, primaryKey...) |
| 274 | } |
| 275 | |
| 276 | m.dynamicTableAdd(name, tmap) |
| 277 | |
| 278 | return tmap |
| 279 | } |
| 280 | |
| 281 | func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey []*ColumnMap) { |
| 282 | primaryKey = make([]*ColumnMap, 0) |