Last active
February 6, 2021 09:44
-
-
Save ralfbecher/210408184329d83b37cac309cb4ef2ef to your computer and use it in GitHub Desktop.
Golang get Snowflake QueryID out of *sql.Rows
This file contains hidden or 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
import ( | |
"context" | |
"database/sql" | |
"database/sql/driver" | |
"errors" | |
"reflect" | |
// ... | |
sf "github.com/snowflakedb/gosnowflake" | |
) | |
// from: https://stackoverflow.com/questions/42664837/how-to-access-unexported-struct-fields/60598827#60598827 | |
func GetUnexportedField(field reflect.Value) interface{} { | |
return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface() | |
} | |
resultSet, err := s.DB.QueryContext(ctxWithID, statement) | |
// ... | |
var queryID string | |
val := reflect.ValueOf(resultSet).Elem().FieldByName("rowsi") | |
field := GetUnexportedField(val) | |
if driverRows, ok := field.(driver.Rows); ok { | |
queryID = driverRows.(sf.SnowflakeResult).GetQueryID() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment