Created
December 4, 2013 01:30
-
-
Save tux21b/7780822 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" | |
"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