Skip to content

Instantly share code, notes, and snippets.

@lcaballero
Created July 25, 2013 20:32
Show Gist options
  • Save lcaballero/6083479 to your computer and use it in GitHub Desktop.
Save lcaballero/6083479 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
_ "github.com/lib/pq"
_ "github.com/jmoiron/sqlx"
"database/sql"
"reflect"
)
func main() {
db, _ := sql.Open(
"postgres",
"user=postgres dbname=go_testing password=postgres sslmode=disable")
rows, _ := db.Query("SELECT * FROM _user;")
columns, _ := rows.Columns();
column2value := make(map[string]*interface{})
valuePtrs := make([]interface{}, len(columns))
for rows.Next() {
for i, column := range columns {
var value interface{}
column2value[column] = &value
valuePtrs[i] = &value
}
var scan_errs = rows.Scan(valuePtrs...)
if (scan_errs != nil) {
fmt.Println(scan_errs)
}
fmt.Println(column2value);
for i, _ := range columns {
val := valuePtrs[i]
fmt.Println(val)
fmt.Println(reflect.Indirect(val))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment