Instead of using a struct
, which is predefined in terms of its number of data fileds, capacity, and types of that fields, having a map
, which is expandable and can contain several data types as value, will be more advantageous. For example, on database side, changes to column names, column types, or number of columns in a table will not affect the go code related to querying the database, such as go data structure you put the rows
returned form your database query.
Is there a way in golang sql package or related drivers to know the types of the data, in rows, returned by a database query to define a struct
with appropriate number of fields and types?
If not how can a map
be used to accomplish this with column names of returned rows
are keys and row fields are values of this map
?