advsql/old/table_structure.go

29 lines
599 B
Go
Raw Permalink Normal View History

2022-07-05 12:44:25 +02:00
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
}