Skip to content

Instantly share code, notes, and snippets.

@robertgro
robertgro / main.go
Last active February 16, 2021 14:29
Golang reflection to use in conjunction with sql package's rows.Scan() for any (nested) struct passed in as interface{}, please refer to the disclaimer within this file
package main
import (
"fmt"
"reflect"
)
// to be used in association with the golang sql package, rows.Scan()
// pass in any struct object/object slice you like and get appropriate results using reflection
// restriction: the sql query result's columns length must match the struct object fields length (len(rows.Columns(), fix your query)