29 lines
599 B
Go
29 lines
599 B
Go
|
package advsql
|
||
|
|
||
|
func (s *Store) tableStructure(tableName string) (*structure, error) {
|
||
|
rows, err := s.db.Query("SELECT * FROM " + tableName)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
|
||
|
types, err := rows.ColumnTypes()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
structure := new(structure)
|
||
|
structure.TypeName = tableName
|
||
|
|
||
|
columnAmount := len(types)
|
||
|
structure.Fields = make([]field, columnAmount)
|
||
|
|
||
|
for columnIndex, columType := range types {
|
||
|
structure.Fields[columnIndex] = field{
|
||
|
FieldName: columType.Name(),
|
||
|
FieldType: columType.ScanType(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return structure, nil
|
||
|
}
|