Skip to content

Instantly share code, notes, and snippets.

@tux21b
Created December 4, 2013 01:30
Show Gist options
  • Save tux21b/7780822 to your computer and use it in GitHub Desktop.
Save tux21b/7780822 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"reflect"
"tux21b.org/v1/gocql"
)
func main() {
cluster := gocql.NewCluster("127.0.0.1")
session, err := cluster.CreateSession()
if err != nil {
log.Fatal("New Cluster:", err)
}
iter := session.Query("SELECT * FROM system.schema_keyspaces").Iter()
columns := iter.Columns()
for {
row := make([]interface{}, len(columns))
for i := 0; i < len(columns); i++ {
switch columns[i].TypeInfo.Type {
case gocql.TypeVarchar:
row[i] = new(string)
case gocql.TypeBoolean:
row[i] = new(bool)
default:
log.Fatal("unhandled type:", columns[i].TypeInfo)
}
}
if !iter.Scan(row...) {
break
}
for i := 0; i < len(columns); i++ {
row[i] = reflect.ValueOf(row[i]).Elem().Interface()
}
fmt.Println(row)
}
if err := iter.Close(); err != nil {
log.Fatal("Query:", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment