reflection - Is there a way to get the Type for a Column using package database/sql in golang? -


basically, without knowing before hand resulting structure of query might be, i'd query database, , return structure (json-y)

// rows [    // row 1    [       { columnname: "id", value: 1, type: int },       { columnname: "name", value: "batman", type: string },       ...    ],     // row 2    [       { columnname: "id", value: 2, type: int },       { columnname: "name", value: "superman", type: string },       ...    ] ] 

is there way type column using package database/sql in golang?

i'm suspecting want is

  1. make array of interface{} size of column(),
  2. then each column determine it's type,
  3. then fill array pointer type,
  4. and pass array scan()

which little code example sqlx, without first knowing struct data populating.

using database/sql? no (as far know).

but can use this code arbitrary queries. , json.marshall() json package use reflection determine right way print value, have structure this:

type column struct {     columnname  string     columnvalue interface{}     columntype  string } 

and use reflect.typeof(somevariable).string() type columntype.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -