Skip to content

Instantly share code, notes, and snippets.

@seut
Last active August 29, 2015 14:03
Show Gist options
  • Save seut/08db7525977c8834bb6a to your computer and use it in GitHub Desktop.
Save seut/08db7525977c8834bb6a to your computer and use it in GitHub Desktop.
example main go script using crate go driver
/*
Prerequisites:
install go: http://golang.org/dl/
#: export GOPATH=<PATH-WHERE-TO-SAVE-GO-CODE>
#: go get github.com/fxposter/crate/sql
start a crate node
run this script:
#: go run main.go
*/
package main
import (
"database/sql"
"fmt"
_ "github.com/fxposter/crate/sql"
"log"
)
func main() {
db, _ := sql.Open("crate", "http://localhost:4200, http://localhost:4200")
for i := 0; i < 10; i++ {
rows, err := db.Query("select table_name from information_schema.tables")
if err != nil {
log.Fatal(err)
}
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", name)
}
if err := rows.Err(); err != nil {
log.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment