instantRows iterator calls setColumnInfo()
so (untested code :-) ) where theDb is your dbConn object and myTestTbl is the table being queried, and using count(*) to return only one result so that the column representation is not printed for multiple rows
var dbC: DbColumns
for x in theDb.instantRows(dbC, sql"select count(*) from myTestTbl"):
for c in dbC:
echo repr(c)
and FYI (from db_common lib)
DbColumn* = object ## information about a database column
name*: string ## name of the column
tableName*: string ## name of the table the column belongs to (optional)
typ*: DbType ## type of the column
primaryKey*: bool ## is this a primary key?
foreignKey*: bool ## is this a foreign key?
DbColumns* = seq[DbColumn]
After realizing that my "native" module attempt is futile since the existence of intantRows() I quickly came up with this example:
import strutils, os
import db_mysql
proc test() =
let db: DBConn = open("localhost", "root", "", "test")
assert(db != nil)
defer:
db.close()
var dbC: DbColumns = @[]
for x in db.instantRows(dbC, sql"SELECT * FROM data LIMIT 2"):
echo "........."
for idx, f in dbC:
echo f.name, ": ", x[idx]
test()
Will I get in trouble for saying:
MySQL sucks, use PostgreSQL :P
</public-service-announcement>