MCPcopy Index your code
hub / github.com/go-gorp/gorp / AddTableDynamic

Method AddTableDynamic

db.go:254–279  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

252// The table name will be dynamically determined at runtime by
253// using the GetTableName method on DynamicTable interface
254func (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
281func (m *DbMap) readStructColumns(t reflect.Type) (cols []*ColumnMap, primaryKey []*ColumnMap) {
282 primaryKey = make([]*ColumnMap, 0)

Callers 1

initDBMapFunction · 0.80

Calls 4

dynamicTableFindMethod · 0.95
readStructColumnsMethod · 0.95
dynamicTableAddMethod · 0.95
TableNameMethod · 0.65

Tested by 1

initDBMapFunction · 0.64