How can golang sql get rid of the problem that the parameters of Scan must correspond to the columns returned by the query?

this problem is somewhat difficult to describe in the title sentence
specifically: the row queried by
can only be obtained using the Scan method.
and the Scan method must fill in the parameters one by one according to the queried column in order to get the value.
more or less will return error
for example, if sql is select col1,col2,col3
, you must first var col1,col2,col3
and then row.Scan (& col1, & col2, & col3)

.

if I want to make such a simple wheel:
enter a sql statement as a parameter (no matter how many values this sql statement queries), and return an array or key-value pair of results.

here, because I don"t know how many select columns are in sql, and QueryRow (). Scan () must fill in the parameters one by one, in this case, how can I achieve the desired effect?

if there is already a ready-made wheel, I can also look at the source code to learn.

Go
Jun.17,2022

get
you can refer to this: https://github.com/jinzhu/gor...


get the table structure first. Rereflect


ready-made wheels: http://jmoiron.github.io/sqlx/

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e96d76-4608e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e96d76-4608e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?