Created
July 25, 2013 20:32
-
-
Save lcaballero/6083479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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